Spaces:
Sleeping
Sleeping
| """Standalone screenshot test for assets/diorama.html. | |
| Serves the repo over http, builds a sample scene with real sprite + backdrop | |
| URLs (relative to the server root), loads the diorama in a headless browser, | |
| captures the canvas, and reports any console errors. | |
| """ | |
| from __future__ import annotations | |
| import base64 | |
| import json | |
| import threading | |
| import time | |
| from functools import partial | |
| from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer | |
| from pathlib import Path | |
| from playwright.sync_api import sync_playwright | |
| ROOT = Path(__file__).resolve().parent.parent | |
| PORT = 8741 | |
| def serve(): | |
| handler = partial(SimpleHTTPRequestHandler, directory=str(ROOT)) | |
| httpd = ThreadingHTTPServer(("127.0.0.1", PORT), handler) | |
| threading.Thread(target=httpd.serve_forever, daemon=True).start() | |
| return httpd | |
| def scene(): | |
| base = f"http://127.0.0.1:{PORT}/assets" | |
| chars = [ | |
| ("Joke Dragon", "creature", "char_joke_dragon.png"), | |
| ("Unfed Bonfire", "place", "char_unfed_bonfire.png"), | |
| ("Lantern Fox", "creature", "char_lantern_fox.png"), | |
| ("Blind Cartographer", "character", "char_blind_cartographer.png"), | |
| ("Crystal Tree", "creature", "char_crystal_tree.png"), | |
| ] | |
| return { | |
| "location": { | |
| "id": 6, "name": "The Ember Crossroads", "slug": "crossroads", | |
| "ambience": "The bonfire shifts colour as you approach. It is deciding about you.", | |
| "lore": "", "special": "", "glow_color": "#e08a3c", | |
| "backdrop_url": f"{base}/loc_crossroads.jpg", | |
| "mood": {"fog": "#140a06", "ambient": 0.55, "warmth": 1.2, "particles": "ember"}, | |
| }, | |
| "characters": [ | |
| {"id": f"id{i}", "name": n, "type": t, "status": "active", | |
| "sprite_url": f"{base}/{f}", | |
| "profile": {"appearance": "A test soul.", "greeting": "Hello.", | |
| "primary_goal": "x", "secondary_goal": "y", "primary_fear": "z", | |
| "memory_summary": "", "days_in_realm": 3, "status": "active", "type": t}} | |
| for i, (n, t, f) in enumerate(chars) | |
| ], | |
| } | |
| def main(): | |
| serve() | |
| time.sleep(0.5) | |
| b64 = base64.b64encode(json.dumps(scene()).encode()).decode() | |
| url = f"http://127.0.0.1:{PORT}/assets/diorama.html#data={b64}" | |
| with sync_playwright() as pw: | |
| browser = pw.chromium.launch(args=["--use-gl=swiftshader", "--enable-webgl", "--ignore-gpu-blocklist"]) | |
| page = browser.new_page(viewport={"width": 1100, "height": 680}) | |
| errors = [] | |
| page.on("console", lambda m: errors.append(m.text) if m.type == "error" else None) | |
| page.on("pageerror", lambda e: errors.append(str(e))) | |
| page.goto(url) | |
| page.wait_for_timeout(6000) | |
| out = ROOT / "assets" / "_diorama_shot.png" | |
| page.screenshot(path=str(out)) | |
| browser.close() | |
| print("ERRORS:", errors if errors else "none") | |
| print("shot:", out) | |
| if __name__ == "__main__": | |
| main() | |