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
Branches
Tags
No related merge requests found
......@@ -111,31 +111,11 @@ 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) {
var p={};
var i;
for(i in PlayerProperties) {
p[PlayerProperties[i]['prop']]=this[PlayerProperties[i]['prop']];
}
db.write(Settings.DB,'players.'+this.Record,p,lock);
}
ret.Put=function () {
this.PutLocked(LOCK_WRITE);
}
ret.ReInit=function() {
for(i in PlayerProperties) {
this[PlayerProperties[i]['prop']]=PlayerProperties[i]['def'];
}
}
return ret;
return undefined;
return new Player(db.read(Settings.DB,'players.'+playerNum, lock), playerNum);
},
Get:function GetLocked(playerNum, lock) {
Get:function GetLocked(playerNum) {
return this.GetLocked(playerNum, LOCK_READ);
},
get length() {
......@@ -143,6 +123,33 @@ var players = {
}
}
function Player(player,playerNum)
{
if(playerNum==undefined)
return undefined;
this.Record=playerNum;
this.PutLocked=function(lock) {
var p={};
var i;
for(i in PlayerProperties) {
p[PlayerProperties[i]['prop']]=this[PlayerProperties[i]['prop']];
}
db.write(Settings.DB,'players.'+this.Record,p,lock);
}
this.Put=function () {
this.PutLocked(LOCK_WRITE);
}
this.ReInit=function() {
for(i in PlayerProperties) {
this[PlayerProperties[i]['prop']]=PlayerProperties[i]['def'];
}
}
for(i in PlayerProperties) {
this[PlayerProperties[i]['prop']]=player[PlayerProperties[i]['prop']];
}
}
function AttackPlayer()
{
var count=0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment