Commit 2687ddde authored by Zak Stephens's avatar Zak Stephens

Add proxy on playerState to keep track of when the object was updated.

parent 89309dd1
......@@ -33,7 +33,18 @@ module.exports = {
let playerState = gameState.players[id];
if (playerState == null) {
playerState = {};
/* Whenever a value is set on playerState, record the time it happened.
* Used to "log out" inactive players. */
const handler = {
set: (target, property, value) => {
assert(property !== 'updatedAt'); // Don't be dumb.
target.updatedAt = Date.now();
return Reflect.set(target, property, value);
}
};
playerState = new Proxy({}, handler);
playerState.location = await playerRepository.getPlayerLocation(id);
gameState.players[id] = playerState;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment