settings.py¶
Part of PirateMaker.
1"""PirateMaker port: global constants and editor data table.
2
3Mirrors `source/28_finish/settings.py` 1:1; paths rebased to local assets/.
4"""
5
6from __future__ import annotations
7
8from pathlib import Path
9
10# Asset roots
11PORT_DIR = Path(__file__).resolve().parent
12ASSET_DIR = PORT_DIR / "assets"
13GFX = ASSET_DIR / "graphics"
14SFX = ASSET_DIR / "audio"
15
16# General setup
17TILE_SIZE = 64
18WINDOW_WIDTH = 1280
19WINDOW_HEIGHT = 720
20ANIMATION_SPEED = 8
21
22
23# Colours (HTML → RGBA float tuples)
24def _hex(s: str, a: float = 1.0):
25 s = s.lstrip("#")
26 return (int(s[0:2], 16) / 255, int(s[2:4], 16) / 255, int(s[4:6], 16) / 255, a)
27
28
29SKY_COLOUR = _hex("#ddc6a1")
30SEA_COLOUR = _hex("#92a9ce")
31HORIZON_COLOUR = _hex("#f5f1de")
32HORIZON_TOP_COLOUR = _hex("#d1aa9d")
33LINE_COLOUR = (0, 0, 0, 0.25)
34BUTTON_BG_COLOUR = _hex("#33323d")
35BUTTON_LINE_COLOUR = _hex("#f5f1de")
36
37
38# Editor data: keys are tile_ids.
39# style: gameplay class; kind: "tile" (snaps to grid) or "object" (free pos);
40# menu: which palette button group (None = not placeable from the palette);
41# menu_surf: palette thumbnail; preview: translucent ghost under the cursor;
42# graphics: folder of animation frames (None for a static tile).
43#
44# menu_surf and preview are always menu/<name>.png and preview/<name>.png, so
45# they are derived from the entry name rather than repeated per row.
46def _entry(style: str, kind: str, menu: str | None, name: str, graphics: Path | None = None) -> dict:
47 return {
48 "style": style,
49 "type": kind,
50 "menu": menu,
51 "menu_surf": GFX / f"menu/{name}.png" if menu else None,
52 "preview": GFX / f"preview/{name}.png" if menu else None,
53 "graphics": graphics,
54 }
55
56
57EDITOR_DATA: dict[int, dict] = {
58 0: _entry("player", "object", None, "player", GFX / "player/idle_right"),
59 1: _entry("sky", "object", None, "sky"),
60 2: _entry("terrain", "tile", "terrain", "land"),
61 3: _entry("water", "tile", "terrain", "water", GFX / "terrain/water/animation"),
62 4: _entry("coin", "tile", "coin", "gold", GFX / "items/gold"),
63 5: _entry("coin", "tile", "coin", "silver", GFX / "items/silver"),
64 6: _entry("coin", "tile", "coin", "diamond", GFX / "items/diamond"),
65 7: _entry("enemy", "tile", "enemy", "spikes", GFX / "enemies/spikes"),
66 8: _entry("enemy", "tile", "enemy", "tooth", GFX / "enemies/tooth/idle"),
67 9: _entry("enemy", "tile", "enemy", "shell_left", GFX / "enemies/shell_left/idle"),
68 10: _entry("enemy", "tile", "enemy", "shell_right", GFX / "enemies/shell_right/idle"),
69}
70
71# Palms come in matched foreground / background sets sharing one naming scheme.
72PALM_NAMES = ("small", "large", "left", "right")
73for _index, _base in enumerate(PALM_NAMES):
74 for _style, _menu, _suffix, _first_id in (
75 ("palm_fg", "palm fg", "fg", 11),
76 ("palm_bg", "palm bg", "bg", 15),
77 ):
78 _name = f"{_base}_{_suffix}"
79 EDITOR_DATA[_first_id + _index] = _entry(_style, "object", _menu, _name, GFX / f"terrain/palm/{_name}")
80
81# 8-neighbour terrain auto-tile keys
82NEIGHBOUR_DIRECTIONS = {
83 "A": (0, -1),
84 "B": (1, -1),
85 "C": (1, 0),
86 "D": (1, 1),
87 "E": (0, 1),
88 "F": (-1, 1),
89 "G": (-1, 0),
90 "H": (-1, -1),
91}
92
93LEVEL_LAYERS = {
94 "clouds": 1,
95 "ocean": 2,
96 "bg": 3,
97 "water": 4,
98 "main": 5,
99}