Skip to content

Commit

Permalink
Shorten the piece adjustment script.
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoknjas committed Jan 19, 2025
1 parent 5b5ab49 commit 5901437
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions bin/gen/update_pieces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,15 @@ def update_svg(piece_abbrv: str, shift_amt: float | int, vertical: bool) -> None
def update_css() -> None:
new_css_str = ''
for piece_abbrv in pieces:
with open(deduce_svg_filepath(piece_abbrv), 'r') as f: svg_contents = f.read()
svg_encoded = encode_svg(svg_contents)
assert svg_contents == decode_svg(svg_encoded)
with open(deduce_svg_filepath(piece_abbrv), 'r') as f:
svg_encoded = base64.b64encode(f.read().encode()).decode()
new_css_str += (
".is2d " + pieces[piece_abbrv] + " {background-image:url('data:image/svg+xml;base64," +
svg_encoded + "')}\n"
)
with open(Path.joinpath(lila_root_dir, f"public/piece-css/{piece_style}.css"), 'w') as f:
f.write(new_css_str)

def encode_svg(svg: str) -> str:
return human_readable(base64.b64encode(svg.encode()))

def decode_svg(svg: str) -> str:
return human_readable(base64.b64decode(svg))

def human_readable(encoded_str: bytes) -> str:
return encoded_str.decode("utf-8")

def main() -> None:
"""Example: `python update_pieces.py *piece style name* *shift amount* *piece abbrvs, like wP or bR* *optionally, 'horizontal' to do that instead of vertical*
To test this script, run it with a vertical shift of 0. Then, no files should be modified.
Expand Down

0 comments on commit 5901437

Please sign in to comment.