Tidy typings for client server-connection dependency injection

This commit is contained in:
Tangent Wantwight 2020-05-17 23:17:39 -04:00
parent 9798687693
commit 9df57e4aa9
3 changed files with 5 additions and 6 deletions

View file

@ -17,7 +17,7 @@ class Selection {
/**
* 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 => {
if(e instanceof HTMLCanvasElement) {
const cx = e.getContext("2d") as CanvasRenderingContext2D;

View file

@ -6,8 +6,7 @@ import { DrawSet } from "../applet/Render";
import { Location, PolygonComponent, RenderBounds } from "../ecs/Components";
import { Create } from "../ecs/Data";
import { RunRenderBounds } from "../ecs/Renderers";
import { LockstepClient } from "../net/LockstepClient";
import { LoopbackServer } from "../net/LoopbackServer";
import { LockstepClient, Server } from "../net/LockstepClient";
import { Data, Engine, PlayerControl } from "./GameComponents";
import { Buttons } from "./Input";
@ -15,11 +14,11 @@ export class Main extends LockstepClient<KeyName[], KeyName[][], Data> {
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());
keys.setHandler(this.buttons);
this.connect(server.socket);
this.connect(server);
pipe(
this.renderFrames,

View file

@ -18,6 +18,6 @@ import { LoopbackServer } from "./net/LoopbackServer";
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();