exported set_instance now just takes a string
This commit is contained in:
parent
6e95732fb1
commit
4ef9b79e49
4 changed files with 16 additions and 30 deletions
|
@ -11,5 +11,5 @@ const game_location = LOCATION + "static/games/game.json";
|
||||||
fetch(game_location)
|
fetch(game_location)
|
||||||
.then((r) => r.text())
|
.then((r) => r.text())
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
set_instance(Game.new(response));
|
set_instance(response);
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
|
|
|
@ -195,8 +195,6 @@ class GameInstance {
|
||||||
this.shader.uniform(GL, "u_viewbox", new Uniform4f(this.resizer.get_viewbox()));
|
this.shader.uniform(GL, "u_viewbox", new Uniform4f(this.resizer.get_viewbox()));
|
||||||
this.shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION));
|
this.shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION));
|
||||||
|
|
||||||
this.shader.uniform(GL, "u_animated", new Uniform1i(+this.playing));
|
|
||||||
|
|
||||||
this.renderer.render(GL);
|
this.renderer.render(GL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +213,6 @@ class GameInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKey(event: KeyboardEvent) {
|
handleKey(event: KeyboardEvent) {
|
||||||
console.log(event.keyCode);
|
|
||||||
// Space
|
// Space
|
||||||
if (event.keyCode == 32) {
|
if (event.keyCode == 32) {
|
||||||
if (this.playing) {
|
if (this.playing) {
|
||||||
|
@ -251,14 +248,17 @@ class GameInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
var game_instance: GameInstance;
|
var game_instance: GameInstance;
|
||||||
|
var meshes;
|
||||||
|
|
||||||
export async function set_instance(game: Game) {
|
export async function set_instance(source: string) {
|
||||||
const meshes = await Promise.all(
|
if (!meshes) {
|
||||||
|
meshes = await Promise.all(
|
||||||
["ship.svg", "earth.svg", "mars.svg", "venus.svg"].map(
|
["ship.svg", "earth.svg", "mars.svg", "venus.svg"].map(
|
||||||
(name) => "static/res/assets/" + name
|
(name) => "static/res/assets/" + name
|
||||||
).map(url_to_mesh)
|
).map(url_to_mesh)
|
||||||
);
|
);
|
||||||
game_instance = new GameInstance(game, meshes.slice(1), meshes[0]);
|
}
|
||||||
|
game_instance = new GameInstance(Game.new(source), meshes.slice(1), meshes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
SLIDER.oninput = function() {
|
SLIDER.oninput = function() {
|
||||||
|
@ -272,8 +272,7 @@ FILESELECTOR.onchange = function(){
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
|
|
||||||
reader.onload = function() {
|
reader.onload = function() {
|
||||||
console.log(reader.result);
|
set_instance(<string> reader.result);
|
||||||
set_instance(Game.new(<string> reader.result));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
|
|
|
@ -7,14 +7,9 @@ uniform float u_time;
|
||||||
uniform vec3 u_color;
|
uniform vec3 u_color;
|
||||||
uniform vec3 u_color_next;
|
uniform vec3 u_color_next;
|
||||||
|
|
||||||
uniform bool u_animated;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 color;
|
|
||||||
if (u_animated) {
|
vec3 color = mix(u_color, u_color_next, u_time);
|
||||||
color = mix(u_color, u_color_next, u_time);
|
|
||||||
} else {
|
|
||||||
color = u_color;
|
|
||||||
}
|
|
||||||
gl_FragColor = vec4(color, 1.0);
|
gl_FragColor = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,20 +11,12 @@ uniform vec2 u_resolution;
|
||||||
uniform mat3 u_trans;
|
uniform mat3 u_trans;
|
||||||
uniform mat3 u_trans_next;
|
uniform mat3 u_trans_next;
|
||||||
|
|
||||||
uniform bool u_animated;
|
|
||||||
|
|
||||||
varying vec2 v_pos;
|
varying vec2 v_pos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 pos = vec3(a_position, 1.0);
|
vec3 pos = vec3(a_position, 1.0);
|
||||||
|
|
||||||
mat3 trans;
|
mat3 trans = (u_trans_next * (1.0 - u_time)) + (u_trans * u_time);
|
||||||
|
|
||||||
if (u_animated) {
|
|
||||||
trans = (u_trans_next * (1.0 - u_time)) + (u_trans * u_time);
|
|
||||||
} else {
|
|
||||||
trans = u_trans;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos = trans * pos;
|
pos = trans * pos;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue