Skip to content

Commit

Permalink
feat: add hangman plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Mar 24, 2021
1 parent 44c1b7a commit 2a96811
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
47 changes: 47 additions & 0 deletions beet/contrib/hangman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Plugin that allows hanging indents to spread commands on multiple lines."""


__all__ = [
"fold_hanging_commands",
]


from typing import List

from beet import Context


def beet_default(ctx: Context):
for function in ctx.data.functions.values():
function.lines = fold_hanging_commands(function.lines)


def fold_hanging_commands(lines: List[str]) -> List[str]:
"""Fold hanging commands on a single line."""
result = []
current, *lines = lines
indentation = 0
hanging_blank_lines = 0

for line in lines:
stripped = line.lstrip()

if stripped:
indentation = len(line) - len(stripped)

if indentation > 0:
if stripped.startswith("#"):
result.append(stripped)
elif stripped:
hanging_blank_lines = 0
current += " " + stripped
else:
hanging_blank_lines += 1
else:
result.append(current)
result.extend([""] * hanging_blank_lines)
current = stripped

result.append(current)

return result
6 changes: 6 additions & 0 deletions tests/examples/load_hangman/beet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data_pack": {
"load": ["src"]
},
"pipeline": ["beet.contrib.hangman"]
}
37 changes: 37 additions & 0 deletions tests/examples/load_hangman/src/data/demo/functions/foo.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@


# This is the beginning

say hello

tellraw @s
{
"text": "Hover me!",
"hoverEvent": {
"action": "show_text",
"value": "Hi!"
}
}

execute
# When the player is on wool
as @a
at @s
if block ~ ~-1 ~ #wool

# Give a special stone block
run give @s
stone{
display: {
Name: '[{
"text": "Hello",
"bold": true
}]',
Lore: [
'[{ "text": "Something else here" }]'
]
}
}
1

say foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


# This is the beginning

say hello

tellraw @s { "text": "Hover me!", "hoverEvent": { "action": "show_text", "value": "Hi!" } }

# When the player is on wool
# Give a special stone block
execute as @a at @s if block ~ ~-1 ~ #wool run give @s stone{ display: { Name: '[{ "text": "Hello", "bold": true }]', Lore: [ '[{ "text": "Something else here" }]' ] } } 1

say foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 6,
"description": ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 6,
"description": ""
}
}

0 comments on commit 2a96811

Please sign in to comment.