Bitflag Metainfo, Usable (Happy 90000th) (#90000)

## About The Pull Request

Makes wrapper procs to support working with bitflags as defined "things"
rather then EXCLUSIVELY numbers, mostly for getting random flags.

I've ~~also added a unit test to prevent bitfields from being double
defined~~ stolen some code form moth to make double definitions here a
compile error.

This does rely on people actually using the bitfield lists, essentially
upgrading them from breaking just admin debug to POTENTIALLY breaking
game logic (slightly). Would like input on this @tgstation/commit-access

## Why It's Good For The Game

More tools for feature coders to play with, more sane code
This commit is contained in:
LemonInTheDark
2025-03-19 19:54:03 +00:00
committed by GitHub
parent 443289499c
commit ded0ee6362
7 changed files with 45 additions and 31 deletions
@@ -86,21 +86,21 @@
items += debug_variable(key, val, level + 1, sanitize = sanitize)
return "<a href='byond://?_src_=vars;[HrefToken()];[link_vars]'>/list ([list_value.len])</a><ul>[items.Join()]</ul>"
else
return "<a href='byond://?_src_=vars;[HrefToken()];[link_vars]'>/list ([list_value.len])</a>"
return "<a href='byond://?_src_=vars;[HrefToken()];[link_vars]'>/list ([list_value.len])</a>"
if(name in GLOB.bitfields)
var/list/flags = list()
for (var/i in GLOB.bitfields[name])
if (value & GLOB.bitfields[name][i])
flags += i
if(length(flags))
return "[VV_HTML_ENCODE(jointext(flags, ", "))]"
else
return "NONE"
else
// if it's a number, is it a bitflag?
var/list/valid_bitflags = get_valid_bitflags(name)
if(!length(valid_bitflags))
return "<span class='value'>[VV_HTML_ENCODE(value)]</span>"
var/list/flags = list()
for (var/bit_name in valid_bitflags)
if (value & valid_bitflags[bit_name])
flags += bit_name
if(length(flags))
return "[VV_HTML_ENCODE(flags.Join(", "))]"
return "NONE"
/datum/proc/debug_variable_value(name, level, datum/owner, sanitize, display_flags)
if("[src]" != "[type]") // If we have a name var, let's use it.
return "<a href='byond://?_src_=vars;[HrefToken()];Vars=[REF(src)]'>[src] [type] [REF(src)]</a>"