diff --git a/frontend/www/index.js b/frontend/www/index.js index 898f153..ea926a0 100644 --- a/frontend/www/index.js +++ b/frontend/www/index.js @@ -11,5 +11,5 @@ const game_location = LOCATION + "static/games/game.json"; fetch(game_location) .then((r) => r.text()) .then((response) => { - set_instance(Game.new(response)); + set_instance(response); }).catch(console.error); diff --git a/frontend/www/index.ts b/frontend/www/index.ts index 6e3a03b..697b059 100644 --- a/frontend/www/index.ts +++ b/frontend/www/index.ts @@ -195,8 +195,6 @@ class GameInstance { 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_animated", new Uniform1i(+this.playing)); - this.renderer.render(GL); } @@ -215,7 +213,6 @@ class GameInstance { } handleKey(event: KeyboardEvent) { - console.log(event.keyCode); // Space if (event.keyCode == 32) { if (this.playing) { @@ -251,14 +248,17 @@ class GameInstance { } var game_instance: GameInstance; +var meshes; -export async function set_instance(game: Game) { - const meshes = await Promise.all( - ["ship.svg", "earth.svg", "mars.svg", "venus.svg"].map( - (name) => "static/res/assets/" + name - ).map(url_to_mesh) - ); - game_instance = new GameInstance(game, meshes.slice(1), meshes[0]); +export async function set_instance(source: string) { + if (!meshes) { + meshes = await Promise.all( + ["ship.svg", "earth.svg", "mars.svg", "venus.svg"].map( + (name) => "static/res/assets/" + name + ).map(url_to_mesh) + ); + } + game_instance = new GameInstance(Game.new(source), meshes.slice(1), meshes[0]); } SLIDER.oninput = function() { @@ -272,8 +272,7 @@ FILESELECTOR.onchange = function(){ var reader = new FileReader(); reader.onload = function() { - console.log(reader.result); - set_instance(Game.new( reader.result)); + set_instance( reader.result); } reader.readAsText(file); diff --git a/frontend/www/static/shaders/frag/simple.glsl b/frontend/www/static/shaders/frag/simple.glsl index 812fdbd..1292569 100644 --- a/frontend/www/static/shaders/frag/simple.glsl +++ b/frontend/www/static/shaders/frag/simple.glsl @@ -7,14 +7,9 @@ uniform float u_time; uniform vec3 u_color; uniform vec3 u_color_next; -uniform bool u_animated; - void main() { - vec3 color; - if (u_animated) { - color = mix(u_color, u_color_next, u_time); - } else { - color = u_color; - } + + vec3 color = mix(u_color, u_color_next, u_time); + gl_FragColor = vec4(color, 1.0); } diff --git a/frontend/www/static/shaders/vert/simple.glsl b/frontend/www/static/shaders/vert/simple.glsl index e340029..49026b1 100644 --- a/frontend/www/static/shaders/vert/simple.glsl +++ b/frontend/www/static/shaders/vert/simple.glsl @@ -11,20 +11,12 @@ uniform vec2 u_resolution; uniform mat3 u_trans; uniform mat3 u_trans_next; -uniform bool u_animated; - varying vec2 v_pos; void main() { vec3 pos = vec3(a_position, 1.0); - mat3 trans; - - if (u_animated) { - trans = (u_trans_next * (1.0 - u_time)) + (u_trans * u_time); - } else { - trans = u_trans; - } + mat3 trans = (u_trans_next * (1.0 - u_time)) + (u_trans * u_time); pos = trans * pos;