From 284bec42164a777e32b6883b5cf10b43b69759ad Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Mon, 16 Feb 2026 16:27:36 +0100 Subject: [PATCH] feat(nds): atlas versionning --- app/composables/useAssets.ts.in | 2 +- modules/asset-generator.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/composables/useAssets.ts.in b/app/composables/useAssets.ts.in index e235005..e5f62a7 100644 --- a/app/composables/useAssets.ts.in +++ b/app/composables/useAssets.ts.in @@ -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; diff --git a/modules/asset-generator.ts b/modules/asset-generator.ts index 36208b1..5ee2b3f 100644 --- a/modules/asset-generator.ts +++ b/modules/asset-generator.ts @@ -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);