Skip to content

Commit

Permalink
Loadout DB Storage Refactor (ParadiseSS13#16453)
Browse files Browse the repository at this point in the history
* `display_name` -> Typepaths V1

* Loadout display name capitalisation

ParadiseSS13#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
  • Loading branch information
SabreML authored Oct 9, 2021
1 parent ab4aeec commit bc739c3
Show file tree
Hide file tree
Showing 20 changed files with 927 additions and 361 deletions.
9 changes: 4 additions & 5 deletions code/__HELPERS/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@
for(var/geartype in subtypesof(/datum/gear))
var/datum/gear/G = geartype

var/use_name = initial(G.display_name)
var/use_category = initial(G.sort_category)

if(G == initial(G.subtype_path))
if(G == initial(G.main_typepath))
continue

if(!use_name)
if(!initial(G.display_name))
stack_trace("Loadout - Missing display name: [G]")
continue
if(!initial(G.cost))
Expand All @@ -96,8 +95,8 @@
if(!GLOB.loadout_categories[use_category])
GLOB.loadout_categories[use_category] = new /datum/loadout_category(use_category)
var/datum/loadout_category/LC = GLOB.loadout_categories[use_category]
GLOB.gear_datums[use_name] = new geartype
LC.gear[use_name] = GLOB.gear_datums[use_name]
GLOB.gear_datums[geartype] = new geartype
LC.gear[geartype] = GLOB.gear_datums[geartype]

GLOB.loadout_categories = sortAssoc(GLOB.loadout_categories)
for(var/loadout_category in GLOB.loadout_categories)
Expand Down
4 changes: 4 additions & 0 deletions code/__HELPERS/sanitize_values.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
if(default) return default
if(List && List.len)return pick(List)

/proc/sanitize_json(json_input)
if(length(json_input) && istext(json_input))
return json_decode(json_input)
return list()


//more specialised stuff
Expand Down
11 changes: 4 additions & 7 deletions code/game/jobs/job/job.dm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

if(allow_loadout && H.client && length(H.client.prefs.active_character.loadout_gear))
for(var/gear in H.client.prefs.active_character.loadout_gear)
var/datum/gear/G = GLOB.gear_datums[gear]
var/datum/gear/G = GLOB.gear_datums[text2path(gear) || gear]
if(G)
var/permitted = FALSE

Expand All @@ -185,16 +185,13 @@
else
permitted = TRUE

if(G.whitelisted && (G.whitelisted != H.dna.species.name || !is_alien_whitelisted(H, G.whitelisted)))
permitted = FALSE

if(!permitted)
to_chat(H, "<span class='warning'>Your current job or whitelist status does not permit you to spawn with [gear]!</span>")
to_chat(H, "<span class='warning'>Your current job or whitelist status does not permit you to spawn with [G.display_name]!</span>")
continue

if(G.slot)
if(H.equip_to_slot_or_del(G.spawn_item(H), G.slot, TRUE))
to_chat(H, "<span class='notice'>Equipping you with [gear]!</span>")
to_chat(H, "<span class='notice'>Equipping you with [G.display_name]!</span>")
else
gear_leftovers += G
else
Expand All @@ -217,7 +214,7 @@
if(isturf(placed_in))
to_chat(H, "<span class='notice'>Placing [G.display_name] on [placed_in]!</span>")
else
to_chat(H, "<span class='notice'>Placing [G.display_name] in [placed_in.name].</span>")
to_chat(H, "<span class='notice'>Placing [G.display_name] in your [placed_in.name].</span>")
continue
if(H.equip_to_appropriate_slot(G))
to_chat(H, "<span class='notice'>Placing [G.display_name] in your inventory!</span>")
Expand Down
11 changes: 6 additions & 5 deletions code/modules/client/preference/character.dm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
if(!isemptylist(player_alt_titles))
playertitlelist = list2params(player_alt_titles)
if(!isemptylist(loadout_gear))
gearlist = list2params(loadout_gear)
gearlist = json_encode(loadout_gear)

var/datum/db_query/firstquery = SSdbcore.NewQuery("SELECT slot FROM characters WHERE ckey=:ckey ORDER BY slot", list(
"ckey" = C.ckey
Expand Down Expand Up @@ -438,7 +438,7 @@
//socks
socks = query.item[49]
body_accessory = query.item[50]
loadout_gear = params2list(query.item[51])
loadout_gear = query.item[51]
autohiss_mode = text2num(query.item[52])

//Sanitize
Expand Down Expand Up @@ -507,6 +507,7 @@

socks = sanitize_text(socks, initial(socks))
body_accessory = sanitize_text(body_accessory, initial(body_accessory))
loadout_gear = sanitize_json(loadout_gear)

if(!player_alt_titles)
player_alt_titles = new()
Expand Down Expand Up @@ -1457,11 +1458,11 @@



/datum/character_save/proc/get_gear_metadata(datum/gear/G)
. = loadout_gear[G.display_name]
/datum/character_save/proc/get_gear_metadata(datum/gear/G) // NYI
. = loadout_gear[G.type]
if(!.)
. = list()
loadout_gear[G.display_name] = .
loadout_gear[G.type] = .

/datum/character_save/proc/get_tweak_metadata(datum/gear/G, datum/gear_tweak/tweak)
var/list/metadata = get_gear_metadata(G)
Expand Down
24 changes: 6 additions & 18 deletions code/modules/client/preference/link_processing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,17 @@

if(href_list["preference"] == "gear")
if(href_list["toggle_gear"])
var/datum/gear/TG = GLOB.gear_datums[href_list["toggle_gear"]]
if(TG.display_name in active_character.loadout_gear)
active_character.loadout_gear -= TG.display_name
var/datum/gear/TG = GLOB.gear_datums[text2path(href_list["toggle_gear"])]
if(TG && (TG.type in active_character.loadout_gear))
active_character.loadout_gear -= TG.type
else
if(TG.donator_tier && user.client.donator_level < TG.donator_tier)
to_chat(user, "<span class='warning'>That gear is only available at a higher donation tier than you are on.</span>")
return
var/total_cost = 0
var/list/type_blacklist = list()
for(var/gear_name in active_character.loadout_gear)
var/datum/gear/G = GLOB.gear_datums[gear_name]
if(istype(G))
if(!G.subtype_cost_overlap)
if(G.subtype_path in type_blacklist)
continue
type_blacklist += G.subtype_path
total_cost += G.cost

if((total_cost + TG.cost) <= max_gear_slots)
active_character.loadout_gear += TG.display_name
build_loadout(TG)

else if(href_list["gear"] && href_list["tweak"])
var/datum/gear/gear = GLOB.gear_datums[href_list["gear"]]
else if(href_list["gear"] && href_list["tweak"]) // NYI
var/datum/gear/gear = GLOB.gear_datums[text2path(href_list["gear"])]
var/datum/gear_tweak/tweak = locate(href_list["tweak"])
if(!tweak || !istype(gear) || !(tweak in gear.gear_tweaks))
return
Expand Down
30 changes: 20 additions & 10 deletions code/modules/client/preference/loadout/loadout.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,27 @@ GLOBAL_LIST_EMPTY(gear_datums)
..()

/datum/gear
var/display_name //Name/index. Must be unique.
var/description //Description of this gear. If left blank will default to the description of the pathed item.
var/path //Path to item.
var/cost = 1 //Number of points used. Items in general cost 1 point, storage/armor/gloves/special use costs 2 points.
var/slot //Slot to equip to.
var/list/allowed_roles //Roles that can spawn with this item.
var/whitelisted //Term to check the whitelist for..
/// Displayed name of the item listing.
var/display_name
/// Description of the item listing. If left blank will default to the description of the pathed item.
var/description
/// Typepath of the item.
var/path
/// Loadout points cost to select the item listing.
var/cost = 1
/// Slot to equip the item to.
var/slot
/// List of job roles which can spawn with the item.
var/list/allowed_roles
/// Loadout category of the item listing.
var/sort_category = "General"
var/list/gear_tweaks = list() //List of datums which will alter the item after it has been spawned.
var/subtype_path = /datum/gear //for skipping organizational subtypes (optional)
var/subtype_cost_overlap = TRUE //if subtypes can take points at the same time
/// List of datums which will alter the item after it has been spawned. (NYI)
var/list/gear_tweaks = list()
/// Set on empty category datums to skip them being added to the list. (/datum/gear/accessory, /datum/gear/suit/coat/job, etc.)
var/main_typepath = /datum/gear
/// Does selecting a second item with the same `main_typepath` cost loadout points.
var/subtype_selection_cost = TRUE
/// Patreon donator tier needed to select this item listing.
var/donator_tier = 0

/datum/gear/New()
Expand Down
Loading

0 comments on commit bc739c3

Please sign in to comment.