204 lines
7.3 KiB
Python
204 lines
7.3 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Karten-Mock — Draufsicht-Karte mit UI bei 640x360 (2x = 1280x720).
|
||
|
|
|
||
|
|
Zwei Screens: Stadt (Garana) und Dungeon. Die Karte füllt den Bildschirm,
|
||
|
|
Partyspalte und Dialog liegen darüber. Kein Modell, kein pixelize.
|
||
|
|
|
||
|
|
python3 art/tools/map_mock.py [ZIELORDNER] # Default art/prep/map-mock
|
||
|
|
"""
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from PIL import Image, ImageDraw
|
||
|
|
|
||
|
|
ART = Path(__file__).resolve().parent.parent
|
||
|
|
sys.path.insert(0, str(ART / "tools"))
|
||
|
|
import ui # noqa: E402
|
||
|
|
|
||
|
|
T = 32
|
||
|
|
W, H = 640, 360
|
||
|
|
COLS, ROWS = 20, 12
|
||
|
|
FINAL = ART / "final"
|
||
|
|
|
||
|
|
|
||
|
|
def load(path: Path) -> Image.Image:
|
||
|
|
return Image.open(path).convert("RGBA").resize((T, T), Image.NEAREST)
|
||
|
|
|
||
|
|
|
||
|
|
erde = load(FINAL / "Terrain/battle_erde_32px.png")
|
||
|
|
stein = load(FINAL / "Terrain/battle_stein_32px.png")
|
||
|
|
gras = load(FINAL / "Terrain/battle_gras_32px.png")
|
||
|
|
wand = load(FINAL / "Terrain/tile_wand_stein_32px.png")
|
||
|
|
dach = load(FINAL / "Terrain/tile_dach_fachwerk_32px.png")
|
||
|
|
PROPS = {n: load(FINAL / f"Objects/objekt_{n}_32px.png") for n in
|
||
|
|
("tuer", "truhe", "fass", "kiste", "tisch", "fackel", "tor", "treppe",
|
||
|
|
"geroell", "brunnen", "bett", "regal", "wagen", "grabstein")}
|
||
|
|
NPC = {}
|
||
|
|
for n in ("dorfbewohner", "dorfbewohnerin", "wache", "haendler", "druide",
|
||
|
|
"bettler"):
|
||
|
|
NPC[n] = Image.open(FINAL / f"NPCs/nsc_{n}_32px.png").convert("RGBA").resize(
|
||
|
|
(32, 40), Image.NEAREST)
|
||
|
|
|
||
|
|
|
||
|
|
def empty(floor) -> list[list[str]]:
|
||
|
|
return [[floor for _ in range(COLS)] for _ in range(ROWS)]
|
||
|
|
|
||
|
|
|
||
|
|
def town() -> list[list[str]]:
|
||
|
|
g = empty(".")
|
||
|
|
for x in range(COLS):
|
||
|
|
g[0][x] = "#"
|
||
|
|
g[ROWS - 1][x] = "#"
|
||
|
|
for y in range(ROWS):
|
||
|
|
g[y][0] = "#"
|
||
|
|
g[y][COLS - 1] = "#"
|
||
|
|
g[ROWS - 1][9] = "."
|
||
|
|
for (x0, y0, x1, y1) in ((4, 1, 7, 4), (12, 1, 17, 4),
|
||
|
|
(4, 8, 7, 10), (12, 8, 17, 10)):
|
||
|
|
for y in range(y0, y1 + 1):
|
||
|
|
for x in range(x0, x1 + 1):
|
||
|
|
g[y][x] = "B"
|
||
|
|
for (x, y) in ((6, 4), (14, 4), (6, 8), (14, 8)):
|
||
|
|
g[y][x] = "D"
|
||
|
|
for y in range(6, 8):
|
||
|
|
for x in range(8, 12):
|
||
|
|
g[y][x] = "g"
|
||
|
|
return g
|
||
|
|
|
||
|
|
|
||
|
|
def dungeon() -> list[list[str]]:
|
||
|
|
g = [["#" for _ in range(COLS)] for _ in range(ROWS)]
|
||
|
|
|
||
|
|
def carve(x0, y0, x1, y1):
|
||
|
|
for y in range(y0, y1 + 1):
|
||
|
|
for x in range(x0, x1 + 1):
|
||
|
|
g[y][x] = "."
|
||
|
|
|
||
|
|
carve(1, 1, 6, 4)
|
||
|
|
carve(12, 6, 18, 10)
|
||
|
|
carve(7, 3, 11, 3)
|
||
|
|
carve(11, 4, 11, 8)
|
||
|
|
return g
|
||
|
|
|
||
|
|
|
||
|
|
TILES = {"#": wand, "B": dach, "D": dach, ".": erde, "g": gras}
|
||
|
|
DTILES = {"#": wand, ".": stein}
|
||
|
|
|
||
|
|
|
||
|
|
def render(grid, tiles, buildings=(), walls=True) -> Image.Image:
|
||
|
|
im = Image.new("RGBA", (COLS * T, ROWS * T))
|
||
|
|
for y in range(ROWS):
|
||
|
|
for x in range(COLS):
|
||
|
|
im.paste(tiles[grid[y][x]], (x * T, y * T))
|
||
|
|
d = ImageDraw.Draw(im)
|
||
|
|
if walls:
|
||
|
|
for y in range(ROWS):
|
||
|
|
for x in range(COLS):
|
||
|
|
if grid[y][x] in "#B":
|
||
|
|
if y + 1 < ROWS and grid[y + 1][x] not in "#B":
|
||
|
|
d.rectangle((x * T, (y + 1) * T, x * T + T - 1,
|
||
|
|
(y + 1) * T + 1), fill=(0, 0, 0, 80))
|
||
|
|
if x + 1 < COLS and grid[y][x + 1] not in "#B":
|
||
|
|
d.rectangle(((x + 1) * T, y * T, (x + 1) * T + 1,
|
||
|
|
y * T + T - 1), fill=(0, 0, 0, 55))
|
||
|
|
for (x0, y0, x1, y1) in buildings:
|
||
|
|
px0, py0, px1, py1 = x0 * T, y0 * T, (x1 + 1) * T, (y1 + 1) * T
|
||
|
|
d.rectangle((px0, py0, px1 - 1, py1 - 1), outline=(0, 0, 0, 110))
|
||
|
|
d.rectangle((px0 + 1, py0 + 1, px1 - 2, py1 - 2),
|
||
|
|
outline=(210, 190, 150, 90))
|
||
|
|
cy = (py0 + py1) // 2
|
||
|
|
d.rectangle((px0 + 3, cy - 1, px1 - 4, cy), fill=(226, 209, 176, 120))
|
||
|
|
d.rectangle((px0 + 3, cy - 2, px1 - 4, cy - 2), fill=(0, 0, 0, 70))
|
||
|
|
return im
|
||
|
|
|
||
|
|
|
||
|
|
def place(im, spr, x, y, npc=False):
|
||
|
|
im.alpha_composite(spr, (x * T, y * T + (T - 40 if npc else 0)))
|
||
|
|
|
||
|
|
|
||
|
|
def screen_town() -> Image.Image:
|
||
|
|
grid = town()
|
||
|
|
im = render(grid, TILES,
|
||
|
|
buildings=((4, 1, 7, 4), (12, 1, 17, 4), (4, 8, 7, 10),
|
||
|
|
(12, 8, 17, 10)))
|
||
|
|
for name, x, y in (("brunnen", 2, 6), ("wagen", 7, 5), ("tisch", 9, 6),
|
||
|
|
("fass", 3, 5), ("kiste", 4, 5), ("fass", 18, 5),
|
||
|
|
("grabstein", 18, 2), ("tor", 9, 11),
|
||
|
|
("tuer", 6, 4), ("tuer", 14, 4), ("tuer", 6, 8),
|
||
|
|
("tuer", 14, 8)):
|
||
|
|
im.alpha_composite(PROPS[name], (x * T, y * T))
|
||
|
|
for name, x, y in (("dorfbewohner", 2, 2), ("dorfbewohnerin", 9, 5),
|
||
|
|
("wache", 10, 10), ("haendler", 14, 5),
|
||
|
|
("druide", 2, 9), ("bettler", 11, 9)):
|
||
|
|
place(im, NPC[name], x, y, npc=True)
|
||
|
|
return im
|
||
|
|
|
||
|
|
|
||
|
|
def screen_dungeon() -> Image.Image:
|
||
|
|
im = render(dungeon(), DTILES)
|
||
|
|
for name, x, y in (("truhe", 2, 2), ("truhe", 16, 7), ("treppe", 15, 8),
|
||
|
|
("geroell", 11, 6), ("bett", 13, 9), ("regal", 17, 6),
|
||
|
|
("fackel", 0, 2), ("fackel", 19, 2), ("fackel", 8, 2),
|
||
|
|
("fackel", 19, 8), ("fackel", 11, 4)):
|
||
|
|
im.alpha_composite(PROPS[name], (x * T, y * T))
|
||
|
|
return im
|
||
|
|
|
||
|
|
|
||
|
|
def frame(map_im: Image.Image, name: str, lines: list[str]) -> Image.Image:
|
||
|
|
base = Image.new("RGBA", (W, H), ui.alpha(ui.INK))
|
||
|
|
base.alpha_composite(map_im.crop((0, 0, W, H)), (0, 0))
|
||
|
|
|
||
|
|
party = ui.elem_party(ui.party_portraits())
|
||
|
|
base.alpha_composite(party, (W - party.size[0] - 4, 8))
|
||
|
|
|
||
|
|
d = ImageDraw.Draw(base)
|
||
|
|
d.rectangle((8, 8, 55, 25), fill=ui.alpha(ui.PANEL, 232))
|
||
|
|
d.rectangle((8, 8, 55, 25), outline=ui.LINE)
|
||
|
|
ui.draw_text(d, 15, 12, "MENU", ui.CREAM)
|
||
|
|
|
||
|
|
base.alpha_composite(ui.elem_dialog(lines, name, 66), (8, H - 79))
|
||
|
|
return base
|
||
|
|
|
||
|
|
|
||
|
|
def screen_inventory() -> Image.Image:
|
||
|
|
base = Image.new("RGBA", (W, H), ui.alpha(ui.INK))
|
||
|
|
base.alpha_composite(screen_town().crop((0, 0, W, H)), (0, 0))
|
||
|
|
dim = Image.new("RGBA", (W, H), (0, 0, 0, 120))
|
||
|
|
base.alpha_composite(dim, (0, 0))
|
||
|
|
pack = ui.elem_pack()
|
||
|
|
base.alpha_composite(pack, ((W - pack.width) // 2, 70))
|
||
|
|
slots = ui.elem_slots()
|
||
|
|
base.alpha_composite(slots, ((W - slots.width) // 2, 216))
|
||
|
|
party = ui.elem_party(ui.party_portraits())
|
||
|
|
base.alpha_composite(party, (W - party.size[0] - 4, 8))
|
||
|
|
d = ImageDraw.Draw(base)
|
||
|
|
d.rectangle((8, 8, 55, 25), fill=ui.alpha(ui.PANEL, 232))
|
||
|
|
d.rectangle((8, 8, 55, 25), outline=ui.LINE)
|
||
|
|
ui.draw_text(d, 15, 12, "MENU", ui.CREAM)
|
||
|
|
return base
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> int:
|
||
|
|
out = Path(sys.argv[1]) if len(sys.argv) > 1 else ART / "prep" / "map-mock"
|
||
|
|
out.mkdir(parents=True, exist_ok=True)
|
||
|
|
screens = {
|
||
|
|
"_mock_stadt": frame(screen_town(), "WACHE",
|
||
|
|
["Valyria zahlt in Ferrum, nicht in Gold.",
|
||
|
|
"Was wollt Ihr in Garana?"]),
|
||
|
|
"_mock_dungeon": frame(screen_dungeon(), "ERZAEHLER",
|
||
|
|
["Die Luft riecht nach nassem Stein.",
|
||
|
|
"Seit Jahren war hier niemand."]),
|
||
|
|
"_mock_inventar": screen_inventory(),
|
||
|
|
}
|
||
|
|
for name, im in screens.items():
|
||
|
|
im.save(out / f"{name}_640x360.png")
|
||
|
|
im.resize((W * 2, H * 2), Image.NEAREST).save(out / f"{name}_1280x720.png")
|
||
|
|
print(f"{out}/_mock_stadt_1280x720.png, _mock_dungeon_1280x720.png")
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
sys.exit(main())
|