Skip to content

Commit

Permalink
Merge pull request #4157 from out-of-phaze/codequality/hook-removal
Browse files Browse the repository at this point in the history
Replace a number of hooks with observation decls, remove deprecated hooks
  • Loading branch information
MistakeNot4892 authored Jul 8, 2024
2 parents 66c016a + cd84df7 commit 253dae5
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 95 deletions.
12 changes: 10 additions & 2 deletions code/_helpers/auxtools.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ var/global/auxtools_debug_server = world.GetConfig("env", "AUXTOOLS_DEBUG_DLL")
/proc/enable_debugging(mode, port)
CRASH("auxtools not loaded")

/hook/startup/proc/auxtools_init()
/world/New()
auxtools_init()
return ..()

/world/proc/auxtools_init()
if (global.auxtools_debug_server)
call_ext(global.auxtools_debug_server, "auxtools_init")()
enable_debugging()
return TRUE

/hook/shutdown/proc/auxtools_shutdown()
/world/Del()
auxtools_shutdown()
return ..()

/world/proc/auxtools_shutdown()
if (global.auxtools_debug_server)
call_ext(global.auxtools_debug_server, "auxtools_shutdown")()
return TRUE
77 changes: 0 additions & 77 deletions code/controllers/hooks-defs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,80 +33,3 @@
* Called in world.dm prior to the parent call in world/Reboot.
*/
/hook/reboot

/**
* Death hook.
* Called in death.dm when someone dies.
* Parameters: var/mob/living/human, var/gibbed
*/
/hook/death

/**
* Cloning hook.
* Called in cloning.dm when someone is brought back by the wonders of modern science.
* Parameters: var/mob/living/human
*/
/hook/clone

/**
* Debrained hook.
* Called in brain_item.dm when someone gets debrained.
* Parameters: var/obj/item/organ/internal/brain
*/
/hook/debrain

/**
* Borged hook.
* Called in robot_parts.dm when someone gets turned into a cyborg.
* Parameters: var/mob/living/silicon/robot
*/
/hook/borgify

/**
* Payroll revoked hook.
* Called in Accounts_DB.dm when someone's payroll is stolen at the Accounts terminal.
* Parameters: var/datum/money_account
*/
/hook/revoke_payroll

/**
* Account suspension hook.
* Called in Accounts_DB.dm when someone's account is suspended or unsuspended at the Accounts terminal.
* Parameters: var/datum/money_account
*/
/hook/change_account_status

/**
* Employee reassignment hook.
* Called in card.dm when someone's card is reassigned at the HoP's desk.
* Parameters: var/obj/item/card/id
*/
/hook/reassign_employee

/**
* Employee terminated hook.
* Called in card.dm when someone's card is terminated at the HoP's desk.
* Parameters: var/obj/item/card/id
*/
/hook/terminate_employee

/**
* Crate sold hook.
* Called in supplyshuttle.dm when a crate is sold on the shuttle.
* Parameters: var/obj/structure/closet/crate/sold, var/area/shuttle
*/
/hook/sell_crate

/**
* Player latejoin hook.
* Called in new_player.dm when a player joins the round after it has started.
* Parameters: var/datum/job/job, var/mob/living/character
*/
/hook/player_latejoin

/**
* Submap join hook.
* Called in submap_join.dm when a player joins a submap.
* Parameters: var/datum/submap/submap, var/datum/job/job, var/mob/living/character
*/
/hook/submap_join
4 changes: 2 additions & 2 deletions code/controllers/subsystems/supply.dm
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ SUBSYSTEM_DEF(supply)
for(var/atom/movable/AM in subarea)
if(AM.anchored)
continue
if(istype(AM, /obj/structure/closet/crate/))
if(istype(AM, /obj/structure/closet/crate))
var/obj/structure/closet/crate/CR = AM
callHook("sell_crate", list(CR, subarea))
RAISE_EVENT(/decl/observ/crate_sold, subarea, CR)
add_points_from_source(CR.get_single_monetary_worth() * crate_return_rebate * 0.1, "crate")
var/find_slip = 1

Expand Down
11 changes: 11 additions & 0 deletions code/datums/observation/crate_sold.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Observer Pattern Implementation: Crate Sold
// Registration type: /area
//
// Raised when: A crate is sold on the shuttle.
//
// Arguments that the called proc should expect:
// /area/shuttle: The shuttle the crate was sold on.
// /obj/structure/closet/crate/sold: The crate that was sold.

/decl/observ/crate_sold
name = "Crate Sold"
10 changes: 10 additions & 0 deletions code/datums/observation/cyborg_created.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Observer Pattern Implementation: Cyborg Created
*
* Raised when: A cyborg is created.
*
* Arguments that the called proc should expect:
* /mob/living/silicon/robot: The cyborg that was created.
*/
/decl/observ/cyborg_created
name = "Cyborg Created"
13 changes: 13 additions & 0 deletions code/datums/observation/debrain.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Observer Pattern Implementation: Debrained
*
* Raised when: A brainmob is created by the removal of a brain.
*
* Arguments that the called proc should expect:
* /mob/living/brainmob: The brainmob that was created.
* /obj/item/organ/internal/brain: The brain that was removed.
* /mob/living/owner: The mob the brain was formerly installed in.
*/
/decl/observ/debrain
name = "Debrained"
expected_type = /mob/living
22 changes: 22 additions & 0 deletions code/datums/observation/employee_id.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Observer Pattern Implementation: Employee ID Reassigned
*
* Raised when: A card's assignment is changed in the ID card modification program.
*
* Arguments that the called proc should expect:
* /obj/item/card/id: The card that was reassigned.
*/
/decl/observ/employee_id_reassigned
name = "Employee ID Reassigned"

// Observer Pattern Implementation: Employee ID Terminated
// Registration type: /obj/item/card/id
//
// Raised when: A card is terminated in the ID card modification program.
//
// Arguments that the called proc should expect:
// /area/shuttle: The shuttle the crate was sold on.
// /obj/structure/closet/crate/sold: The crate that was sold.

/decl/observ/employee_id_terminated
name = "Employee ID Terminated"
22 changes: 22 additions & 0 deletions code/datums/observation/money_accounts.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

/**
* Observer Pattern Implementation: Payroll Revoked
*
* Raised when: Someone's payroll is stolen at the Accounts terminal.
*
* Arguments that the called proc should expect:
* /datum/money_account: The account whose payroll was revoked.
*/
/decl/observ/revoke_payroll
name = "Payroll Revoked"

/**
* Observer Pattern Implementation: Account Status Changed
*
* Raised when: Someone's account is suspended or unsuspended at the Accounts terminal.
*
* Arguments that the called proc should expect:
* /datum/money_account: The account whose status was changed.
*/
/decl/observ/change_account_status
name = "Account Status Changed"
11 changes: 11 additions & 0 deletions code/datums/observation/player_latejoin.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Observer Pattern Implementation: Player Latejoin
// Registration type: /mob/living
//
// Raised when: A player joins the round after it has started.
//
// Arguments that the called proc should expect:
// /mob/living/character: The mob that joined the round.
// /datum/job/job: The job the mob joined as.

/decl/observ/player_latejoin
name = "Player Latejoin"
13 changes: 13 additions & 0 deletions code/datums/observation/submap_join.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Observer Pattern Implementation: Submap Join
// Registration type: /datum/submap
//
// Raised when: A mob joins on a submap
//
// Arguments that the called proc should expect:
// /datum/submap/submap: The submap the mob joined.
// /mob/joiner: The mob that joined the submap.
// /datum/job/job: The job the mob joined as.

/decl/observ/submap_join
name = "Submap Joined"
expected_type = /datum/submap
2 changes: 1 addition & 1 deletion code/game/objects/items/robot/robot_frame.dm
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
cell_component.installed = 1

SSstatistics.add_field("cyborg_birth",1)
callHook("borgify", list(O))
RAISE_EVENT(/decl/observ/cyborg_created, O)
O.Namepick()
qdel(src)

Expand Down
4 changes: 2 additions & 2 deletions code/modules/economy/cael/Accounts_DB.dm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
if("toggle_suspension")
if(detailed_account_view)
detailed_account_view.suspended = !detailed_account_view.suspended
callHook("change_account_status", list(detailed_account_view))
RAISE_EVENT(/decl/observ/change_account_status, detailed_account_view)

if("finalise_create_account")
var/account_name = href_list["holder_name"]
Expand Down Expand Up @@ -149,7 +149,7 @@
var/funds = detailed_account_view.money
detailed_account_view.transfer(station_account, funds, "Revocation of payroll")

callHook("revoke_payroll", list(detailed_account_view))
RAISE_EVENT(/decl/observ/revoke_payroll, detailed_account_view)

if("print")

Expand Down
1 change: 0 additions & 1 deletion code/modules/mob/living/human/death.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
BITSET(hud_updateflag, LIFE_HUD)

//Handle species-specific deaths.
callHook("death", list(src, gibbed))
handle_hud_list()
if(!gibbed)
animate_tail_stop()
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 @@ -241,7 +241,7 @@ INITIALIZE_IMMEDIATE(/mob/new_player)
else if(spawnpoint.spawn_announcement)
AnnounceCyborg(character, job, spawnpoint.spawn_announcement)

callHook("player_latejoin", list(job, character))
RAISE_EVENT(/decl/observ/player_latejoin, character, job)
log_and_message_admins("has joined the round as [character.mind.assigned_role].", character)

qdel(src)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/transform_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@

O.dropInto(loc)
O.job = ASSIGNMENT_ROBOT
callHook("borgify", list(O))
RAISE_EVENT(/decl/observ/cyborg_created, O)
O.Namepick()

qdel(src) // Queues us for a hard delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
if(computer)
id_card.assignment = "Terminated"
remove_nt_access(id_card)
callHook("terminate_employee", list(id_card))
RAISE_EVENT(/decl/observ/employee_id_terminated, id_card)
if("edit")
if(!(get_file_perms(module.get_access(user), user) & OS_WRITE_ACCESS))
to_chat(usr, SPAN_WARNING("Access denied."))
Expand Down Expand Up @@ -296,7 +296,7 @@
id_card.assignment = t1
id_card.position = t1

callHook("reassign_employee", list(id_card))
RAISE_EVENT(/decl/observ/employee_id_reassigned, id_card)
if("access")
if(href_list["allowed"] && id_card)
var/access_type = href_list["access_target"]
Expand Down
2 changes: 1 addition & 1 deletion code/modules/organs/internal/_internal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
brainmob.languages = M.languages?.Copy()
brainmob.default_language = M.default_language
to_chat(brainmob, SPAN_NOTICE("You feel slightly disoriented. That's normal when you're just \a [initial(src.name)]."))
callHook("debrain", list(brainmob))
RAISE_EVENT(/decl/observ/debrain, brainmob, src, M)
return TRUE
return FALSE

Expand Down
2 changes: 1 addition & 1 deletion code/modules/submaps/submap_join.dm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
SSticker.mode.handle_offsite_latejoin(character)
global.universe.OnPlayerLatejoin(character)
log_and_message_admins("has joined the round as offsite role [character.mind.assigned_role].", character)
callHook("submap_join", list(job, character))
RAISE_EVENT(/decl/observ/submap_join, src, character, job)
if(character.cannot_stand()) equip_wheelchair(character)
job.post_equip_job_title(character, job.title)
qdel(joining)
Expand Down
10 changes: 7 additions & 3 deletions mods/content/matchmaking/matchmaker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ var/global/datum/matchmaker/matchmaker = new()
matchmaker.do_matchmaking()
return TRUE

/hook/player_latejoin/proc/matchmaking(var/datum/job/job, var/mob/living/character)
/datum/matchmaker/matchmaker/New()
. = ..()
events_repository.register_global(/decl/observ/player_latejoin, src, PROC_REF(matchmake_latejoiner))

/datum/matchmaker/proc/matchmake_latejoiner(mob/living/character, datum/job/job)
if(character.mind && character.client?.prefs.relations.len)
for(var/T in character.client.prefs.relations)
var/TT = matchmaker.relation_types[T]
var/TT = relation_types[T]
var/datum/relation/R = new TT
R.holder = character.mind
R.info = character.client.prefs.relations_info[T]
Expand All @@ -16,7 +20,7 @@ var/global/datum/matchmaker/matchmaker = new()
return TRUE
if(!job.create_record)
return TRUE
matchmaker.do_matchmaking()
do_matchmaking()
return TRUE

/datum/mind
Expand Down
7 changes: 7 additions & 0 deletions nebula.dme
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,15 @@
#include "code\datums\music_tracks\wake.dm"
#include "code\datums\observation\_defines.dm"
#include "code\datums\observation\area_power_change.dm"
#include "code\datums\observation\crate_sold.dm"
#include "code\datums\observation\cyborg_created.dm"
#include "code\datums\observation\death.dm"
#include "code\datums\observation\debrain.dm"
#include "code\datums\observation\density_set.dm"
#include "code\datums\observation\destroyed.dm"
#include "code\datums\observation\dir_set.dm"
#include "code\datums\observation\dismembered.dm"
#include "code\datums\observation\employee_id.dm"
#include "code\datums\observation\entered.dm"
#include "code\datums\observation\equipped.dm"
#include "code\datums\observation\examine.dm"
Expand All @@ -561,17 +565,20 @@
#include "code\datums\observation\life.dm"
#include "code\datums\observation\logged_in.dm"
#include "code\datums\observation\logged_out.dm"
#include "code\datums\observation\money_accounts.dm"
#include "code\datums\observation\moved.dm"
#include "code\datums\observation\name_set.dm"
#include "code\datums\observation\observation.dm"
#include "code\datums\observation\opacity_set.dm"
#include "code\datums\observation\player_latejoin.dm"
#include "code\datums\observation\see_in_dark_set.dm"
#include "code\datums\observation\see_invisible_set.dm"
#include "code\datums\observation\set_invisibility.dm"
#include "code\datums\observation\shuttle_added.dm"
#include "code\datums\observation\shuttle_moved.dm"
#include "code\datums\observation\sight_set.dm"
#include "code\datums\observation\stat_set.dm"
#include "code\datums\observation\submap_join.dm"
#include "code\datums\observation\unequipped.dm"
#include "code\datums\observation\updated_icon.dm"
#include "code\datums\observation\zone_selected.dm"
Expand Down
2 changes: 1 addition & 1 deletion test/check-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exactly() { # exactly N name search [mode] [filter]
# With the potential exception of << if you increase any of these numbers you're probably doing it wrong
# Additional exception August 2020: \b is a regex symbol as well as a BYOND macro.
exactly 1 "escapes" '\\\\(red|blue|green|black|b|i[^mc])'
exactly 5 "Del()s" '\WDel\('
exactly 6 "Del()s" '\WDel\('
exactly 2 "/atom text paths" '"/atom'
exactly 2 "/area text paths" '"/area'
exactly 2 "/datum text paths" '"/datum'
Expand Down

0 comments on commit 253dae5

Please sign in to comment.