1
Fork 0
mirror of https://github.com/Steffo99/flyingsnake.git synced 2024-12-22 06:34:18 +00:00

Add paints support (closes #2)

This commit is contained in:
Steffo 2019-08-28 14:03:33 +02:00
parent 2024257c41
commit 7c9387c9d9
5 changed files with 278 additions and 8587 deletions

View file

@ -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. 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) ![The wall layer](https://i.imgur.com/Grkq5PQ.png)
#### Liquids #### 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. 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) ![The blocks layer](https://i.imgur.com/E05kgOA.png)
#### Wires #### Wires

View file

@ -20,6 +20,8 @@ from .default_colors import DEFAULT_COLORS
help="Draw the liquids present in the world.", default=None) help="Draw the liquids present in the world.", default=None)
@c.option("--wires/--no-wires", "draw_wires", @c.option("--wires/--no-wires", "draw_wires",
help="Draw the liquids present in the world.", default=None) 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, def flyingsnake(input_file: str,
output_file: str, output_file: str,
colors_file: str, colors_file: str,
@ -27,7 +29,8 @@ def flyingsnake(input_file: str,
draw_blocks: bool, draw_blocks: bool,
draw_walls: bool, draw_walls: bool,
draw_liquids: 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 at least a draw flag is set to True, default everything else to False
if draw_background is True \ if draw_background is True \
or draw_blocks 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 walls layer: {draw_walls}")
c.echo(f"Draw liquids layer: {draw_liquids}") c.echo(f"Draw liquids layer: {draw_liquids}")
c.echo(f"Draw wires layer: {draw_wires}") c.echo(f"Draw wires layer: {draw_wires}")
c.echo(f"Draw paints: {draw_paint}")
if colors_file: if colors_file:
c.echo(f"Colors: from {colors_file}") c.echo(f"Colors: from {colors_file}")
else: else:
@ -116,7 +120,11 @@ def flyingsnake(input_file: str,
for y in range(world.size.y): for y in range(world.size.y):
tile = world.tiles[x, y] tile = world.tiles[x, y]
if tile.wall: 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: if not x % 100:
c.echo(f"{x} / {world.size.x} rows done") c.echo(f"{x} / {world.size.x} rows done")
del draw del draw
@ -149,7 +157,11 @@ def flyingsnake(input_file: str,
for y in range(world.size.y): for y in range(world.size.y):
tile = world.tiles[x, y] tile = world.tiles[x, y]
if tile.block: 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: if not x % 100:
c.echo(f"{x} / {world.size.x} rows done") c.echo(f"{x} / {world.size.x} rows done")
del draw del draw

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -4,8 +4,7 @@ from PIL import ImageColor
import json import json
def get_block_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typing.Tuple[int, int, int, int]]: def get_block_colors_from_tedit_settings(tree: ElementTree) -> typing.Dict[int, typing.Tuple[int, int, int, int]]:
tree = ElementTree.parse(filename)
root = tree.findall(".//Tile") root = tree.findall(".//Tile")
colors = {} colors = {}
@ -19,8 +18,7 @@ def get_block_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typi
return colors return colors
def get_wall_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typing.Tuple[int, int, int, int]]: def get_wall_colors_from_tedit_settings(tree: ElementTree) -> typing.Dict[int, typing.Tuple[int, int, int, int]]:
tree = ElementTree.parse(filename)
root = tree.findall(".//Wall") root = tree.findall(".//Wall")
colors = {} colors = {}
@ -34,29 +32,44 @@ def get_wall_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typin
return colors return colors
def get_global_colors_from_tedit_settings(filename: str) -> typing.Dict[int, typing.Tuple[int, int, int, int]]: def get_global_colors_from_tedit_settings(tree: ElementTree) -> typing.Dict[str, typing.Tuple[int, int, int, int]]:
tree = ElementTree.parse(filename)
root = tree.findall(".//GlobalColor") root = tree.findall(".//GlobalColor")
colors = {} colors = {}
for wall in root: for g in root:
name = wall.attrib["Name"] name = g.attrib["Name"]
color = wall.attrib["Color"] color = g.attrib["Color"]
alpha, red, green, blue = ImageColor.getrgb(color) alpha, red, green, blue = ImageColor.getrgb(color)
colors[name] = red, green, blue, alpha colors[name] = red, green, blue, alpha
return colors 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: def get_colors_from_tedit_settings(filename: str) -> typing.Dict:
tree = ElementTree.parse(filename)
return { return {
"Blocks": get_block_colors_from_tedit_settings(filename), "Blocks": get_block_colors_from_tedit_settings(tree),
"Walls": get_wall_colors_from_tedit_settings(filename), "Walls": get_wall_colors_from_tedit_settings(tree),
"Globals": get_global_colors_from_tedit_settings(filename) "Globals": get_global_colors_from_tedit_settings(tree),
"Paints": get_paint_colors_from_tedit_settings(tree)
} }
if __name__ == "__main__": 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) json.dump(get_colors_from_tedit_settings("settings.xml"), file)