Rename component (#59511) (#6199)

Co-authored-by: cacogen <25089914+cacogen@users.noreply.github.com>
This commit is contained in:
SkyratBot
2021-06-09 10:44:59 +12:00
committed by GitHub
co-authored by cacogen
parent 8c6c5f023a
commit 70c089f6ef
3 changed files with 75 additions and 6 deletions
+65
View File
@@ -0,0 +1,65 @@
/**
The rename component.
This component is used to manage names and descriptions changed with the pen.
Atoms can only have one instance of this component at a time.
When a player renames or changes the description of an atom with a pen, this component gets applied to it.
If a player resets the name and description, they will be reverted to their state before being changed and the component will be removed.
*/
/datum/component/rename
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
///The name the player is applying to the parent.
var/custom_name
///The desc the player is applying to the parent.
var/custom_desc
///The name before the player changed it.
var/original_name
///The desc before the player changed it.
var/original_desc
/datum/component/rename/Initialize(custom_name, custom_desc)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
src.custom_name = custom_name
src.custom_desc = custom_desc
apply_rename()
/**
This proc will fire after the parent's name or desc is changed with a pen, which is trying to apply another rename component.
Since the parent already has a rename component, it will remove the old one and apply the new one.
The name and description changes will be merged or overwritten.
*/
/datum/component/rename/InheritComponent(datum/component/rename/new_comp , i_am_original, custom_name, custom_desc)
revert_rename()
if(new_comp)
src.custom_name = new_comp.custom_name
src.custom_desc = new_comp.custom_desc
else
src.custom_name = custom_name
src.custom_desc = custom_desc
apply_rename()
///Saves the current name and description before changing them to the player's inputs.
/datum/component/rename/proc/apply_rename()
var/atom/owner = parent
original_name = owner.name
original_desc = owner.desc
owner.name = custom_name
owner.desc = custom_desc
///Reverts the name and description to the state before they were changed.
/datum/component/rename/proc/revert_rename()
var/atom/owner = parent
owner.name = original_name
owner.desc = original_desc
/datum/component/rename/proc/remove_component()
revert_rename()
qdel(src)
/datum/component/rename/Destroy()
revert_rename()
return ..()
+9 -6
View File
@@ -150,10 +150,10 @@
var/oldname = O.name
if(QDELETED(O) || !user.canUseTopic(O, BE_CLOSE))
return
if(oldname == input || input == "")
if(input == oldname || !input)
to_chat(user, "<span class='notice'>You changed [O] to... well... [O].</span>")
else
O.name = input
O.AddComponent(/datum/component/rename, input, O.desc)
var/datum/component/label/label = O.GetComponent(/datum/component/label)
if(label)
label.remove_label()
@@ -166,22 +166,25 @@
var/olddesc = O.desc
if(QDELETED(O) || !user.canUseTopic(O, BE_CLOSE))
return
if(olddesc == input || input == "")
if(input == olddesc || !input)
to_chat(user, "<span class='notice'>You decide against changing [O]'s description.</span>")
else
O.desc = input
O.AddComponent(/datum/component/rename, O.name, input)
to_chat(user, "<span class='notice'>You have successfully changed [O]'s description.</span>")
O.renamedByPlayer = TRUE
if(penchoice == "Reset")
if(QDELETED(O) || !user.canUseTopic(O, BE_CLOSE))
return
O.desc = initial(O.desc)
O.name = initial(O.name)
qdel(O.GetComponent(/datum/component/rename))
//reapply any label to name
var/datum/component/label/label = O.GetComponent(/datum/component/label)
if(label)
label.remove_label()
label.apply_label()
to_chat(user, "<span class='notice'>You have successfully reset [O]'s name and description.</span>")
O.renamedByPlayer = FALSE
+1
View File
@@ -581,6 +581,7 @@
#include "code\datums\components\radioactive.dm"
#include "code\datums\components\religious_tool.dm"
#include "code\datums\components\remote_materials.dm"
#include "code\datums\components\rename.dm"
#include "code\datums\components\rot.dm"
#include "code\datums\components\rotation.dm"
#include "code\datums\components\shell.dm"