diff --git a/code/__DEFINES/components.dm b/code/__DEFINES/components.dm index 827556df94a..f1a4e014a17 100644 --- a/code/__DEFINES/components.dm +++ b/code/__DEFINES/components.dm @@ -39,6 +39,7 @@ #define COMSIG_ATOM_SING_PULL "atom_sing_pull" //from base of atom/singularity_pull(): (S, current_size) #define COMSIG_ATOM_SET_LIGHT "atom_set_light" //from base of atom/set_light(): (l_range, l_power, l_color) #define COMSIG_ATOM_ROTATE "atom_rotate" //from base of atom/shuttleRotate(): (rotation, params) +#define COMSIG_ATOM_DIR_CHANGE "atom_dir_change" //from base of atom/setDir(): (old_dir, new_dir) #define COMSIG_CLICK "atom_click" //from base of atom/Click(): (location, control, params) #define COMSIG_CLICK_SHIFT "shift_click" //from base of atom/ShiftClick(): (/mob) diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index 75985f9c2e9..d5d311ab644 100644 --- a/code/__HELPERS/type2type.dm +++ b/code/__HELPERS/type2type.dm @@ -146,7 +146,6 @@ return NORTH //returns the north-zero clockwise angle in degrees, given a direction - /proc/dir2angle(D) switch(D) if(NORTH) diff --git a/code/datums/components/decal.dm b/code/datums/components/decal.dm new file mode 100644 index 00000000000..5f8aa3e0328 --- /dev/null +++ b/code/datums/components/decal.dm @@ -0,0 +1,53 @@ +/datum/component/decal + dupe_mode = COMPONENT_DUPE_ALLOWED + + var/cleanable + var/mutable_appearance/pic + +/datum/component/decal/Initialize(_icon, _icon_state, _dir, _cleanable=CLEAN_GOD, _color, _layer=TURF_DECAL_LAYER) + if(!isatom(parent) || !_icon || !_icon_state) + . = COMPONENT_INCOMPATIBLE + CRASH("A turf decal was applied incorrectly to [parent.type]: icon:[_icon ? _icon : "none"] icon_state:[_icon_state ? _icon_state : "none"]") + + // It has to be made from an image or dir breaks because of a byond bug + var/temp_image = image(_icon, null, _icon_state, _layer, _dir) + pic = new(temp_image) + pic.color = _color + + cleanable = _cleanable + + apply() + + if(_dir) // If no dir is assigned at start then it follows the atom's dir + RegisterSignal(COMSIG_ATOM_DIR_CHANGE, .proc/rotate_react) + if(_cleanable) + RegisterSignal(COMSIG_COMPONENT_CLEAN_ACT, .proc/clean_react) + +/datum/component/decal/Destroy() + remove() + return ..() + +/datum/component/decal/OnTransfer(atom/thing) + remove() + remove(thing) + apply(thing) + +/datum/component/decal/proc/apply(atom/thing) + var/atom/master = thing || parent + master.add_overlay(pic, TRUE) + +/datum/component/decal/proc/remove(atom/thing) + var/atom/master = thing || parent + master.cut_overlay(pic, TRUE) + +/datum/component/decal/proc/rotate_react(old_dir, new_dir) + if(old_dir == new_dir) + return + remove() + var/rotation = SimplifyDegrees(dir2angle(new_dir)-dir2angle(old_dir)) + pic.dir = turn(pic.dir, rotation) + apply() + +/datum/component/decal/proc/clean_react(strength) + if(strength >= cleanable) + qdel(src) \ No newline at end of file diff --git a/code/datums/components/turf_decal.dm b/code/datums/components/turf_decal.dm deleted file mode 100644 index 0cd4cb969e4..00000000000 --- a/code/datums/components/turf_decal.dm +++ /dev/null @@ -1,51 +0,0 @@ -/datum/component/turf_decal - var/dir - var/icon - var/icon_state - var/layer - var/group - -/datum/component/turf_decal/Initialize(_dir, _icon, _icon_state, _layer=TURF_DECAL_LAYER, _group=TURF_DECAL_PAINT) - if(!isturf(parent) || !_icon || !_icon_state) - WARNING("A turf decal was applied incorrectly to [parent]: icon:[_icon ? _icon : "none"] icon_state:[_icon_state ? _icon_state : "none"]") - return COMPONENT_INCOMPATIBLE - - dir = _dir - icon = _icon - icon_state = _icon_state - layer = _layer - group = _group - apply_decal() - - RegisterSignal(COMSIG_ATOM_ROTATE, .proc/rotate_react) - RegisterSignal(COMSIG_COMPONENT_CLEAN_ACT, .proc/clean_react) - -/datum/component/turf_decal/Destroy() - remove_decal() - return ..() - -/datum/component/turf_decal/OnTransfer(turf/newT) - remove_decal() - remove_decal(newT) - apply_decal(newT) - -/datum/component/turf_decal/proc/get_decal() - return image(icon, null, icon_state, layer, dir) - -/datum/component/turf_decal/proc/apply_decal(turf/overT) - var/turf/master = overT || parent - master.add_decal(get_decal(), group) - -/datum/component/turf_decal/proc/remove_decal(turf/overT) - var/turf/master = overT || parent - master.remove_decal(group) - -/datum/component/turf_decal/proc/rotate_react(rotation, params) - if(params & ROTATE_DIR) - dir = angle2dir(rotation+dir2angle(dir)) - remove_decal() - apply_decal() - -/datum/component/turf_decal/proc/clean_react(strength) - if(strength >= CLEAN_IMPRESSIVE) - qdel(src) \ No newline at end of file diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 7abb3ce9587..a6182fb5f77 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -523,6 +523,7 @@ GLOBAL_LIST_EMPTY(blood_splatter_icons) //Hook for running code when a dir change occurs /atom/proc/setDir(newdir) + SendSignal(COMSIG_ATOM_DIR_CHANGE, dir, newdir) dir = newdir /atom/proc/mech_melee_attack(obj/mecha/M) diff --git a/code/game/objects/effects/decals/decal.dm b/code/game/objects/effects/decals/decal.dm index 3ded6ea8fc8..e2f74907f49 100644 --- a/code/game/objects/effects/decals/decal.dm +++ b/code/game/objects/effects/decals/decal.dm @@ -30,7 +30,7 @@ var/turf/T = loc if(!istype(T)) //you know this will happen somehow CRASH("Turf decal initialized in an object/nullspace") - T.AddComponent(/datum/component/turf_decal, dir, icon, icon_state) + T.AddComponent(/datum/component/decal, icon, icon_state, dir) /obj/effect/turf_decal/stripes/line icon_state = "warningline" diff --git a/tgstation.dme b/tgstation.dme index ff38fd9d018..a414a204eb5 100755 --- a/tgstation.dme +++ b/tgstation.dme @@ -277,6 +277,7 @@ #include "code\datums\antagonists\wizard.dm" #include "code\datums\components\_component.dm" #include "code\datums\components\archaeology.dm" +#include "code\datums\components\decal.dm" #include "code\datums\components\infective.dm" #include "code\datums\components\material_container.dm" #include "code\datums\components\paintable.dm" @@ -287,7 +288,6 @@ #include "code\datums\components\spooky.dm" #include "code\datums\components\squeek.dm" #include "code\datums\components\thermite.dm" -#include "code\datums\components\turf_decal.dm" #include "code\datums\diseases\_disease.dm" #include "code\datums\diseases\_MobProcs.dm" #include "code\datums\diseases\anxiety.dm"