Skip to content

Commit

Permalink
Toggle fullscreen button
Browse files Browse the repository at this point in the history
  • Loading branch information
Zikoat committed Aug 6, 2024
1 parent f551301 commit 65c6700
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
</div>
<!-- todo add settings -->
<div>Score:<span id="score"></span></div>
<div><button onclick="restart()">restart</button><br /></div>
<div>
<button onclick="restart()">restart</button><br />
<button onclick="toggleFullscreen()">Toggle Fullscreen</button>
</div>
<hr />
<div>Zoom: Ctrl +</div>
<div>Keyboard controls:<br />arrow keys and z/x</div>
Expand Down
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare global {
FieldStorage: FieldPersistence;
toggleMenu: () => void;
restart: () => void;
toggleFullscreen: () => void;
fieldName: string;
}
}
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ self.restart = function () {
window.location.reload();
};

self.toggleFullscreen = function () {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch((err) => {
console.error(
`Error attempting to enable fullscreen mode: ${err.message} (${err.name})`,
);
});
} else {
document.exitFullscreen().catch((err) => {
console.error(
`Error attempting to exit fullscreen mode: ${err.message} (${err.name})`,
);
});
}
};

(async () => {
PIXI.TextureSource.defaultOptions.scaleMode = "nearest";
PIXI.TextureSource.defaultOptions.autoGenerateMipmaps = true;
Expand Down

0 comments on commit 65c6700

Please sign in to comment.