wobblyhead hg > minor_monsters
comparison tools/build.py @ 15:c1c7e4f54bf6
balance work prep
| author | ark |
|---|---|
| date | 2026-10-19 23:36 +0200 |
| parents | 7fda634d15ad |
| children | 30bd10284fd8 |
comparison
equal
deleted
inserted
replaced
| 14:7fda634d15ad | 15:c1c7e4f54bf6 |
|---|---|
| 69 ROUTE_TOLERANCE = 0.8 | 69 ROUTE_TOLERANCE = 0.8 |
| 70 # number of decimals of route points in maps.js | 70 # number of decimals of route points in maps.js |
| 71 ROUTE_DECIMALS = 1 | 71 ROUTE_DECIMALS = 1 |
| 72 # per map settings used by the mask step | 72 # per map settings used by the mask step |
| 73 MASK_SETTINGS = ("path_half_width", "spawn_distance", "exit_distance") | 73 MASK_SETTINGS = ("path_half_width", "spawn_distance", "exit_distance") |
| 74 # tower levels, and the tower settings given as [level 1, last level] | |
| 75 TOWER_LEVELS = 5 | |
| 76 TOWER_BY_LEVEL = ("damage", "range", "cost", "slow") | |
| 77 # number of decimals of tower values filled in between non-whole ends | |
| 78 TOWER_DECIMALS = 3 | |
| 74 | 79 |
| 75 warnings = [] | 80 warnings = [] |
| 76 | 81 |
| 77 | 82 |
| 78 def warn(msg): | 83 def warn(msg): |
| 334 raise ConfigError(f"section [{sec}] missing") | 339 raise ConfigError(f"section [{sec}] missing") |
| 335 for mid, mon in cfg["monster"].items(): | 340 for mid, mon in cfg["monster"].items(): |
| 336 for k in ("hp", "coins", "speed"): | 341 for k in ("hp", "coins", "speed"): |
| 337 need(mon, k, float, f"monster.{mid}") | 342 need(mon, k, float, f"monster.{mid}") |
| 338 for tid, tw in cfg["tower"].items(): | 343 for tid, tw in cfg["tower"].items(): |
| 339 for k in ("damage", "range"): | 344 for k in TOWER_BY_LEVEL: |
| 345 if k == "slow" and k not in tw: | |
| 346 continue | |
| 340 v = need(tw, k, list, f"tower.{tid}") | 347 v = need(tw, k, list, f"tower.{tid}") |
| 341 if len(v) != 5: | 348 if len(v) != 2 or not all(isinstance(x, (int, float)) and not isinstance(x, bool) |
| 342 raise ConfigError(f"tower.{tid}: {k} needs 5 levels, has {len(v)}") | 349 for x in v): |
| 343 for k in ("cost", "attack_time", "projectile_speed"): | 350 raise ConfigError(f"tower.{tid}: {k} should be [level 1, level " |
| 351 f"{TOWER_LEVELS}], is {v!r}") | |
| 352 for k in ("attack_time", "projectile_speed"): | |
| 344 need(tw, k, float, f"tower.{tid}") | 353 need(tw, k, float, f"tower.{tid}") |
| 345 need(tw, "projectile", str, f"tower.{tid}") | 354 need(tw, "projectile", str, f"tower.{tid}") |
| 346 if "slow" in tw and len(tw["slow"]) != 5: | |
| 347 raise ConfigError(f"tower.{tid}: slow needs 5 levels") | |
| 348 for k in ("speed_variation", "offset", "lean", "wander_step", "fade_in"): | 355 for k in ("speed_variation", "offset", "lean", "wander_step", "fade_in"): |
| 349 need(cfg["movement"], k, float, "movement") | 356 need(cfg["movement"], k, float, "movement") |
| 350 for k in ("footprint_radius", "max_gap", "min_tower_distance", "edge_distance", | 357 for k in ("footprint_radius", "max_gap", "min_tower_distance", "edge_distance", |
| 351 "snap_radius", "grid_cell"): | 358 "snap_radius", "grid_cell"): |
| 352 need(cfg["placement"], k, float, "placement") | 359 need(cfg["placement"], k, float, "placement") |
| 378 if mon not in cfg["monster"]: | 385 if mon not in cfg["monster"]: |
| 379 raise ConfigError(f"{ww}: unknown monster {mon}") | 386 raise ConfigError(f"{ww}: unknown monster {mon}") |
| 380 need(wave["monsters"], mon, int, ww) | 387 need(wave["monsters"], mon, int, ww) |
| 381 | 388 |
| 382 | 389 |
| 390 def tower_levels(ends): | |
| 391 """ | |
| 392 the values for all tower levels from [level 1, last level], in equal | |
| 393 steps. whole numbers when both ends are whole (halves round up), | |
| 394 otherwise rounded to TOWER_DECIMALS. | |
| 395 """ | |
| 396 first, last = ends | |
| 397 whole = isinstance(first, int) and isinstance(last, int) | |
| 398 out = [] | |
| 399 for i in range(TOWER_LEVELS): | |
| 400 v = first + (last - first) * i / (TOWER_LEVELS - 1) | |
| 401 out.append(math.floor(v + 0.5) if whole else round(v, TOWER_DECIMALS)) | |
| 402 return out | |
| 403 | |
| 404 | |
| 383 def sprite_table(): | 405 def sprite_table(): |
| 384 """name -> [width, height] of every image in game/assets/ except maps.""" | 406 """name -> [width, height] of every image in game/assets/ except maps.""" |
| 385 out = {} | 407 out = {} |
| 386 for p in sorted(ASSETS.glob("*.png")): | 408 for p in sorted(ASSETS.glob("*.png")): |
| 387 with Image.open(p) as im: | 409 with Image.open(p) as im: |
| 394 dst = DATA / "config.js" | 416 dst = DATA / "config.js" |
| 395 if not stale([src], [dst], force) and not assets_changed: | 417 if not stale([src], [dst], force) and not assets_changed: |
| 396 print("config: up to date") | 418 print("config: up to date") |
| 397 return | 419 return |
| 398 out = {k: v for k, v in cfg.items() if k != "map"} | 420 out = {k: v for k, v in cfg.items() if k != "map"} |
| 421 out["tower"] = {tid: {k: tower_levels(v) if k in TOWER_BY_LEVEL else v | |
| 422 for k, v in tw.items()} | |
| 423 for tid, tw in cfg["tower"].items()} | |
| 399 out["maps"] = [] | 424 out["maps"] = [] |
| 400 for m in range(MAPS): | 425 for m in range(MAPS): |
| 401 mp = dict(cfg["map"][str(m)]) | 426 mp = dict(cfg["map"][str(m)]) |
| 402 mp["waves"] = mp.pop("wave", []) | 427 mp["waves"] = mp.pop("wave", []) |
| 403 out["maps"].append(mp) | 428 out["maps"].append(mp) |
