added world saving/loading

This commit is contained in:
MaxRobinsonTheGreat
2022-04-15 13:13:19 -05:00
parent dabeb4463d
commit 8df3accff7
9 changed files with 184 additions and 25 deletions

View File

@@ -18,7 +18,6 @@ class KillerCell extends BodyCell{
}
killNeighbor(n_cell) {
// console.log(n_cell)
if(n_cell == null || n_cell.owner == null || n_cell.owner == this.org || !n_cell.owner.living || n_cell.state == CellStates.armor)
return;
var is_hit = n_cell.state == CellStates.killer; // has to be calculated before death

View File

@@ -34,7 +34,6 @@ class Organism {
this.move_range = parent.move_range;
this.mutability = parent.mutability;
this.species = parent.species;
// this.birth_distance = parent.birth_distance;
for (var c of parent.anatomy.cells){
//deep copy parent cells
this.anatomy.addInheritCell(c);
@@ -321,21 +320,17 @@ class Organism {
serialize() {
let org = SerializeHelper.copyNonObjects(this);
org.anatomy = this.anatomy.serialize();
if (this.brain)
if (this.anatomy.is_mover && this.anatomy.has_eyes)
org.brain = this.brain.serialize();
org.species_name = this.species.name;
return org;
}
loadRaw(org) {
for (let key in org)
if (typeof org[key] !== 'object')
this[key] = org[key];
SerializeHelper.overwriteNonObjects(org, this);
this.anatomy.loadRaw(org.anatomy)
console.log(org)
if (org.brain) {
console.log('load brain')
if (org.brain)
this.brain.copy(org.brain)
}
}
}