Skip to content

Commit

Permalink
code_imp: pref holder & improve pref viewer (ss220-space#6422)
Browse files Browse the repository at this point in the history
* 1

* dme

* rework to element

* 2

* fastfix

* inconsistent

* 3

* fix x10

* fix x11

* fix x12

* parenthesis....

* fix x14
  • Loading branch information
Antoonij authored Jan 24, 2025
1 parent 2fed474 commit ef7e307
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 63 deletions.
6 changes: 3 additions & 3 deletions code/__HELPERS/bitflags.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define HASBIT(CONTAINER, FLAG) ((CONTAINER) & (FLAG))

#define SETBIT(CONTAINER, FLAG) (CONTAINER |= (FLAG))
#define SETBIT(CONTAINER, FLAG) ((CONTAINER) |= (FLAG))

#define CLEARBIT(CONTAINER, FLAG) (CONTAINER &= ~(FLAG))
#define CLEARBIT(CONTAINER, FLAG) ((CONTAINER) &= ~(FLAG))

#define TOGGLEBIT(CONTAINER, FLAG) (CONTAINER ^= (FLAG))
#define TOGGLEBIT(CONTAINER, FLAG) ((CONTAINER) ^= (FLAG))
1 change: 1 addition & 0 deletions code/__HELPERS/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

init_subtypes(/datum/surgery_step, GLOB.surgery_steps)
init_subtypes(/obj/item/slimepotion, GLOB.slime_potions)
init_subtypes(/datum/preference_info, GLOB.preferences_info)
// Different bodies
__init_body_accessory(/datum/body_accessory/body)
// Different tails
Expand Down
49 changes: 49 additions & 0 deletions code/datums/components/pref_holder.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/datum/component/pref_holder
var/list/preferences

/datum/component/pref_holder/Destroy(force)
LAZYNULL(preferences)

return ..()

/datum/component/pref_holder/Initialize(list/preferences)
var/mob/target = parent

if(!istype(target))
return COMPONENT_INCOMPATIBLE

src.preferences = preferences || forge_preferences()

/datum/component/pref_holder/RegisterWithParent()
RegisterSignal(parent, COMSIG_BODY_TRANSFER_TO, PROC_REF(on_mind_transfer))

/datum/component/pref_holder/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_BODY_TRANSFER_TO)

/datum/component/pref_holder/proc/on_mind_transfer(mob/source)
SIGNAL_HANDLER

preferences = forge_preferences()

/datum/component/pref_holder/proc/forge_preferences()
var/mob/mob = parent

if(!mob.client)
return

var/list/prefs

for(var/datum/preference_info/pref as anything in GLOB.preferences_info)
var/datum/preference_toggle/toggle = pref.get_preference_toggle()

if(!toggle)
continue

if(!HASBIT(mob.client.prefs.toggles, toggle.preftoggle_bitflag) \
&& !HASBIT(mob.client.prefs.toggles2, toggle.preftoggle_bitflag)
)
continue

LAZYADD(prefs, new pref.type)

return prefs
41 changes: 0 additions & 41 deletions code/datums/components/pref_viewer.dm

This file was deleted.

42 changes: 42 additions & 0 deletions code/datums/elements/pref_viewer.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/datum/element/pref_viewer
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY
var/list/preferences_to_show

/datum/element/pref_viewer/Destroy(force)
LAZYNULL(preferences_to_show)

return ..()

/datum/element/pref_viewer/Attach(
mob/target,
list/preferences_to_show
)
. = ..()

if(!istype(target))
return ELEMENT_INCOMPATIBLE

src.preferences_to_show = preferences_to_show
RegisterSignal(target, COMSIG_MOB_RUN_EXAMINATE, PROC_REF(on_examine))

/datum/element/pref_viewer/Detach(mob/target)
. = ..()

UnregisterSignal(target, COMSIG_MOB_RUN_EXAMINATE)

/datum/element/pref_viewer/proc/on_examine(mob/source, mob/target, list/result)
SIGNAL_HANDLER

if(!istype(target) || !target.client || !target.GetComponent(/datum/component/pref_holder))
return

INVOKE_ASYNC(src, PROC_REF(modify_examine), target, result)

/datum/element/pref_viewer/proc/modify_examine(mob/target, list/result)
var/datum/component/pref_holder/holder = target.GetComponent(/datum/component/pref_holder)

for(var/datum/preference_info/info as anything in holder.preferences)
if(!is_type_in_list(info, preferences_to_show))
continue

LAZYADD(result, info.get_examine_text())
1 change: 0 additions & 1 deletion code/datums/mind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@


/datum/mind/proc/transfer_to(mob/living/new_character)

if(!istype(new_character))
stack_trace("transfer_to(): Some idiot has tried to transfer_to() a non mob/living mob.")

Expand Down
8 changes: 4 additions & 4 deletions code/modules/antagonists/changeling/changeling_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ GLOBAL_LIST_INIT(possible_changeling_IDs, list("Alpha","Beta","Gamma","Delta","E
var/obj/item/organ/internal/brain/ling_brain = carbon_user.get_organ_slot(INTERNAL_ORGAN_BRAIN)
ling_brain?.decoy_brain = TRUE

user.AddComponent( \
/datum/component/pref_viewer, \
user.AddElement( \
/datum/element/pref_viewer, \
list(/datum/preference_info/take_out_of_the_round_without_obj), \
)

/datum/antagonist/changeling/on_body_transfer(mob/living/old_body, mob/living/new_body)
. = ..()
qdel(old_body.GetComponent(/datum/component/pref_viewer))
old_body.RemoveElement(/datum/element/pref_viewer)

/datum/antagonist/changeling/handle_last_instance_removal()
qdel(owner.current.GetComponent(/datum/component/pref_viewer))
owner.current.RemoveElement(/datum/element/pref_viewer)

/datum/antagonist/changeling/remove_innate_effects(mob/living/mob_override)
var/mob/living/user = ..()
Expand Down
8 changes: 4 additions & 4 deletions code/modules/antagonists/space_ninja/ninja_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@
var/mob/living/user = ..()
user.faction = list(ROLE_NINJA)

user.AddComponent( \
/datum/component/pref_viewer, \
user.AddElement( \
/datum/element/pref_viewer, \
list(/datum/preference_info/take_out_of_the_round_without_obj), \
)

/datum/antagonist/ninja/handle_last_instance_removal()
qdel(owner.current.GetComponent(/datum/component/pref_viewer))
owner.current.RemoveElement(/datum/element/pref_viewer)

/datum/antagonist/ninja/on_body_transfer(mob/living/old_body, mob/living/new_body)
. = ..()
qdel(old_body.GetComponent(/datum/component/pref_viewer))
old_body.RemoveElement(/datum/element/pref_viewer)

/datum/antagonist/ninja/proc/change_species(mob/living/mob_to_change = null) // This should be used to fully to remove robo-limbs & change species for lack of sprites
human_ninja = ishuman(mob_to_change) ? mob_to_change : null
Expand Down
8 changes: 4 additions & 4 deletions code/modules/antagonists/traitor/datum_traitor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
datum_owner.AddComponent(/datum/component/codeword_hearing, GLOB.syndicate_code_phrase_regex, "codephrases", src)
datum_owner.AddComponent(/datum/component/codeword_hearing, GLOB.syndicate_code_response_regex, "coderesponses", src)

datum_owner.AddComponent( \
/datum/component/pref_viewer, \
datum_owner.AddElement( \
/datum/element/pref_viewer, \
list(/datum/preference_info/take_out_of_the_round_without_obj), \
)

/datum/antagonist/traitor/on_body_transfer(mob/living/old_body, mob/living/new_body)
. = ..()
qdel(old_body.GetComponent(/datum/component/pref_viewer))
old_body.RemoveElement(/datum/element/pref_viewer)

/datum/antagonist/traitor/handle_last_instance_removal()
qdel(owner.current.GetComponent(/datum/component/pref_viewer))
owner.current.RemoveElement(/datum/element/pref_viewer)

/datum/antagonist/traitor/remove_innate_effects(mob/living/mob_override)
. = ..()
Expand Down
8 changes: 4 additions & 4 deletions code/modules/antagonists/vampire/vampire_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@
//slaved.leave_serv_hud(mob_override.mind)
//.mind.som = null

user.AddComponent( \
/datum/component/pref_viewer, \
user.AddElement( \
/datum/element/pref_viewer, \
list(/datum/preference_info/take_out_of_the_round_without_obj), \
)

/datum/antagonist/vampire/on_body_transfer(mob/living/old_body, mob/living/new_body)
. = ..()
qdel(old_body.GetComponent(/datum/component/pref_viewer))
old_body.RemoveElement(/datum/element/pref_viewer)

/datum/antagonist/vampire/handle_last_instance_removal()
qdel(owner.current.GetComponent(/datum/component/pref_viewer))
owner.current.RemoveElement(/datum/element/pref_viewer)

/datum/antagonist/vampire/remove_innate_effects(mob/living/mob_override, transformation = FALSE)
var/mob/living/user = ..()
Expand Down
2 changes: 2 additions & 0 deletions code/modules/client/preference/preference_info.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GLOBAL_LIST_INIT(preferences_info, list())

/datum/preference_info
var/name

Expand Down
2 changes: 2 additions & 0 deletions code/modules/mob/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
if(can_strip())
ADD_TRAIT(src, TRAIT_CAN_STRIP, GENERIC_TRAIT)

AddComponent(/datum/component/pref_holder)

/mob/vv_edit_var(var_name, var_value)
switch(var_name)
if(NAMEOF(src, focus))
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/new_player/new_player.dm
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@
GLOB.human_names_list += new_character.real_name


new_character.key = key //Manually transfer the key to log them in
new_character.key = key // Manually transfer the key to log them in

return new_character

Expand Down
3 changes: 2 additions & 1 deletion paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@
#include "code\datums\components\paintable.dm"
#include "code\datums\components\pellet_cloud.dm"
#include "code\datums\components\persistent_overlay.dm"
#include "code\datums\components\pref_viewer.dm"
#include "code\datums\components\proximity_monitor.dm"
#include "code\datums\components\pref_holder.dm"
#include "code\datums\components\radioactivity.dm"
#include "code\datums\components\ritual_object.dm"
#include "code\datums\components\shielded.dm"
Expand Down Expand Up @@ -592,6 +592,7 @@
#include "code\datums\elements\devil_banishment.dm"
#include "code\datums\elements\devil_regen.dm"
#include "code\datums\elements\diona_internals.dm"
#include "code\datums\elements\pref_viewer.dm"
#include "code\datums\elements\falling_hazard.dm"
#include "code\datums\elements\footstep.dm"
#include "code\datums\elements\give_turf_traits.dm"
Expand Down

0 comments on commit ef7e307

Please sign in to comment.