-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added support for chat (closes #1) - Player color names used instead of ids - Doubled camera speed - Aliased wasd to camera movements - Change Large hotkey from w to e
- Loading branch information
Showing
9 changed files
with
152 additions
and
23 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
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,72 @@ | ||
|
||
import network from "../network.js"; | ||
import game from "../index.js"; | ||
|
||
const chatLog = document.getElementById( "chat-log" ); | ||
const chatInput = document.getElementById( "chat-input" ); | ||
|
||
class Chat { | ||
|
||
activate() { | ||
|
||
chatInput.style.visibility = "visible"; | ||
chatInput.focus(); | ||
|
||
} | ||
|
||
onEnter() { | ||
|
||
chatInput.style.visibility = "hidden"; | ||
network.send( { type: "chat", message: chatInput.value } ); | ||
chatInput.value = ""; | ||
|
||
} | ||
|
||
} | ||
|
||
const chat = new Chat(); | ||
|
||
window.addEventListener( "keydown", e => { | ||
|
||
if ( ! chat.active && e.key === "Enter" ) chat.activate(); | ||
|
||
} ); | ||
|
||
chatInput.addEventListener( "keydown", e => { | ||
|
||
e.stopPropagation(); | ||
if ( e.key === "Enter" ) chat.onEnter(); | ||
|
||
} ); | ||
|
||
const maxLength = 250; | ||
network.addEventListener( "chat", ( { connection, message } ) => { | ||
|
||
message = message.slice( 0, maxLength ); | ||
|
||
const player = game.players.find( p => p.id === connection ); | ||
if ( ! player ) return; | ||
|
||
const entry = document.createElement( "div" ); | ||
|
||
const playerName = document.createElement( "span" ); | ||
playerName.textContent = player.color.name; | ||
playerName.style.color = player.color.hex; | ||
entry.appendChild( playerName ); | ||
|
||
const rest = document.createTextNode( `: ${message}` ); | ||
entry.append( rest ); | ||
|
||
chatLog.appendChild( entry ); | ||
|
||
setTimeout( () => { | ||
|
||
entry.style.opacity = "0"; | ||
setTimeout( () => entry.remove(), maxLength * 50 ); | ||
|
||
}, 5000 + message.length * 50 ); | ||
|
||
} ); | ||
|
||
export default chat; | ||
|
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
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