Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
silicons committed Aug 7, 2019
1 parent 39dea96 commit 2779719
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 2 deletions.
18 changes: 18 additions & 0 deletions code/__DEFINES/donator_groupings.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#define DONATOR_GROUPING_TIER_1_CONFIG_PATH /datum/config_entry/keyed_list/donator/tier_1_donators
#define DONATOR_GROUPING_TIER_2_CONFIG_PATH /datum/config_entry/keyed_list/donator/tier_2_donators
#define DONATOR_GROUPING_TIER_3_CONFIG_PATH /datum/config_entry/keyed_list/donator/tier_3_donators

#define DONATOR_GROUPING_TIER_1_CONFIG_SUBPATH keyed_list/donator/tier_1_donators
#define DONATOR_GROUPING_TIER_2_CONFIG_SUBPATH keyed_list/donator/tier_2_donators
#define DONATOR_GROUPING_TIER_3_CONFIG_SUBPATH keyed_list/donator/tier_3_donators

#define TIER_1_DONATORS CONFIG_GET(DONATOR_GROUPING_TIER_1_CONFIG_SUBPATH)
#define TIER_2_DONATORS CONFIG_GET(DONATOR_GROUPING_TIER_2_CONFIG_SUBPATH)
#define TIER_3_DONATORS CONFIG_GET(DONATOR_GROUPING_TIER_3_CONFIG_SUBPATH)

//flags
#define DONATOR_GROUP_TIER_1 "T1"
#define DONATOR_GROUP_TIER_2 "T2"
#define DONATOR_GROUP_TIER_3 "T3"

#define IS_CKEY_DONATOR_GROUP(ckey, group) is_donator_group(ckey, group)
26 changes: 26 additions & 0 deletions code/__HELPERS/donator_groupings.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Current specifications:
Donator groups in __DEFINES/donator_groupings.dm, config entries in controllers/configuration/entries/donator.dm
3 groups, Tier 1/2/3
Each tier includes the one before it (ascending)
For fast lookups, this is generated using regenerate_donator_grouping_list()
*/

/proc/is_donator_group(ckey, group)
ckey = ckey(ckey) //make sure it's ckey'd.
return GLOB.donators_by_group[group]?.Find(ckey)

/proc/regenerate_donator_grouping_list()
var/list/donator_list = GLOB.donators_by_group = list() //reinit everything

var/list/inclusive_add = list() //speed!

inclusive_add += TIER_1_DONATORS
donator_list[DONATOR_GROUP_TIER_1] = inclusive_add.Copy()
inclusive_add += TIER_2_DONATORS
donator_list[DONATOR_GROUP_TIER_2] = inclusive_add.Copy()
inclusive_add += TIER_3_DONATORS
donator_list[DONATOR_GROUP_TIER_3] = inclusive_add.Copy()
1 change: 1 addition & 0 deletions code/_globalvars/lists/misc.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GLOBAL_LIST_EMPTY(donators_by_group) //group id = donator list of ckeys
6 changes: 5 additions & 1 deletion code/controllers/configuration/config_entry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
var/abstract_type = /datum/config_entry //do not instantiate if type matches this

var/vv_VAS = TRUE //Force validate and set on VV. VAS proccall guard will run regardless.
var/postload_required = FALSE //requires running OnPostload()

var/dupes_allowed = FALSE

Expand Down Expand Up @@ -72,6 +73,9 @@
/datum/config_entry/proc/DeprecationUpdate(value)
return

/datum/config_entry/proc/OnPostload()
return

/datum/config_entry/string
config_entry_value = ""
abstract_type = /datum/config_entry/string
Expand All @@ -80,7 +84,7 @@
/datum/config_entry/string/vv_edit_var(var_name, var_value)
return var_name != "auto_trim" && ..()

/datum/config_entry/string/ValidateAndSet(str_val)
/datum/config_entry/string/ValidateAndSet(str_val, during_load)
if(!VASProcCallGuard(str_val))
return FALSE
config_entry_value = auto_trim ? trim(str_val) : str_val
Expand Down
9 changes: 8 additions & 1 deletion code/controllers/configuration/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
log_config("Loading config file [filename]...")
var/list/lines = world.file2list("[directory]/[filename]")
var/list/_entries = entries
var/list/postload_required = list()
for(var/L in lines)
L = trim(L)
if(!L)
Expand Down Expand Up @@ -157,18 +158,24 @@
else
warning("[new_ver.type] is deprecated but gave no proper return for DeprecationUpdate()")

var/validated = E.ValidateAndSet(value)
var/validated = E.ValidateAndSet(value, TRUE)
if(!validated)
log_config("Failed to validate setting \"[value]\" for [entry]")
else
if(E.modified && !E.dupes_allowed)
log_config("Duplicate setting for [entry] ([value], [E.resident_file]) detected! Using latest.")
if(E.postload_required)
postload_required[E] = TRUE

E.resident_file = filename

if(validated)
E.modified = TRUE

for(var/i in postload_required)
var/datum/config_entry/E = i
E.OnPostload()

++.

/datum/controller/configuration/can_vv_get(var_name)
Expand Down
22 changes: 22 additions & 0 deletions code/controllers/configuration/entries/donator.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/datum/config_entry/keyed_list/donator_group
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_FLAG
abstract_type = /datum/config_entry/keyed_list/donator_group

//If we're in the middle of a config load, only do the regeneration afterwards to prevent this from wasting a massive amount of CPU for list regenerations.
/datum/config_entry/keyed_list/donator_group/ValidateAndSet(str_val, during_load)
. = ..()
if(. && during_load)
regenerate_donator_grouping_list()

/datum/config_entry/keyed_list/donator_group/OnPostload()
. = ..()
regenerate_donator_grouping_list()

//This is kinda weird in that the config entries are defined here but all the handling/calculations are in __HELPERS/donator_groupings.dm

/datum/config_entry/keyed_list/donator_group/tier_1_donators

/datum/config_entry/keyed_list/donator_group/tier_2_donators

/datum/config_entry/keyed_list/donator_group/tier_3_donators
1 change: 1 addition & 0 deletions config/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $include game_options.txt
$include dbconfig.txt
$include comms.txt
$include antag_rep.txt
$include donator_groupings.txt

# You can use the @ character at the beginning of a config option to lock it from being edited in-game
# Example usage:
Expand Down
8 changes: 8 additions & 0 deletions config/donator_groupings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#this is a bad system but I'm lazy so it piggybacks off config loader system.
#Specify group followed by ckey for each ckey.

#TIER_1_DONATORS test_ckey

#TIER_2_DONATORS test_ckey

#TIER_3_DONATORS test_ckey
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ GLOBAL_LIST_EMPTY(loadout_whitelist_ids)
var/path //item-to-spawn path
var/cost = 1 //normally, each loadout costs a single point.
var/geargroupID //defines the ID that the gear inherits from the config

var/donator_group_id //New donator group ID system.

var/list/restricted_roles
var/list/ckeywhitelist
var/restricted_desc
Expand Down

0 comments on commit 2779719

Please sign in to comment.