Merge pull request #2560 from Citadel-Station-13/upstream-merge-30121

[MIRROR] Converts npc saves to jsons
This commit is contained in:
LetterJay
2017-09-02 05:20:31 -05:00
committed by GitHub
7 changed files with 224 additions and 134 deletions
@@ -87,17 +87,28 @@
/// SNPC voice handling
/mob/living/carbon/human/interactive/proc/loadVoice()
var/savefile/S = new /savefile("data/npc_saves/snpc.sav")
S["knownStrings"] >> knownStrings
if(fexists("data/npc_saves/snpc.sav"))
var/savefile/S = new /savefile("data/npc_saves/snpc.sav")
S["knownStrings"] >> knownStrings
fdel(S)
else
var/json_file = file("data/npc_saves/snpc.json")
if(!fexists(json_file))
return
var/list/json = list()
json = json_decode(file2text(json_file))
knownStrings = json["knownStrings"]
if(isnull(knownStrings))
knownStrings = list()
/mob/living/carbon/human/interactive/proc/saveVoice()
if(voice_saved)
return
var/savefile/S = new /savefile("data/npc_saves/snpc.sav")
WRITE_FILE(S["knownStrings"], knownStrings)
var/json_file = file("data/npc_saves/snpc.json")
var/list/file_data = list()
file_data["knownStrings"] = knownStrings
fdel(json_file)
WRITE_FILE(json_file, json_encode(file_data))
//botPool funcs
/mob/living/carbon/human/interactive/proc/takeDelegate(mob/living/carbon/human/interactive/from,doReset=TRUE)
+32 -24
View File
@@ -24,7 +24,7 @@
..()
//These have to be after the parent new to ensure that the monkey
//bodyparts are actually created before we try to equip things to
//bodyparts are actually created before we try to equip things to
//those slots
if(relic_hat)
equip_to_slot_or_del(new relic_hat, slot_head)
@@ -42,32 +42,40 @@
..()
/mob/living/carbon/monkey/punpun/proc/Read_Memory()
var/savefile/S = new /savefile("data/npc_saves/Punpun.sav")
S["ancestor_name"] >> ancestor_name
S["ancestor_chain"] >> ancestor_chain
S["relic_hat"] >> relic_hat
S["relic_mask"] >> relic_mask
if(fexists("data/npc_saves/Punpun.sav"))
var/savefile/S = new /savefile("data/npc_saves/Punpun.sav")
S["ancestor_name"] >> ancestor_name
S["ancestor_chain"] >> ancestor_chain
S["relic_hat"] >> relic_hat
S["relic_mask"] >> relic_mask
fdel(S)
else
var/json_file = file("data/npc_saves/Punpun.json")
if(!fexists(json_file))
return
var/list/json = list()
json = json_decode(file2text(json_file))
ancestor_name = json["ancestor_name"]
ancestor_chain = json["ancestor_chain"]
relic_hat = json["relic_hat"]
relic_mask = json["relic_hat"]
/mob/living/carbon/monkey/punpun/proc/Write_Memory(dead, gibbed)
var/savefile/S = new /savefile("data/npc_saves/Punpun.sav")
var/json_file = file("data/npc_saves/Punpun.json")
var/list/file_data = list()
if(gibbed)
WRITE_FILE(S["ancestor_name"], null)
WRITE_FILE(S["ancestor_chain"], 1)
WRITE_FILE(S["relic_hat"], null)
WRITE_FILE(S["relic_mask"], null)
return
file_data["ancestor_name"] = null
file_data["ancestor_chain"] = null
file_data["relic_hat"] = null
file_data["relic_mask"] = null
if(dead)
WRITE_FILE(S["ancestor_name"], ancestor_name)
WRITE_FILE(S["ancestor_chain"], ancestor_chain + 1)
if(!ancestor_name) //new monkey name this round
WRITE_FILE(S["ancestor_name"], name)
if(head)
WRITE_FILE(S["relic_hat"], head.type)
else
WRITE_FILE(S["relic_hat"], null)
if(wear_mask)
WRITE_FILE(S["relic_mask"], wear_mask.type)
else
WRITE_FILE(S["relic_mask"], null)
file_data["ancestor_name"] = ancestor_name
file_data["ancestor_chain"] = ancestor_chain + 1
file_data["relic_hat"] = head ? head.type : null
file_data["relic_mask"] = wear_mask ? wear_mask.type : null
if(!ancestor_name)
file_data["ancestor_name"] = name
fdel(json_file)
WRITE_FILE(json_file, json_encode(json_file))
if(!dead)
memory_saved = 1
@@ -113,14 +113,22 @@
..()
/mob/living/simple_animal/pet/cat/Runtime/proc/Read_Memory()
var/savefile/S = new /savefile("data/npc_saves/Runtime.sav")
S["family"] >> family
if(fexists("data/npc_saves/Runtime.sav")) //legacy compatability to convert old format to new
var/savefile/S = new /savefile("data/npc_saves/Runtime.sav")
S["family"] >> family
fdel(S)
else
var/json_file = file("data/npc_saves/Runtime.json")
if(!fexists(json_file))
return
var/list/json = list()
json = json_decode(file2text(json_file))
family = json["family"]
if(isnull(family))
family = list()
/mob/living/simple_animal/pet/cat/Runtime/proc/Write_Memory(dead)
var/savefile/S = new /savefile("data/npc_saves/Runtime.sav")
var/json_file = file("data/npc_saves/Runtime.json")
family = list()
if(!dead)
for(var/mob/living/simple_animal/pet/cat/kitten/C in children)
@@ -130,7 +138,8 @@
family[C.type] += 1
else
family[C.type] = 1
WRITE_FILE(S["family"], family)
fdel(json_file)
WRITE_FILE(json_file, json_encode(family))
memory_saved = 1
/mob/living/simple_animal/pet/cat/Runtime/proc/Deploy_The_Cats()
@@ -328,33 +328,44 @@
..()
/mob/living/simple_animal/pet/dog/corgi/Ian/proc/Read_Memory()
var/savefile/S = new /savefile("data/npc_saves/Ian.sav")
S["age"] >> age
S["record_age"] >> record_age
S["saved_head"] >> saved_head
if(fexists("data/npc_saves/Ian.sav")) //legacy compatability to convert old format to new
var/savefile/S = new /savefile("data/npc_saves/Ian.sav")
S["age"] >> age
S["record_age"] >> record_age
S["saved_head"] >> saved_head
fdel(S)
else
var/json_file = file("data/npc_saves/Ian.json")
if(!fexists(json_file))
return
var/list/json = list()
json = json_decode(file2text(json_file))
age = json["age"]
record_age = json["record_age"]
saved_head = json["saved_head"]
if(isnull(age))
age = 0
if(isnull(record_age))
record_age = 1
if(saved_head)
place_on_head(new saved_head)
/mob/living/simple_animal/pet/dog/corgi/Ian/proc/Write_Memory(dead)
var/savefile/S = new /savefile("data/npc_saves/Ian.sav")
var/json_file = file("data/npc_saves/Ian.json")
var/list/file_data = list()
if(!dead)
WRITE_FILE(S["age"], age + 1)
file_data["age"] = age + 1
if((age + 1) > record_age)
WRITE_FILE(S["record_age"], record_age + 1)
file_data["record_age"] = record_age + 1
if(inventory_head)
WRITE_FILE(S["saved_head"], inventory_head.type)
file_data["saved_head"] = inventory_head.type
else
WRITE_FILE(S["age"], 0)
WRITE_FILE(S["saved_head"], null)
file_data["age"] = 0
file_data["saved_head"] = null
fdel(json_file)
WRITE_FILE(json_file, json_encode(file_data))
memory_saved = 1
/mob/living/simple_animal/pet/dog/corgi/Ian/Life()
..()
@@ -277,19 +277,29 @@ Difficulty: Very Hard
WriteMemory()
/obj/machinery/smartfridge/black_box/proc/WriteMemory()
var/savefile/S = new /savefile("data/npc_saves/Blackbox.sav")
var/json_file = file("data/npc_saves/Blackbox.json")
stored_items = list()
for(var/obj/O in (contents-component_parts))
stored_items += O.type
WRITE_FILE(S["stored_items"], stored_items)
var/list/file_data = list()
file_data["data"] = stored_items
fdel(json_file)
WRITE_FILE(json_file, json_encode(file_data))
memory_saved = TRUE
/obj/machinery/smartfridge/black_box/proc/ReadMemory()
var/savefile/S = new /savefile("data/npc_saves/Blackbox.sav")
S["stored_items"] >> stored_items
if(fexists("data/npc_saves/Blackbox.sav")) //legacy compatability to convert old format to new
var/savefile/S = new /savefile("data/npc_saves/Blackbox.sav")
S["stored_items"] >> stored_items
fdel(S)
else
var/json_file = file("data/npc_saves/Blackbox.json")
if(!fexists(json_file))
return
var/list/json = list()
json = json_decode(file2text(json_file))
stored_items = json["data"]
if(isnull(stored_items))
stored_items = list()
+25 -11
View File
@@ -924,22 +924,36 @@
..(gibbed)
/mob/living/simple_animal/parrot/Poly/proc/Read_Memory()
var/savefile/S = new /savefile("data/npc_saves/Poly.sav")
S["phrases"] >> speech_buffer
S["roundssurvived"] >> rounds_survived
S["longestsurvival"] >> longest_survival
S["longestdeathstreak"] >> longest_deathstreak
if(fexists("data/npc_saves/Poly.sav")) //legacy compatability to convert old format to new
var/savefile/S = new /savefile("data/npc_saves/Poly.sav")
S["phrases"] >> speech_buffer
S["roundssurvived"] >> rounds_survived
S["longestsurvival"] >> longest_survival
S["longestdeathstreak"] >> longest_deathstreak
fdel(S)
else
var/json_file = file("data/npc_saves/Poly.json")
if(!fexists(json_file))
return
var/list/json = list()
json = json_decode(file2text(json_file))
speech_buffer = json["phrases"]
rounds_survived = json["roundssurvived"]
longest_survival = json["longestsurvival"]
longest_deathstreak = json["longestdeathstreak"]
if(!islist(speech_buffer))
speech_buffer = list()
/mob/living/simple_animal/parrot/Poly/proc/Write_Memory()
var/savefile/S = new /savefile("data/npc_saves/Poly.sav")
var/json_file = file("data/npc_saves/Punpun.json")
var/list/file_data = list()
if(islist(speech_buffer))
WRITE_FILE(S["phrases"], speech_buffer)
WRITE_FILE(S["roundssurvived"], rounds_survived)
WRITE_FILE(S["longestsurvival"], longest_survival)
WRITE_FILE(S["longestdeathstreak"], longest_deathstreak)
file_data["phrases"] = speech_buffer
file_data["roundssurvived"] = rounds_survived
file_data["longestsurvival"] = longest_survival
file_data["longestdeathstreak"] = longest_deathstreak
fdel(json_file)
WRITE_FILE(json_file, json_encode(file_data))
memory_saved = 1
/mob/living/simple_animal/parrot/Poly/ghost