diff --git a/maps.json b/maps.json index de456fa..0cd04d5 100644 --- a/maps.json +++ b/maps.json @@ -337,10 +337,127 @@ ], "crop": null, "place": { - "cx": 826.6, - "cy": 765.64, - "w": 450.0, - "h": 450.0 + "cx": 822.93, + "cy": 773.28, + "w": 390.0, + "h": 460.0 + }, + "trim": { + "points": [ + [ + 0.279515, + 0.06833 + ], + [ + 0.191688, + 0.119718 + ], + [ + 0.184213, + 0.196333 + ], + [ + 0.185148, + 0.282291 + ], + [ + 0.160855, + 0.379462 + ], + [ + 0.126285, + 0.480369 + ], + [ + 0.122547, + 0.560722 + ], + [ + 0.11881, + 0.664432 + ], + [ + 0.124416, + 0.739178 + ], + [ + 0.353327, + 0.755062 + ], + [ + 0.41873, + 0.682184 + ], + [ + 0.472921, + 0.684987 + ], + [ + 0.457972, + 0.733572 + ], + [ + 0.470118, + 0.767208 + ], + [ + 0.574763, + 0.769077 + ], + [ + 0.949429, + 0.679381 + ], + [ + 0.998014, + 0.644811 + ], + [ + 0.992408, + 0.519611 + ], + [ + 0.920465, + 0.421506 + ], + [ + 0.888698, + 0.343023 + ], + [ + 0.820491, + 0.266408 + ], + [ + 0.845718, + 0.232772 + ], + [ + 0.819557, + 0.219691 + ], + [ + 0.790593, + 0.239312 + ], + [ + 0.821426, + 0.260802 + ], + [ + 0.651378, + 0.181384 + ], + [ + 0.442088, + 0.04684 + ], + [ + 0.338378, + 0.044972 + ] + ], + "outsideTransparency": 1.0 } }, { @@ -350,6 +467,13 @@ "baseLayers": [ "3DRENDER" ], + "baseUnderlaySmartObjects": [ + "3DRENDER/3DRender with gradients/Group 5/Group 4/Group 3/LargeExterior/Layer 1" + ], + "excludeLayers": [ + "TemporaryMapFixes", + "Sniper Minefield dotted lines" + ], "crop": null, "minZoom": 0, "place": { diff --git a/tools/export_base.py b/tools/export_base.py index d01b9da..d45835a 100644 --- a/tools/export_base.py +++ b/tools/export_base.py @@ -29,6 +29,7 @@ import sys import time import importlib +from io import BytesIO from PIL import Image from psd_tools import PSDImage @@ -125,6 +126,69 @@ def hide(psd, names: list[str], map_id: str) -> None: print(f"[{map_id}] WARNING: excludeLayers entry {missing!r} matched nothing") +def find_layer(psd, raw_path: str, map_id: str): + node = psd + for name in raw_path.split("/"): + layer = next((child for child in node if child.name == name), None) + if layer is None: + raise SystemExit( + f"[{map_id}] layer path {raw_path!r} matched nothing. " + "Run: python tools/psd_tree.py --depth 6" + ) + node = layer + return node + + +def embedded_underlays(psd, paths: list[str], map_id: str): + """Expand layered PSB smart objects that psd-tools flattens incorrectly. + + Interchange's exterior is a four-layer PSB. Re-compositing the outer PSD + uses an incomplete cached rendering and drops much of the west side. The + internal composite has alpha bounds that exactly match the outer smart + object's bbox, so render it explicitly as the bottom map-art layer and + keep the outer fixes, boundaries, interiors and inset above it. + """ + result = [] + for path in paths: + layer = find_layer(psd, path, map_id) + if layer.kind != "smartobject" or layer.smart_object is None: + raise SystemExit(f"[{map_id}] underlay {path!r} is not a smart object") + if layer.smart_object.filetype not in {"8bps", "8bpb"}: + raise SystemExit(f"[{map_id}] underlay {path!r} is not an embedded PSD/PSB") + + embedded = PSDImage.open(BytesIO(layer.smart_object.data)) + image = embedded.composite(viewport=embedded.viewbox, force=True).convert("RGBA") + alpha_bbox = image.getchannel("A").getbbox() + if alpha_bbox is None: + raise SystemExit(f"[{map_id}] underlay {path!r} rendered empty") + image = image.crop(alpha_bbox) + + left, top, right, bottom = layer.bbox + expected = (right - left, bottom - top) + if image.size != expected: + raise SystemExit( + f"[{map_id}] underlay {path!r} rendered {image.size}, " + f"expected outer bbox {expected}" + ) + layer.visible = False + view_left, view_top, _, _ = psd.viewbox + result.append((image, (left - view_left, top - view_top))) + print(f"[{map_id}] expanded embedded underlay {path!r}") + return result + + +def alpha_composite_clipped(canvas: Image.Image, source: Image.Image, + position: tuple[int, int]) -> None: + x, y = position + left, top = max(0, x), max(0, y) + right = min(canvas.width, x + source.width) + bottom = min(canvas.height, y + source.height) + if right <= left or bottom <= top: + return + crop = source.crop((left - x, top - y, right - x, bottom - y)) + canvas.alpha_composite(crop, (left, top)) + + def export(m: dict) -> None: psd_path = ROOT / m["psd"] if not psd_path.exists(): @@ -146,10 +210,21 @@ def export(m: dict) -> None: if m.get("excludeLayers"): hide(psd, m["excludeLayers"], m["id"]) + underlays = embedded_underlays( + psd, m.get("baseUnderlaySmartObjects", []), m["id"], + ) + # Keep alpha: these maps are composited onto the overall base map, so # anything outside the map art should show the terrain underneath rather # than an opaque white or black rectangle. - img = psd.composite(viewport=psd.viewbox, force=True).convert("RGBA") + remainder = psd.composite(viewport=psd.viewbox, force=True).convert("RGBA") + if underlays: + img = Image.new("RGBA", remainder.size, (0, 0, 0, 0)) + for underlay, position in underlays: + alpha_composite_clipped(img, underlay, position) + img.alpha_composite(remainder) + else: + img = remainder img.save(out, "PNG", optimize=False, compress_level=1) print(f"[{m['id']}] wrote {out.relative_to(ROOT)} " f"{img.size[0]}x{img.size[1]} in {time.time() - t0:.0f}s\n") diff --git a/tools/extract_markers.py b/tools/extract_markers.py index 13fcaef..0990f77 100644 --- a/tools/extract_markers.py +++ b/tools/extract_markers.py @@ -57,6 +57,16 @@ MAP_CATEGORY_OVERRIDES = { EXTRACT_CATEGORIES = { "extract-pmc", "extract-scav", "extract-neutral", "extract-hidden", "transit", } +EXTRACT_PRIORITY = ( + "extract-pmc", "extract-neutral", "extract-scav", "transit", "extract-hidden", +) + + +def highest_priority_extract_category(*categories: str | None) -> str | None: + available = {category for category in categories if category} + return next((category for category in EXTRACT_PRIORITY if category in available), None) + + EXTRACT_LABEL_PATHS = ( "overlay captions", "extract name text / extract text pmc", "extract name text / extract text scav", "extract name text / extract text neutral", @@ -192,29 +202,36 @@ def explicit_extract_category(path: tuple[str, ...], label: str) -> str | None: if ("smuggler" in lower_label and "basement" in lower_label) \ or "passage by the lake" in lower_label: return "extract-hidden" + label_category = None if any(term in lower_label for term in ("co-op", "coop")) \ or any(term in lower_label for term in ( "scav camp", "factory gate", "scav lands", "emercom checkpoint", "railway exfil", "armored train", "bunker hermetic door", "road to customs", "smuggler’s path", "smuggler's path", )): - return "extract-neutral" + label_category = "extract-neutral" # Walk from the leaf upward so a direct PMC/SCAV subgroup wins over a # broad ancestor such as Shoreline's "Hidden + Transit" container. + path_category = None for raw_part in reversed(path): part = clean_name(raw_part).lower().replace("_", " ") words = set(re.findall(r"[a-z]+", part)) if "neutral" in words or ("pmc" in words and "scav" in words): - return "extract-neutral" + path_category = "extract-neutral" + break if part in {"scav", "scav extracts", "extract dots scav", "extract dot scav"}: - return "extract-scav" + path_category = "extract-scav" + break if part in {"pmc", "pmc extracts", "extract dots pmc", "extract dot pmc"}: - return "extract-pmc" + path_category = "extract-pmc" + break if part in {"hidden", "hidden exfil", "hidden exfil onmap"}: - return "extract-hidden" + path_category = "extract-hidden" + break if part in {"transit", "transits", "transit dots", "transit onmap"}: - return "transit" - return None + path_category = "transit" + break + return highest_priority_extract_category(path_category, label_category) def semantic_path_label(path: tuple[str, ...], category: str) -> str: @@ -445,7 +462,8 @@ def extract_map(m: dict, source_root: Path | None) -> list[dict]: **label, "x": anchor["x"] if anchor_is_playable else label["x"], "y": anchor["y"] if anchor_is_playable else label["y"], - "category": explicit or anchor["category"], + "category": highest_priority_extract_category(explicit, anchor["category"]) + or anchor["category"], }) for label_index in sorted(unmatched_labels): diff --git a/web/app.js b/web/app.js index a2494d2..5949ebd 100644 --- a/web/app.js +++ b/web/app.js @@ -466,6 +466,7 @@ async function main() { const settings = categoryConfig(record.category); const size = safeSize(settings.size); const color = safeColor(settings.color); + const textColor = safeColor(settings.textColor || '#f5f7f8'); const label = record.label || settings.label || record.category.replaceAll('-', ' '); const text = settings.displayText ? `${escapeHTML(label)}` : ''; @@ -473,7 +474,7 @@ async function main() { className: `poi-icon marker-${record.category}${extractCategories.has(record.category) ? ' marker-extract' : ''}`, iconSize: [size, size], iconAnchor: [size / 2, size / 2], - html: `