exported set_instance now just takes a string

This commit is contained in:
ajuvercr 2019-09-21 11:37:26 +02:00
parent 6e95732fb1
commit 4ef9b79e49
4 changed files with 16 additions and 30 deletions

View file

@ -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);

View file

@ -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(
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, meshes.slice(1), meshes[0]);
}
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(<string> reader.result));
set_instance(<string> reader.result);
}
reader.readAsText(file);

View file

@ -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);
}

View file

@ -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;