From 35747ae6cb501d089bb691c44d8c4a931f9e9eef Mon Sep 17 00:00:00 2001 From: ajuvercr Date: Tue, 17 Sep 2019 14:03:16 +0200 Subject: [PATCH] fix types --- frontend/www/index.js | 36 ++++++++++++++++++------------------ frontend/www/index.ts | 5 +++++ 2 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 frontend/www/index.ts diff --git a/frontend/www/index.js b/frontend/www/index.js index dcc5aa1..6967f0b 100644 --- a/frontend/www/index.js +++ b/frontend/www/index.js @@ -2,31 +2,31 @@ import { Game } from "planetwars"; import { memory } from "planetwars/plantwars_bg" import { Shader } from "./webgl/shader" +import { main } from './index.ts' + const URL = window.location.origin+window.location.pathname; const LOCATION = URL.substring(0, URL.lastIndexOf("/") + 1); const game_location = LOCATION + "static/game.json"; -// fetch(game_location) -// .then((r) => r.text()) -// .then((response) => { -// console.log(response); -// let game = Game.new(response); -// console.log(game.turn_count()); -// }).catch(console.error); +fetch(game_location) + .then((r) => r.text()) + .then((response) => { + main(Game.new(response)); + }).catch(console.error); -const g = Game.new(""); +// const g = Game.new(""); -const p1 = g.locations(); -const s1 = g.location_count(); -console.log(p1, s1); -const a1 = new Float64Array(memory.buffer, p1, s1 * 3); -console.log(a1); +// const p1 = g.locations(); +// const s1 = g.location_count(); +// console.log(p1, s1); +// const a1 = new Float64Array(memory.buffer, p1, s1 * 3); +// console.log(a1); -g.add_location(0.5, 1.2, 3.14); +// g.add_location(0.5, 1.2, 3.14); -const p2 = g.locations(); -const s2 = g.location_count(); -const a2 = new Float64Array(memory.buffer, p2, s2 * 3); -console.log(a2); +// const p2 = g.locations(); +// const s2 = g.location_count(); +// const a2 = new Float64Array(memory.buffer, p2, s2 * 3); +// console.log(a2); diff --git a/frontend/www/index.ts b/frontend/www/index.ts new file mode 100644 index 0000000..142f771 --- /dev/null +++ b/frontend/www/index.ts @@ -0,0 +1,5 @@ +import { Game } from "planetwars"; + +export function main(game: Game) { + console.log(game.turn_count()); +}