Tidy typings for client server-connection dependency injection
This commit is contained in:
parent
9798687693
commit
9df57e4aa9
3 changed files with 5 additions and 6 deletions
|
@ -17,7 +17,7 @@ class Selection {
|
||||||
/**
|
/**
|
||||||
* Run a callback for selected canvases, with a 2d context & KeyControl established for use.
|
* Run a callback for selected canvases, with a 2d context & KeyControl established for use.
|
||||||
*/
|
*/
|
||||||
public forEachCanvas(callback: (canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl) => {}, tabIndex = -1) {
|
public forEachCanvas(callback: (canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl) => void, tabIndex = -1) {
|
||||||
this.elements.forEach(e => {
|
this.elements.forEach(e => {
|
||||||
if(e instanceof HTMLCanvasElement) {
|
if(e instanceof HTMLCanvasElement) {
|
||||||
const cx = e.getContext("2d") as CanvasRenderingContext2D;
|
const cx = e.getContext("2d") as CanvasRenderingContext2D;
|
||||||
|
|
|
@ -6,8 +6,7 @@ import { DrawSet } from "../applet/Render";
|
||||||
import { Location, PolygonComponent, RenderBounds } from "../ecs/Components";
|
import { Location, PolygonComponent, RenderBounds } from "../ecs/Components";
|
||||||
import { Create } from "../ecs/Data";
|
import { Create } from "../ecs/Data";
|
||||||
import { RunRenderBounds } from "../ecs/Renderers";
|
import { RunRenderBounds } from "../ecs/Renderers";
|
||||||
import { LockstepClient } from "../net/LockstepClient";
|
import { LockstepClient, Server } from "../net/LockstepClient";
|
||||||
import { LoopbackServer } from "../net/LoopbackServer";
|
|
||||||
import { Data, Engine, PlayerControl } from "./GameComponents";
|
import { Data, Engine, PlayerControl } from "./GameComponents";
|
||||||
import { Buttons } from "./Input";
|
import { Buttons } from "./Input";
|
||||||
|
|
||||||
|
@ -15,11 +14,11 @@ export class Main extends LockstepClient<KeyName[], KeyName[][], Data> {
|
||||||
|
|
||||||
buttons = new Buttons();
|
buttons = new Buttons();
|
||||||
|
|
||||||
constructor(canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl, server: LoopbackServer<KeyName[], Data>) {
|
constructor(canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl, server: Server<KeyName[], KeyName[][], Data>) {
|
||||||
super(new Engine());
|
super(new Engine());
|
||||||
keys.setHandler(this.buttons);
|
keys.setHandler(this.buttons);
|
||||||
|
|
||||||
this.connect(server.socket);
|
this.connect(server);
|
||||||
|
|
||||||
pipe(
|
pipe(
|
||||||
this.renderFrames,
|
this.renderFrames,
|
||||||
|
|
|
@ -18,6 +18,6 @@ import { LoopbackServer } from "./net/LoopbackServer";
|
||||||
|
|
||||||
const server = new LoopbackServer<KeyName[], Data>();
|
const server = new LoopbackServer<KeyName[], Data>();
|
||||||
|
|
||||||
Select(".GameCanvas").forEachCanvas((c, cx, keys) => new Main(c, cx, keys, server));
|
Select(".GameCanvas").forEachCanvas((c, cx, keys) => new Main(c, cx, keys, server.socket));
|
||||||
|
|
||||||
BindTests();
|
BindTests();
|
||||||
|
|
Loading…
Reference in a new issue