-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Reintroduce mobile controllers #230 * Clean up mobile controls code
- Loading branch information
Showing
4 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { GameClient } from "@neu5/types/src"; | ||
import type { DialogWrapper } from "../ui/dialog"; | ||
|
||
const isTouchDevice = () => "ontouchstart" in window; | ||
|
||
const pEl = document.createElement("p"); | ||
pEl.textContent = | ||
"The game may be more playable if you rotate the screen horizontally"; | ||
|
||
const updateControls = ({ | ||
dialog, | ||
game, | ||
mobileControlsEls, | ||
}: { | ||
dialog: DialogWrapper; | ||
game: GameClient; | ||
mobileControlsEls: HTMLElement[]; | ||
}) => { | ||
if (isTouchDevice()) { | ||
mobileControlsEls.forEach((el) => el.classList.remove("hide")); | ||
} else { | ||
mobileControlsEls.forEach((el) => el.classList.add("hide")); | ||
} | ||
|
||
if (isTouchDevice() && game.windowSize.width / game.windowSize.height < 1) { | ||
dialog.show({ | ||
content: pEl, | ||
}); | ||
} | ||
}; | ||
|
||
const updateWindowSize = (game: GameClient) => { | ||
game.windowSize = { | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
}; | ||
}; | ||
|
||
const MobileControls = { | ||
updateControls, | ||
updateWindowSize, | ||
}; | ||
|
||
export { MobileControls }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters