Skip to content

Commit

Permalink
Update donator example config & Refactoring (#7612)
Browse files Browse the repository at this point in the history
# About the pull request

This PR is a follow up to #7306 updating the example config, makes the
ckey entry in the config a bit more resilient to stuff like case
sensitivity by using the [ckey
proc](https://www.byond.com/docs/ref/#/proc/ckey), and refactors the two
master lists to GLOBs that automatically initialize. Also makes it
possible to reload the custom_items config at runtime via advanced proc
call.

# Explain why it's good for the game

More flexible config, and an accurate example.

# Testing Photographs and Procedure
<details>
<summary>Screenshots & Videos</summary>


![image](https://github.com/user-attachments/assets/916effc5-7c92-4fa4-acdb-2faa25e98cf6)

![image](https://github.com/user-attachments/assets/df9eb536-89fc-411c-bd14-b9c03948064b)

</details>


# Changelog
:cl:
code: Refactored donator lists to GLOBs that automatically initialize
and made ckeys in custom_items.txt more flexible
config: Updated example config for custom_items.txt
/:cl:
  • Loading branch information
Drulikar authored Nov 19, 2024
1 parent 0e1ae6b commit a4e7bcf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
66 changes: 31 additions & 35 deletions code/modules/cm_marines/custom_items.dm
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
GLOBAL_LIST_FILE_LOAD(custom_items, "config/custom_items.txt")
GLOBAL_LIST_EMPTY(donator_items)
GLOBAL_LIST_INIT(donator_items, generate_donor_kits(FALSE))
GLOBAL_LIST_INIT(random_personal_possessions, generate_random_possessions())

/obj/structure/machinery/personal_gear_vendor
name = "personal gear vendor"
desc = "A console that allows the user to retrieve their personal possessions from the ASRS."
icon = 'icons/obj/structures/machinery/computer.dmi'
icon_state = "cellconsole"
density = TRUE
unacidable = TRUE
unslashable = TRUE
///a random item that can be claimed if there is no valid kit
var/static/list/random_personal_possessions = list()
///assoc list of ckeys to list of kits redeemed
var/static/list/ckeys_redeemed_kits = list()

/obj/structure/machinery/personal_gear_vendor/Initialize(mapload, ...)
. = ..()
if(!length(GLOB.donator_items))
generate_donor_kits()

if(!length(random_personal_possessions))
generate_random_possessions()

/obj/structure/machinery/personal_gear_vendor/proc/generate_donor_kits(regenerate_kits = FALSE)
if(regenerate_kits)
GLOB.donator_items = list()
/proc/generate_donor_kits(assign_to_glob = TRUE)
. = list()

for(var/current_line in GLOB.custom_items)
var/list/custom_items = file2list("config/custom_items.txt")
for(var/current_line in custom_items)
if(!length(current_line)) //empty line
continue
if(copytext(current_line, 1, 2) == "#") //comment line
Expand All @@ -38,7 +17,7 @@ GLOBAL_LIST_EMPTY(donator_items)

var/split_line = splittext(current_line, ":")

donor_key = trim(split_line[1])
donor_key = ckey(trim(split_line[1]))
if(length(split_line) > 2) //if someone has multiple kits, name them
kit_name = trim(split_line[2])

Expand All @@ -53,20 +32,37 @@ GLOBAL_LIST_EMPTY(donator_items)
stack_trace("Missing gear in Donator Gear. [donor_key] has an empty Donator Kit.")
continue

if(kit_name in GLOB.donator_items[donor_key]) //multiple kits with same name
if(kit_name in .[donor_key]) //multiple kits with same name
stack_trace("Duplicate kit in Donator Gear. [donor_key] has multiple [kit_name] Donator Kits.")
continue

GLOB.donator_items[donor_key] += list("[kit_name]" = kit_gear)
.[donor_key] += list("[kit_name]" = kit_gear)

/obj/structure/machinery/personal_gear_vendor/proc/generate_random_possessions(regenerate_kits = FALSE)
if(regenerate_kits)
random_personal_possessions = list()
if(assign_to_glob)
GLOB.donator_items = .

return .

/proc/generate_random_possessions()
. = list()

for(var/datum/gear/current_gear as anything in subtypesof(/datum/gear))
if(!initial(current_gear.display_name))
continue
random_personal_possessions += initial(current_gear.path)
. += initial(current_gear.path)

return .

/obj/structure/machinery/personal_gear_vendor
name = "personal gear vendor"
desc = "A console that allows the user to retrieve their personal possessions from the ASRS."
icon = 'icons/obj/structures/machinery/computer.dmi'
icon_state = "cellconsole"
density = TRUE
unacidable = TRUE
unslashable = TRUE
///assoc list of ckeys to list of kits redeemed
var/static/list/ckeys_redeemed_kits = list()

/obj/structure/machinery/personal_gear_vendor/attack_hand(mob/living/user)
if(..())
Expand All @@ -86,7 +82,7 @@ GLOBAL_LIST_EMPTY(donator_items)
return TRUE

if(length(possible_kits) == 0) //if no donor kit they can get something else
var/random_item_path = pick(random_personal_possessions)
var/random_item_path = pick(GLOB.random_personal_possessions)
var/random_item = new random_item_path(get_turf(src))
user.put_in_any_hand_if_possible(random_item)
to_chat(user, SPAN_NOTICE("You take [random_item] from [src]."))
Expand Down
10 changes: 9 additions & 1 deletion config/example/custom_items.txt
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
ckey: name: /path/to/obj
# Ckey: Variant: Typepath, Typepath, ...
# Variant is used if there are multiple kits for one ckey
# Multiple typepaths can be used to make a kit with multiple items

# For example...
# CKEY: /obj/item/toy/plush/random_plushie
# CKEY2: /obj/item/toy/plush/farwa, /obj/item/toy/plush/shark
# CKEY3: Kit1: /obj/item/toy/plush/moth
# CKEY3: Kit2: /obj/item/toy/plush/therapy/red, /obj/item/reagent_container/food/drinks/cans/waterbottle

0 comments on commit a4e7bcf

Please sign in to comment.