mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 18:21:51 +00:00
Add some mod signals
This commit is contained in:
parent
8a60acc6e3
commit
a7b957642f
@ -6,6 +6,7 @@ import { GameState } from "./game_state";
|
||||
import { createLogger } from "./logging";
|
||||
import { APPLICATION_ERROR_OCCURED } from "./error_handler";
|
||||
import { waitNextFrame, removeAllChildren } from "./utils";
|
||||
import { MOD_SIGNALS } from "../mods/mod_signals";
|
||||
|
||||
const logger = createLogger("state_manager");
|
||||
|
||||
@ -109,6 +110,8 @@ export class StateManager {
|
||||
key
|
||||
);
|
||||
|
||||
MOD_SIGNALS.stateEntered.dispatch(this.currentState);
|
||||
|
||||
waitNextFrame().then(() => {
|
||||
document.body.classList.add("arrived");
|
||||
});
|
||||
|
||||
@ -38,6 +38,7 @@ import { ShapeDefinitionManager } from "./shape_definition_manager";
|
||||
import { AchievementProxy } from "./achievement_proxy";
|
||||
import { SoundProxy } from "./sound_proxy";
|
||||
import { GameTime } from "./time/game_time";
|
||||
import { MOD_SIGNALS } from "../mods/mod_signals";
|
||||
|
||||
const logger = createLogger("ingame/core");
|
||||
|
||||
@ -161,6 +162,7 @@ export class GameCore {
|
||||
}
|
||||
|
||||
logger.log("root initialized");
|
||||
MOD_SIGNALS.gameInitialized.dispatch(root);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -208,6 +208,28 @@ registerMod(shapez => {
|
||||
return shapez.STOP_PROPAGATION;
|
||||
},
|
||||
});
|
||||
|
||||
// Add fancy sign to main menu
|
||||
this.signals.stateEntered.add(state => {
|
||||
if (state.key === "MainMenuState") {
|
||||
const element = document.createElement("div");
|
||||
element.innerText = "Hello World from mod!";
|
||||
element.id = "demo_mod_hello_world_element";
|
||||
document.body.appendChild(element);
|
||||
}
|
||||
});
|
||||
|
||||
this.modInterface.registerCss(`
|
||||
#demo_mod_hello_world_element {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
color: red;
|
||||
z-index: 999;
|
||||
font-size: 50px;
|
||||
}
|
||||
|
||||
`);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
/* typehints:start */
|
||||
import { BaseHUDPart } from "../game/hud/base_hud_part";
|
||||
import { GameRoot } from "../game/root";
|
||||
import { GameState } from "../core/game_state";
|
||||
import { InGameState } from "../states/ingame";
|
||||
/* typehints:end */
|
||||
|
||||
import { Signal } from "../core/signal";
|
||||
@ -18,5 +20,10 @@ export const MOD_SIGNALS = {
|
||||
hudElementInitialized: /** @type {TypedSignal<[BaseHUDPart]>} */ (new Signal()),
|
||||
hudElementFinalized: /** @type {TypedSignal<[BaseHUDPart]>} */ (new Signal()),
|
||||
|
||||
gameInitialized: /** @type {TypedSignal<[GameRoot]>} */ (new Signal()),
|
||||
gameLoadingStageEntered: /** @type {TypedSignal<[InGameState, string]>} */ (new Signal()),
|
||||
|
||||
gameStarted: /** @type {TypedSignal<[GameRoot]>} */ (new Signal()),
|
||||
|
||||
stateEntered: /** @type {TypedSignal<[GameState]>} */ (new Signal()),
|
||||
};
|
||||
|
||||
@ -96,6 +96,7 @@ export class InGameState extends GameState {
|
||||
if (stage !== this.stage) {
|
||||
this.stage = stage;
|
||||
logger.log(this.stage);
|
||||
MOD_SIGNALS.gameLoadingStageEntered.dispatch(this, stage);
|
||||
return true;
|
||||
} else {
|
||||
// log(this, "Re entering", stage);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user