diff options
author | John Eisenmann <esperantanaso@gmail.com> | 2018-05-05 23:25:58 -0400 |
---|---|---|
committer | John Eisenmann <esperantanaso@gmail.com> | 2018-05-05 23:25:58 -0400 |
commit | 549aa5b4dad6d4f0bc5d877d05e1655dae536556 (patch) | |
tree | 5304f4cf4380707372a1fc96f66a1713032fb1ad | |
parent | 0231313791366fcc205fe174aa5ee5ad97a17d2f (diff) |
Added chat messages for announcements
-rw-r--r-- | models/chatMessage.js | 7 | ||||
-rw-r--r-- | models/player.js | 8 | ||||
-rw-r--r-- | public/javascript/game.js | 19 |
3 files changed, 29 insertions, 5 deletions
diff --git a/models/chatMessage.js b/models/chatMessage.js index 346e18d..4719e28 100644 --- a/models/chatMessage.js +++ b/models/chatMessage.js @@ -19,9 +19,14 @@ function getNextChatMessageId() { return nextChatMessageId; } +function announceMessageInChat(message) { + new ChatMessage(null, message); +} + module.exports = { ChatMessage: ChatMessage, chatMessageList: chatMessageList, - getNextChatMessageId: getNextChatMessageId + getNextChatMessageId: getNextChatMessageId, + announceMessageInChat: announceMessageInChat } diff --git a/models/player.js b/models/player.js index 55237c7..704a233 100644 --- a/models/player.js +++ b/models/player.js @@ -10,6 +10,10 @@ var Entity = tempResource.Entity; var entityList = tempResource.entityList; var entityWalkOffsetList = tempResource.entityWalkOffsetList; +var tempResource = require("models/chatMessage"); +var announceMessageInChat = tempResource.announceMessageInChat; +var getNextChatMessageId = tempResource.getNextChatMessageId; + function Player(account) { if ("respawnPos" in account) { this.respawnPos = createPosFromJson(account.respawnPos); @@ -58,6 +62,7 @@ function Player(account) { tempEnemy.remove(); index += 1; } + announceMessageInChat(this.username + " has joined the game."); } classUtils.setParentClass(Player, Entity); @@ -68,7 +73,6 @@ module.exports = { var Enemy = require("models/enemy").Enemy; var Crack = require("models/crack").Crack; var Inventory = require("models/inventory").Inventory; -var getNextChatMessageId = require("models/chatMessage").getNextChatMessageId; var accountUtils = require("utils/account"); var gameUtils = require("utils/game"); var chunkUtils = require("utils/chunk"); @@ -151,6 +155,7 @@ Player.prototype.die = function() { this.dropItems([FLOUR_TILE, WATER_TILE, POWDER_TILE]); this.pos = this.respawnPos.copy(); this.health = maximumPlayerHealth; + announceMessageInChat(this.username + " has died."); } Player.prototype.isInvincible = function() { @@ -183,6 +188,7 @@ Player.prototype.tick = function() { var tempDate = new Date(); var tempTime = tempDate.getTime(); if (tempTime > this.lastActivityTime + 10 * 1000) { + announceMessageInChat(this.username + " has left the game."); this.remove(); return; } diff --git a/public/javascript/game.js b/public/javascript/game.js index ed16445..aeb04ca 100644 --- a/public/javascript/game.js +++ b/public/javascript/game.js @@ -383,11 +383,20 @@ function performAddEntityCommand(command) { } function performAddChatMessageCommand(command) { - var tempPlayerName = encodeHtmlEntity(command.username); + var tempPlayerName; + if (command.username === null) { + tempPlayerName = null; + } else { + tempPlayerName = encodeHtmlEntity(command.username); + } var tempText = encodeHtmlEntity(command.text); var tempIsAtBottom = (chatOutput.scrollTop + 150 > chatOutput.scrollHeight - 30); var tempTag = document.createElement("div"); - tempTag.innerHTML = "<strong>" + tempPlayerName + ":</strong> " + tempText; + if (tempPlayerName === null) { + tempTag.innerHTML = tempText; + } else { + tempTag.innerHTML = "<strong>" + tempPlayerName + ":</strong> " + tempText; + } chatOutput.appendChild(tempTag); chatMessageTagList.push(tempTag); while (chatMessageTagList.length > maximumChatMessageCount) { @@ -887,7 +896,11 @@ colorSet = [ function OverlayChatMessage(playerName, text) { this.tag = document.createElement("div"); - this.tag.innerHTML = "<strong>" + playerName + ":</strong> " + text; + if (playerName === null) { + this.tag.innerHTML = text; + } else { + this.tag.innerHTML = "<strong>" + playerName + ":</strong> " + text; + } overlayChatOutput.appendChild(this.tag); this.delay = 8 * framesPerSecond; overlayChatMessageList.push(this); |