From 292ecc35c82e0a9f541e50c624d757ce35413fd3 Mon Sep 17 00:00:00 2001 From: Brandon Cornejo Date: Sun, 8 Feb 2026 18:33:37 -0600 Subject: [PATCH] map-door-text custom matches updates --- .gitignore | 1 + src/mdt_matchcontrol.py | 61 +++++++++++++++++++++++++++++++++++++++++ src/mdtparse.py | 6 ++++ 3 files changed, 68 insertions(+) create mode 100644 src/mdt_matchcontrol.py diff --git a/.gitignore b/.gitignore index 7e52b31..a8a1b1e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ src/personal.tin src/wamgsaver.tin src/constants.tin src/timer.tin +src/testing.tin diff --git a/src/mdt_matchcontrol.py b/src/mdt_matchcontrol.py new file mode 100644 index 0000000..8726640 --- /dev/null +++ b/src/mdt_matchcontrol.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import re +import sys +import json + + +class MapDoorTextControl: + colour_map = { + # http://terminal-color-builder.mudasobwa.ru/ + "orange": "\033[01;38;05;214m", + "red": "\033[01;38;05;196m", + "cyan": "\033[01;38;05;37m", + "reset": "\033[00;39;49m" + } + + def __init__(self): + self.custom_matches = [] + + # Load any additional custom matches + with open('logs/features/mdt_custom_matches.json', 'r') as custom_file: + config = json.load(custom_file) + + # Strip comments from custom matches + for match in config: + if len(match) > 1: + self.custom_matches.append(match) + + def _write_file(self): + with open('logs/features/mdt_custom_matches.json', 'w') as custom_file: + json.dump(self.custom_matches, custom_file) + + def add_match(self, pattern, color="red", value=5, is_regex=False): + self.custom_matches.append([pattern, color, value, is_regex]) + self._write_file() + + def remove_match(self, pattern): + for match in self.custom_matches: + if match[0] == pattern or pattern in match[0]: + self.custom_matches.remove(match) + self._write_file() + + +if __name__ == '__main__': + if len(sys.argv) < 2: + #print('[error] Missing inputs. Usage: mdt_matchcontrol.py ') + print(0) + sys.exit() + + script, command, pattern = sys.argv.pop(0), sys.argv.pop(0), " ".join(sys.argv) + + mdtc = MapDoorTextControl() + if command == "add": + mdtc.add_match(pattern) + print(1) + elif command == "remove": + mdtc.remove_match(pattern) + print(1) + else: + #print('[error] Unrecognized command, valid commands are "add" and "remove".') + print(0) diff --git a/src/mdtparse.py b/src/mdtparse.py index 1fe80f1..b155595 100644 --- a/src/mdtparse.py +++ b/src/mdtparse.py @@ -86,6 +86,12 @@ class MapDoorText: with open('mdtconfig.json', 'r') as config_file: config = json.load(config_file) + # Load any additional custom matches + with open('logs/features/mdt_custom_matches.json', 'r') as custom_file: + additional_matches = json.load(custom_file) + + config['custom_matches'] = config['custom_matches'] + additional_matches; + # Strip comments from custom matches for match in config['custom_matches']: if len(match) > 1: