jumpstorm/engine/systems/NetworkUpdate.ts

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-08-13 18:47:58 -04:00
import { System, SystemNames } from ".";
import { Game } from "../Game";
import { ComponentNames, NetworkUpdateable } from "../components";
export interface MessageQueueProvider {
getNewMessages(): any[];
clearMessages(): void;
}
export interface MessagePublisher {
addMessage(message: any): void;
publish(): void;
}
2023-08-13 18:47:58 -04:00
export class NetworkUpdate extends System {
private queueProvider: MessageQueueProvider;
private publisher: MessagePublisher;
constructor(
queueProvider: MessageQueueProvider,
publisher: MessagePublisher
) {
2023-08-13 18:47:58 -04:00
super(SystemNames.NetworkUpdate);
this.queueProvider = queueProvider;
this.publisher = publisher;
2023-08-13 18:47:58 -04:00
}
public update(_dt: number, game: Game) {
const messages = this.queueProvider.getNewMessages();
if (messages.length) console.log(messages);
this.queueProvider.clearMessages();
game.forEachEntityWithComponent(
ComponentNames.NetworkUpdateable,
(entity) => {
const networkUpdateComponent = entity.getComponent<NetworkUpdateable>(
ComponentNames.NetworkUpdateable
);
}
);
}
2023-08-13 18:47:58 -04:00
}