With the help of my partner - the two of us banged our heads against this for a few hours lol - we found a workable way to have the Character() displayable highlight in its original color.
Replace:
def get_all_character_names(): # dynamically fetch all Character() instances and returns their names, then adds them to a list
persistent.character_names.clear() # Clear previous names
for key, value in globals().items():
if hasattr(value, "name") and isinstance(value.name, str): # Check for valid character names
cleaned_name = remove_renpy_tags(value.name) # Strip {sc} or other tags
persistent.character_names.add(cleaned_name) # Add the character name to the list
return persistent.character_names
With:
def get_names_and_colors(): # get all Character() instance names and colors
persistent.character_coloration.clear() #clear previous list
for key, value in globals().items():
if isinstance(value, type(renpy.store.adv)) and isinstance(value.name, str): # make sure it's calling up the character type and not directly taking variable names for dynamic names
cleaned_name = remove_renpy_tags(value.name) # strip out text tags for name
screen, show_args, who_args, what_args, window_args, properties = value.get_show_properties(None)
if not "color" in who_args: #ignore names with no color argument
continue
cleaned_color = remove_renpy_tags(who_args["color"]) # strip out text tags for color
persistent.character_coloration.update({cleaned_name: cleaned_color}) # add the cleaned tags to the dictionary
return persistent.character_coloration
and replace:
if enable_character_name_highlighting:
escaped_names = [re.escape(name) for name in persistent.character_names]
if escaped_names: # This section makes sure we match whole words only. E.g if you have a character called Bill, the 'Bill' in Billby won't highlight.
pattern = r'\b(' + r'|'.join(escaped_names) + r')\b'
text = re.sub(pattern, r"{{color={}}}\1{{/color}}".format(highlight_color_names), text)
with:
if enable_character_name_highlighting:
for name, color in persistent.character_coloration.items():
escaped_name = re.escape(name)
pattern = r'\b(' + escaped_name + r')\b'
text = re.sub(pattern, r"{{color={}}}\1{{/color}}".format(color), text)
And whenever you use 'character_names' or 'persistent.character_names', use 'persistent.character_coloration' or 'persistent.character_coloration' respectively instead in the script.
OH RIGHT and for the very top, you want to change 'define persistent.character_names = set()' to 'define persistent.character_coloration = {}' - basically instead of a set, it's a dictionary.
Behind the scenes, what this is doing is it's tying the character name to a key and the color to a value. It's also making sure that it's only taking from the Character() object, rather than anything with a name value or otherwise, which it was doing before. (If your game name was highlighting when you didn't enable that - yes, that's why.) If you have a character without a color value (such as, for example, if you have a default 'new' character like I do, whose name is '???' or 'Stranger', so you don't have every instance of the name 'stranger' highlighting in your text), it just ignores it and moves on to the next value.
Then, in the highlight filter stuff, it's still only taking the full and whole name (so 'William' will highlight, but not 'Will', or 'Bill' but not 'Billby'), and using the color attached to the name key to fill in what color it shows up as.
I hope this helps!
Also, everyone say 'thank you Kunabee's partner', because his patience and assistance is the reason this exists at all. Like 99% of this code is his, he's the smart one, I'm just here creating things and asking him to do ridiculous stuff lol







