mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-31 00:58:26 +01:00
[MODULAR] Fixes All Known Modular Persistence (NIF) Saving Issues (#19096)
* Fuck * Holy shit
This commit is contained in:
@@ -30,31 +30,32 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
|
||||
player.save_individual_persistence()
|
||||
|
||||
/// Loads the contents of the player's modular_persistence file to their character.
|
||||
/datum/controller/subsystem/persistence/proc/load_modular_persistence(mob/living/carbon/human/player)
|
||||
if(!ishuman(player))
|
||||
return FALSE
|
||||
|
||||
var/obj/item/organ/internal/brain/brain = player.getorganslot(ORGAN_SLOT_BRAIN)
|
||||
/datum/controller/subsystem/persistence/proc/load_modular_persistence(obj/item/organ/internal/brain/brain)
|
||||
if(!brain)
|
||||
return FALSE
|
||||
|
||||
if(!ishuman(brain.owner))
|
||||
return FALSE
|
||||
|
||||
var/mob/living/carbon/human/player = brain.owner
|
||||
|
||||
var/json_file = file("data/player_saves/[player.ckey[1]]/[player.ckey]/modular_persistence.json")
|
||||
var/list/json = fexists(json_file) ? json_decode(file2text(json_file)) : null
|
||||
|
||||
brain.modular_persistence = new(player, islist(json) ? json["[player.mind.original_character_slot_index]"] : null)
|
||||
brain.modular_persistence = new(brain, islist(json) ? json["[player.mind.original_character_slot_index]"] : null)
|
||||
|
||||
/// The master persistence datum. Add vars onto this in your own code. Just be aware that you'll need to use simple data types, such as strings, ints, and lists.
|
||||
/datum/modular_persistence
|
||||
/// The human that this is attached to.
|
||||
var/mob/living/carbon/human/owner
|
||||
var/obj/item/organ/internal/brain/owner
|
||||
/// The owner's character slot index.
|
||||
var/stored_character_slot_index
|
||||
|
||||
/datum/modular_persistence/New(mob/living/carbon/human/player, list/persistence_data)
|
||||
owner = player
|
||||
/datum/modular_persistence/New(obj/item/organ/internal/brain/brain, list/persistence_data)
|
||||
owner = brain
|
||||
. = ..()
|
||||
|
||||
stored_character_slot_index = player.mind?.original_character_slot_index
|
||||
stored_character_slot_index = owner.owner.mind?.original_character_slot_index
|
||||
|
||||
if(!persistence_data)
|
||||
return
|
||||
@@ -65,7 +66,11 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
|
||||
if(var_entry)
|
||||
vars[var_name] = var_entry
|
||||
|
||||
owner.load_nif_data(src)
|
||||
if(!owner.owner)
|
||||
CRASH("Tried to load modular persistence on a brain with no owner! How did this happen?! (\ref[brain], [brain.brainmob?.ckey], [brain])")
|
||||
|
||||
var/mob/living/carbon/human/human = owner.owner
|
||||
human.load_nif_data(src)
|
||||
|
||||
/datum/modular_persistence/Destroy(force, ...)
|
||||
owner = null
|
||||
@@ -75,7 +80,8 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
|
||||
/datum/modular_persistence/proc/serialize_contents_to_list()
|
||||
var/list/returned_list = list()
|
||||
|
||||
owner.save_nif_data(src)
|
||||
var/mob/living/carbon/human/human = owner.owner
|
||||
human.save_nif_data(src)
|
||||
|
||||
for(var/var_name in vars)
|
||||
if(var_name in GLOB.modular_persistence_ignored_vars)
|
||||
@@ -88,12 +94,13 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
|
||||
|
||||
return returned_list
|
||||
|
||||
/// Saves the persistence data for the owner.
|
||||
/mob/living/carbon/human/proc/save_individual_persistence()
|
||||
var/obj/item/organ/internal/brain/brain = getorganslot(ORGAN_SLOT_BRAIN)
|
||||
|
||||
if(!client?.prefs || !brain || ! brain.modular_persistence)
|
||||
return FALSE
|
||||
/// Saves the held persistence data to where it needs to go.
|
||||
/datum/modular_persistence/proc/save_data()
|
||||
var/ckey = replacetext(owner.owner?.ckey || owner.brainmob?.ckey, "@", "")
|
||||
if(!owner.owner && !owner.brainmob)
|
||||
CRASH("Modular persistence save called on a brain with no owning mob or brainmob! How did this happen?! (\ref[owner], [owner])")
|
||||
if(!ckey)
|
||||
CRASH("Modular persistence save called on a brain with no ckey! How did this happen?! (\ref[owner], [owner])")
|
||||
|
||||
var/json_file = file("data/player_saves/[ckey[1]]/[ckey]/modular_persistence.json")
|
||||
var/list/json = fexists(json_file) ? json_decode(file2text(json_file)) : list()
|
||||
@@ -102,5 +109,11 @@ GLOBAL_LIST_INIT(modular_persistence_ignored_vars, list(
|
||||
if(!islist(json))
|
||||
json = list()
|
||||
|
||||
json["[brain.modular_persistence.stored_character_slot_index]"] = brain.modular_persistence.serialize_contents_to_list()
|
||||
json["[stored_character_slot_index]"] = serialize_contents_to_list()
|
||||
WRITE_FILE(json_file, json_encode(json))
|
||||
|
||||
/// Saves the persistence data for the owner.
|
||||
/mob/living/carbon/human/proc/save_individual_persistence()
|
||||
var/obj/item/organ/internal/brain/brain = getorganslot(ORGAN_SLOT_BRAIN)
|
||||
|
||||
return brain?.modular_persistence?.save_data()
|
||||
|
||||
Reference in New Issue
Block a user