forked from Citadel-Station-13/Citadel-Station-13-RP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a verb to invert yourself 180 degrees horizontally. also, refact…
…ors update transform. (Citadel-Station-13#6909) look, mom! components can hook transform updates now. surely this will be used responsibly and i won't have to revisit this in the future. when do we get structs so we can go full ECS pattern with appearance updates? having this fragmented across multiple procs is kinda annoying!
- Loading branch information
Showing
14 changed files
with
177 additions
and
66 deletions.
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
10 changes: 10 additions & 0 deletions
10
code/__DEFINES/dcs/signals/signals_atom/signals_movable-update_icon.dm
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,10 @@ | ||
/** | ||
* Anything relating to update icon/rendering | ||
*/ | ||
|
||
/// Called at the base of base_transform with the matrix that's being generated. | ||
/// * Signature: (matrix/applying) | ||
#define COMSIG_MOVABLE_BASE_TRANSFORM "movable-base_transform" | ||
/// Called at the base of update_transform with the matrix that's being generated. | ||
/// * Signature: (matrix/old_matrix, matrix/new_matrix) | ||
#define COMSIG_MOVABLE_ON_UPDATE_TRANSFORM "movable-on_update_transform" |
33 changes: 33 additions & 0 deletions
33
code/datums/components/mobs/mob_self_horizontal_inversion.dm
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,33 @@ | ||
//* This file is explicitly licensed under the MIT license. *// | ||
//* Copyright (c) 2024 Citadel Station Developers *// | ||
|
||
/** | ||
* Component added to a mob by the mob themselves to invert themselves horizontally. | ||
*/ | ||
/datum/component/mob_self_horizontal_inversion | ||
registered_type = /datum/component/mob_self_horizontal_inversion | ||
|
||
/datum/component/mob_self_horizontal_inversion/Initialize() | ||
if(!ismob(parent)) | ||
return COMPONENT_INCOMPATIBLE | ||
return ..() | ||
|
||
/datum/component/mob_self_horizontal_inversion/RegisterWithParent() | ||
. = ..() | ||
RegisterSignal(parent, COMSIG_MOVABLE_BASE_TRANSFORM, PROC_REF(alter_base_transform)) | ||
var/mob/target = parent | ||
var/matrix/to_apply = target.transform | ||
to_apply.Scale(-1, 1) | ||
target.set_transform(to_apply) | ||
|
||
/datum/component/mob_self_horizontal_inversion/UnregisterFromParent() | ||
. = ..() | ||
UnregisterSignal(parent, COMSIG_MOVABLE_BASE_TRANSFORM) | ||
var/mob/target = parent | ||
var/matrix/to_apply = target.transform | ||
to_apply.Scale(-1, 1) | ||
target.set_transform(to_apply) | ||
|
||
/datum/component/mob_self_horizontal_inversion/proc/alter_base_transform(datum/source, matrix/applying) | ||
SIGNAL_HANDLER | ||
applying.Scale(-1, 1) |
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,47 @@ | ||
// Ok ok I know it says update_icon but this actually has everything from // | ||
// update_appearance to update_transform and others. // | ||
|
||
// todo: rework UPDATE_ICON flags or something for "should we transform" | ||
|
||
/** | ||
* Our transform is reset at the base of /atom/movable/proc/update_transform() | ||
*/ | ||
/atom/movable/proc/update_transform() | ||
SHOULD_CALL_PARENT(TRUE) | ||
SHOULD_NOT_SLEEP(TRUE) | ||
SHOULD_NOT_OVERRIDE(TRUE) | ||
|
||
var/matrix/new_transform = matrix() | ||
var/matrix/old_transform = transform | ||
|
||
base_transform(new_transform) | ||
apply_transform(new_transform) | ||
|
||
SEND_SIGNAL(src, COMSIG_MOVABLE_ON_UPDATE_TRANSFORM, old_transform, new_transform) | ||
|
||
/atom/movable/proc/apply_transform(matrix/to_apply) | ||
SHOULD_NOT_SLEEP(TRUE) | ||
transform = to_apply | ||
|
||
/** | ||
* Changing the transform before ..() and after ..() is allowed. | ||
* | ||
* @return the matrix to apply. | ||
*/ | ||
/atom/movable/proc/base_transform(matrix/applying) | ||
SHOULD_CALL_PARENT(TRUE) | ||
SHOULD_NOT_SLEEP(TRUE) | ||
applying.Scale(icon_scale_x, icon_scale_y) | ||
applying.Turn(icon_rotation) | ||
SEND_SIGNAL(src, COMSIG_MOVABLE_BASE_TRANSFORM, applying) | ||
return applying | ||
|
||
/** | ||
* Immediate transform modify. | ||
* | ||
* todo: this should use apply_transform and use update icon flags or something, like NO_ANIMATIONS | ||
*/ | ||
/atom/movable/proc/set_transform(matrix/new_transform) | ||
var/matrix/old_transform = transform | ||
src.transform = new_transform | ||
SEND_SIGNAL(src, COMSIG_MOVABLE_ON_UPDATE_TRANSFORM, old_transform, new_transform) |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//* This file is explicitly licensed under the MIT license. *// | ||
//* Copyright (c) 2024 Citadel Station Developers *// | ||
|
||
/mob/verb/horizontal_invert_self() | ||
set name = "Invert Yourself (Horizontal)" | ||
set desc = "Mirror your sprite across the N-S axis." | ||
set category = VERB_CATEGORY_IC | ||
|
||
// todo: remote control? mobs that don't allow it? | ||
|
||
if(TIMER_COOLDOWN_CHECK(src, CD_INDEX_MOB_VERB_INVERT_SELF)) | ||
// todo: don't usr lol | ||
to_chat(usr, SPAN_WARNING("You can't do that yet!")) | ||
return | ||
TIMER_COOLDOWN_START(src, CD_INDEX_MOB_VERB_INVERT_SELF, 0.5 SECONDS) | ||
|
||
log_game("[key_name(usr)] invoked horizontal_invert_self on [key_name(src)].") | ||
|
||
var/datum/component/mob_self_horizontal_inversion/inversion = GetComponent(/datum/component/mob_self_horizontal_inversion) | ||
if(inversion) | ||
qdel(inversion) | ||
else | ||
AddComponent(/datum/component/mob_self_horizontal_inversion) |
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