Skip to content

Commit

Permalink
feat: added getCurrentScene function (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
amyspark-ng authored May 26, 2024
1 parent a7a21da commit 4939bbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
// misc
gravity: 0,
scenes: {},
currentScene: null,

// on screen log
logs: [],
Expand Down Expand Up @@ -3471,6 +3472,8 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {

game.scenes[name](...args);
});

game.currentScene = name;
}

function onSceneLeave(
Expand All @@ -3479,6 +3482,10 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
return game.events.on("sceneLeave", action);
}

function getSceneName() {
return game.currentScene;
}

function getData<T>(key: string, def?: T): T {
try {
return JSON.parse(window.localStorage[key]);
Expand Down Expand Up @@ -5146,6 +5153,7 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
debug,
// scene
scene,
getSceneName,
go,
onSceneLeave,
// level
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,14 @@ export interface KaboomCtx {
* @group Events
*/
onSceneLeave(action: (newScene?: string) => void): EventController;
/**
/**
* Gets the name of the current scene.
*
* @since v3001.0
* @group Scene
*/
getSceneName(): string;
/**
* Sets the root for all subsequent resource urls.
*
Expand Down

0 comments on commit 4939bbf

Please sign in to comment.