Skip to content

Commit

Permalink
feat: add ability to toggle Stan's debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
Stan-Stani committed Jan 25, 2024
1 parent e0fb2c3 commit 7df7af4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
"webRoot": "${workspaceFolder}",
// Preserve localStorage
"userDataDir": "${workspaceFolder}/.vscode/chrome"
},
{
"name": "Launch Vite Dev Server",
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<body>
<div class="take-up-viewport shelf-flex">
<div id="info" class="flex-grow-and-shrink">
<div id="info" class="flex-grow-and-shrink displayNone">
<div id="log"></div>
</div>
<div id="game-wrapper" class="flex-grow-and-shrink">
Expand Down
45 changes: 32 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ function isLocalStorageAvailable() {
}

const HAS_LOCAL_STORAGE = isLocalStorageAvailable()
const toggleStanDebug = () => {
document.getElementById('info')?.classList.toggle('displayNone')
}

// apply local settings from local storage
if (HAS_LOCAL_STORAGE) {
if (localStorage.getItem('show-stan-debug-stats') === 'TRUE') {
toggleStanDebug()
}
}

const WIDTH = 256
const HEIGHT = 240
Expand All @@ -44,6 +54,7 @@ interface IMenuScene {
mainMenuSeed: IMenuItemSeed[]
settingsMenuSeed: IMenuItemSeed[]
activeMenu: IBuiltMenu
mainMenu: IBuiltMenu
settingsMenu: IBuiltMenu
}

Expand Down Expand Up @@ -83,33 +94,41 @@ class MenuScene extends Scene implements IMenuScene {
},
]



settingsMenuSeed: IMenuScene['settingsMenuSeed'] = [
{
id: 'debug',
text: `Debug Stats = False`,
text: `Debug Stats = ${
localStorage.getItem('show-stan-debug-stats') === 'TRUE'
? 'TRUE'
: 'FALSE'
}`,
action: () => {
const item = this.settingsMenu.get('debug')
if (HAS_LOCAL_STORAGE) {
localStorage.getItem('show-debug-stats')
const showDebugStats = localStorage.getItem('show-stan-debug-stats')
if (item) {
if (
localStorage.getItem('show-debus-stats') === 'FALSE' ||
!localStorage.getItem('show-debug-stats')
) {
localStorage.setItem('show-debug-stats', 'TRUE')
item.text = item.text.replace('False', 'True')
if (showDebugStats === 'FALSE' || !showDebugStats) {
localStorage.setItem('show-stan-debug-stats', 'TRUE')
item.text = item.text.replace('FALSE', 'TRUE')
document.getElementById('info')?.classList.toggle('displayNone')
} else {
localStorage.setItem('show-debug-stats', 'FALSE')
item.text = item.text.replace('True', 'False')
localStorage.setItem('show-stan-debug-stats', 'FALSE')
item.text = item.text.replace('TRUE', 'FALSE')
document.getElementById('info')?.classList.toggle('displayNone')
}
}
}
},
},
{
text: 'Back',
action: () => {
this.toggleToMenu(this.mainMenu)
}
}
]
activeMenu: IMenuScene['activeMenu'] = new Map()
mainMenu: IMenuScene['mainMenu'] = new Map()
settingsMenu: IMenuScene['settingsMenu'] = new Map()

// https://newdocs.phaser.io/docs/3.55.2/Phaser.Tilemaps.TilemapLayer#putTilesAt
Expand Down Expand Up @@ -152,7 +171,7 @@ class MenuScene extends Scene implements IMenuScene {
return builtMenu
}
create() {
this.setUpMenu(this.mainMenuSeed, true)
this.mainMenu = this.setUpMenu(this.mainMenuSeed, true)
this.settingsMenu = this.setUpMenu(this.settingsMenuSeed, false)
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ body {
/* display: none; */
}

.displayNone {
display: none;
}

#log {
/* position: absolute; */
top: 0;
Expand Down

0 comments on commit 7df7af4

Please sign in to comment.