Centralised persistent data management framework (#14169)

* Centralised persistent data management framework

* register() proc

* Deletes lavaland black box
This commit is contained in:
AffectedArc07
2020-10-26 17:54:15 -04:00
committed by GitHub
parent 61328bdd76
commit 9e8932afac
5 changed files with 84 additions and 117 deletions
@@ -40,20 +40,18 @@
gold_core_spawnable = NO_SPAWN
unique_pet = TRUE
var/list/family = list()
var/memory_saved = 0
var/list/children = list() //Actual mob instances of children
var/cats_deployed = 0
/mob/living/simple_animal/pet/cat/Runtime/New()
Read_Memory()
SSpersistent_data.register(src)
..()
/mob/living/simple_animal/pet/cat/Runtime/Life(seconds, times_fired)
if(!cats_deployed && SSticker.current_state >= GAME_STATE_SETTING_UP)
Deploy_The_Cats()
if(!stat && SSticker.current_state == GAME_STATE_FINISHED && !memory_saved)
Write_Memory()
..()
/mob/living/simple_animal/pet/cat/Runtime/PersistentLoad()
Read_Memory()
Deploy_The_Cats()
/mob/living/simple_animal/pet/cat/Runtime/PersistentSave()
Write_Memory(FALSE)
/mob/living/simple_animal/pet/cat/Runtime/make_babies()
var/mob/baby = ..()
@@ -62,8 +60,9 @@
return baby
/mob/living/simple_animal/pet/cat/Runtime/death()
if(can_die() && !memory_saved)
Write_Memory(1)
if(can_die())
Write_Memory(TRUE)
SSpersistent_data.registered_atoms -= src // We just saved. Dont save at round end
return ..()
/mob/living/simple_animal/pet/cat/Runtime/proc/Read_Memory()
@@ -72,6 +71,7 @@
if(isnull(family))
family = list()
log_debug("Persistent data for [src] loaded (family: [list2params(family)])")
/mob/living/simple_animal/pet/cat/Runtime/proc/Write_Memory(dead)
var/savefile/S = new /savefile("data/npc_saves/Runtime.sav")
@@ -85,21 +85,18 @@
else
family[C.type] = 1
S["family"] << family
memory_saved = 1
log_debug("Persistent data for [src] saved (family: [list2params(family)])")
/mob/living/simple_animal/pet/cat/Runtime/proc/Deploy_The_Cats()
cats_deployed = 1
for(var/cat_type in family)
if(family[cat_type] > 0)
for(var/i in 1 to min(family[cat_type],100)) //Limits to about 500 cats, you wouldn't think this would be needed (BUT IT IS)
new cat_type(loc)
/mob/living/simple_animal/pet/cat/Life()
..()
make_babies()
/mob/living/simple_animal/pet/cat/handle_automated_action()
if(!stat && !buckled)
if(prob(1))
@@ -420,13 +420,18 @@
unique_pet = TRUE
var/age = 0
var/record_age = 1
var/memory_saved = FALSE
var/saved_head //path
/mob/living/simple_animal/pet/dog/corgi/Ian/Initialize(mapload)
. = ..()
//parent call must happen first to ensure IAN
//is not in nullspace when child puppies spawn
SSpersistent_data.register(src)
/mob/living/simple_animal/pet/dog/corgi/Ian/death()
Write_Memory(TRUE)
SSpersistent_data.registered_atoms -= src // We already wrote here, dont overwrite!
..()
/mob/living/simple_animal/pet/dog/corgi/Ian/PersistentLoad()
Read_Memory()
if(age == 0)
var/turf/target = get_turf(loc)
@@ -437,6 +442,7 @@
P.gender = MALE
P.desc = "It's the HoP's beloved corgi puppy."
Write_Memory(FALSE)
SSpersistent_data.registered_atoms -= src // We already wrote here, dont overwrite!
qdel(src)
return
else if(age == record_age)
@@ -446,16 +452,8 @@
desc = "At a ripe old age of [record_age], Ian's not as spry as he used to be, but he'll always be the HoP's beloved corgi." //RIP
turns_per_move = 20
/mob/living/simple_animal/pet/dog/corgi/Ian/Life()
if(!stat && SSticker.current_state == GAME_STATE_FINISHED && !memory_saved)
Write_Memory(FALSE)
memory_saved = TRUE
..()
/mob/living/simple_animal/pet/dog/corgi/Ian/death()
if(!memory_saved)
Write_Memory(TRUE)
..()
/mob/living/simple_animal/pet/dog/corgi/Ian/PersistentSave()
Write_Memory(FALSE)
/mob/living/simple_animal/pet/dog/corgi/Ian/proc/Read_Memory()
if(fexists("data/npc_saves/Ian.sav")) //legacy compatability to convert old format to new
@@ -478,6 +476,7 @@
record_age = 1
if(saved_head)
place_on_head(new saved_head)
log_debug("Persistent data for [src] loaded (age: [age] | record_age: [record_age] | saved_head: [saved_head])")
/mob/living/simple_animal/pet/dog/corgi/Ian/proc/Write_Memory(dead)
var/json_file = file("data/npc_saves/Ian.json")
@@ -498,6 +497,7 @@
file_data["saved_head"] = null
fdel(json_file)
WRITE_FILE(json_file, json_encode(file_data))
log_debug("Persistent data for [src] saved (age: [age] | record_age: [record_age] | saved_head: [saved_head])")
/mob/living/simple_animal/pet/dog/corgi/Ian/handle_automated_movement()
. = ..()