From 2bb2d2a7ca4bb3d45f60ad543227989bbea036cf Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 25 Jun 2022 02:24:23 +0200 Subject: [PATCH] All code files must now be included in the .dme, removes some old duplicate files that never were (#14485) Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- code/__HELPERS/logging/tools.dm | 3 - .../ai/objects/cursed/cursed_subtrees.dm | 15 --- code/datums/ai/objects/item_behaviors.dm | 13 --- tgstation.dme | 1 + tools/validate_dme.py | 92 +++++++++++++++++++ 5 files changed, 93 insertions(+), 31 deletions(-) delete mode 100644 code/__HELPERS/logging/tools.dm delete mode 100644 code/datums/ai/objects/cursed/cursed_subtrees.dm delete mode 100644 code/datums/ai/objects/item_behaviors.dm create mode 100644 tools/validate_dme.py diff --git a/code/__HELPERS/logging/tools.dm b/code/__HELPERS/logging/tools.dm deleted file mode 100644 index 4c5f2d3e655..00000000000 --- a/code/__HELPERS/logging/tools.dm +++ /dev/null @@ -1,3 +0,0 @@ -/proc/log_tool(text, mob/initiator) - if(CONFIG_GET(flag/log_tools)) - WRITE_LOG(GLOB.world_tool_log, "TOOL: [text]") diff --git a/code/datums/ai/objects/cursed/cursed_subtrees.dm b/code/datums/ai/objects/cursed/cursed_subtrees.dm deleted file mode 100644 index b884334cb03..00000000000 --- a/code/datums/ai/objects/cursed/cursed_subtrees.dm +++ /dev/null @@ -1,15 +0,0 @@ -/datum/ai_planning_subtree/cursed/SelectBehaviors(datum/ai_controller/controller, delta_time) - var/obj/item/item_pawn = controller.pawn - - //make sure we have a target - var/datum/weakref/target_ref = controller.blackboard[BB_ITEM_TARGET] - var/mob/living/carbon/curse_target = target_ref?.resolve() - - if(curse_target && get_dist(curse_target, item_pawn) > ITEM_AGGRO_VIEW_RANGE) - controller.blackboard[BB_ITEM_TARGET] = null - return - - if(!curse_target) - controller.queue_behavior(/datum/ai_behavior/find_and_set/item_target, BB_ITEM_TARGET, /mob/living/carbon, ITEM_AGGRO_VIEW_RANGE) - - controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/ghostly, BB_ITEM_TARGET, BB_ITEM_THROW_ATTEMPT_COUNT) diff --git a/code/datums/ai/objects/item_behaviors.dm b/code/datums/ai/objects/item_behaviors.dm deleted file mode 100644 index 2d98593743f..00000000000 --- a/code/datums/ai/objects/item_behaviors.dm +++ /dev/null @@ -1,13 +0,0 @@ - -///This behavior is for obj/items, it is used to free themselves out of the hands of whoever is holding them -/datum/ai_behavior/item_escape_grasp - -/datum/ai_behavior/item_escape_grasp/perform(delta_time, datum/ai_controller/controller) - . = ..() - var/obj/item/item_pawn = controller.pawn - var/mob/item_holder = item_pawn.loc - if(!istype(item_holder)) - finish_action(controller, FALSE) //We're no longer beind held. abort abort!! - item_pawn.visible_message(span_warning("[item_pawn] slips out of the hands of [item_holder]!")) - item_holder.dropItemToGround(item_pawn, TRUE) - finish_action(controller, TRUE) diff --git a/tgstation.dme b/tgstation.dme index e5b92d04bed..511742df4cd 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -2835,6 +2835,7 @@ #include "code\modules\events\anomaly_bluespace.dm" #include "code\modules\events\anomaly_flux.dm" #include "code\modules\events\anomaly_grav.dm" +#include "code\modules\events\anomaly_hallucination.dm" #include "code\modules\events\anomaly_pyro.dm" #include "code\modules\events\anomaly_vortex.dm" #include "code\modules\events\aurora_caelus.dm" diff --git a/tools/validate_dme.py b/tools/validate_dme.py new file mode 100644 index 00000000000..c2b4bfda5b3 --- /dev/null +++ b/tools/validate_dme.py @@ -0,0 +1,92 @@ +import fnmatch +import functools +import glob +import sys + +reading = False + +FORBID_INCLUDE = [ + # Included by _unit_test.dm + r'code/modules/unit_tests/[!_]*.dm', + + # Included by tgs/includes.dm + r'code/modules/tgs/**/*.dm', +] + +lines = [] + +for line in sys.stdin: + line = line.strip() + + if line == "// BEGIN_INCLUDE": + reading = True + continue + elif line == "// END_INCLUDE": + break + elif not reading: + continue + + lines.append(line) + +fail_no_include = False + +for code_file in glob.glob("code/**/*.dm", recursive=True): + dm_path = code_file.replace('/', '\\') + + included = f"#include \"{dm_path}\"" in lines + forbid_include = False + + for forbid in FORBID_INCLUDE: + if not fnmatch.fnmatch(code_file, forbid): + continue + + forbid_include = True + + if included: + print(f"{dm_path} should not be included") + print(f"::error file={code_file},line=1,title=DME Validator::File should not be included") + fail_no_include = True + + if forbid_include: + continue + + if not included: + print(f"{dm_path} is not included") + print(f"::error file={code_file},line=1,title=DME Validator::File is not included") + fail_no_include = True + +if fail_no_include: + sys.exit(1) + +def compare_lines(a, b): + # Remove initial include as well as the final quotation mark + a = a[len("#include \""):-1].lower() + b = b[len("#include \""):-1].lower() + + a_segments = a.split('\\') + b_segments = b.split('\\') + + for (a_segment, b_segment) in zip(a_segments, b_segments): + a_is_file = a_segment.endswith(".dm") + b_is_file = b_segment.endswith(".dm") + + # code\something.dm will ALWAYS come before code\directory\something.dm + if a_is_file and not b_is_file: + return -1 + + if b_is_file and not a_is_file: + return 1 + + # interface\something.dm will ALWAYS come after code\something.dm + if a_segment != b_segment: + return (a_segment > b_segment) - (a_segment < b_segment) + + raise f"Two lines were exactly the same ({a} vs. {b})" + +sorted_lines = sorted(lines, key = functools.cmp_to_key(compare_lines)) + +for (index, line) in enumerate(lines): + if sorted_lines[index] != line: + print(f"The include at line {index + 1} is out of order ({line})") + print(f"::error file=tgstation.dme,line={index+1},title=DME Validator::The include at line {index + 1} is out of order ({line})") + sys.exit(1)