wobblyhead hg > minor_monsters
diff tools/build.py @ 9:53f015966118
map, path, tower placement adjustments
| author | ark |
|---|---|
| date | 2026-10-19 15:55 +0200 |
| parents | 2c4fed8baed9 |
| children | 22b604680c5a |
line wrap: on
line diff
--- a/tools/build.py Mon Oct 19 13:37:52 2026 +0200 +++ b/tools/build.py Mon Oct 19 15:55:37 2026 +0200 @@ -69,6 +69,8 @@ ROUTE_TOLERANCE = 0.8 # number of decimals of route points in maps.js ROUTE_DECIMALS = 1 +# per map settings used by the mask step +MASK_SETTINGS = ("path_half_width", "spawn_distance", "exit_distance") warnings = [] @@ -195,6 +197,8 @@ def step_masks(cfg, force): placement = cfg["placement"] + settings = {"placement": placement, + "maps": [{k: cfg["map"][str(m)][k] for k in MASK_SETTINGS} for m in range(MAPS)]} routes_toml = CONFIG / "routes.toml" inputs = [ART / f"map{m}mask.png" for m in range(MAPS)] + [routes_toml] outputs = [DATA / "maps.js", MAPS_CACHE] @@ -202,7 +206,7 @@ if MAPS_CACHE.exists(): cached = json.loads(MAPS_CACHE.read_text()) # the placement settings are part of the input, compared by value - if not stale(inputs, outputs, force) and cached and cached["placement"] == placement: + if not stale(inputs, outputs, force) and cached and cached.get("settings") == settings: print("masks: up to date") return cached["maps"], False @@ -210,9 +214,13 @@ out = [] for m in range(MAPS): t0 = time.time() + mc = settings["maps"][m] mask = masks.Mask(ART / f"map{m}mask.png") - cols, rows, grid = masks.placement_grid(mask, placement) found = masks.extract_routes(mask, ROUTE_SMOOTH, ROUTE_TOLERANCE) + spaces = [(found["spawns"], mc["spawn_distance"]), + (found["exit_points"], mc["exit_distance"])] + cols, rows, grid = masks.placement_grid(mask, placement, found["centre"], + mc["path_half_width"], spaces) routes = [{"points": pts, "manual": False} for pts in found["routes"]] routes = apply_corrections(m, routes, fixes.get(str(m), {})) route_values(routes) @@ -225,7 +233,7 @@ "cols": cols, "rows": rows, "grid": grid, - "path_width": found["width"], + "line_width": found["width"], "entrances": [b[:3] for b in found["entrances"]], "exits": [b[:3] for b in found["exits"]], "routes": routes, @@ -238,7 +246,7 @@ write_maps_js(out) MAPS_CACHE.parent.mkdir(parents=True, exist_ok=True) - MAPS_CACHE.write_text(json.dumps({"placement": placement, "maps": out})) + MAPS_CACHE.write_text(json.dumps({"settings": settings, "maps": out})) return out, True @@ -357,7 +365,7 @@ if mp is None: raise ConfigError(f"[map.{m}] missing") where = f"map.{m}" - for k in ("starting_coins", "early_bonus", "wave_count"): + for k in ("starting_coins", "early_bonus", "wave_count") + MASK_SETTINGS: need(mp, k, float, where) need(mp, "monster_share", list, where) for w, wave in enumerate(mp.get("wave", []), start=1): @@ -422,8 +430,8 @@ speeds = sorted({v["speed"] for v in mons.values()}) for m, mp in enumerate(maps): c = cfg["map"][str(m)] - print(f"\nmap{m}: {mp['width']}x{mp['height']}, path width {mp['path_width']:.0f}," - f" {mp['grid'].count('1')} placement cells") + print(f"\nmap{m}: {mp['width']}x{mp['height']}, line width {mp['line_width']:.0f}," + f" road half width {c['path_half_width']}, {mp['grid'].count('1')} placement cells") if len(mp["entrances"]) == 0 or len(mp["exits"]) == 0: warn(f"map{m}: no entrance or no exit found") if not mp["routes"]:
