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

GAGS: Rust-g #10455

Merged
merged 8 commits into from
Feb 16, 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
14 changes: 14 additions & 0 deletions code/__DEFINES/rust_g.dm
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@
#define rustg_iconforge_cache_valid(input_hash, dmi_hashes, sprites) RUSTG_CALL(RUST_G, "iconforge_cache_valid")(input_hash, dmi_hashes, sprites)
/// Returns a job_id for use with rustg_iconforge_check()
#define rustg_iconforge_cache_valid_async(input_hash, dmi_hashes, sprites) RUSTG_CALL(RUST_G, "iconforge_cache_valid_async")(input_hash, dmi_hashes, sprites)
/// Provided a /datum/greyscale_config typepath, JSON string containing the greyscale config, and path to a DMI file containing the base icons,
/// Loads that config into memory for later use by rustg_iconforge_gags(). The config_path is the unique identifier used later.
/// JSON Config schema: https://hackmd.io/@tgstation/GAGS-Layer-Types
/// Unsupported features: color_matrix layer type, 'or' blend_mode. May not have BYOND parity with animated icons or varying dirs between layers.
/// Returns "OK" if successful, otherwise, returns a string containing the error.
#define rustg_iconforge_load_gags_config(config_path, config_json, config_icon_path) RUSTG_CALL(RUST_G, "iconforge_load_gags_config")("[config_path]", config_json, config_icon_path)
/// Given a config_path (previously loaded by rustg_iconforge_load_gags_config), and a string of hex colors formatted as "#ff00ff#ffaa00"
/// Outputs a DMI containing all of the states within the config JSON to output_dmi_path, creating any directories leading up to it if necessary.
/// Returns "OK" if successful, otherwise, returns a string containing the error.
#define rustg_iconforge_gags(config_path, colors, output_dmi_path) RUSTG_CALL(RUST_G, "iconforge_gags")("[config_path]", colors, output_dmi_path)
/// Returns a job_id for use with rustg_iconforge_check()
#define rustg_iconforge_load_gags_config_async(config_path, config_json, config_icon_path) RUSTG_CALL(RUST_G, "iconforge_load_gags_config_async")("[config_path]", config_json, config_icon_path)
/// Returns a job_id for use with rustg_iconforge_check()
#define rustg_iconforge_gags_async(config_path, colors, output_dmi_path) RUSTG_CALL(RUST_G, "iconforge_gags_async")("[config_path]", colors, output_dmi_path)

#define RUSTG_ICONFORGE_BLEND_COLOR "BlendColor"
#define RUSTG_ICONFORGE_BLEND_ICON "BlendIcon"
Expand Down
29 changes: 28 additions & 1 deletion code/controllers/subsystem/processing/greyscale.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PROCESSING_SUBSYSTEM_DEF(greyscale)

var/list/datum/greyscale_config/configurations = list()
var/list/datum/greyscale_layer/layer_types = list()
var/list/gags_cache = list()

/datum/controller/subsystem/processing/greyscale/Initialize(start_timeofday)
for(var/datum/greyscale_layer/fake_type as anything in subtypesof(/datum/greyscale_layer))
Expand All @@ -21,27 +22,53 @@ PROCESSING_SUBSYSTEM_DEF(greyscale)
var/datum/greyscale_config/config = configurations[greyscale_type]
config.Refresh()

var/list/job_ids = list()
// This final verification step is for things that need other greyscale configurations to be finished loading
for(var/greyscale_type as anything in configurations)
CHECK_TICK
var/datum/greyscale_config/config = configurations[greyscale_type]
config.CrossVerify()
job_ids += rustg_iconforge_load_gags_config_async(greyscale_type, config.raw_json_string, config.string_icon_file)

UNTIL(jobs_completed(job_ids))
return ..()

/datum/controller/subsystem/processing/greyscale/proc/jobs_completed(list/job_ids)
for(var/job in job_ids)
var/result = rustg_iconforge_check(job)
if(result == RUSTG_JOB_NO_RESULTS_YET)
return FALSE
if(result != "OK")
stack_trace("Error during rustg_iconforge_load_gags_config job: [result]")
job_ids -= job
return TRUE

/datum/controller/subsystem/processing/greyscale/proc/RefreshConfigsFromFile()
for(var/i in configurations)
configurations[i].Refresh(TRUE)

/datum/controller/subsystem/processing/greyscale/proc/GetColoredIconByType(type, list/colors)
if(!ispath(type, /datum/greyscale_config))
CRASH("An invalid greyscale configuration was given to `GetColoredIconByType()`: [type]")
if(!initialized)
CRASH("GetColoredIconByType() called before greyscale subsystem initialized!")
type = "[type]"
if(istype(colors)) // It's the color list format
colors = colors.Join()
else if(!istext(colors))
CRASH("Invalid colors were given to `GetColoredIconByType()`: [colors]")
return configurations[type].Generate(colors)
var/uid = "[replacetext(replacetext(type, "/datum/greyscale_config", ""), "/", "-")]-[colors]"
var/cached = gags_cache[uid]
if(cached)
return cached
var/path = "tmp/gags/gags-[uid].dmi"
var/err = rustg_iconforge_gags(type, colors, path)
if(err != "OK")
CRASH(err)
// We'll just explicitly do fcopy_rsc here, so the game doesn't have to do it again from the cached file.
var/result = fcopy_rsc(file(path))
gags_cache[uid] = result
return result //configurations[type].Generate(colors)

/datum/controller/subsystem/processing/greyscale/proc/GetColoredIconEntryByType(type, list/colors, target_icon_state)
if(!ispath(type, /datum/greyscale_config))
Expand Down
8 changes: 6 additions & 2 deletions code/datums/greyscale/_greyscale_config.dm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
/// The md5 file hash for the json configuration. Used to check if the file has changed
var/json_config_hash

/// The raw string contnts of the JSON config file.
var/raw_json_string

/// String path to the icon file, used for reloading
var/string_icon_file

Expand Down Expand Up @@ -103,7 +106,7 @@
var/changed = FALSE

json_config = file(string_json_config)
var/json_hash = md5asfile(json_config)
var/json_hash = rustg_hash_file("md5", json_config)
if(json_config_hash != json_hash)
json_config_hash = json_hash
changed = TRUE
Expand All @@ -121,7 +124,8 @@
if(!changed)
return FALSE

var/list/raw = json_decode(file2text(json_config))
raw_json_string = rustg_file_read(json_config)
var/list/raw = json_decode(raw_json_string)
ReadIconStateConfiguration(raw)

if(!length(icon_states))
Expand Down
7 changes: 6 additions & 1 deletion code/datums/greyscale/layer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,15 @@

/datum/greyscale_layer/icon_state/Initialize(icon_file)
. = ..()
src.icon_file = icon_file
#ifdef UNIT_TESTS
// icon_states is slow as fuck and rustg is no better in this case.
// We don't use GAGS enough to care if some fool puts in the wrong iconstate in the live editor, and furthermore sacrifice 0.2sec of init for said fools
// Because configs are loaded by the greyscale subsystem this should always catch during unit tests :)
var/list/icon_states = icon_states(icon_file)
if(!(icon_state in icon_states))
CRASH("Configured icon state \[[icon_state]\] was not found in [icon_file]. Double check your json configuration.")
#endif
src.icon_file = icon_file
icon = new(icon_file, icon_state)

if(length(color_ids) > 1)
Expand Down
2 changes: 1 addition & 1 deletion dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export BYOND_MINOR=1589
export RUST_VERSION=1.70

#rust_g git tag
export RUST_G_VERSION=3.1.1
export RUST_G_VERSION=3.1.2

#node version
export NODE_VERSION=18
Expand Down
Binary file modified rust_g.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions tools/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fi
mkdir -p \
$1/_maps \
$1/auxtools \
$1/code/datums/greyscale/json_configs \
$1/data/spritesheets \
$1/icons \
$1/sound/runtime \
Expand All @@ -26,7 +27,9 @@ fi

cp beestation.dmb beestation.rsc $1/
cp -r _maps/* $1/_maps/
cp -r code/datums/greyscale/json_configs/* $1/code/datums/greyscale/json_configs/
cp -r icons/* $1/icons/
cp -r sound/runtime/* $1/sound/runtime/
cp -r strings/* $1/strings/
cp -r tgui/public/* $1/tgui/public/
cp -r tgui/packages/tgfont/dist/* $1/tgui/packages/tgfont/dist/
Expand Down
Loading