diff options
author | John Eisenmann <johneisenmann@Johns-iMac.local> | 2018-01-15 15:50:50 -0500 |
---|---|---|
committer | John Eisenmann <johneisenmann@Johns-iMac.local> | 2018-01-15 15:50:50 -0500 |
commit | 2fcfe238f3a4c612fe5be36d6167ef44c5a5105c (patch) | |
tree | fcdd0ac271c5ba5a079b4d64f3740f558d4722a1 | |
parent | 4db4817ec9cf3a473a6246297ad3400a91b221d6 (diff) |
Persisting guidelines
-rw-r--r-- | models/player.js | 15 | ||||
-rw-r--r-- | public/javascript/game.js | 34 | ||||
-rw-r--r-- | utils/game.js | 31 |
3 files changed, 80 insertions, 0 deletions
diff --git a/models/player.js b/models/player.js index f77dbb8..55237c7 100644 --- a/models/player.js +++ b/models/player.js @@ -37,6 +37,16 @@ function Player(account) { } else { this.health = maximumPlayerHealth; } + if ("guidelinePos" in account) { + var tempData = account.guidelinePos; + if (tempData === null) { + this.guidelinePos = tempData; + } else { + this.guidelinePos = createPosFromJson(tempData); + } + } else { + this.guidelinePos = null; + } this.invincibilityDelay = 0; var tempEnemyList = gameUtils.getEntitiesByClassNearPos(Enemy, this.pos, 10); var index = 0; @@ -196,6 +206,11 @@ Player.prototype.persist = function(done) { account.respawnPos = self.respawnPos.toJson(); account.pos = self.pos.toJson(); account.health = self.health; + if (self.guidelinePos === null) { + account.guidelinePos = self.guidelinePos; + } else { + account.guidelinePos = self.guidelinePos.toJson(); + } accountUtils.setAccount(index, account, function(error) { accountUtils.releaseLock(); if (error) { diff --git a/public/javascript/game.js b/public/javascript/game.js index 95b5aad..d3404bf 100644 --- a/public/javascript/game.js +++ b/public/javascript/game.js @@ -143,6 +143,9 @@ GameUpdateRequest.prototype.respond = function(data) { if (tempCommand.commandName == "setAvatar") { performSetAvatarCommand(tempCommand); } + if (tempCommand.commandName == "setGuidelinePos") { + performSetGuidelinePosCommand(tempCommand); + } index += 1; } // Repeat unprocessed client-side commands. @@ -287,6 +290,25 @@ function addPlaceSymbolTileCommand(tile) { }); } +function addSetGuidelinePosCommand() { + var tempValue; + if (guidelinePos === null) { + tempValue = guidelinePos; + } else { + tempValue = guidelinePos.toJson(); + } + gameUpdateCommandList.push({ + commandName: "setGuidelinePos", + pos: tempValue, + }); +} + +function addGetGuidelinePosCommand() { + gameUpdateCommandList.push({ + commandName: "getGuidelinePos" + }); +} + function performSetLocalPlayerInfoCommand(command) { localPlayer.username = command.username; localPlayer.avatar = command.avatar; @@ -430,6 +452,15 @@ function performWalkCommand(command) { placeLocalPlayerTrail(tempPos); } +function performSetGuidelinePosCommand(command) { + if (command.pos === null) { + guidelinePos = command.pos; + } else { + guidelinePos = createPosFromJson(command.pos); + } + displayGuidelinePos(); +} + function placeLocalPlayerTrail(pos) { var tempTile = getTileBufferValue(pos); if ((tempTile >= trailStartTile && tempTile < trailStartTile + trailTileAmount) @@ -1161,6 +1192,7 @@ function displayGuidelinePos() { function clearGuidelinePos() { guidelinePos = null; displayGuidelinePos(); + addSetGuidelinePosCommand(); } function setGuidelinePosFromInput() { @@ -1181,6 +1213,7 @@ function setGuidelinePosFromInput() { guidelinePosInput.blur(); setAllInputIsFocusedAsFalse(); canvasIsFocused = true; + addSetGuidelinePosCommand(); } function displayGuideline() { @@ -1594,6 +1627,7 @@ function initializeGame() { localPlayer = new Player(-1, new Pos(0, 0), null, null, null); addStartPlayingCommand(); + addGetGuidelinePosCommand(); setInterval(timerEvent, Math.floor(1000 / framesPerSecond)); setInterval(barTimerEvent, Math.floor(1000 / 30)); diff --git a/utils/game.js b/utils/game.js index 090938d..2d1350b 100644 --- a/utils/game.js +++ b/utils/game.js @@ -223,6 +223,12 @@ GameUtils.prototype.performUpdate = function(username, commandList, done) { if (tempCommand.commandName == "placeSymbolTile") { performPlaceSymbolTileCommand(tempCommand, tempPlayer, tempCommandList); } + if (tempCommand.commandName == "setGuidelinePos") { + performSetGuidelinePosCommand(tempCommand, tempPlayer, tempCommandList); + } + if (tempCommand.commandName == "getGuidelinePos") { + performGetGuidelinePosCommand(tempCommand, tempPlayer, tempCommandList); + } } } tempPlayer = gameUtils.getPlayerByUsername(username); @@ -338,6 +344,19 @@ function addSetAvatarCommand(player, commandList) { }); } +function addSetGuidelinePosCommand(player, commandList) { + var tempValue; + if (player.guidelinePos === null) { + tempValue = player.guidelinePos; + } else { + tempValue = player.guidelinePos.toJson(); + } + commandList.push({ + commandName: "setGuidelinePos", + pos: tempValue + }); +} + function performStartPlayingCommand(command, player, commandList, done, errorHandler) { accountUtils.acquireLock(function() { accountUtils.findAccountByUsername(player.username, function(error, index, result) { @@ -483,6 +502,18 @@ function performPlaceSymbolTileCommand(command, player, commandList) { player.placeSymbolTile(command.tile); } +function performSetGuidelinePosCommand(command, player, commandList) { + if (command.pos === null) { + player.guidelinePos = command.pos; + } else { + player.guidelinePos = createPosFromJson(command.pos); + } +} + +function performGetGuidelinePosCommand(command, player, commandList) { + addSetGuidelinePosCommand(player, commandList); +} + GameUtils.prototype.persistEverything = function(done) { if (this.isPersistingEverything) { done(); |