mirror of
https://github.com/Steffo99/flyingsnake.git
synced 2024-12-21 22:24:19 +00:00
Add paints support (closes #2)
This commit is contained in:
parent
2024257c41
commit
7c9387c9d9
5 changed files with 278 additions and 8587 deletions
|
@ -51,6 +51,9 @@ The walls layer contains the colors of the walls present in the world.
|
|||
|
||||
It can be selected exclusively with the `--walls` flag, or turned off with the `--no-walls` flag.
|
||||
|
||||
If the walls are painted, they will be colored with the paint color.
|
||||
You can turn off paint colors with the `--no-paints` flag.
|
||||
|
||||
![The wall layer](https://i.imgur.com/Grkq5PQ.png)
|
||||
|
||||
#### Liquids
|
||||
|
@ -67,6 +70,9 @@ The blocks layer contains the colors of the blocks present in the world.
|
|||
|
||||
It can be selected exclusively with the `--blocks` flag, or turned off with the `--no-blocks` flag.
|
||||
|
||||
If the blocks are painted, they will be colored with the paint color.
|
||||
You can turn off paint colors with the `--no-paints` flag.
|
||||
|
||||
![The blocks layer](https://i.imgur.com/E05kgOA.png)
|
||||
|
||||
#### Wires
|
||||
|
|
|
@ -20,6 +20,8 @@ from .default_colors import DEFAULT_COLORS
|
|||
help="Draw the liquids present in the world.", default=None)
|
||||
@c.option("--wires/--no-wires", "draw_wires",
|
||||
help="Draw the liquids present in the world.", default=None)
|
||||
@c.option("--paint/--no-paint", "draw_paint",
|
||||
help="Draw painted blocks with the paint color overlayed on them.", default=True)
|
||||
def flyingsnake(input_file: str,
|
||||
output_file: str,
|
||||
colors_file: str,
|
||||
|
@ -27,7 +29,8 @@ def flyingsnake(input_file: str,
|
|||
draw_blocks: bool,
|
||||
draw_walls: bool,
|
||||
draw_liquids: bool,
|
||||
draw_wires: bool):
|
||||
draw_wires: bool,
|
||||
draw_paint: bool):
|
||||
# If at least a draw flag is set to True, default everything else to False
|
||||
if draw_background is True \
|
||||
or draw_blocks is True \
|
||||
|
@ -77,6 +80,7 @@ def flyingsnake(input_file: str,
|
|||
c.echo(f"Draw walls layer: {draw_walls}")
|
||||
c.echo(f"Draw liquids layer: {draw_liquids}")
|
||||
c.echo(f"Draw wires layer: {draw_wires}")
|
||||
c.echo(f"Draw paints: {draw_paint}")
|
||||
if colors_file:
|
||||
c.echo(f"Colors: from {colors_file}")
|
||||
else:
|
||||
|
@ -116,7 +120,11 @@ def flyingsnake(input_file: str,
|
|||
for y in range(world.size.y):
|
||||
tile = world.tiles[x, y]
|
||||
if tile.wall:
|
||||
draw.point((x, y), tuple(colors["Walls"][str(tile.wall.type.value)]))
|
||||
if draw_paint and tile.wall.paint:
|
||||
color = tuple(colors["Paints"][str(tile.wall.paint)])
|
||||
else:
|
||||
color = tuple(colors["Walls"][str(tile.wall.type.value)])
|
||||
draw.point((x, y), color)
|
||||
if not x % 100:
|
||||
c.echo(f"{x} / {world.size.x} rows done")
|
||||
del draw
|
||||
|
@ -149,7 +157,11 @@ def flyingsnake(input_file: str,
|
|||
for y in range(world.size.y):
|
||||
tile = world.tiles[x, y]
|
||||
if tile.block:
|
||||
draw.point((x, y), tuple(colors["Blocks"][str(tile.block.type.value)]))
|
||||
if draw_paint and tile.block.paint:
|
||||
color = tuple(colors["Paints"][str(tile.block.paint)])
|
||||
else:
|
||||
color = tuple(colors["Blocks"][str(tile.block.type.value)])
|
||||
draw.point((x, y), color)
|
||||
if not x % 100:
|
||||
c.echo(f"{x} / {world.size.x} rows done")
|
||||
del draw
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
@ -4,8 +4,7 @@ from PIL import ImageColor
|
|||
import json
|
||||
|
||||
|
||||
def get_block_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typing.Tuple[int, int, int, int]]:
|
||||
tree = ElementTree.parse(filename)
|
||||
def get_block_colors_from_tedit_settings(tree: ElementTree) -> typing.Dict[int, typing.Tuple[int, int, int, int]]:
|
||||
root = tree.findall(".//Tile")
|
||||
|
||||
colors = {}
|
||||
|
@ -19,8 +18,7 @@ def get_block_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typi
|
|||
return colors
|
||||
|
||||
|
||||
def get_wall_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typing.Tuple[int, int, int, int]]:
|
||||
tree = ElementTree.parse(filename)
|
||||
def get_wall_colors_from_tedit_settings(tree: ElementTree) -> typing.Dict[int, typing.Tuple[int, int, int, int]]:
|
||||
root = tree.findall(".//Wall")
|
||||
|
||||
colors = {}
|
||||
|
@ -34,29 +32,44 @@ def get_wall_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typin
|
|||
return colors
|
||||
|
||||
|
||||
def get_global_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typing.Tuple[int, int, int, int]]:
|
||||
tree = ElementTree.parse(filename)
|
||||
def get_global_colors_from_tedit_settings(tree: ElementTree) -> typing.Dict[str, typing.Tuple[int, int, int, int]]:
|
||||
root = tree.findall(".//GlobalColor")
|
||||
|
||||
colors = {}
|
||||
|
||||
for wall in root:
|
||||
name = wall.attrib["Name"]
|
||||
color = wall.attrib["Color"]
|
||||
for g in root:
|
||||
name = g.attrib["Name"]
|
||||
color = g.attrib["Color"]
|
||||
alpha, red, green, blue = ImageColor.getrgb(color)
|
||||
colors[name] = red, green, blue, alpha
|
||||
|
||||
return colors
|
||||
|
||||
|
||||
def get_paint_colors_from_tedit_settings(tree: ElementTree) -> typing.Dict[int, typing.Tuple[int, int, int, int]]:
|
||||
root = tree.findall(".//Paint")
|
||||
|
||||
colors = {}
|
||||
|
||||
for color in root:
|
||||
id_ = color.attrib["Id"]
|
||||
color = color.attrib["Color"]
|
||||
alpha, red, green, blue = ImageColor.getrgb(color)
|
||||
colors[id_] = red, green, blue, alpha
|
||||
|
||||
return colors
|
||||
|
||||
|
||||
def get_colors_from_tedit_settings(filename: str) -> typing.Dict:
|
||||
tree = ElementTree.parse(filename)
|
||||
return {
|
||||
"Blocks": get_block_colors_from_tedit_settings(filename),
|
||||
"Walls": get_wall_colors_from_tedit_settings(filename),
|
||||
"Globals": get_global_colors_from_tedit_settings(filename)
|
||||
"Blocks": get_block_colors_from_tedit_settings(tree),
|
||||
"Walls": get_wall_colors_from_tedit_settings(tree),
|
||||
"Globals": get_global_colors_from_tedit_settings(tree),
|
||||
"Paints": get_paint_colors_from_tedit_settings(tree)
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("colors.json", "w") as file:
|
||||
with open("example_colors.json", "w") as file:
|
||||
json.dump(get_colors_from_tedit_settings("settings.xml"), file)
|
||||
|
|
Loading…
Reference in a new issue