INNER CODE UNIT · Python

add_splash_image

ivoyager/planetarium · web/post_export.py:93

def add_splash_image(name):
    shutil.copyfile(SPLASH_IMAGE, EXPORT_DIR / SPLASH_IMAGE.name)
    worker_path = EXPORT_DIR / (name + ".service.worker.js")
    with open(worker_path, encoding="utf-8", newline="") as file:
        worker = file.read()
    match = re.search(r"^const CACHED_FILES = (\[.*?\]);", worker, flags=re.MULTILINE)
    if not match:
        sys.exit(f"ERROR: found no CACHED_FILES array in {worker_path}.")
    cached_files = json.loads(match.group(1))
    if SPLASH_IMAGE.name in cached_files:
        print(f"{worker_path.name}: CACHED_FILES already has {SPLASH_IMAGE.name}")
        return
    cached_files.append(SPLASH_IMAGE.name)
    # Godot writes the array as compact JSON.
    cached_files_json = json.dumps(cached_files, separators=(",", ":"))
    worker = worker[:match.start(1)] + cached_files_json + worker[match.end(1):]
    with open(worker_path, "w", encoding="utf-8", newline="") as file:
        file.write(worker)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…