mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-23 21:12:24 +01:00
Refactored item equipement observable away (#19241)
Refactored item equipement observable away, turned them into signals. Partially ported on_equipped / equipped procs from TG, updated logic, added signals for them.
This commit is contained in:
@@ -455,7 +455,6 @@
|
||||
#include "code\datums\observation\destroyed.dm"
|
||||
#include "code\datums\observation\dir_set.dm"
|
||||
#include "code\datums\observation\entered.dm"
|
||||
#include "code\datums\observation\equipped.dm"
|
||||
#include "code\datums\observation\exited.dm"
|
||||
#include "code\datums\observation\helpers.dm"
|
||||
#include "code\datums\observation\instruments.dm"
|
||||
|
||||
@@ -5,6 +5,14 @@
|
||||
|
||||
// /obj/item signals
|
||||
|
||||
///from base of obj/item/equipped(): (mob/equipper, slot)
|
||||
#define COMSIG_ITEM_EQUIPPED "item_equip"
|
||||
///From base of obj/item/on_equipped() (mob/equipped, slot)
|
||||
#define COMSIG_ITEM_POST_EQUIPPED "item_post_equipped"
|
||||
/// This will make the on_equipped proc return FALSE.
|
||||
#define COMPONENT_EQUIPPED_FAILED (1<<0)
|
||||
/// A mob has just equipped an item. Called on [/mob] from base of [/obj/item/equipped()]: (/obj/item/equipped_item, slot)
|
||||
#define COMSIG_MOB_EQUIPPED_ITEM "mob_equipped_item"
|
||||
///from base of obj/item/dropped(): (mob/user)
|
||||
#define COMSIG_ITEM_DROPPED "item_drop"
|
||||
///from base of obj/item/pickup(): (mob/user)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
// Observer Pattern Implementation: Equipped
|
||||
// Registration type: /mob
|
||||
//
|
||||
// Raised when: A mob equips an item.
|
||||
//
|
||||
// Arguments that the called proc should expect:
|
||||
// /mob/equipper: The mob that equipped the item.
|
||||
// /obj/item/item: The equipped item.
|
||||
// slot: The slot equipped to.
|
||||
|
||||
GLOBAL_DATUM_INIT(mob_equipped_event, /singleton/observ/mob_equipped, new)
|
||||
|
||||
/singleton/observ/mob_equipped
|
||||
name = "Mob Equipped"
|
||||
expected_type = /mob
|
||||
|
||||
// Observer Pattern Implementation: Equipped
|
||||
// Registration type: /obj/item
|
||||
//
|
||||
// Raised when: A mob equips an item.
|
||||
//
|
||||
// Arguments that the called proc should expect:
|
||||
// /obj/item/item: The equipped item.
|
||||
// /mob/equipper: The mob that equipped the item.
|
||||
// slot: The slot equipped to.
|
||||
|
||||
var/singleton/observ/item_equipped/item_equipped_event = new()
|
||||
|
||||
/singleton/observ/item_equipped
|
||||
name = "Item Equipped"
|
||||
expected_type = /obj/item
|
||||
|
||||
/********************
|
||||
* Equipped Handling *
|
||||
********************/
|
||||
|
||||
/obj/item/proc/check_equipped(var/mob/user, var/slot, var/assisted_equip = FALSE)
|
||||
return TRUE
|
||||
+44
-14
@@ -544,24 +544,53 @@
|
||||
/obj/item/proc/on_found(mob/finder as mob)
|
||||
return
|
||||
|
||||
// called after an item is placed in an equipment slot
|
||||
// user is mob that equipped it
|
||||
// slot uses the slot_X defines found in setup.dm
|
||||
// for items that can be placed in multiple slots
|
||||
/obj/item/proc/equipped(var/mob/user, var/slot)
|
||||
/**
|
||||
* Called after an item is placed in an equipment slot. Runs equipped(), then sends a signal.
|
||||
* This should be called last or near-to-last, after all other inventory code stuff is handled.
|
||||
*
|
||||
* Arguments:
|
||||
* * user is mob that equipped it
|
||||
* * slot uses the slot_X defines found in setup.dm for items that can be placed in multiple slots
|
||||
* * initial is used to indicate whether or not this is the initial equipment (job datums etc) or just a player doing it
|
||||
*/
|
||||
/obj/item/proc/on_equipped(mob/user, slot, initial = FALSE)
|
||||
SHOULD_NOT_OVERRIDE(TRUE)
|
||||
equipped(user, slot, initial)
|
||||
if(SEND_SIGNAL(src, COMSIG_ITEM_POST_EQUIPPED, user, slot) && COMPONENT_EQUIPPED_FAILED)
|
||||
return FALSE
|
||||
return TRUE
|
||||
|
||||
|
||||
/**
|
||||
* Called by on_equipped. Don't call this directly, we want the ITEM_POST_EQUIPPED signal to be sent after everything else.
|
||||
*
|
||||
* Note that hands count as slots.
|
||||
*
|
||||
* Arguments:
|
||||
* * user is mob that equipped it
|
||||
* * slot uses the slot_X defines found in setup.dm for items that can be placed in multiple slots
|
||||
* * initial is used to indicate whether or not this is the initial equipment (job datums etc) or just a player doing it
|
||||
*/
|
||||
/obj/item/proc/equipped(mob/user, slot, initial = FALSE)
|
||||
SHOULD_CALL_PARENT(TRUE)
|
||||
PROTECTED_PROC(TRUE)
|
||||
SEND_SIGNAL(src, COMSIG_ITEM_EQUIPPED, user, slot)
|
||||
SEND_SIGNAL(user, COMSIG_MOB_EQUIPPED_ITEM, src, slot)
|
||||
hud_layerise()
|
||||
equip_slot = slot
|
||||
if(user.client) user.client.screen |= src
|
||||
if(user.pulling == src) user.stop_pulling()
|
||||
in_inventory = TRUE
|
||||
if(slot == slot_l_hand || slot == slot_r_hand)
|
||||
playsound(src, pickup_sound, PICKUP_SOUND_VOLUME)
|
||||
else if(slot_flags && slot)
|
||||
if(equip_sound)
|
||||
playsound(src, equip_sound, EQUIP_SOUND_VOLUME, TRUE, ignore_walls = FALSE)
|
||||
else
|
||||
playsound(src, drop_sound, DROP_SOUND_VOLUME, ignore_walls = FALSE)
|
||||
|
||||
if(!initial)
|
||||
if(slot == slot_l_hand || slot == slot_r_hand)
|
||||
playsound(src, pickup_sound, PICKUP_SOUND_VOLUME)
|
||||
else if(slot_flags && slot)
|
||||
if(equip_sound)
|
||||
playsound(src, equip_sound, EQUIP_SOUND_VOLUME, TRUE, ignore_walls = FALSE)
|
||||
else
|
||||
playsound(src, drop_sound, DROP_SOUND_VOLUME, ignore_walls = FALSE)
|
||||
|
||||
if(item_action_slot_check(user, slot))
|
||||
add_verb(user, verbs)
|
||||
for(var/v in verbs)
|
||||
@@ -570,13 +599,14 @@
|
||||
remove_item_verbs(user)
|
||||
|
||||
//Ěent for observable
|
||||
GLOB.mob_equipped_event.raise_event(user, src, slot)
|
||||
item_equipped_event.raise_event(src, user, slot)
|
||||
SEND_SIGNAL(src, COMSIG_ITEM_REMOVE, src)
|
||||
|
||||
if(user && (z_flags & ZMM_MANGLE_PLANES))
|
||||
addtimer(CALLBACK(user, /mob/proc/check_emissive_equipment), 0, TIMER_UNIQUE)
|
||||
|
||||
/obj/item/proc/check_equipped(var/mob/user, var/slot, var/assisted_equip = FALSE)
|
||||
return TRUE
|
||||
|
||||
//sometimes we only want to grant the item's action if it's equipped in a specific slot.
|
||||
/obj/item/proc/item_action_slot_check(mob/user, slot)
|
||||
return TRUE
|
||||
|
||||
@@ -106,8 +106,8 @@
|
||||
current_weight += I.w_class
|
||||
add_vis_contents(I)
|
||||
I.vis_flags |= VIS_INHERIT_LAYER | VIS_INHERIT_PLANE
|
||||
item_equipped_event.register(I, src, PROC_REF(pick_up))
|
||||
GLOB.destroyed_event.register(I, src, PROC_REF(unload_item))
|
||||
RegisterSignal(I, COMSIG_ITEM_EQUIPPED, PROC_REF(pick_up))
|
||||
RegisterSignal(I, COMSIG_QDELETING, PROC_REF(unload_item))
|
||||
|
||||
/obj/item/tray/verb/unload()
|
||||
set name = "Unload Tray"
|
||||
@@ -144,7 +144,8 @@
|
||||
unload_item(contained, moved_to)
|
||||
|
||||
/obj/item/tray/proc/unload_item(var/obj/item/contained, var/atom/dropspot = null)
|
||||
item_equipped_event.unregister(contained, src)
|
||||
UnregisterSignal(contained, COMSIG_ITEM_EQUIPPED)
|
||||
UnregisterSignal(contained, COMSIG_QDELETING)
|
||||
if(dropspot)
|
||||
contained.forceMove(dropspot)
|
||||
vis_contents.Remove(contained)
|
||||
|
||||
@@ -243,7 +243,7 @@ This saves us from having to call add_fingerprint() any time something is put in
|
||||
switch(slot)
|
||||
if(slot_back)
|
||||
src.back = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_back(redraw_mob)
|
||||
if(slot_wear_mask)
|
||||
src.wear_mask = W
|
||||
@@ -251,32 +251,32 @@ This saves us from having to call add_fingerprint() any time something is put in
|
||||
update_hair(redraw_mob) //rebuild hair
|
||||
update_inv_l_ear(0)
|
||||
update_inv_r_ear(0)
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_wear_mask(redraw_mob)
|
||||
if(slot_handcuffed)
|
||||
src.handcuffed = W
|
||||
update_inv_handcuffed(redraw_mob)
|
||||
if(slot_legcuffed)
|
||||
src.legcuffed = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_legcuffed(redraw_mob)
|
||||
if(slot_l_hand)
|
||||
src.l_hand = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
W.screen_loc = ui_lhand
|
||||
update_inv_l_hand(redraw_mob)
|
||||
if(slot_r_hand)
|
||||
src.r_hand = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
W.screen_loc = ui_rhand
|
||||
update_inv_r_hand(redraw_mob)
|
||||
if(slot_belt)
|
||||
src.belt = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_belt(redraw_mob)
|
||||
if(slot_wear_id)
|
||||
src.wear_id = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_wear_id(redraw_mob)
|
||||
if(slot_l_ear)
|
||||
src.l_ear = W
|
||||
@@ -288,7 +288,7 @@ This saves us from having to call add_fingerprint() any time something is put in
|
||||
var/obj/item/clothing/ears/offear/O = new /obj/item/clothing/ears/offear(src)
|
||||
O.copy_ear(W)
|
||||
src.r_ear = O
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_l_ear(redraw_mob)
|
||||
if(slot_r_ear)
|
||||
src.r_ear = W
|
||||
@@ -300,19 +300,19 @@ This saves us from having to call add_fingerprint() any time something is put in
|
||||
var/obj/item/clothing/ears/offear/O = new /obj/item/clothing/ears/offear(src)
|
||||
O.copy_ear(W)
|
||||
src.l_ear = O
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_r_ear(redraw_mob)
|
||||
if(slot_glasses)
|
||||
src.glasses = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_glasses(redraw_mob)
|
||||
if(slot_gloves)
|
||||
src.gloves = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_gloves(redraw_mob)
|
||||
if(slot_wrists)
|
||||
src.wrists = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_wrists(redraw_mob)
|
||||
if(slot_head)
|
||||
src.head = W
|
||||
@@ -321,34 +321,34 @@ This saves us from having to call add_fingerprint() any time something is put in
|
||||
update_inv_l_ear(0)
|
||||
update_inv_r_ear(0)
|
||||
update_inv_wear_mask(0)
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_head(redraw_mob)
|
||||
if(slot_shoes)
|
||||
src.shoes = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_shoes(redraw_mob)
|
||||
update_noise_level()
|
||||
if(slot_wear_suit)
|
||||
src.wear_suit = W
|
||||
if(wear_suit.flags_inv & HIDESHOES)
|
||||
update_inv_shoes(0)
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_wear_suit(redraw_mob)
|
||||
if(slot_w_uniform)
|
||||
src.w_uniform = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_w_uniform(redraw_mob)
|
||||
if(slot_l_store)
|
||||
src.l_store = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_pockets(redraw_mob)
|
||||
if(slot_r_store)
|
||||
src.r_store = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_pockets(redraw_mob)
|
||||
if(slot_s_store)
|
||||
src.s_store = W
|
||||
W.equipped(src, slot, assisted_equip)
|
||||
W.on_equipped(src, slot, assisted_equip)
|
||||
update_inv_s_store(redraw_mob)
|
||||
if(slot_in_backpack)
|
||||
if(src.get_active_hand() == W)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
################################
|
||||
# Example Changelog File
|
||||
#
|
||||
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
|
||||
#
|
||||
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
|
||||
# When it is, any changes listed below will disappear.
|
||||
#
|
||||
# Valid Prefixes:
|
||||
# bugfix
|
||||
# - (fixes bugs)
|
||||
# wip
|
||||
# - (work in progress)
|
||||
# qol
|
||||
# - (quality of life)
|
||||
# soundadd
|
||||
# - (adds a sound)
|
||||
# sounddel
|
||||
# - (removes a sound)
|
||||
# rscadd
|
||||
# - (adds a feature)
|
||||
# rscdel
|
||||
# - (removes a feature)
|
||||
# imageadd
|
||||
# - (adds an image or sprite)
|
||||
# imagedel
|
||||
# - (removes an image or sprite)
|
||||
# spellcheck
|
||||
# - (fixes spelling or grammar)
|
||||
# experiment
|
||||
# - (experimental change)
|
||||
# balance
|
||||
# - (balance changes)
|
||||
# code_imp
|
||||
# - (misc internal code change)
|
||||
# refactor
|
||||
# - (refactors code)
|
||||
# config
|
||||
# - (makes a change to the config files)
|
||||
# admin
|
||||
# - (makes changes to administrator tools)
|
||||
# server
|
||||
# - (miscellaneous changes to server)
|
||||
#################################
|
||||
|
||||
# Your name.
|
||||
author: FluffyGhost
|
||||
|
||||
# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
|
||||
delete-after: True
|
||||
|
||||
# Any changes you've made. See valid prefix list above.
|
||||
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
|
||||
# SCREW THIS UP AND IT WON'T WORK.
|
||||
# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit.
|
||||
# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog.
|
||||
changes:
|
||||
- refactor: "Refactored item equipement observable away, turned them into signals."
|
||||
- code_imp: "Partially ported on_equipped / equipped procs from TG, updated logic, added signals for them."
|
||||
Reference in New Issue
Block a user