Change gameplay

This commit is contained in:
schmelczerandras 2020-10-24 22:24:27 +02:00
parent d79900e3ea
commit 34dae300da
56 changed files with 906 additions and 400 deletions

View file

@ -1,14 +1,37 @@
import { UpdateMessage, UpdateObjectMessage } from '../main';
import { Id } from '../transport/identity';
import { serializable } from '../transport/serialization/serializable';
export abstract class GameObject {
constructor(public readonly id: Id) {}
@serializable
export class RemoteCall {
constructor(public readonly functionName: string, public readonly args: Array<any>) {}
public calculateUpdates(): UpdateObjectMessage | undefined {
return;
}
update(updates: Array<UpdateMessage>): void {
updates.forEach((u) => ((this as any)[u.key] = u.value));
public toArray(): Array<any> {
return [this.functionName, this.args];
}
}
export abstract class GameObject {
private remoteCalls: Array<RemoteCall> = [];
constructor(public readonly id: Id) {}
public processRemoteCalls(remoteCalls: Array<RemoteCall>) {
remoteCalls.forEach((r) =>
((this[r.functionName as keyof this] as unknown) as (
...args: Array<any>
) => unknown)(...r.args),
);
}
public getRemoteCalls(): Array<RemoteCall> {
return this.remoteCalls;
}
public resetRemoteCalls() {
this.remoteCalls = [];
}
protected remoteCall(name: string & keyof this, ...args: Array<any>) {
this.remoteCalls.push(new RemoteCall(name, args));
}
}