diff --git a/scripts/bundle.js b/scripts/bundle.js index 88dad6fc..439965ee 100644 --- a/scripts/bundle.js +++ b/scripts/bundle.js @@ -18,11 +18,8 @@ const outputFix = (output, dir) => { const matches = out.matchAll(reg); let match; while(!(match = matches.next()).done) { - const exp = new RegExp(`${match.value[1]}\.`); - exp.multiline = true; - + const exp = new RegExp(`${match.value[1]}\.`, 'gm'); scanFile(path.join(dir, match.value[2]), dir); - out = out.replace(match.value[0], '').replace(exp, 'exports.'); } diff --git a/ts/asset/AssetManager.ts b/ts/asset/AssetManager.ts new file mode 100644 index 00000000..e69de29b diff --git a/ts/game/Game.ts b/ts/game/Game.ts new file mode 100644 index 00000000..acce15b9 --- /dev/null +++ b/ts/game/Game.ts @@ -0,0 +1,40 @@ + +export abstract class Game { + constructor() { + + } + + init() { + print("init"); + } + + update() { + print("update"); + } + + dispose() { + print("Disposed"); + } +} + +let GAME_MAIN:Game|null = null; + +export const gameSetMain = (game:Game) => { + print("setting", game); + GAME_MAIN = game; +} + +const init = () => { + if(!GAME_MAIN) return; + GAME_MAIN.init(); +} + +const update = () => { + if(!GAME_MAIN) return; + GAME_MAIN.update(); +} + +const dispose = () => { + if(!GAME_MAIN) return; + GAME_MAIN.dispose(); +} \ No newline at end of file diff --git a/ts/main.ts b/ts/main.ts index 6aea9d8b..56cf8781 100644 --- a/ts/main.ts +++ b/ts/main.ts @@ -1,47 +1,7 @@ -let cube:Primitive; -let shader:Shader; -let camera:Camera; -let texture:Texture; -let n:number; +import { Game, gameSetMain } from "./game/Game"; -const init = () => { - print('Main invoked'); - - n = 0; - - // Create Quad - cube = primitiveCreate(); - quadInit(cube, 0, -1, -1, 0, 0, 1, 1, 1, 1); - - // Create Camera - camera = cameraCreate(); - - // Load Shader - shader = shaderCreate(); - assetShaderLoad(shader, "shaders/textured.vert", "shaders/textured.frag"); +class MainGame extends Game { - // Texture load - texture = textureCreate(); - assetTextureLoad(texture, "test_texture.png"); } -const update = () => { - shaderUse(shader); - shaderUseTexture(shader, texture); - - n += epochGetDelta(); - - - cameraLookAt(camera, 3,3,3, 0,0,0); - cameraPerspective(camera, 45, 16/9, 0.01, 100); - - - shaderUseCamera(shader, camera); - shaderUsePosition(shader, 0,0,0, 0,n,0); - primitiveDraw(cube, 0, -1); -} - -const dispose = () => { - cameraDispose(camera); - shaderDispose(shader); -} \ No newline at end of file +gameSetMain(new MainGame()); \ No newline at end of file