Skip to content

Commit

Permalink
fix: dbg display name for objectives generated with `generate_objecti…
Browse files Browse the repository at this point in the history
…ve()`
  • Loading branch information
vberlier committed Oct 22, 2021
1 parent 26d5ca1 commit f8669c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions beet/contrib/dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class DbgOptions(BaseModel):
},
{"text": "[{{ project_id }}]: ", "color": "gray"},
{
"text": "{{ target }} for {{ name }} = ",
"text": "",
"color": "gold",
"extra": ["{{ accessor }}"],
"extra": ["{{ display_name or target }} for {{ name }} = {{ accessor }}"],
},
]

Expand Down Expand Up @@ -120,6 +120,7 @@ def render_preview(self, path: str, lineno: int) -> TextComponent:

def render(self, mode: str, name: str, target: str, path: str, lineno: int) -> str:
"""Return the formatted command."""

preview = json.dumps(self.render_preview(path, lineno))

kwargs = {
Expand All @@ -130,11 +131,17 @@ def render(self, mode: str, name: str, target: str, path: str, lineno: int) -> s
"preview": '",' + preview + ',"',
}

if mode == "score":
if scoreboard_data := self.ctx.meta.get("generate_scoreboard"):
if entry := scoreboard_data.get(target):
if display_name := entry.partition(" ")[-1]:
kwargs["display_name"] = '",' + display_name + ',"'

accessor = self.ctx.template.render_json(self.accessors[mode], **kwargs)
kwargs["accessor"] = '",' + json.dumps(accessor) + ',"'

payload = self.ctx.template.render_string(
json.dumps(self.opts.payload),
accessor='",' + json.dumps(accessor) + ',"',
**kwargs,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ say hello

scoreboard players set @p 5wyugd7r8mxoc 123
say Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
tellraw @a [{"text": "", "hoverEvent": {"action": "show_text", "contents": ["", {"text": "demo:foo ", "color": "aqua"}, {"text": "(score)\n\n", "color": "dark_aqua"}, "",{"text": "", "extra": ["", {"text": ""}, {"text": " ", "bold": true}, {"text": "7", "color": "dark_red"}, {"text": " | ", "color": "dark_gray"}, {"text": "scoreboard players set @p __foo__ 123\n", "color": "#dddddd"}, {"text": ""}, {"text": " ", "bold": true}, {"text": "8", "color": "dark_red"}, {"text": " | ", "color": "dark_gray"}, {"text": "say Lorem ipsum dolor sit amet, consectet...\n", "color": "gray"}, {"text": ""}, {"text": " ", "bold": true}, {"text": "9", "color": "red"}, {"text": " | ", "color": "dark_gray"}, {"text": "#!dbg score \"@p\", foo\n", "color": "#dddddd"}, {"text": " "}, {"text": "", "bold": true}, {"text": "10", "color": "dark_red"}, {"text": " | ", "color": "dark_gray"}, {"text": "say 42\n", "color": "gray"}, {"text": " "}, {"text": "", "bold": true}, {"text": "11", "color": "dark_red"}, {"text": " | ", "color": "dark_gray"}, {"text": "scoreboard players reset @p __foo__\n", "color": "#dddddd"}]},""]}}, {"text": "[load_dbg]: ", "color": "gray"}, {"text": "5wyugd7r8mxoc for @p = ", "color": "gold", "extra": ["",{"score": {"name": "@p", "objective": "5wyugd7r8mxoc"}},""]}]
tellraw @a [{"text": "", "hoverEvent": {"action": "show_text", "contents": ["", {"text": "demo:foo ", "color": "aqua"}, {"text": "(score)\n\n", "color": "dark_aqua"}, "",{"text": "", "extra": ["", {"text": ""}, {"text": " ", "bold": true}, {"text": "7", "color": "dark_red"}, {"text": " | ", "color": "dark_gray"}, {"text": "scoreboard players set @p __foo__ 123\n", "color": "#dddddd"}, {"text": ""}, {"text": " ", "bold": true}, {"text": "8", "color": "dark_red"}, {"text": " | ", "color": "dark_gray"}, {"text": "say Lorem ipsum dolor sit amet, consectet...\n", "color": "gray"}, {"text": ""}, {"text": " ", "bold": true}, {"text": "9", "color": "red"}, {"text": " | ", "color": "dark_gray"}, {"text": "#!dbg score \"@p\", foo\n", "color": "#dddddd"}, {"text": " "}, {"text": "", "bold": true}, {"text": "10", "color": "dark_red"}, {"text": " | ", "color": "dark_gray"}, {"text": "say 42\n", "color": "gray"}, {"text": " "}, {"text": "", "bold": true}, {"text": "11", "color": "dark_red"}, {"text": " | ", "color": "dark_gray"}, {"text": "scoreboard players reset @p __foo__\n", "color": "#dddddd"}]},""]}}, {"text": "[load_dbg]: ", "color": "gray"}, {"text": "", "color": "gold", "extra": ["","load_dbg.foo"," for @p = ",{"score": {"name": "@p", "objective": "5wyugd7r8mxoc"}},""]}]
say 42
scoreboard players reset @p 5wyugd7r8mxoc

0 comments on commit f8669c5

Please sign in to comment.