From 51ff7e2524d04ec2f699e499133ca0ebfc9527b9 Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Sat, 17 May 2025 21:49:18 +0530 Subject: [PATCH] Simplifies borg omnitool test (#91026) ## About The Pull Request Makes the unit test much more light weight & faster Testing individual tools in the toolkit is redundant, We only need to test 1 & can know the others will work for all borg model types as we only need to check if it reaches the attack chain or not ## Changelog :cl: code: borg omnitool unit test is much faster /:cl: --------- Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> --- code/game/objects/items/robot/items/tools.dm | 34 +++++-- code/modules/unit_tests/omnitools.dm | 97 +++----------------- 2 files changed, 40 insertions(+), 91 deletions(-) diff --git a/code/game/objects/items/robot/items/tools.dm b/code/game/objects/items/robot/items/tools.dm index 68c41bdc281..0cf8a7522a8 100644 --- a/code/game/objects/items/robot/items/tools.dm +++ b/code/game/objects/items/robot/items/tools.dm @@ -186,6 +186,21 @@ return ..() +/** + * Sets the new internal tool to be used + * Arguments + * + * * obj/item/ref - typepath for the new internal omnitool + */ +/obj/item/borg/cyborg_omnitool/proc/set_internal_tool(obj/item/tool) + SHOULD_NOT_OVERRIDE(TRUE) + + for(var/obj/item/internal_tool as anything in omni_toolkit) + if(internal_tool == tool) + reference = internal_tool + tool_behaviour = initial(internal_tool.tool_behaviour) + break + /obj/item/borg/cyborg_omnitool/get_all_tool_behaviours() . = list() for(var/obj/item/tool as anything in omni_toolkit) @@ -220,20 +235,21 @@ /obj/item/borg/cyborg_omnitool/attack_self(mob/user) //build the radial menu options var/list/radial_menu_options = list() + var/list/tool_map = list() for(var/obj/item as anything in omni_toolkit) - radial_menu_options[initial(item.name)] = image(icon = initial(item.icon), icon_state = initial(item.icon_state)) + var/tool_name = initial(item.name) + radial_menu_options[tool_name] = image(icon = initial(item.icon), icon_state = initial(item.icon_state)) + tool_map[tool_name] = item //assign the new tool behaviour - var/toolkit_menu = show_radial_menu(user, src, radial_menu_options, require_near = TRUE, tooltips = TRUE) + var/internal_tool_name = show_radial_menu(user, src, radial_menu_options, require_near = TRUE, tooltips = TRUE) + if(!internal_tool_name) + return //set the reference & update icons - for(var/obj/item/tool as anything in omni_toolkit) - if(initial(tool.name) == toolkit_menu) - reference = tool - tool_behaviour = initial(tool.tool_behaviour) - update_appearance(UPDATE_ICON_STATE) - playsound(src, 'sound/items/tools/change_jaws.ogg', 50, TRUE) - break + set_internal_tool(tool_map[internal_tool_name]) + update_appearance(UPDATE_ICON_STATE) + playsound(src, 'sound/items/tools/change_jaws.ogg', 50, TRUE) /obj/item/borg/cyborg_omnitool/update_icon_state() if (reference) diff --git a/code/modules/unit_tests/omnitools.dm b/code/modules/unit_tests/omnitools.dm index 9d974138de6..930c6a34f0a 100644 --- a/code/modules/unit_tests/omnitools.dm +++ b/code/modules/unit_tests/omnitools.dm @@ -1,28 +1,16 @@ -/datum/unit_test/omnitools - abstract_type = /datum/unit_test/omnitools - - //The borg model tot ransform to - var/borg_model = /obj/item/robot_model - //Tool type - var/tool_type = /obj/item/borg/cyborg_omnitool - -///Test the current tool in the toolkit -/datum/unit_test/omnitools/proc/TestTool(mob/living/silicon/robot/borg, obj/item/borg/cyborg_omnitool) - PROTECTED_PROC(TRUE) - - return - /datum/unit_test/omnitools/Run() var/mob/living/silicon/robot/borg = allocate(__IMPLIED_TYPE__) + var/obj/structure/frame/machine/test_frame = allocate(__IMPLIED_TYPE__) + test_frame.state = FRAME_STATE_WIRED //transform to engiborg - borg.model.transform_to(borg_model, forced = TRUE, transform = FALSE) + borg.model.transform_to(/obj/item/robot_model/engineering, forced = TRUE, transform = FALSE) var/obj/item/borg/cyborg_omnitool/omnitool = null for(var/obj/item/borg/tool as anything in borg.model.modules) - if(istype(tool, tool_type)) + if(istype(tool, /obj/item/borg/cyborg_omnitool/engineering)) omnitool = tool break - TEST_ASSERT_NOTNULL(omnitool, "Could not find [tool_type] in borg inbuilt modules!") + TEST_ASSERT_NOTNULL(omnitool, "Could not find /obj/item/borg/cyborg_omnitool/engineering in borg inbuilt modules!") borg.shown_robot_modules = TRUE //stops hud from updating which would runtime cause our mob does not have one borg.equip_module_to_slot(omnitool, 1) borg.select_module(1) @@ -30,71 +18,16 @@ //these must match TEST_ASSERT_EQUAL(borg.get_active_held_item(), omnitool, "Borg held tool is not the selected omnitool!") - for(var/obj/item/internal_tool as anything in omnitool.omni_toolkit) - //Initialize the tool - omnitool.reference = internal_tool - omnitool.tool_behaviour = initial(internal_tool.tool_behaviour) + //Initialize the tool + omnitool.set_internal_tool(/obj/item/wirecutters/cyborg) - //Test it - TestTool(borg, omnitool) + //Check the proxy attacker is of this type + var/obj/item/proxy = omnitool.get_proxy_attacker_for(test_frame, borg) + TEST_ASSERT_EQUAL(proxy.type, /obj/item/wirecutters/cyborg, "Omnitool proxy attacker [proxy.type] does not match selected type /obj/item/wirecutters/cyborg") + //Test the attack chain to see if the internal tool interacted correctly with the target + omnitool.melee_attack_chain(borg, test_frame) + TEST_ASSERT_EQUAL(test_frame.state, FRAME_STATE_EMPTY, "Machine frame's wires were not cut by the borg omnitool wirecutters!") + + //unequip borg.unequip_module_from_slot(omnitool, 1) - - -/// Tests for engiborg omnitool -/datum/unit_test/omnitools/engiborg - borg_model = /obj/item/robot_model/engineering - tool_type = /obj/item/borg/cyborg_omnitool/engineering - - /// frame to test wirecutter & screwdriver - var/obj/structure/frame/machine/test_frame - -/datum/unit_test/omnitools/engiborg/TestTool(mob/living/silicon/robot/borg, obj/item/borg/cyborg_omnitool/held_item) - var/tool_behaviour = held_item.tool_behaviour - - switch(tool_behaviour) - //Tests for omnitool wrench - if(TOOL_WRENCH) - var/obj/machinery/cell_charger/charger = allocate(__IMPLIED_TYPE__) - //Test 1: charger must be anchored - held_item.melee_attack_chain(borg, charger) - TEST_ASSERT(!charger.anchored, "Cell charger was not unanchored by borg omnitool wrench!") - //Test 2: charger must be unanchored - held_item.melee_attack_chain(borg, charger) - TEST_ASSERT(charger.anchored, "Cell charger was not anchored by borg omnitool wrench!") - - //Tests for omnitool wirecutter - if(TOOL_WIRECUTTER) - //Test 1: is holding wirecutters for wires - TEST_ASSERT(borg.is_holding_tool_quality(TOOL_WIRECUTTER), "Cannot find borg omnitool wirecutters in borgs hand!") - - //Test 2: frame wires must be cut - if(isnull(test_frame)) - test_frame = allocate(__IMPLIED_TYPE__) - test_frame.state = FRAME_STATE_WIRED - held_item.melee_attack_chain(borg, test_frame) - TEST_ASSERT_EQUAL(test_frame.state, FRAME_STATE_EMPTY, "Machine frame's wires were not cut by the borg omnitool wirecutters!") - - //Test for omnitool screwdriver - if(TOOL_SCREWDRIVER) - //Test 1: dissemble frame - held_item.melee_attack_chain(borg, test_frame) - TEST_ASSERT(QDELETED(test_frame), "Machine frame was not deconstructed by borg omnitool screwdriver!") - - //Test for borg omnitool crowbar - if(TOOL_CROWBAR) - var/obj/machinery/recharger/recharger = allocate(__IMPLIED_TYPE__) - recharger.panel_open = TRUE - //Test 1: should dissemble the charger - held_item.melee_attack_chain(borg, recharger) - TEST_ASSERT(QDELETED(recharger), "Recharger was not deconstructed by borg omnitool crowbar!") - - //Test for borg omnitool multitool - if(TOOL_MULTITOOL) - var/obj/machinery/ore_silo/silo = allocate(__IMPLIED_TYPE__) - //Test 1: should store silo in buffer - held_item.melee_attack_chain(borg, silo) - var/obj/item/multitool/tool = held_item.get_proxy_attacker_for(silo, borg) - TEST_ASSERT(istype(tool), "Borg failed to switch internal tool to multitool") - TEST_ASSERT(istype(tool.buffer, /obj/machinery/ore_silo), "Borg omnitool multitool failed to log ore silo!") -