Skip to content

feat: added debugKey #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion 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 @@ -4876,7 +4883,7 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
});

if (gopt.debug !== false) {
app.onKeyPress("f1", () => debug.inspect = !debug.inspect);
app.onKeyPress(!gopt.debugKey ? "f1" : gopt.debugKey, () => debug.inspect = !debug.inspect);
app.onKeyPress("f2", () => debug.clearLog());
app.onKeyPress("f8", () => debug.paused = !debug.paused);
app.onKeyPress("f7", () => {
Expand Down Expand Up @@ -5146,6 +5153,7 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
debug,
// scene
scene,
getSceneName,
go,
onSceneLeave,
// level
Expand Down
12 changes: 12 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 v3000.0
* @group Scenes
*/
getSceneName(): string;
/**
* Sets the root for all subsequent resource urls.
*
Expand Down Expand Up @@ -3252,6 +3260,10 @@ export interface KaboomOpt<T extends PluginList<any> = any> {
* If register debug buttons (default true)
*/
debug?: boolean;
/**
* Key used to toggle debug mode (default "f1")
*/
debugKey?: Key;
/**
* Default font (defaults to "monospace").
*/
Expand Down