better loadout

This commit is contained in:
Timothy Teakettle
2020-10-20 21:02:17 +01:00
parent 36040e0689
commit e6895bec04
3 changed files with 60 additions and 28 deletions
+20 -18
View File
@@ -5,7 +5,7 @@
// You do not need to raise this if you are adding new values that have sane defaults.
// Only raise this value when changing the meaning/format/name/layout of an existing value
// where you would want the updater procs below to run
#define SAVEFILE_VERSION_MAX 38
#define SAVEFILE_VERSION_MAX 40
/*
SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Carn
@@ -226,6 +226,20 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
left_eye_color = "#BAB99E"
right_eye_color = "#BAB99E"
if(current_version < 40) //loadout save gets changed to json
var/text_to_load
S["loadout"] >> text_to_load
var/list/saved_loadout_paths = splittext(text_to_load, "|")
//MAXIMUM_LOADOUT_SAVES save slots per loadout now
for(var/i=1, i<= MAXIMUM_LOADOUT_SAVES, i++)
loadout_data["SAVE_[i]"] = list()
for(var/some_gear_item in saved_loadout_paths)
if(!ispath(some_gear_item))
message_admins("Failed to copy item [some_gear_item] to new loadout system when migrating from version [current_version] to 40, issue: item is not a path")
continue
loadout_data["SAVE_1"] += list(list(LOADOUT_ITEM = some_gear_item)) //for the migration we put their old save into the first save slot, which is loaded by default!
//it's double packed into a list because += will union the two lists contents
/datum/preferences/proc/load_path(ckey,filename="preferences.sav")
if(!ckey)
return
@@ -669,20 +683,9 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
var/list/json_from_file = json_decode(file2text(char_vr_path))
if(json_from_file)
belly_prefs = json_from_file["belly_prefs"]
//gear loadout
var/text_to_load
S["loadout"] >> text_to_load
var/list/saved_loadout_paths = splittext(text_to_load, "|")
chosen_gear = list()
gear_points = CONFIG_GET(number/initial_gear_points)
for(var/i in saved_loadout_paths)
var/datum/gear/path = text2path(i)
if(path)
var/init_cost = initial(path.cost)
if(init_cost > gear_points)
continue
chosen_gear += path
gear_points -= init_cost
loadout_data = safe_json_decode(S["loadout"])
//try to fix any outdated data if necessary
//preference updating will handle saving the updated data for us.
@@ -962,11 +965,10 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
//gear loadout
if(chosen_gear.len)
var/text_to_save = chosen_gear.Join("|")
S["loadout"] << text_to_save
if(length(loadout_data))
S["loadout"] << safe_json_encode(loadout_data)
else
S["loadout"] << "" //empty string to reset the value
S["loadout"] << safe_json_encode(list())
cit_character_pref_save(S)