Skip to content
Snippets Groups Projects
Commit 22ce9688 authored by deuce's avatar deuce
Browse files

Add a Player class created from a players record so you can get a player

object from the record rather than having to re-read it.
parent f26e54c4
No related branches found
No related tags found
No related merge requests found
......@@ -111,12 +111,24 @@ var PlayerProperties=[
var players = {
GetLocked:function GetLocked(playerNum, lock) {
var ret;
if(playerNum==undefined)
return ret;
ret=db.read(Settings.DB,'players.'+playerNum,lock);
ret.Record=playerNum;
ret.PutLocked=function(lock) {
return undefined;
return new Player(db.read(Settings.DB,'players.'+playerNum, lock), playerNum);
},
Get:function GetLocked(playerNum) {
return this.GetLocked(playerNum, LOCK_READ);
},
get length() {
return(db.read(Settings.DB,'players.length',LOCK_READ));
}
}
function Player(player,playerNum)
{
if(playerNum==undefined)
return undefined;
this.Record=playerNum;
this.PutLocked=function(lock) {
var p={};
var i;
......@@ -125,21 +137,16 @@ var players = {
}
db.write(Settings.DB,'players.'+this.Record,p,lock);
}
ret.Put=function () {
this.Put=function () {
this.PutLocked(LOCK_WRITE);
}
ret.ReInit=function() {
this.ReInit=function() {
for(i in PlayerProperties) {
this[PlayerProperties[i]['prop']]=PlayerProperties[i]['def'];
}
}
return ret;
},
Get:function GetLocked(playerNum, lock) {
return this.GetLocked(playerNum, LOCK_READ);
},
get length() {
return(db.read(Settings.DB,'players.length',LOCK_READ));
for(i in PlayerProperties) {
this[PlayerProperties[i]['prop']]=player[PlayerProperties[i]['prop']];
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment