Skip to content

Commit

Permalink
tweak local storage emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Jan 13, 2022
1 parent a14a3e3 commit f51d0ac
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 67 deletions.
1 change: 0 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def size_fmt(num: float) -> str:
"js/grid.js",
"js/html_actuator.js",
"js/keyboard_input_manager.js",
"js/local_storage_manager.js",
"js/tile.js",
]
for path in paths:
Expand Down
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ <h1 class="title">2048</h1>
<script src="js/html_actuator.js"></script>
<script src="js/grid.js"></script>
<script src="js/tile.js"></script>
<script src="js/local_storage_manager.js"></script>
<script src="js/game_manager.js"></script>
<script src="js/application.js"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion js/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Wait till the browser is ready to render the game (avoids glitches)
window.requestAnimationFrame(function () {
new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
new GameManager(4, KeyboardInputManager, HTMLActuator);
});
27 changes: 25 additions & 2 deletions js/game_manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
function GameManager(size, InputManager, Actuator, StorageManager) {
function GameManager(size, InputManager, Actuator) {
this.size = size; // Size of the grid
this.inputManager = new InputManager;
this.storageManager = new StorageManager;
this.storageManager = (() => {
let gameState = undefined;
const players = {};

return {
getBestScore: (addr) => (players[addr] ? players[addr].score : 0),

setBestScore: (addr, name, score) => {
players[addr] = {"name": name, "score": score};
},

getScoreboard: () => {
return Object.keys(players).map(function (key) {
return [key, players[key]["name"], players[key]["score"]];
}).sort((a, b) => b[2] - a[2]);
},

getGameState: () => gameState,

setGameState: (state) => {gameState = state},

clearGameState: () => {gameState = undefined}
};
})();
this.actuator = new Actuator;

this.startTiles = 2;
Expand Down
62 changes: 0 additions & 62 deletions js/local_storage_manager.js

This file was deleted.

0 comments on commit f51d0ac

Please sign in to comment.