mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-27 14:07:51 +01:00
Loadout DB Storage Refactor (#16453)
* `display_name` -> Typepaths V1 * Loadout display name capitalisation #15857 * Review 1, plus json fixes * (Hopefully) final tweaks * Styling nitpicks * Extra tweaks because why not It never caused a runtime, but the `?.` is just in case. * Deconflicting * Warning comment * Whoops Typing faster than my brain
This commit is contained in:
@@ -413,19 +413,9 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
|
||||
dat += "</td></tr></table>"
|
||||
|
||||
if(TAB_GEAR)
|
||||
var/total_cost = 0
|
||||
var/list/type_blacklist = list()
|
||||
if(length(active_character.loadout_gear))
|
||||
for(var/i in 1 to length(active_character.loadout_gear))
|
||||
var/datum/gear/G = GLOB.gear_datums[active_character.loadout_gear[i]]
|
||||
if(G)
|
||||
if(!G.subtype_cost_overlap)
|
||||
if(G.subtype_path in type_blacklist)
|
||||
continue
|
||||
type_blacklist += G.subtype_path
|
||||
total_cost += G.cost
|
||||
var/total_cost = build_loadout()
|
||||
|
||||
var/fcolor = "#3366CC"
|
||||
var/fcolor = "#3366CC"
|
||||
if(total_cost < max_gear_slots)
|
||||
fcolor = "#E67300"
|
||||
dat += "<table align='center' width='100%'>"
|
||||
@@ -450,11 +440,11 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
|
||||
dat += "<tr><td colspan=4><hr></td></tr>"
|
||||
for(var/gear_name in LC.gear)
|
||||
var/datum/gear/G = LC.gear[gear_name]
|
||||
var/ticked = (G.display_name in active_character.loadout_gear)
|
||||
var/ticked = (G.type in active_character.loadout_gear)
|
||||
if(G.donator_tier > user.client.donator_level)
|
||||
dat += "<tr style='vertical-align:top;'><td width=15%><B>[G.display_name]</B></td>"
|
||||
else
|
||||
dat += "<tr style='vertical-align:top;'><td width=15%><a style='white-space:normal;' [ticked ? "class='linkOn' " : ""]href='?_src_=prefs;preference=gear;toggle_gear=[G.display_name]'>[G.display_name]</a></td>"
|
||||
dat += "<tr style='vertical-align:top;'><td width=15%><a style='white-space:normal;' [ticked ? "class='linkOn' " : ""]href='?_src_=prefs;preference=gear;toggle_gear=[G.type]'>[G.display_name]</a></td>"
|
||||
dat += "<td width = 5% style='vertical-align:top'>[G.cost]</td><td>"
|
||||
if(G.allowed_roles)
|
||||
dat += "<font size=2>Restrictions: "
|
||||
@@ -465,7 +455,7 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
|
||||
if(ticked)
|
||||
. += "<tr><td colspan=4>"
|
||||
for(var/datum/gear_tweak/tweak in G.gear_tweaks)
|
||||
. += " <a href='?_src_=prefs;preference=gear;gear=[G.display_name];tweak=\ref[tweak]'>[tweak.get_contents(active_character.get_tweak_metadata(G, tweak))]</a>"
|
||||
. += " <a href='?_src_=prefs;preference=gear;gear=[G.type];tweak=\ref[tweak]'>[tweak.get_contents(active_character.get_tweak_metadata(G, tweak))]</a>"
|
||||
. += "</td></tr>"
|
||||
dat += "</table>"
|
||||
|
||||
@@ -562,3 +552,39 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
|
||||
|
||||
active_character.SetChoices(user)
|
||||
return 1
|
||||
|
||||
/**
|
||||
* Rebuilds the `loadout_gear` list of the [active_character], and returns the total end cost.
|
||||
*
|
||||
* Caches and cuts the existing [/datum/character_save/var/loadout_gear] list and remakes it, checking the `subtype_selection_cost` and overall cost validity of each item.
|
||||
*
|
||||
* If the item's [/datum/gear/var/subtype_selection_cost] is `FALSE`, any future items with the same [/datum/gear/var/main_typepath] will have their cost skipped.
|
||||
* If adding the item will take the total cost over the maximum, it won't be added to the list.
|
||||
*
|
||||
* Arguments:
|
||||
* * new_item - A new [/datum/gear] item to be added to the `loadout_gear` list.
|
||||
*/
|
||||
/datum/preferences/proc/build_loadout(datum/gear/new_item)
|
||||
var/total_cost = 0
|
||||
var/list/type_blacklist = list()
|
||||
var/list/loadout_cache = active_character.loadout_gear.Copy()
|
||||
active_character.loadout_gear.Cut()
|
||||
if(new_item)
|
||||
loadout_cache += new_item.type
|
||||
|
||||
for(var/I in loadout_cache)
|
||||
var/datum/gear/G = GLOB.gear_datums[text2path(I) || I]
|
||||
if(!G)
|
||||
continue
|
||||
var/added_cost = G.cost
|
||||
if(!G.subtype_selection_cost) // If listings of the same subtype shouldn't have their cost added.
|
||||
if(G.main_typepath in type_blacklist)
|
||||
added_cost = 0
|
||||
else
|
||||
type_blacklist += G.main_typepath
|
||||
|
||||
if((total_cost + added_cost) > max_gear_slots)
|
||||
continue // If the final cost is too high, don't add the item.
|
||||
active_character.loadout_gear += G.type
|
||||
total_cost += added_cost
|
||||
return total_cost
|
||||
|
||||
Reference in New Issue
Block a user