From c244d6c69aacf9a63fda8a83ee7ef9f8995482d3 Mon Sep 17 00:00:00 2001 From: AnturK Date: Wed, 2 Feb 2022 06:34:43 +0100 Subject: [PATCH] Adds direct support for weakrefs to vv (#64521) * Adds direct support for weakrefs to vv * Update code/modules/admin/view_variables/get_variables.dm Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> * Fine, have a readable name. Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- code/__DEFINES/vv.dm | 3 +++ code/datums/weakrefs.dm | 14 ++++++++++++++ .../admin/view_variables/debug_variables.dm | 3 +++ .../admin/view_variables/get_variables.dm | 17 +++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/code/__DEFINES/vv.dm b/code/__DEFINES/vv.dm index 23da32cc827..0334870cf1a 100644 --- a/code/__DEFINES/vv.dm +++ b/code/__DEFINES/vv.dm @@ -25,6 +25,7 @@ #define VV_BITFIELD "Bitfield" #define VV_TEXT_LOCATE "Custom Reference Locate" #define VV_PROCCALL_RETVAL "Return Value of Proccall" +#define VV_WEAKREF "Weak Reference Datum" #define VV_MSG_MARKED "
Marked Object" #define VV_MSG_EDITED "
Var Edited" @@ -163,3 +164,5 @@ #define VV_HK_SPELL_UNSET_HUMANONLY "spell_unset_humanonly" /// Abstract mobs such as brains or pAIs can cast this spell. #define VV_HK_SPELL_UNSET_NONABSTRACT "spell_unset_nonabstract" + +#define VV_HK_WEAKREF_RESOLVE "weakref_resolve" diff --git a/code/datums/weakrefs.dm b/code/datums/weakrefs.dm index 9da63abd07e..302aa29b53c 100644 --- a/code/datums/weakrefs.dm +++ b/code/datums/weakrefs.dm @@ -75,3 +75,17 @@ /datum/weakref/proc/resolve() var/datum/D = locate(reference) return (!QDELETED(D) && D.weak_reference == src) ? D : null + + +/datum/weakref/vv_get_dropdown() + . = ..() + VV_DROPDOWN_OPTION(VV_HK_WEAKREF_RESOLVE, "Go to reference") + +/datum/weakref/vv_do_topic(list/href_list) + . = ..() + if(href_list[VV_HK_WEAKREF_RESOLVE]) + if(!check_rights(NONE)) + return + var/datum/R = resolve() + if(R) + usr.client.debug_variables(R) diff --git a/code/modules/admin/view_variables/debug_variables.dm b/code/modules/admin/view_variables/debug_variables.dm index 938cac122e4..8e9d77cf098 100644 --- a/code/modules/admin/view_variables/debug_variables.dm +++ b/code/modules/admin/view_variables/debug_variables.dm @@ -61,6 +61,9 @@ item = "[name_part] = [DV] [DV.type] [REF(value)]" else item = "[name_part] = [DV.type] [REF(value)]" + if(istype(value,/datum/weakref)) + var/datum/weakref/weakref = value + item += " (Resolve)" else if (islist(value)) var/list/L = value diff --git a/code/modules/admin/view_variables/get_variables.dm b/code/modules/admin/view_variables/get_variables.dm index 9dd0083898a..8120a710c70 100644 --- a/code/modules/admin/view_variables/get_variables.dm +++ b/code/modules/admin/view_variables/get_variables.dm @@ -28,6 +28,9 @@ else if(istype(var_value, /client)) . = VV_CLIENT + else if(istype(var_value, /datum/weakref)) + . = VV_WEAKREF + else if(istype(var_value, /datum)) . = VV_DATUM_REFERENCE @@ -78,6 +81,7 @@ VV_RESTORE_DEFAULT, VV_TEXT_LOCATE, VV_PROCCALL_RETVAL, + VV_WEAKREF, ) var/markstring @@ -201,6 +205,19 @@ return .["value"] = things[value] + if(VV_WEAKREF) + var/type = pick_closest_path(FALSE, get_fancy_list_of_datum_types()) + var/subtypes = vv_subtype_prompt(type) + if(subtypes == null) + .["class"] = null + return + var/list/things = vv_reference_list(type, subtypes) + var/value = input("Select reference:", "Reference", current_value) as null|anything in things + if(!value) + .["class"] = null + return + .["value"] = WEAKREF(things[value]) + if(VV_CLIENT) .["value"] = input("Select reference:", "Reference", current_value) as null|anything in GLOB.clients if(.["value"] == null)