SC2: Fix /received display bugs (#3949)

* SC2: Fix location display in /received command

* SC2: Backport broken markup fix in /received output from the dev branch

* Cleanup
This commit is contained in:
Ziktofel 2024-09-17 23:18:43 +02:00 committed by GitHub
parent 8f7e0dc441
commit b982e9ebb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 8 deletions

View File

@ -97,12 +97,12 @@ class ConfigurableOptionInfo(typing.NamedTuple):
class ColouredMessage: class ColouredMessage:
def __init__(self, text: str = '') -> None: def __init__(self, text: str = '', *, keep_markup: bool = False) -> None:
self.parts: typing.List[dict] = [] self.parts: typing.List[dict] = []
if text: if text:
self(text) self(text, keep_markup=keep_markup)
def __call__(self, text: str) -> 'ColouredMessage': def __call__(self, text: str, *, keep_markup: bool = False) -> 'ColouredMessage':
add_json_text(self.parts, text) add_json_text(self.parts, text, keep_markup=keep_markup)
return self return self
def coloured(self, text: str, colour: str) -> 'ColouredMessage': def coloured(self, text: str, colour: str) -> 'ColouredMessage':
add_json_text(self.parts, text, type="color", color=colour) add_json_text(self.parts, text, type="color", color=colour)
@ -128,7 +128,7 @@ class StarcraftClientProcessor(ClientCommandProcessor):
# Note(mm): Bold/underline can help readability, but unfortunately the CommonClient does not filter bold tags from command-line output. # Note(mm): Bold/underline can help readability, but unfortunately the CommonClient does not filter bold tags from command-line output.
# Regardless, using `on_print_json` to get formatted text in the GUI and output in the command-line and in the logs, # Regardless, using `on_print_json` to get formatted text in the GUI and output in the command-line and in the logs,
# without having to branch code from CommonClient # without having to branch code from CommonClient
self.ctx.on_print_json({"data": [{"text": text}]}) self.ctx.on_print_json({"data": [{"text": text, "keep_markup": True}]})
def _cmd_difficulty(self, difficulty: str = "") -> bool: def _cmd_difficulty(self, difficulty: str = "") -> bool:
"""Overrides the current difficulty set for the world. Takes the argument casual, normal, hard, or brutal""" """Overrides the current difficulty set for the world. Takes the argument casual, normal, hard, or brutal"""
@ -257,7 +257,7 @@ class StarcraftClientProcessor(ClientCommandProcessor):
print_faction_title() print_faction_title()
has_printed_faction_title = True has_printed_faction_title = True
(ColouredMessage('* ').item(item.item, self.ctx.slot, flags=item.flags) (ColouredMessage('* ').item(item.item, self.ctx.slot, flags=item.flags)
(" from ").location(item.location, self.ctx.slot) (" from ").location(item.location, item.player)
(" by ").player(item.player) (" by ").player(item.player)
).send(self.ctx) ).send(self.ctx)
@ -278,7 +278,7 @@ class StarcraftClientProcessor(ClientCommandProcessor):
for item in received_items_of_this_type: for item in received_items_of_this_type:
filter_match_count += len(received_items_of_this_type) filter_match_count += len(received_items_of_this_type)
(ColouredMessage(' * ').item(item.item, self.ctx.slot, flags=item.flags) (ColouredMessage(' * ').item(item.item, self.ctx.slot, flags=item.flags)
(" from ").location(item.location, self.ctx.slot) (" from ").location(item.location, item.player)
(" by ").player(item.player) (" by ").player(item.player)
).send(self.ctx) ).send(self.ctx)

View File

@ -1,7 +1,8 @@
from typing import * from typing import *
import asyncio import asyncio
from kvui import GameManager, HoverBehavior, ServerToolTip from NetUtils import JSONMessagePart
from kvui import GameManager, HoverBehavior, ServerToolTip, KivyJSONtoTextParser
from kivy.app import App from kivy.app import App
from kivy.clock import Clock from kivy.clock import Clock
from kivy.uix.tabbedpanel import TabbedPanelItem from kivy.uix.tabbedpanel import TabbedPanelItem
@ -69,6 +70,18 @@ class MissionLayout(GridLayout):
class MissionCategory(GridLayout): class MissionCategory(GridLayout):
pass pass
class SC2JSONtoKivyParser(KivyJSONtoTextParser):
def _handle_text(self, node: JSONMessagePart):
if node.get("keep_markup", False):
for ref in node.get("refs", []):
node["text"] = f"[ref={self.ref_count}|{ref}]{node['text']}[/ref]"
self.ref_count += 1
return super(KivyJSONtoTextParser, self)._handle_text(node)
else:
return super()._handle_text(node)
class SC2Manager(GameManager): class SC2Manager(GameManager):
logging_pairs = [ logging_pairs = [
("Client", "Archipelago"), ("Client", "Archipelago"),
@ -87,6 +100,7 @@ class SC2Manager(GameManager):
def __init__(self, ctx) -> None: def __init__(self, ctx) -> None:
super().__init__(ctx) super().__init__(ctx)
self.json_to_kivy_parser = SC2JSONtoKivyParser(ctx)
def clear_tooltip(self) -> None: def clear_tooltip(self) -> None:
if self.ctx.current_tooltip: if self.ctx.current_tooltip: