organism saving/loading

This commit is contained in:
MaxRobinsonTheGreat
2022-04-10 13:07:10 -05:00
parent 8005b5312c
commit dabeb4463d
7 changed files with 118 additions and 23 deletions

View File

@@ -1,14 +1,19 @@
const CellStates = require("./Cell/CellStates");
const BodyCellFactory = require("./Cell/BodyCells/BodyCellFactory");
const SerializeHelper = require("../Utils/SerializeHelper");
class Anatomy {
constructor(owner) {
this.owner = owner;
this.birth_distance = 4;
this.clear();
}
clear() {
this.cells = [];
this.is_producer = false;
this.is_mover = false;
this.has_eyes = false;
this.birth_distance = 4;
}
canAddCellAt(c, r) {
@@ -118,6 +123,24 @@ class Anatomy {
}
return true;
}
serialize() {
let anatomy = SerializeHelper.copyNonObjects(this);
anatomy.cells = [];
for (let cell of this.cells) {
let newcell = SerializeHelper.copyNonObjects(cell);
newcell.state = {name: cell.state.name};
anatomy.cells.push(newcell)
}
return anatomy;
}
loadRaw(anatomy) {
this.clear();
for (let cell of anatomy.cells){
this.addInheritCell(cell);
}
}
}
module.exports = Anatomy;