-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
refactor: Elementize decals. #27104
Open
warriorstar-orion
wants to merge
6
commits into
ParadiseSS13:master
Choose a base branch
from
warriorstar-orion:refactor/decal-element
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+197
−87
Open
refactor: Elementize decals. #27104
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b35ffe9
refactor: Elementize decals.
warriorstar-orion b8063ea
fix for cases of managed_overlay being a single item
warriorstar-orion a0a1af0
Merge remote-tracking branch 'upstream/master' into refactor/decal-el…
warriorstar-orion 45a4b55
Update code/datums/elements/decal_element.dm
warriorstar-orion ffd4ca9
Merge branch 'refactor/decal-element' of github.com:warriorstar-orion…
warriorstar-orion 0c16457
review comments
warriorstar-orion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// NOTE: | ||
// This is an incredibly piecemeal port of /tg/'s decal element. | ||
// It does not include several pieces of functionality that exist in /tg/. | ||
// | ||
// Namely: | ||
// - It does not support smoothing decals | ||
// - It does not send a signal when a decal is detached (used for trapdoors on /tg/) | ||
// - It does not support custom plane configuration as this behavior seems primarily concerned with multi-z | ||
|
||
/datum/element/decal | ||
element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH_ON_HOST_DESTROY | ||
argument_hash_start_idx = 2 | ||
/// Whether this decal can be cleaned. | ||
var/cleanable | ||
/// A description this decal appends to the target's examine message. | ||
var/description | ||
/// If true this was initialized with no set direction - will follow the parent dir. | ||
var/directional | ||
/// The base icon state that this decal was initialized with. | ||
var/base_icon_state | ||
/// The overlay applied by this decal to the target. | ||
var/mutable_appearance/pic | ||
|
||
/datum/element/decal/Attach(atom/target, _icon, _icon_state, _dir, _layer=TURF_LAYER, _alpha=255, _color, _cleanable=FALSE, _description, mutable_appearance/_pic) | ||
. = ..() | ||
if(!isatom(target)) | ||
return ELEMENT_INCOMPATIBLE | ||
if(_pic) | ||
pic = _pic | ||
else if(!generate_appearance(_icon, _icon_state, _dir, _layer, _color, _alpha, target)) | ||
return ELEMENT_INCOMPATIBLE | ||
description = _description | ||
cleanable = _cleanable | ||
directional = _dir | ||
base_icon_state = _icon_state | ||
|
||
RegisterSignal(target, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(apply_overlay), TRUE) | ||
if(target.initialized) | ||
target.update_appearance(UPDATE_OVERLAYS) //could use some queuing here now maybe. | ||
else | ||
RegisterSignal(target, COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZE, PROC_REF(late_update_icon), TRUE) | ||
if(isitem(target)) | ||
INVOKE_ASYNC(target, TYPE_PROC_REF(/obj/item/, update_slot_icon), TRUE) | ||
if(_dir) | ||
RegisterSignal(target, COMSIG_ATOM_DECALS_ROTATING, PROC_REF(shuttle_rotate), TRUE) | ||
SSdcs.RegisterSignal(target, COMSIG_ATOM_DIR_CHANGE, TYPE_PROC_REF(/datum/controller/subsystem/processing/dcs, rotate_decals), override=TRUE) | ||
if(_cleanable) | ||
RegisterSignal(target, COMSIG_COMPONENT_CLEAN_ACT, PROC_REF(clean_react), TRUE) | ||
if(_description) | ||
RegisterSignal(target, COMSIG_PARENT_EXAMINE, PROC_REF(examine), TRUE) | ||
|
||
RegisterSignal(target, COMSIG_TURF_ON_SHUTTLE_MOVE, PROC_REF(shuttle_move_react), TRUE) | ||
|
||
/// Remove old decals and apply new decals after rotation as necessary | ||
/datum/controller/subsystem/processing/dcs/proc/rotate_decals(datum/source, old_dir, new_dir) | ||
SIGNAL_HANDLER // COMSIG_ATOM_DIR_CHANGE | ||
|
||
if(old_dir == new_dir) | ||
return | ||
|
||
var/list/datum/element/decal/old_decals = list() //instances | ||
SEND_SIGNAL(source, COMSIG_ATOM_DECALS_ROTATING, old_decals) | ||
|
||
if(!length(old_decals)) | ||
UnregisterSignal(source, COMSIG_ATOM_DIR_CHANGE) | ||
return | ||
|
||
var/list/resulting_decals_params = list() // param lists | ||
for(var/datum/element/decal/rotating as anything in old_decals) | ||
resulting_decals_params += list(rotating.get_rotated_parameters(old_dir,new_dir)) | ||
|
||
//Instead we could generate ids and only remove duplicates to save on churn on four-corners symmetry ? | ||
for(var/datum/element/decal/decal in old_decals) | ||
decal.Detach(source) | ||
|
||
for(var/result in resulting_decals_params) | ||
source.AddElement(/datum/element/decal, result["icon"], result["icon_state"], result["dir"], result["layer"], result["alpha"], result["color"], result["cleanable"], result["desc"]) | ||
|
||
/datum/element/decal/proc/get_rotated_parameters(old_dir,new_dir) | ||
var/rotation = 0 | ||
if(directional) //Even when the dirs are the same rotation is coming out as not 0 for some reason | ||
rotation = SIMPLIFY_DEGREES(dir2angle(new_dir)-dir2angle(old_dir)) | ||
new_dir = turn(pic.dir,-rotation) | ||
return list( | ||
"icon" = pic.icon, | ||
"icon_state" = base_icon_state, | ||
"dir" = new_dir, | ||
"plane" = pic.plane, | ||
"layer" = pic.layer, | ||
"alpha" = pic.alpha, | ||
"color" = pic.color, | ||
"cleanable" = cleanable, | ||
"desc" = description | ||
) | ||
|
||
/datum/element/decal/proc/late_update_icon(atom/source) | ||
SIGNAL_HANDLER // COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZE | ||
|
||
if(istype(source) && !(source.flags_2 & DECAL_INIT_UPDATE_EXPERIENCED_2)) | ||
source.flags_2 |= DECAL_INIT_UPDATE_EXPERIENCED_2 | ||
source.update_appearance(UPDATE_OVERLAYS) | ||
UnregisterSignal(source, COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZE) | ||
|
||
/** | ||
* If the decal was not given an appearance, it will generate one based on the other given arguments. | ||
* element won't be compatible if it cannot do either | ||
* all args are fed into creating an image, they are byond vars for images you'll recognize in the byond docs | ||
* (except source, source is the object whose appearance we're copying.) | ||
*/ | ||
/datum/element/decal/proc/generate_appearance(_icon, _icon_state, _dir, _layer, _color, _alpha, source) | ||
if(!_icon || !_icon_state) | ||
return FALSE | ||
var/temp_image = image(_icon, null, _icon_state, _layer, _dir) | ||
pic = new(temp_image) | ||
pic.color = _color | ||
pic.alpha = _alpha | ||
return TRUE | ||
|
||
/datum/element/decal/Detach(atom/source) | ||
UnregisterSignal(source, list( | ||
COMSIG_ATOM_DIR_CHANGE, | ||
COMSIG_COMPONENT_CLEAN_ACT, | ||
COMSIG_PARENT_EXAMINE, | ||
COMSIG_ATOM_UPDATE_OVERLAYS, | ||
COMSIG_TURF_ON_SHUTTLE_MOVE, | ||
COMSIG_ATOM_DECALS_ROTATING | ||
)) | ||
SSdcs.UnregisterSignal(source, COMSIG_ATOM_DIR_CHANGE) | ||
source.update_appearance(UPDATE_OVERLAYS) | ||
if(isitem(source)) | ||
INVOKE_ASYNC(source, TYPE_PROC_REF(/obj/item/, update_slot_icon)) | ||
return ..() | ||
|
||
/datum/element/decal/proc/apply_overlay(atom/source) | ||
SIGNAL_HANDLER // COMSIG_ATOM_UPDATE_OVERLAYS | ||
|
||
source.add_overlay(pic) | ||
// TODO: Fix this disgusting hack | ||
// | ||
// `COMSIG_ATOM_UPDATE_OVERLAYS` is sent at the end of | ||
// /atom/proc/update_icon's stanza for updating overlays, instead | ||
// somewhere useful, like, during it. /tg/ handles this by sending | ||
// a list of overlays with the signal, allowing receivers to add to | ||
// the list, instead of returning their own. | ||
// | ||
// This is much saner and more flexible, but would require refactoring | ||
// many many uses of update_overlay() across the code base, which is left | ||
// as an exercise for the next poor sap to touch this code (probably me). | ||
if(source.managed_overlays && !islist(source.managed_overlays)) | ||
source.managed_overlays = list(source.managed_overlays, pic) | ||
else | ||
LAZYDISTINCTADD(source.managed_overlays, pic) | ||
|
||
/datum/element/decal/proc/clean_react(datum/source, clean_types) | ||
SIGNAL_HANDLER // COMSIG_COMPONENT_CLEAN_ACT | ||
|
||
if(clean_types & cleanable) | ||
Detach(source) | ||
return COMPONENT_CLEANED | ||
return NONE | ||
|
||
/datum/element/decal/proc/examine(datum/source, mob/user, list/examine_list) | ||
SIGNAL_HANDLER // COMSIG_PARENT_EXAMINE | ||
|
||
examine_list += description | ||
|
||
/datum/element/decal/proc/shuttle_move_react(datum/source, turf/new_turf) | ||
SIGNAL_HANDLER // COMSIG_TURF_ON_SHUTTLE_MOVE | ||
|
||
if(new_turf == source) | ||
return | ||
Detach(source) | ||
new_turf.AddElement(type, pic.icon, base_icon_state, directional, pic.layer, pic.alpha, pic.color, cleanable, description) | ||
|
||
/datum/element/decal/proc/shuttle_rotate(datum/source, list/datum/element/decal/rotating) | ||
SIGNAL_HANDLER // COMSIG_ATOM_DECALS_ROTATING | ||
rotating += src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noting the todo here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup.
left as an exercise for the next poor sap to touch this code (probably me)