Skip to content

Commit 931f5ef

Browse files
authored
Merge pull request #10 from dhcold/dhc/mystifying-brown
Refactor: split monolithic main.py into turnt_o_mapper package
2 parents 7005014 + 7458377 commit 931f5ef

13 files changed

Lines changed: 4084 additions & 4009 deletions

File tree

main.py

Lines changed: 3 additions & 4009 deletions
Large diffs are not rendered by default.

turnt_o_mapper/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Turnt-o-mapper -- Quake 3 .map generator and Diabotical importer."""
2+
3+
__version__ = "3.1.0"

turnt_o_mapper/app.py

Lines changed: 995 additions & 0 deletions
Large diffs are not rendered by default.

turnt_o_mapper/brushes.py

Lines changed: 561 additions & 0 deletions
Large diffs are not rendered by default.

turnt_o_mapper/config.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Application configuration persistence.
3+
4+
Reads and writes ``turnt_config.json`` located next to the main entry point.
5+
The config stores all UI settings (room sizes, physics params, paths, etc.)
6+
so they survive between sessions.
7+
"""
8+
9+
import json
10+
import os
11+
12+
_CFG_FILE = os.path.join(
13+
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
14+
"turnt_config.json",
15+
)
16+
17+
18+
def load_app_cfg() -> dict:
19+
"""Load the application config from *turnt_config.json*.
20+
21+
Returns an empty dict if the file does not exist or is malformed.
22+
"""
23+
try:
24+
with open(_CFG_FILE, "r", encoding="utf-8") as f:
25+
return json.load(f)
26+
except Exception:
27+
return {}
28+
29+
30+
def save_app_cfg(data: dict):
31+
"""Merge *data* into the existing config file and persist to disk.
32+
33+
Keys in *data* overwrite existing keys; keys not present in *data*
34+
are preserved from the previous save. Silently ignores write errors.
35+
"""
36+
try:
37+
existing = load_app_cfg()
38+
existing.update(data)
39+
with open(_CFG_FILE, "w", encoding="utf-8") as f:
40+
json.dump(existing, f, indent=2)
41+
except Exception:
42+
pass

turnt_o_mapper/constants.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"""
2+
Shared constants used across all Turnt-o-mapper modules.
3+
4+
Contains:
5+
- Texture registry and category lists (floor, wall, ceiling, special)
6+
- Map geometry parameters (wall thickness, door dimensions)
7+
- Ramp physics constants (slope ratio, max angle)
8+
- UI theme colour palette
9+
- Image file extensions for texture thumbnail loading
10+
"""
11+
12+
import math
13+
from typing import Dict
14+
15+
# ══════════════════════════════════════════════════════════════════════════════
16+
# TEXTURES
17+
# ══════════════════════════════════════════════════════════════════════════════
18+
ALL_TEXTURES: Dict[str, int] = {
19+
"NULL":2,"common/caulk":2,"common/lavacaulk":4,"common/nodraw":2,
20+
"common/nodrawnonsolid":2,"common/slick":5,"common/slimecaulk":4,
21+
"common/watercaulk":3,"common/weapclip":2,"common/playerclip":2,
22+
"turnt/temp_blue":8,"turnt/temp_dark":0,"turnt/temp_green":7,
23+
"turnt/temp_light":1,"turnt/temp_orange":9,"turnt/temp_purple":10,
24+
"turnt/temp_red":6,"turnt/temp_yellow":11,
25+
"turnt/turnt_asphalt":12,"turnt/turnt_asphalt_t2":30,
26+
"turnt/turnt_boost":13,"turnt/turnt_boost_2":31,
27+
"turnt/turnt_checkpoint":14,"turnt/turnt_checkpoint_2":32,
28+
"turnt/turnt_concrete":15,"turnt/turnt_concrete_2":33,
29+
"turnt/turnt_coral":16,"turnt/turnt_coral_t2":34,
30+
"turnt/turnt_cyan":17,"turnt/turnt_cyan_t2":17,
31+
"turnt/turnt_gold":18,"turnt/turnt_gold_t2":36,
32+
"turnt/turnt_hazard":19,"turnt/turnt_hazard_2t":37,
33+
"turnt/turnt_lime":20,"turnt/turnt_lime_t2":38,
34+
"turnt/turnt_magenta":21,"turnt/turnt_magenta_t2":39,
35+
"turnt/turnt_mint":22,"turnt/turnt_mint_t2":40,
36+
"turnt/turnt_orange":9,"turnt/turnt_orange_2t":41,
37+
"turnt/turnt_platform":23,"turnt/turnt_platform_2t":42,
38+
"turnt/turnt_sky":24,"turnt/turnt_sky_2t":43,
39+
"turnt/turnt_speed":25,"turnt/turnt_speed_2t":44,
40+
"turnt/turnt_teal":26,"turnt/turnt_teal_2t":45,
41+
"turnt/turnt_tech":27,"turnt/turnt_tech_2t":46,
42+
"turnt/turnt_violet":28,"turnt/turnt_violet_2t":47,
43+
"turnt/turnt_white":29,"turnt/turnt_white_2t":48,
44+
}
45+
46+
# Mutable texture category lists — the UI mutates these in place via
47+
# _update_tex_lists(); other modules (layout, generation) import the same
48+
# list objects and see the updated selections automatically.
49+
FLOOR_TEX = ["turnt/turnt_concrete", "turnt/turnt_asphalt",
50+
"turnt/turnt_platform", "turnt/turnt_tech", "turnt/turnt_teal"]
51+
WALL_TEX = ["turnt/turnt_concrete", "turnt/turnt_tech", "turnt/turnt_white",
52+
"turnt/turnt_cyan", "turnt/turnt_mint", "turnt/turnt_violet"]
53+
CEIL_TEX = ["turnt/turnt_sky", "turnt/turnt_white", "turnt/turnt_tech"]
54+
55+
HIDDEN_TEX = "common/caulk"
56+
NODRAW_TEX = "common/nodrawnonsolid"
57+
TRIGGER_TEX = "common/trigger"
58+
59+
# ══════════════════════════════════════════════════════════════════════════════
60+
# MAP GEOMETRY PARAMETERS
61+
# ══════════════════════════════════════════════════════════════════════════════
62+
WALL_T = 16 # wall / shell thickness in Quake units
63+
DOOR_W = 128 # default door width
64+
DOOR_H = 128 # default door height
65+
66+
# ══════════════════════════════════════════════════════════════════════════════
67+
# RAMP PHYSICS CONSTANTS
68+
# ══════════════════════════════════════════════════════════════════════════════
69+
SLOPE_RATIO = 4.0 # horizontal / vertical ~= 14deg -- ideal shallow slope
70+
MAX_RAMP_ANGLE = 30 # degrees -- steepest allowed ramp
71+
# Minimum slope ratio that keeps angle <= MAX_RAMP_ANGLE: 1/tan(30deg) ~= 1.732
72+
MIN_SLOPE_RATIO = 1.0 / math.tan(math.radians(MAX_RAMP_ANGLE))
73+
74+
# ══════════════════════════════════════════════════════════════════════════════
75+
# THEME (dark UI colour palette)
76+
# ══════════════════════════════════════════════════════════════════════════════
77+
T = {
78+
"bg": "#0c0e1a",
79+
"bg_panel": "#12162a",
80+
"bg_card": "#1a1f38",
81+
"bg_input": "#0e1224",
82+
"accent": "#4fc3f7",
83+
"accent2": "#9575cd",
84+
"text": "#e8eaf6",
85+
"text_dim": "#78849e",
86+
"success": "#66bb6a",
87+
"warning": "#ffa726",
88+
"border": "#2a3050",
89+
"btn_fg": "#ffffff",
90+
"prev_bg": "#0b0f1e",
91+
"room_col": "#1a3358",
92+
"room_bdr": "#4fc3f7",
93+
"corr_col": "#162238",
94+
"start_col": "#1b5e20",
95+
"end_col": "#b71c1c",
96+
"lbx_bg": "#0e1224",
97+
"lbx_sel": "#263850",
98+
"dot_grid": "#182236",
99+
}
100+
101+
# ══════════════════════════════════════════════════════════════════════════════
102+
# FILE EXTENSIONS recognised as texture images
103+
# ══════════════════════════════════════════════════════════════════════════════
104+
IMG_EXTS = {".jpg", ".jpeg", ".png", ".bmp", ".tga", ".gif", ".tiff"}

0 commit comments

Comments
 (0)