From ca99c1680374d8b1d20b5a0dc8993a0a20454c8b Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 23 Feb 2026 13:41:45 +0100 Subject: [PATCH 1/3] Add a debugging script --- .gitignore | 1 + .vscode/build.py | 2 +- .vscode/debug.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++ .vscode/tasks.json | 26 +++++++++++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 .vscode/debug.py diff --git a/.gitignore b/.gitignore index d5b17b37e..d55a43adc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/settings.json +.vscode/temp/ .mo \ No newline at end of file diff --git a/.vscode/build.py b/.vscode/build.py index ff0144fdb..1dd92f635 100644 --- a/.vscode/build.py +++ b/.vscode/build.py @@ -19,6 +19,7 @@ except ImportError: pygetwindow = None +PLATFORM = platform.system() # Helper Functions @@ -124,7 +125,6 @@ def copy_preview_image(output_folder, branch): GAME_NAME = CONFIG["GAME_NAME"] HOTKEY = CONFIG["HOTKEY"] FORCE_GO = CONFIG["FORCE_GO"] -PLATFORM = platform.system() WINDOW_TITLE = "Tabletop Simulator" diff --git a/.vscode/debug.py b/.vscode/debug.py new file mode 100644 index 000000000..3eda9d9d3 --- /dev/null +++ b/.vscode/debug.py @@ -0,0 +1,82 @@ +import json +import platform +import sys +import subprocess +from pathlib import Path + +PLATFORM = platform.system() + + +def load_config(): + """Loads configuration from build_config.json with defaults.""" + config_path = Path(__file__).parent / "build_config.json" + data = {"GAME_NAME": "ArkhamSCE", "HOTKEY": "f13", "FORCE_GO": False} # Defaults + + if config_path.is_file(): + try: + with open(config_path, "r") as f: + user_config = json.load(f) + data.update(user_config) + except Exception as e: + print(f"Warning: Could not read build_config.json ({e}). Using defaults.") + return data + + +# CONFIGURATION +CONFIG = load_config() +GAME_NAME = CONFIG["GAME_NAME"] +HOTKEY = CONFIG["HOTKEY"] +FORCE_GO = CONFIG["FORCE_GO"] +WINDOW_TITLE = "Tabletop Simulator" + + +def get_output_folder(): + home = Path.home() + if PLATFORM == "Windows": + return home / "Documents" / "My Games" / "Tabletop Simulator" / "Saves" + else: + return home / "Library" / "Tabletop Simulator" / "Saves" + + +# Recursive search for the GUID in ObjectStates +def find_script(objects, target_guid): + for obj in objects: + if obj.get("GUID") == target_guid: + return obj.get("LuaScript", "") + if "ContainedObjects" in obj: + result = find_script(obj["ContainedObjects"], target_guid) + if result: + return result + return None + + +def open_bundled_script(target_guid, line_number): + output_folder = get_output_folder() + save_path = output_folder / f"{GAME_NAME}.json" + + with open(save_path, "r", encoding="utf-8") as f: + data = json.load(f) + + if target_guid.lower() == "global": + script_content = data.get("LuaScript", "") + else: + script_content = find_script(data.get("ObjectStates", []), target_guid) + + if script_content: + # Create a temp file for debugging + temp_dir = Path(__file__).parent / "temp" + temp_dir.mkdir(exist_ok=True) + temp_path = temp_dir / f"DEBUG_{target_guid}.ttslua" + with open(temp_path, "w", encoding="utf-8", newline='') as f: + f.write(script_content) + + # Open in VS Code at the specific line: code -g file:line + subprocess.run(["code", "-g", f"{temp_path}:{line_number}"], shell=True) + print("Opened bundled script at correct line for debugging.") + else: + print(f"Object {target_guid} not found.") + + +if __name__ == "__main__": + # Usage: python debug.py + open_bundled_script(sys.argv[1], sys.argv[2]) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c80815599..9bbbbc8b5 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -36,6 +36,32 @@ "cwd": "${workspaceFolder}${pathSeparator}.vscode" }, "problemMatcher": [] + }, + { + "label": "Arkham SCE: Debug Line", + "type": "shell", + "command": "python", + "args": [ + "${workspaceFolder}/.vscode/debug.py", + "${input:guid}", + "${input:line}" + ], + "options": { + "cwd": "${workspaceFolder}${pathSeparator}.vscode" + }, + "problemMatcher": [] + } + ], + "inputs": [ + { + "id": "guid", + "type": "promptString", + "description": "Enter Object GUID (or global)" + }, + { + "id": "line", + "type": "promptString", + "description": "Enter Error Line Number" } ] } \ No newline at end of file From 3d5387a7716ed69deea98528c523f3b5a909dd7c Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 23 Feb 2026 14:06:56 +0100 Subject: [PATCH 2/3] update debugging script --- .vscode/debug.py | 67 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/.vscode/debug.py b/.vscode/debug.py index 3eda9d9d3..de33c0091 100644 --- a/.vscode/debug.py +++ b/.vscode/debug.py @@ -1,5 +1,6 @@ import json import platform +import re import sys import subprocess from pathlib import Path @@ -50,6 +51,56 @@ def find_script(objects, target_guid): return None +def open_source_file(bundled_code, error_line): + lines = bundled_code.splitlines() + current_module = "Main / Wrapper" + module_start_line = 0 + + # Regex to find: __bundle_register("module/name", function(...) + register_pattern = re.compile(r'__bundle_register\("([^"]+)"') + + # Step 1: Find which module the error line falls into + for i, line in enumerate(lines): + current_line_num = i + 1 + match = register_pattern.search(line) + + if match: + # If the current error line is before this new register starts, + # it belonged to the previous module. + if current_line_num > error_line: + break + current_module = match.group(1) + module_start_line = current_line_num + + # Step 2: Calculate the local line number within that module + # We subtract the header lines added by the register: + # Usually: __bundle_register(..., function(...) \n do + local_line = (error_line - module_start_line) - 1 + + print(f"Error found in module: {current_module} at local line: {local_line}") + + # Step 3: Find the file in your project + # Assumes your source is in 'src' and this script is in '.vscode' + possible_file = Path.cwd().parent / "src" / f"{current_module}.ttslua" + + print(possible_file) + if possible_file.exists(): + print("Source file found, opening it.") + # Offset of 1 needed for correct line number (due to "actual" script being one require line) + subprocess.run(["code", "-g", f"{str(possible_file)}:{local_line + 1}"], shell=True) + else: + # Fallback: Open the temp bundled file if source not found + print("Source file not found, opening bundled code instead.") + temp_dir = Path(__file__).parent / "temp" + temp_dir.mkdir(exist_ok=True) + temp_path = temp_dir / f"debug.ttslua" + with open(temp_path, "w", encoding="utf-8", newline='') as f: + f.write(bundled_code) + + # Open in VS Code at the specific line: code -g file:line + subprocess.run(["code", "-g", f"{temp_path}:{error_line}"], shell=True) + + def open_bundled_script(target_guid, line_number): output_folder = get_output_folder() save_path = output_folder / f"{GAME_NAME}.json" @@ -57,26 +108,18 @@ def open_bundled_script(target_guid, line_number): with open(save_path, "r", encoding="utf-8") as f: data = json.load(f) + # Find Global or Object script if target_guid.lower() == "global": script_content = data.get("LuaScript", "") else: script_content = find_script(data.get("ObjectStates", []), target_guid) if script_content: - # Create a temp file for debugging - temp_dir = Path(__file__).parent / "temp" - temp_dir.mkdir(exist_ok=True) - temp_path = temp_dir / f"DEBUG_{target_guid}.ttslua" - with open(temp_path, "w", encoding="utf-8", newline='') as f: - f.write(script_content) - - # Open in VS Code at the specific line: code -g file:line - subprocess.run(["code", "-g", f"{temp_path}:{line_number}"], shell=True) - print("Opened bundled script at correct line for debugging.") + open_source_file(script_content, int(line_number)) else: print(f"Object {target_guid} not found.") if __name__ == "__main__": - # Usage: python debug.py - open_bundled_script(sys.argv[1], sys.argv[2]) + if len(sys.argv) > 2: + open_bundled_script(sys.argv[1], sys.argv[2]) From 59e95a221d97b47bb4f892ec652296b3db5ef4aa Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 23 Feb 2026 14:34:01 +0100 Subject: [PATCH 3/3] update for build action --- .vscode/build.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.vscode/build.py b/.vscode/build.py index 1dd92f635..d54d41ec8 100644 --- a/.vscode/build.py +++ b/.vscode/build.py @@ -109,15 +109,20 @@ def load_savegame_in_TTS(): def copy_preview_image(output_folder, branch): - image_name = GAME_NAME + ".png" - if branch and branch != "main": - image_name = GAME_NAME + "_dev.png" + base_image = Path(f"{GAME_NAME}.png") + dev_image = Path(f"{GAME_NAME}_dev.png") - image_path = Path(image_name) - if image_path.is_file(): - shutil.copy(image_path, output_folder / f"{GAME_NAME}.png") + # Use dev image ONLY if on a non-main branch AND the file exists + if branch and branch != "main" and dev_image.exists(): + source_image = dev_image else: - print(f"Note: Icon {image_name} not found, skipping copy.") + source_image = base_image + + # Perform the copy (and maybe rename) with a safety check + if source_image.exists(): + shutil.copy(source_image, output_folder / base_image) + else: + print(f"Note: Icon {source_image} not found, skipping copy.") # CONFIGURATION