actions reactored. multi-tick action support
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { makeAutoObservable, reaction, toJS } from "mobx";
|
||||
import type { WorldState } from "./worldState";
|
||||
import type { Game, Pos3, RuntimeGameScene } from "../types";
|
||||
import type { Game, Pos3, RuntimeGameScene, ScriptContext, ScriptCoroutineContext } from "../types";
|
||||
import type { CameraProps } from "@react-three/fiber";
|
||||
import { GameEventBus, GameFactory } from "../model/gameFactory";
|
||||
import { GameScheduler } from "../model/gameScheduler";
|
||||
import type { GameEventContext } from "../types/runtime/gameBus";
|
||||
import type { ScriptGameEventBus } from "../scripts/eventBus";
|
||||
import { GameFactory } from "../model/gameFactory";
|
||||
import { ScriptCoroutines } from "../scripts/coroutines";
|
||||
|
||||
export class GameState {
|
||||
private readonly world: WorldState;
|
||||
@@ -14,8 +14,8 @@ export class GameState {
|
||||
public isFirstTick: boolean;
|
||||
public scene: RuntimeGameScene;
|
||||
|
||||
private eventBus: GameEventBus;
|
||||
private scheduler: GameScheduler;
|
||||
private coroutines = new ScriptCoroutines();
|
||||
private eventBus: ScriptGameEventBus;
|
||||
|
||||
private startAutoSave() {
|
||||
return reaction(
|
||||
@@ -45,17 +45,13 @@ export class GameState {
|
||||
this.isFirstTick = true;
|
||||
this.scene = game.scene;
|
||||
|
||||
const eventBus = new GameEventBus();
|
||||
this.eventBus = eventBus;
|
||||
this.scheduler = new GameScheduler();
|
||||
|
||||
this._stopAutoSave = this.startAutoSave();
|
||||
makeAutoObservable(this);
|
||||
|
||||
GameFactory.evalGameScripts(rawWorld, this.scene, eventBus, this.scheduler);
|
||||
this.eventBus = GameFactory.evalGameScripts(rawWorld, this.scene, this.coroutines);
|
||||
}
|
||||
|
||||
public emitEvent(event: string, context: Omit<GameEventContext, 'world' | 'scene'> = {}) {
|
||||
public emitEvent(event: string, context: Omit<ScriptContext, 'world' | 'scene' | keyof ScriptCoroutineContext> = {}) {
|
||||
this.eventBus.emit(
|
||||
event,
|
||||
{
|
||||
@@ -128,7 +124,8 @@ export class GameState {
|
||||
if (this.isPaused)
|
||||
return;
|
||||
|
||||
this.scheduler.tick(deltaTime);
|
||||
this.coroutines.tick(deltaTime);
|
||||
|
||||
this.time += deltaTime;
|
||||
|
||||
if (this.isFirstTick) {
|
||||
|
||||
Reference in New Issue
Block a user