1
0
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:
tobspr 2022-01-14 19:07:37 +01:00
parent 8a60acc6e3
commit a7b957642f
5 changed files with 35 additions and 0 deletions

View File

@ -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");
});

View File

@ -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);
}
/**

View File

@ -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;
}
`);
}
};
});

View File

@ -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()),
};

View File

@ -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);