Skip to content

Commit

Permalink
Add emoji support
Browse files Browse the repository at this point in the history
Add mobile typing support
  • Loading branch information
alesan99 committed Nov 19, 2023
1 parent 7c6863f commit db1abb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion website/game/menu/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ MENUS["chatMenu"] = new class extends Menu {
this.buttons[3] = new Button(false, ()=>{if (getOpenMenu() != "mapMenu") {openMenu("mapMenu")} else {closeMenu()}}, {image: IMG.chat, frames:[SPRITE.chatButton.getFrame(0,3),SPRITE.chatButton.getFrame(1,3),SPRITE.chatButton.getFrame(2,3)]}, 737,535, 34,34)
this.buttons[4] = new Button(false, ()=>{if (getOpenMenu() != "usersMenu") {openMenu("usersMenu")} else {closeMenu()}}, {image: IMG.chat, frames:[SPRITE.chatButton.getFrame(0,4),SPRITE.chatButton.getFrame(1,4),SPRITE.chatButton.getFrame(2,4)]}, 775,535, 34,34)

this.buttons[5] = new Button(false, ()=>{this.open = true; this.typing = true; this.timer = 0}, {visible: false}, 255,534, 406,36)
this.textField = document.getElementById('gameTextInput');
this.textField.addEventListener('keydown', (event) => {
if (event.key === 'Enter' || event.code === 'Enter') {
this.enter()
}
});
this.buttons[5] = new Button(false, ()=>{this.open = true; this.typing = true; this.timer = 0; this.textField.focus()}, {visible: false}, 255,534, 406,36)
}

enter() {
Expand Down Expand Up @@ -96,6 +102,8 @@ MENUS["chatMenu"] = new class extends Menu {
this.value = ""
this.open = false
this.typing = false
this.textField.value = ""
this.textField.blur()
}

// Display chat message and add to chat log.
Expand All @@ -116,6 +124,8 @@ MENUS["chatMenu"] = new class extends Menu {

this.timer = (this.timer + dt)%1 // Blinking cursor

this.value = this.textField.value

// Update nugget animation
if (this.nuggetTimer > 0) {
this.nuggetTimer = this.nuggetTimer - 1.4*dt
Expand Down Expand Up @@ -201,6 +211,10 @@ MENUS["chatMenu"] = new class extends Menu {
// Start Typing
this.typing = !this.typing
this.open = !this.open
if (this.typing) {
this.timer = 0
this.textField.focus()
}
} else if (this.typing) {
// Add character to input bar
if (key.length == 1) {
Expand Down
2 changes: 1 addition & 1 deletion website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</form>
</div>
<!-- Invisible text input used to force mobile devices to open keyboard -->
<input id="gameTextInput" type="text" style="position:fixed;left:0px";>
<input id="gameTextInput" type="text" maxlength="47" style="position:fixed;top:0;left:-200px";>

<!-- TODO: Use local version of socket (file downloaded at node_modules/socket.io/client-dist/socket.io.js) -->
<!-- For production, please use the socket.io.min.js bundle, which is an optimized build excluding the debug package. -->
Expand Down

0 comments on commit db1abb6

Please sign in to comment.