diff --git a/package-lock.json b/package-lock.json index 13234a7..da12da0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1603,6 +1603,14 @@ "callbag": "^1.1.0" } }, + "callbag-subscribe": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/callbag-subscribe/-/callbag-subscribe-1.5.1.tgz", + "integrity": "sha512-CRj2jKfcRvG8gap2ehsm/NxZVAjnwUApI+0ZY3bu6nyFfhhOzH+4RWpB/4RSJUZNN3ZILdSgAKQiUov/7ov9BQ==", + "requires": { + "callbag": "^1.2.0" + } + }, "caller-callsite": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/caller-callsite/-/caller-callsite-2.0.0.tgz", diff --git a/package.json b/package.json index 1184421..54342ca 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies": { "callbag": "^1.2.0", "callbag-animation-frames": "^2.1.0", - "callbag-map": "^1.1.0" + "callbag-map": "^1.1.0", + "callbag-subscribe": "^1.5.1" } } diff --git a/src/Game/Main.ts b/src/Game/Main.ts index 6ac5e04..f45dac9 100644 --- a/src/Game/Main.ts +++ b/src/Game/Main.ts @@ -1,2 +1,52 @@ +import subscribe from "callbag-subscribe"; + +import { Game } from "../Applet/Init"; +import { KeyControl, KeyName } from "../Applet/Keyboard"; +import { DrawSet } from "../Applet/Render"; +import { Location, Polygon, RenderBounds } from "../Ecs/Components"; +import { Create } from "../Ecs/Data"; import {} from "../Ecs/Lockstep"; -import {} from "./GameComponents"; +import { RunRenderBounds } from "../Ecs/Renderers"; +import { LockstepClient } from "../Net/LockstepClient"; +import { Data, Engine } from "./GameComponents"; +import { Buttons } from "./Input"; + +@Game("#GameCanvas") +export class Main extends LockstepClient { + + buttons = new Buttons(); + + constructor(canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl) { + super(new Engine()); + keys.setHandler(this.buttons); + + subscribe((frame: Data) => { + const drawSet = new DrawSet(); + + RunRenderBounds(frame, drawSet); + + drawSet.draw(cx, 0); + })(this.renderFrames); + } + + gatherInput() { + return this.buttons.getPressed(); + } + + initState(patch: Partial) { + const newState = new Data(); + + Create(newState, { + location: new Location({ + X: 200, + Y: 200, + VAngle: 0.02, + }), + bounds: new Polygon([-30, 0, 30, 0, 0, 40]), + renderBounds: new RenderBounds("#a0f", 0), + }); + + return newState; + } + +} diff --git a/src/index.html b/src/index.html index 30d54f2..5e8fcac 100644 --- a/src/index.html +++ b/src/index.html @@ -4,7 +4,7 @@ - +