Skip to content

Commit

Permalink
refactor: full screen
Browse files Browse the repository at this point in the history
  • Loading branch information
rei1024 committed Oct 3, 2024
1 parent cdf7f8b commit 22644d7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.env
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"dev": "vite",
"build": "tsc && node prebuild.js && vite build",
"postinstall": "node prebuild.js",
"preview": "vite preview"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export function createTemplateCell(scene: BABYLON.Scene) {
{ size: 1 },
scene
);
// const templateCell = BABYLON.MeshBuilder.CreateSphere(
// "templateCell",
// { diameter: 1 },
// scene
// );
templateCell.isVisible = false; // マスターセル自体は非表示にする

// マテリアルを作成して透明度を設定
Expand Down
24 changes: 4 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BitGrid, BitWorld } from "@ca-ts/algo/bit";
import { setupArcRotateCamera } from "./camera";
import { createTemplateCell } from "./cell";
import { setRLE } from "./setRLE";
import { setupFullScreenButton } from "./settings";

const WORLD_SIZE = 32 * 2;
let historySize = 16;
Expand Down Expand Up @@ -203,23 +204,6 @@ colorInput.addEventListener("input", () => {
});

const fullScreen = document.querySelector("#full-screen") as HTMLElement;
if (document.fullscreenEnabled) {
fullScreen.addEventListener("click", () => {
if (document.fullscreenElement) {
document.exitFullscreen();
settingsDialog.close();
} else {
document.body.requestFullscreen();
settingsDialog.close();
}
});
document.addEventListener("fullscreenchange", () => {
if (document.fullscreenElement) {
fullScreen.textContent = "End Full Screen";
} else {
fullScreen.textContent = "Full Screen";
}
});
} else {
fullScreen.remove();
}
setupFullScreenButton(fullScreen, () => {
settingsDialog.close();
});
25 changes: 25 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export function setupFullScreenButton(
fullScreen: HTMLElement,
onClick: () => void = () => {}
) {
if (!document.fullscreenEnabled) {
fullScreen.remove();
return;
}

fullScreen.addEventListener("click", () => {
if (document.fullscreenElement) {
document.exitFullscreen();
} else {
document.body.requestFullscreen();
}
onClick();
});
document.addEventListener("fullscreenchange", () => {
if (document.fullscreenElement) {
fullScreen.textContent = "End Full Screen";
} else {
fullScreen.textContent = "Full Screen";
}
});
}

0 comments on commit 22644d7

Please sign in to comment.