diff --git a/code/controllers/subsystem/persistence.dm b/code/controllers/subsystem/persistence.dm index a59ec7e79f..13762b83f9 100644 --- a/code/controllers/subsystem/persistence.dm +++ b/code/controllers/subsystem/persistence.dm @@ -2,15 +2,13 @@ SUBSYSTEM_DEF(persistence) name = "Persistence" init_order = INIT_ORDER_PERSISTENCE flags = SS_NO_FIRE - var/secret_satchels var/list/satchel_blacklist = list() //this is a typecache var/list/new_secret_satchels = list() //these are objects - var/list/old_secret_satchels = "" + var/list/old_secret_satchels = list() var/list/obj/structure/chisel_message/chisel_messages = list() var/list/saved_messages = list() - var/trophy_sav var/list/saved_trophies = list() /datum/controller/subsystem/persistence/Initialize() @@ -21,8 +19,6 @@ SUBSYSTEM_DEF(persistence) ..() /datum/controller/subsystem/persistence/proc/LoadSatchels() - secret_satchels = file("data/npc_saves/SecretSatchels[SSmapping.config.map_name].json") - if(!fexists(secret_satchels)) var/placed_satchel = 0 var/path var/obj/item/storage/backpack/satchel/flat/F = new() @@ -58,27 +54,10 @@ SUBSYSTEM_DEF(persistence) path = text2path(old_secret_satchels[pos]["saved_obj"]) if(!ispath(path)) return - satchel_blacklist = typecacheof(list(/obj/item/stack/tile/plasteel, /obj/item/crowbar)) - var/list/json = list() - json = json_decode(file2text(secret_satchels)) - old_secret_satchels = json["data"] - var/placed_satchel = 0 - if(old_secret_satchels.len) - if(old_secret_satchels.len >= 20) //guards against low drop pools assuring that one player cannot reliably find his own gear. - var/pos = rand(1, old_secret_satchels.len) - old_secret_satchels.Cut(pos, pos+1) - var/obj/item/storage/backpack/satchel/flat/F = new() - F.x = old_secret_satchels[pos]["x"] - F.y = old_secret_satchels[pos]["y"] - F.z = ZLEVEL_STATION - var/path = text2path(old_secret_satchels[pos]["saved_obj"]) - if(!ispath(path)) - return - if(isfloorturf(F.loc) && !istype(F.loc, /turf/open/floor/plating/)) - F.hide(1) - new path(F) - placed_satchel++ - + if(isfloorturf(F.loc) && !istype(F.loc, /turf/open/floor/plating/)) + F.hide(1) + new path(F) + placed_satchel++ var/list/free_satchels = list() for(var/turf/T in shuffle(block(locate(TRANSITIONEDGE,TRANSITIONEDGE,ZLEVEL_STATION_PRIMARY), locate(world.maxx-TRANSITIONEDGE,world.maxy-TRANSITIONEDGE,ZLEVEL_STATION_PRIMARY)))) //Nontrivially expensive but it's roundstart only if(isfloorturf(T) && !istype(T, /turf/open/floor/plating/)) @@ -92,16 +71,25 @@ SUBSYSTEM_DEF(persistence) break //Who's been duping the bird?! /datum/controller/subsystem/persistence/proc/LoadChiselMessages() - var/json_file = file("data/npc_saves/ChiselMessages[SSmapping.config.map_name].json") - if(!fexists(json_file)) - return - var/list/json - json = json_decode(file2text(json_file)) + var/list/saved_messages = list() + if(fexists("data/npc_saves/ChiselMessages.sav")) //legacy compatability to convert old format to new + var/savefile/chisel_messages_sav = new /savefile("data/npc_saves/ChiselMessages.sav") + var/saved_json + chisel_messages_sav[SSmapping.config.map_name] >> saved_json + if(!saved_json) + return + saved_messages = json_decode(saved_json) + fdel("data/npc_saves/ChiselMessages.sav") + else + var/json_file = file("data/npc_saves/ChiselMessages[SSmapping.config.map_name].json") + if(!fexists(json_file)) + return + var/list/json + json = json_decode(file2text(json_file)) - if(!json) - return - - var/list/saved_messages = json["data"] + if(!json) + return + saved_messages = json["data"] for(var/item in saved_messages) if(!islist(item)) @@ -129,17 +117,23 @@ SUBSYSTEM_DEF(persistence) log_world("Loaded [saved_messages.len] engraved messages on map [SSmapping.config.map_name]") /datum/controller/subsystem/persistence/proc/LoadTrophies() - trophy_sav = file("data/npc_saves/TrophyItems.json") - if(!fexists(trophy_sav)) - return - var/list/json = list() - json = json_decode(file2text(trophy_sav)) - - if(!json) - return - - saved_trophies = json["data"] - + if(fexists("data/npc_saves/TrophyItems.sav")) //legacy compatability to convert old format to new + var/savefile/S = new /savefile("data/npc_saves/TrophyItems.sav") + var/saved_json + S >> saved_json + if(!saved_json) + return + saved_trophies = json_decode(saved_json) + fdel("data/npc_saves/TrophyItems.sav") + else + var/json_file = file("data/npc_saves/TrophyItems.json") + if(!fexists(json_file)) + return + var/list/json = list() + json = json_decode(file2text(json_file)) + if(!json) + return + saved_trophies = json["data"] SetUpTrophies(saved_trophies.Copy()) /datum/controller/subsystem/persistence/proc/SetUpTrophies(list/trophy_items) @@ -174,6 +168,7 @@ SUBSYSTEM_DEF(persistence) /datum/controller/subsystem/persistence/proc/CollectSecretSatchels() var/list/satchels = list() + satchel_blacklist = typecacheof(list(/obj/item/stack/tile/plasteel, /obj/item/crowbar)) for(var/A in new_secret_satchels) var/obj/item/storage/backpack/satchel/flat/F = A if(QDELETED(F) || F.z != ZLEVEL_STATION_PRIMARY || F.invisibility != INVISIBILITY_MAXIMUM) @@ -193,10 +188,11 @@ SUBSYSTEM_DEF(persistence) data["y"] = F.y data["saved_obj"] = pick(savable_obj) satchels += list(data) + var/json_file = file("data/npc_saves/SecretSatchels[SSmapping.config.map_name].json") var/list/file_data = list() file_data["data"] = satchels - fdel(secret_satchels) - WRITE_FILE(secret_satchels, json_encode(file_data)) + fdel(json_file) + WRITE_FILE(json_file, json_encode(file_data)) /datum/controller/subsystem/persistence/proc/CollectChiselMessages() var/json_file = file("data/npc_saves/ChiselMessages[SSmapping.config.map_name].json") @@ -215,10 +211,11 @@ SUBSYSTEM_DEF(persistence) /datum/controller/subsystem/persistence/proc/CollectTrophies() + var/json_file = file("data/npc_saves/TrophyItems.json") var/list/file_data = list() file_data["data"] = saved_trophies - fdel(trophy_sav) - WRITE_FILE(trophy_sav, json_encode(file_data)) + fdel(json_file) + WRITE_FILE(json_file, json_encode(file_data)) /datum/controller/subsystem/persistence/proc/SaveTrophy(obj/structure/displaycase/trophy/T) if(!T.added_roundstart && T.showpiece)