feat(nds): atlas versionning

This commit is contained in:
2026-02-16 16:27:36 +01:00
parent 50a1bb71b6
commit 284bec4216
2 changed files with 10 additions and 1 deletions

View File

@@ -12,7 +12,7 @@ const isReady = computed(() => loaded.value === total.value);
if (import.meta.client) {
atlasImage = document.createElement('img');
atlasImage.src = '/nds/atlas.webp';
atlasImage.src = '/nds/atlas.webp?v={{ATLAS_HASH}}';
if (atlasImage.complete) {
loaded.value += 1;

View File

@@ -1,4 +1,5 @@
import { defineNuxtModule, useLogger } from "@nuxt/kit";
import { createHash } from "crypto";
import { readdir, readFile, writeFile } from "fs/promises";
import { join, relative, parse } from "path";
import { existsSync, watch } from "fs";
@@ -221,6 +222,7 @@ ${sp} }`;
const totalAssets = (imagePaths.length > 0 ? 1 : 0) + modelPaths.length;
let imageCode = "{}";
let atlasHash = "";
let atlasWidth = 0;
let atlasHeight = 0;
@@ -256,6 +258,12 @@ ${sp} }`;
{ stdio: "pipe" },
);
const finalAtlas = await readFile(atlasOutputPath);
atlasHash = createHash("md5")
.update(finalAtlas)
.digest("hex")
.slice(0, 8);
const imageTree = buildImageTree(imagePaths, rects);
imageCode = generateImageCode(imageTree);
}
@@ -266,6 +274,7 @@ ${sp} }`;
const template = await readFile(templateFile, "utf-8");
const code = template
.replace("{{TOTAL}}", totalAssets.toString())
.replace("{{ATLAS_HASH}}", atlasHash)
.replace("{{IMAGES}}", imageCode)
.replace("{{MODELS}}", modelCode);