Skip to content
Open
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
36 changes: 30 additions & 6 deletions code/__HELPERS/filters.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GLOBAL_LIST_INIT(master_filter_info, list(
"y" = 0,
"icon" = ICON_NOT_SET,
"render_source" = "",
"flags" = 0
"flags" = NONE
),
"flags" = list(
"MASK_INVERSE" = MASK_INVERSE,
Expand All @@ -30,14 +30,20 @@ GLOBAL_LIST_INIT(master_filter_info, list(
"alpha" = 255
)
),
// Not implemented, but if this isn't uncommented some windows will just error
// Not fully implemented, but if this isn't uncommented some windows will just error
// Needs either a proper matrix editor, or just a hook to our existing one
// Issue is filterrific assumes variables will have the same value type if they share the same name, which this violates
// Gotta refactor this sometime
"color" = list(
"defaults" = list(
"color" = matrix(),
"space" = FILTER_COLOR_RGB
),
"options" = list(
"space" = list(
"FILTER_COLOR_RGB" = FILTER_COLOR_RGB,
"FILTER_COLOR_HSV" = FILTER_COLOR_HSV,
"FILTER_COLOR_HSL" = FILTER_COLOR_HSL,
"FILTER_COLOR_HCY" = FILTER_COLOR_HCY
)
)
),
"displace" = list(
Expand All @@ -46,7 +52,11 @@ GLOBAL_LIST_INIT(master_filter_info, list(
"y" = 0,
"size" = null,
"icon" = ICON_NOT_SET,
"render_source" = ""
"render_source" = "",
"flags" = NONE
),
"flags" = list(
"FILTER_OVERLAY" = FILTER_OVERLAY
)
),
"drop_shadow" = list(
Expand All @@ -70,10 +80,24 @@ GLOBAL_LIST_INIT(master_filter_info, list(
"icon" = ICON_NOT_SET,
"render_source" = "",
"flags" = FILTER_OVERLAY,
"color" = "",
"color" = COLOR_WHITE,
"transform" = null,
"blend_mode" = BLEND_DEFAULT
),
"flags" = list(
"FILTER_OVERLAY" = FILTER_OVERLAY,
),
"options" = list(
"blend_mode" = list(
"BLEND_DEFAULT" = BLEND_DEFAULT,
"BLEND_OVERLAY" = BLEND_OVERLAY,
"BLEND_ADD" = BLEND_ADD,
"BLEND_SUBTRACT" = BLEND_SUBTRACT,
"BLEND_MULTIPLY" = BLEND_MULTIPLY,
"BLEND_INSET_OVERLAY" = BLEND_INSET_OVERLAY
)
)

),
"motion_blur" = list(
"defaults" = list(
Expand Down
18 changes: 13 additions & 5 deletions code/datums/datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,13 @@
var/list/copied_parameters = params.Copy()
copied_parameters["name"] = name
copied_parameters["priority"] = priority
for (var/list/filter_info as anything in filter_data)
if (filter_info["name"] == name)
filter_data -= filter_info
filter_cache -= name
break
for (var/index in 1 to length(filter_data))
var/list/filter_info = filter_data[index]
if (filter_info["name"] != name)
continue
filter_data -= list(filter_info)
filter_cache -= filter_cache[index]
break

BINARY_INSERT_DEFINE(list(copied_parameters), filter_data, SORT_VAR_NO_TYPE, copied_parameters, SORT_PRIORITY_INDEX, COMPARE_KEY)

Expand Down Expand Up @@ -486,6 +488,12 @@
var/atom/atom_cast = src // filters only work with images or atoms.
return atom_cast.filters[name]

/// Returns filter data associated with the passed key
/datum/proc/get_filter_data(name)
for (var/list/filter_info as anything in filter_data)
if (filter_info["name"] == name)
return filter_info.Copy()

/// Removes the passed filter, or multiple filters, if supplied with a list.
/datum/proc/remove_filter(name_or_names, update = TRUE)
ASSERT(isatom(src) || isimage(src))
Expand Down
6 changes: 2 additions & 4 deletions code/modules/admin/verbs/plane_debugger.dm
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,12 @@
this_relay["blend_mode"] = GLOB.blend_names["[relay.blend_mode]"]
relays += list(this_relay)

for (var/filter_id in plane.filter_data)
var/list/filter = plane.filter_data[filter_id]
for (var/list/filter in plane.filter_data)
if(!filter["render_source"])
continue

var/list/filter_info = filter.Copy()
filter_info["name"] = filter_id
filter_info["our_ref"] = "[plane.plane]-[filter_id]"
filter_info["our_ref"] = "[plane.plane]-[filter_info["name"]]"
filters += list(filter_info)

this_plane["relays"] = relays
Expand Down
33 changes: 11 additions & 22 deletions code/modules/admin/view_variables/filterrific.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
switch(action)
if("add_filter")
var/target_name = params["name"]
while(target.filter_data && target.filter_data[target_name])
while(target.get_filter(target_name))
target_name = "[target_name]-dupe"
target.add_filter(target_name, params["priority"], list("type" = params["type"]))
. = TRUE
if("remove_filter")
target.remove_filter(params["name"])
. = TRUE
if("rename_filter")
var/list/filter_data = target.filter_data[params["name"]]
var/list/filter_info = target.get_filter_data(params["name"])
target.remove_filter(params["name"])
target.add_filter(params["new_name"], filter_data["priority"], filter_data)
target.add_filter(params["new_name"], filter_data["priority"], filter_info)
. = TRUE
if("edit_filter")
target.remove_filter(params["name"])
Expand All @@ -56,15 +56,7 @@
target.transition_filter(params["name"], params["new_data"], 4)
. = TRUE
if("modify_filter_value")
var/list/old_filter_data = target.filter_data[params["name"]]
var/list/new_filter_data = old_filter_data.Copy()
for(var/entry in params["new_data"])
new_filter_data[entry] = params["new_data"][entry]
for(var/entry in new_filter_data)
if(entry == GLOB.master_filter_info[old_filter_data["type"]]["defaults"][entry])
new_filter_data.Remove(entry)
target.remove_filter(params["name"])
target.add_filter(params["name"], old_filter_data["priority"], new_filter_data)
target.modify_filter(params["name"], params["new_data"])
. = TRUE
if("modify_color_value")
var/new_color = input(usr, "Pick new filter color", "Filteriffic Colors!") as color|null
Expand All @@ -83,16 +75,13 @@
var/target_path = text2path(params["path"])
if(!target_path)
return
var/filters_to_copy = target.filters
var/filter_data_to_copy = target.filter_data
var/list/filter_data_to_copy = target.filter_data
var/count = 0
for(var/thing in world.contents)
if(istype(thing, target_path))
var/atom/thing_at = thing
thing_at.filters = filters_to_copy
thing_at.filter_data = filter_data_to_copy
count += 1
for(var/atom/thing_at as anything in world.contents)
if(!istype(thing_at, target_path))
continue
thing_at.filter_data = filter_data_to_copy.Copy()
thing_at.update_filters()
count += 1
message_admins("LOCAL CLOWN [usr.ckey] JUST MASS FILTER EDITED [count] WITH PATH OF [params["path"]]!")
log_admin("LOCAL CLOWN [usr.ckey] JUST MASS FILTER EDITED [count] WITH PATH OF [params["path"]]!")


52 changes: 46 additions & 6 deletions tgui/packages/tgui/interfaces/Filteriffic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,29 @@ const FilterFlagsEntry = (props) => {
));
};

const FilterOptionsEntry = (props) => {
const { name, value, filterName, filterType } = props;
const { act, data } = useBackend();
const filterInfo = data.filter_info;
const options = filterInfo[filterType].options[name];
return (
<Dropdown
selected={Object.keys(options).find((x) => value === options[x])}
options={Object.keys(options)}
onSelected={(value) =>
act('modify_filter_value', {
name: filterName,
new_data: {
[name]: options[value],
},
})
}
/>
);
};

const FilterDataEntry = (props) => {
const { name, value, hasValue, filterName } = props;
const { name, value, hasValue, filterName, filterType } = props;

const filterEntryTypes = {
int: <FilterIntegerEntry {...props} />,
Expand All @@ -184,6 +205,8 @@ const FilterDataEntry = (props) => {
color: <FilterColorEntry {...props} />,
icon: <FilterIconEntry {...props} />,
flags: <FilterFlagsEntry {...props} />,
options: <FilterOptionsEntry {...props} />,
plug: 'Not Implemented',
};

const filterEntryMap = {
Expand All @@ -193,19 +216,32 @@ const FilterDataEntry = (props) => {
render_source: 'string',
flags: 'flags',
size: 'float',
color: 'color',
color: { default: 'color', color: 'plug' },
offset: 'float',
radius: 'float',
radius: 'int',
falloff: 'float',
density: 'int',
threshold: 'float',
alpha: 'int',
threshold: { rays: 'float', bloom: 'color' },
factor: 'float',
repeat: 'int',
space: 'options',
blend_mode: 'options',
transform: 'plug',
};

let filterInputType = filterEntryMap[name];
// i hate javascript, this checks if its a dict
if (filterInputType !== undefined && filterInputType.constructor === Object) {
filterInputType = filterInputType[filterType] || filterInputType.default;
}

return (
<LabeledList.Item label={name}>
{filterEntryTypes[filterEntryMap[name]] || 'Not Found (This is an error)'}{' '}
<Box inline>
{filterEntryTypes[filterInputType] ||
'Not Found (This is an error)'}{' '}
</Box>
{!hasValue && (
<Box inline color="average">
(Default)
Expand Down Expand Up @@ -341,7 +377,11 @@ export const Filteriffic = (props) => {
<Box>No filters</Box>
) : (
map(filters, (entry, key) => (
<FilterEntry filterDataEntry={entry} name={key} key={key} />
<FilterEntry
filterDataEntry={entry}
name={entry.name}
key={entry.name}
/>
))
)}
</Section>
Expand Down
Loading