HTML and CSS Reference
In-Depth Information
getObject: function(col, row) {
return this.checkBounds(col, row) && this.objects[row][col] || this.tiles.defaultObject
},
setSurface: function(col, row, value) {
this.checkBounds(col, row) && (this.surface[row][col]=value)
},
setObject: function(col, row, value) {
this.checkBounds(col, row) && (this.objects[row][col]=value)
},
Load and save methods can be used to exploit client-side data storage, for instance, localStorage :
load: function(data) { //load previously saved data
var rows = this.rows = data.rows;
var cols = this.cols = data.cols;
var list = [];
for (var i=0;i<data.tiles.length;i++)
list.push(this.tiles.byName[data.tiles[i]])
this.surface = [];
this.objects = [];
for (var i=0;i<rows;i++) {
this.surface.push([]);
for (var j=0;j<cols;j++)
this.surface[i].push(list[data.surface[i][j]] ||
this.tiles.defaultSurface)
this.objects.push([]);
for (var j=0;j<cols;j++)
this.objects[i].push(list[data.objects[i][j]] ||
this.tiles.defaultObject)
}
},
save: function() {
data = { tiles:[], surface: [], objects: [] }
var rows = data.rows = this.rows
var cols = data.cols = this.cols
var list = this.tiles.byId
for (var i=0;i<list.length;i++)
data.tiles.push(list[i].name)
for (var i=0;i<rows;i++) {
data.surface.push([]);
for (var j=0;j<cols;j++)
data.surface[i].push(this.surface[i][j].id)
data.objects.push([]);
for (var j=0;j<cols;j++)
data.objects[i].push(this.objects[i][j].id)
}
return data
}
}
 
Search WWH ::




Custom Search