Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cfg): new configuation solution #12562

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ data/
cfg/
# ignore config, but not subdirs
config/*
!config/names/
!config/example/
!config/translation/
!config/warnings_templates/
!config/schema/
!config/default/
!config/dev/
!config/lobby_art/README.md
build_log.txt
use_map
stopserver
Expand Down
12 changes: 10 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
"type": "byond",
"request": "launch",
"name": "DS Debug",
"dmb": "${workspaceFolder}/${command:CurrentDMB}"
"dmb": "${workspaceFolder}/${command:CurrentDMB}",
"env": {
"MODE": "dev",
"ONYXBAY__GENERAL__SERVER_ID": "test"
}
},
{
"type": "byond",
"request": "launch",
"name": "Build & DS Debug",
"preLaunchTask": "dm: build - ${command:CurrentDME}",
"dmb": "${workspaceFolder}/${command:CurrentDMB}"
"dmb": "${workspaceFolder}/${command:CurrentDMB}",
"env": {
"MODE": "dev",
"ONYXBAY__GENERAL__SERVER_ID": "test"
}
},
{
"name": "Nano Watch",
Expand Down
8 changes: 6 additions & 2 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
#include "code\_global_vars\mobs.dm"
#include "code\_global_vars\radio.dm"
#include "code\_global_vars\regexes.dm"
#include "code\_global_vars\sensitive.dm"
#include "code\_global_vars\sfx.dm"
#include "code\_global_vars\lists\areas.dm"
#include "code\_global_vars\lists\flavor.dm"
Expand Down Expand Up @@ -369,15 +368,19 @@
#include "code\datums\configuration\ban_section.dm"
#include "code\datums\configuration\character_setup_section.dm"
#include "code\datums\configuration\configuration_section.dm"
#include "code\datums\configuration\custom_section.dm"
#include "code\datums\configuration\database_section.dm"
#include "code\datums\configuration\donations_section.dm"
#include "code\datums\configuration\error_section.dm"
#include "code\datums\configuration\events_section.dm"
#include "code\datums\configuration\external_section.dm"
#include "code\datums\configuration\game_section.dm"
#include "code\datums\configuration\gamemode_section.dm"
#include "code\datums\configuration\general_section.dm"
#include "code\datums\configuration\ghost_section.dm"
#include "code\datums\configuration\health_section.dm"
#include "code\datums\configuration\indigo_bot_section.dm"
#include "code\datums\configuration\jobs_configuration.dm"
#include "code\datums\configuration\link_section.dm"
#include "code\datums\configuration\log_section.dm"
#include "code\datums\configuration\mapping_section.dm"
Expand All @@ -387,7 +390,9 @@
#include "code\datums\configuration\overmap.dm"
#include "code\datums\configuration\revival_section.dm"
#include "code\datums\configuration\server_configuration.dm"
#include "code\datums\configuration\texts_section.dm"
#include "code\datums\configuration\vote_section.dm"
#include "code\datums\configuration\whitelist_section.dm"
#include "code\datums\elements\_element.dm"
#include "code\datums\elements\connect_loc.dm"
#include "code\datums\elements\debris.dm"
Expand Down Expand Up @@ -1927,7 +1932,6 @@
#include "code\modules\examine\descriptions\structures.dm"
#include "code\modules\examine\descriptions\turfs.dm"
#include "code\modules\examine\descriptions\weapons.dm"
#include "code\modules\ext_scripts\irc.dm"
#include "code\modules\flufftext\Dreaming.dm"
#include "code\modules\flufftext\TextFilters.dm"
#include "code\modules\food\recipes_microwave.dm"
Expand Down
1 change: 1 addition & 0 deletions code/__defines/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define R_HOST 0x8000 //higher than this will overflow
#define R_INVESTIGATE (R_ADMIN|R_MOD)

#define R_ALL (R_BUILDMODE | R_ADMIN | R_BAN | R_FUN | R_SERVER | R_DEBUG | R_POSSESS | R_PERMISSIONS | R_STEALTH | R_REJUVINATE | R_VAREDIT | R_SOUNDS | R_SPAWN | R_MOD | R_MENTOR | R_HOST)
#define R_MAXPERMISSION 0x8000 // This holds the maximum value for a permission. It is used in iteration, so keep it updated.

#define TICKET_CLOSED 0 // Ticket has been resolved or declined
Expand Down
116 changes: 24 additions & 92 deletions code/__defines/rust_g.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,6 @@
/// Gets the version of rust_g
/proc/rustg_get_version() return RUSTG_CALL(RUST_G, "get_version")()


/**
* Sets up the Aho-Corasick automaton with its default options.
*
* The search patterns list and the replacements must be of the same length when replace is run, but an empty replacements list is allowed if replacements are supplied with the replace call
* Arguments:
* * key - The key for the automaton, to be used with subsequent rustg_acreplace/rustg_acreplace_with_replacements calls
* * patterns - A non-associative list of strings to search for
* * replacements - Default replacements for this automaton, used with rustg_acreplace
*/
#define rustg_setup_acreplace(key, patterns, replacements) RUSTG_CALL(RUST_G, "setup_acreplace")(key, json_encode(patterns), json_encode(replacements))

/**
* Sets up the Aho-Corasick automaton using supplied options.
*
* The search patterns list and the replacements must be of the same length when replace is run, but an empty replacements list is allowed if replacements are supplied with the replace call
* Arguments:
* * key - The key for the automaton, to be used with subsequent rustg_acreplace/rustg_acreplace_with_replacements calls
* * options - An associative list like list("anchored" = 0, "ascii_case_insensitive" = 0, "match_kind" = "Standard"). The values shown on the example are the defaults, and default values may be omitted. See the identically named methods at https://docs.rs/aho-corasick/latest/aho_corasick/struct.AhoCorasickBuilder.html to see what the options do.
* * patterns - A non-associative list of strings to search for
* * replacements - Default replacements for this automaton, used with rustg_acreplace
*/
#define rustg_setup_acreplace_with_options(key, options, patterns, replacements) RUSTG_CALL(RUST_G, "setup_acreplace")(key, json_encode(options), json_encode(patterns), json_encode(replacements))

/**
* Run the specified replacement engine with the provided haystack text to replace, returning replaced text.
*
* Arguments:
* * key - The key for the automaton
* * text - Text to run replacements on
*/
#define rustg_acreplace(key, text) RUSTG_CALL(RUST_G, "acreplace")(key, text)

/**
* Run the specified replacement engine with the provided haystack text to replace, returning replaced text.
*
* Arguments:
* * key - The key for the automaton
* * text - Text to run replacements on
* * replacements - Replacements for this call. Must be the same length as the set-up patterns
*/
#define rustg_acreplace_with_replacements(key, text, replacements) RUSTG_CALL(RUST_G, "acreplace_with_replacements")(key, text, json_encode(replacements))

/**
* This proc generates a cellular automata noise grid which can be used in procedural generation methods.
*
Expand All @@ -107,6 +64,30 @@
#define rustg_cnoise_generate(percentage, smoothing_iterations, birth_limit, death_limit, width, height) \
RUSTG_CALL(RUST_G, "cnoise_generate")(percentage, smoothing_iterations, birth_limit, death_limit, width, height)

/// Call this first to initialize a config builder.
/// Then use the `rustg_cfg_add_*` macros to configure the builder
/// (calling these macros before `begin_builder` of `end_builder` will cause an error).
/// When you are done with configuring the builder - call `rustg_cfg_end_builder`,
/// then you can call `rustg_cfg_try_deserialize` which will return a JSON string with your config.
///
/// **You can only call `rustg_cfg_try_deserialize` only once,
/// then you have to do everything from `rustg_cfg_begin_builder` and to the end again before you can call this again.**
#define rustg_cfg_begin_builder(...) RUSTG_CALL(RUST_G, "cfg_begin_builder")()

/// Add files that match the glob pattern, for example: `config/*`
#define rustg_cfg_add_source_glob(pattern) RUSTG_CALL(RUST_G, "cfg_add_source_glob")(pattern)

/// Add files that match the glob pattern, for example: `config/*`Add the file with the specified path. The extension is optional.
#define rustg_cfg_add_source_file(name) RUSTG_CALL(RUST_G, "cfg_add_source_file")(name)

/// Use environment variables. The prefix is optional.
#define rustg_cfg_add_source_env(prefix, separator) RUSTG_CALL(RUST_G, "cfg_add_source_env")(isnull(prefix) ? "" : prefix, isnull(separator) ? "" : separator)

#define rustg_cfg_end_builder(...) RUSTG_CALL(RUST_G, "cfg_end_builder")()

/// Returns a JSON string.
#define rustg_cfg_try_deserialize(...) RUSTG_CALL(RUST_G, "cfg_try_deserialize")()

/**
* This proc generates a grid of perlin-like noise
*
Expand All @@ -124,37 +105,6 @@
RUSTG_CALL(RUST_G, "dbp_generate")(seed, accuracy, stamp_size, world_size, lower_range, upper_range)


#define rustg_dmi_strip_metadata(fname) RUSTG_CALL(RUST_G, "dmi_strip_metadata")(fname)
#define rustg_dmi_create_png(path, width, height, data) RUSTG_CALL(RUST_G, "dmi_create_png")(path, width, height, data)
#define rustg_dmi_resize_png(path, width, height, resizetype) RUSTG_CALL(RUST_G, "dmi_resize_png")(path, width, height, resizetype)
/**
* input: must be a path, not an /icon; you have to do your own handling if it is one, as icon objects can't be directly passed to rustg.
*
* output: json_encode'd list. json_decode to get a flat list with icon states in the order they're in inside the .dmi
*/
#define rustg_dmi_icon_states(fname) RUSTG_CALL(RUST_G, "dmi_icon_states")(fname)

#define rustg_file_read(fname) RUSTG_CALL(RUST_G, "file_read")(fname)
#define rustg_file_exists(fname) (RUSTG_CALL(RUST_G, "file_exists")(fname) == "true")
#define rustg_file_write(text, fname) RUSTG_CALL(RUST_G, "file_write")(text, fname)
#define rustg_file_append(text, fname) RUSTG_CALL(RUST_G, "file_append")(text, fname)
#define rustg_file_get_line_count(fname) text2num(RUSTG_CALL(RUST_G, "file_get_line_count")(fname))
#define rustg_file_seek_line(fname, line) RUSTG_CALL(RUST_G, "file_seek_line")(fname, "[line]")

#ifdef RUSTG_OVERRIDE_BUILTINS
#define file2text(fname) rustg_file_read("[fname]")
#define text2file(text, fname) rustg_file_append(text, "[fname]")
#endif

/// Returns the git hash of the given revision, ex. "HEAD".
#define rustg_git_revparse(rev) RUSTG_CALL(RUST_G, "rg_git_revparse")(rev)

/**
* Returns the date of the given revision in the format YYYY-MM-DD.
* Returns null if the revision is invalid.
*/
#define rustg_git_commit_date(rev) RUSTG_CALL(RUST_G, "rg_git_commit_date")(rev)

#define rustg_hash_string(algorithm, text) RUSTG_CALL(RUST_G, "hash_string")(algorithm, text)
#define rustg_hash_file(algorithm, fname) RUSTG_CALL(RUST_G, "hash_file")(algorithm, fname)
#define rustg_hash_generate_totp(seed) RUSTG_CALL(RUST_G, "generate_totp")(seed)
Expand Down Expand Up @@ -252,9 +202,6 @@

#define rustg_json_is_valid(text) (RUSTG_CALL(RUST_G, "json_is_valid")(text) == "true")

#define rustg_log_write(fname, text, format) RUSTG_CALL(RUST_G, "log_write")(fname, text, format)
/proc/rustg_log_close_all() return RUSTG_CALL(RUST_G, "log_close_all")()

#define rustg_noise_get_at_coordinates(seed, x, y) RUSTG_CALL(RUST_G, "noise_get_at_coordinates")(seed, x, y)

/// Register a list of nodes into a rust library. This list of nodes must have been serialized in a json.
Expand Down Expand Up @@ -532,21 +479,6 @@
/// https://en.wikipedia.org/wiki/Normal-inverse_Gaussian_distribution
#define rustg_rand_normal_inverse_gaussian(alpha, beta) text2num(RUSTG_CALL(RUST_G, "rand_normal_inverse_gaussian")(istext(alpha) ? alpha : num2text(alpha), istext(beta) ? beta : num2text(beta)))

#define rustg_sql_connect_pool(options) RUSTG_CALL(RUST_G, "sql_connect_pool")(options)
#define rustg_sql_query_async(handle, query, params) RUSTG_CALL(RUST_G, "sql_query_async")(handle, query, params)
#define rustg_sql_query_blocking(handle, query, params) RUSTG_CALL(RUST_G, "sql_query_blocking")(handle, query, params)
#define rustg_sql_connected(handle) RUSTG_CALL(RUST_G, "sql_connected")(handle)
#define rustg_sql_disconnect_pool(handle) RUSTG_CALL(RUST_G, "sql_disconnect_pool")(handle)
#define rustg_sql_check_query(job_id) RUSTG_CALL(RUST_G, "sql_check_query")("[job_id]")

#define rustg_time_microseconds(id) text2num(RUSTG_CALL(RUST_G, "time_microseconds")(id))
#define rustg_time_milliseconds(id) text2num(RUSTG_CALL(RUST_G, "time_milliseconds")(id))
#define rustg_time_reset(id) RUSTG_CALL(RUST_G, "time_reset")(id)

/// Returns the timestamp as a string
/proc/rustg_unix_timestamp()
return RUSTG_CALL(RUST_G, "unix_timestamp")()

#define rustg_raw_read_toml_file(path) json_decode(RUSTG_CALL(RUST_G, "toml_file_to_json")(path) || "null")

/proc/rustg_read_toml_file(path)
Expand Down
4 changes: 2 additions & 2 deletions code/_global_vars/lists/flavor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ GLOBAL_LIST_INIT(robot_module_types, list(
)) // This shouldn't be a static list. Am I the only one who cares about extendability around here?

// Noises made when hit while typing.
GLOBAL_LIST_INIT(hit_appends, world.file2list("config/translation/hit_appends.txt"))
GLOBAL_LIST_INIT(hit_appends, world.file2list("strings/translation/hit_appends.txt"))

// Noises made by lizards when disturbed.
GLOBAL_LIST_INIT(lizard_noises, world.file2list("config/translation/lizard_noises.txt"))
GLOBAL_LIST_INIT(lizard_noises, world.file2list("strings/translation/lizard_noises.txt"))

// Some scary sounds.
GLOBAL_LIST_INIT(scarySounds, list(
Expand Down
34 changes: 17 additions & 17 deletions code/_global_vars/lists/names.dm
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
GLOBAL_LIST_INIT(ai_names, world.file2list("config/names/ai.txt"))
GLOBAL_LIST_INIT(wizard_first, world.file2list("config/names/wizardfirst.txt"))
GLOBAL_LIST_INIT(wizard_second, world.file2list("config/names/wizardsecond.txt"))
GLOBAL_LIST_INIT(ninja_titles, world.file2list("config/names/ninjatitle.txt"))
GLOBAL_LIST_INIT(ninja_names, world.file2list("config/names/ninjaname.txt"))
GLOBAL_LIST_INIT(commando_names, world.file2list("config/names/death_commando.txt"))
GLOBAL_LIST_INIT(first_names_male, world.file2list("config/names/first_male.txt"))
GLOBAL_LIST_INIT(first_names_female, world.file2list("config/names/first_female.txt"))
GLOBAL_LIST_INIT(last_names, world.file2list("config/names/last.txt"))
GLOBAL_LIST_INIT(clown_names, world.file2list("config/names/clown.txt"))
GLOBAL_LIST_INIT(golem_names, world.file2list("config/names/golem.txt"))
GLOBAL_LIST_INIT(ai_names, world.file2list("strings/names/ai.txt"))
GLOBAL_LIST_INIT(wizard_first, world.file2list("strings/names/wizardfirst.txt"))
GLOBAL_LIST_INIT(wizard_second, world.file2list("strings/names/wizardsecond.txt"))
GLOBAL_LIST_INIT(ninja_titles, world.file2list("strings/names/ninjatitle.txt"))
GLOBAL_LIST_INIT(ninja_names, world.file2list("strings/names/ninjaname.txt"))
GLOBAL_LIST_INIT(commando_names, world.file2list("strings/names/death_commando.txt"))
GLOBAL_LIST_INIT(first_names_male, world.file2list("strings/names/first_male.txt"))
GLOBAL_LIST_INIT(first_names_female, world.file2list("strings/names/first_female.txt"))
GLOBAL_LIST_INIT(last_names, world.file2list("strings/names/last.txt"))
GLOBAL_LIST_INIT(clown_names, world.file2list("strings/names/clown.txt"))
GLOBAL_LIST_INIT(golem_names, world.file2list("strings/names/golem.txt"))

GLOBAL_LIST_INIT(rus_nouns, world.file2list("config/names/rus_nouns.txt"))
GLOBAL_LIST_INIT(rus_adjectives, world.file2list("config/names/rus_adjectives.txt"))
GLOBAL_LIST_INIT(rus_verbs, world.file2list("config/names/rus_verbs.txt"))
GLOBAL_LIST_INIT(rus_occupations, world.file2list("config/names/rus_occupations.txt"))
GLOBAL_LIST_INIT(rus_bays, world.file2list("config/names/rus_bays.txt"))
GLOBAL_LIST_INIT(rus_local_terms, world.file2list("config/names/rus_local_terms.txt"))
GLOBAL_LIST_INIT(rus_nouns, world.file2list("strings/names/rus_nouns.txt"))
GLOBAL_LIST_INIT(rus_adjectives, world.file2list("strings/names/rus_adjectives.txt"))
GLOBAL_LIST_INIT(rus_verbs, world.file2list("strings/names/rus_verbs.txt"))
GLOBAL_LIST_INIT(rus_occupations, world.file2list("strings/names/rus_occupations.txt"))
GLOBAL_LIST_INIT(rus_bays, world.file2list("strings/names/rus_bays.txt"))
GLOBAL_LIST_INIT(rus_local_terms, world.file2list("strings/names/rus_local_terms.txt"))
//loaded on startup because of "
//would include in rsc if ' was used
19 changes: 0 additions & 19 deletions code/_global_vars/sensitive.dm

This file was deleted.

Loading
Loading