mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15:33:12 +09:00
#61 chunkStore is getting filled/emptied on demand
This commit is contained in:
1 parent
b1f35c9b72
commit
8fce9a2cfe
6 files changed
+72
-62
No files matched your search
+8
-7
@@ -13,7 +13,7 @@ module.exports = class chunkStore {
|
||||
this.path = (path[path.length] == "/") ? path : path+"/";
|
||||
mkdirpSync(path+name);
|
||||
}
|
||||
setEntity(x, y, newEntity){
|
||||
setEntity(x/**{number}*/, y/**{number}*/, newEntity/**{object}*/){
|
||||
return new Promise((resolve, reject) => {
|
||||
var localX = Math.round(x % this.chunkSize);
|
||||
x = Math.floor(Math.round(x)/this.chunkSize);
|
||||
@@ -21,15 +21,14 @@ module.exports = class chunkStore {
|
||||
y = Math.floor(Math.round(y)/this.chunkSize);
|
||||
|
||||
this.getChunk(x,y).then(chunk => {
|
||||
log("Setentity")
|
||||
log("Setentity");
|
||||
if(!chunk.dataObject[localX]) chunk.dataObject[localX] = {};
|
||||
if(!chunk.dataObject[localX][localY]) chunk.dataObject[localX][localY] = {};
|
||||
|
||||
let entity = chunk.dataObject[localX][localY]
|
||||
|
||||
if(newEntity && typeof newEntity == "object"){
|
||||
log("Overwriting with new entity");
|
||||
entity.name = newEntity.name;
|
||||
log("Overwriting with new entity at "+localX+", "+localY);
|
||||
chunk.dataObject[localX][localY] = newEntity;
|
||||
} else {
|
||||
log("Deleting entry at "+localX+", "+localY);
|
||||
chunk.dataObject[localX][localY] = undefined;
|
||||
@@ -44,8 +43,10 @@ module.exports = class chunkStore {
|
||||
setChunk(x, y, chunk){
|
||||
return new Promise((resolve, reject) => {
|
||||
mkdirp(this.path+this.name+"/"+x).then(() => {
|
||||
fs.writeFile(this.path+this.name+"/"+x+"/"+y, JSON.stringify(chunk), function(){
|
||||
resolve();
|
||||
fs.writeFile(this.path+this.name+"/"+x+"/"+y, JSON.stringify(chunk), function(err){
|
||||
if(err) {
|
||||
reject(err);
|
||||
} else resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user