A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(asset): a map a material names keeps its import settings in Play, where it was decoded as colour
yhhcd969723ddae
diff --git a/sdk/src/runtime/playRealmRuntime.ts b/sdk/src/runtime/playRealmRuntime.tsindex fe61ef6fe..9ace76a6e 100644--- a/sdk/src/runtime/playRealmRuntime.ts+++ b/sdk/src/runtime/playRealmRuntime.ts@@ -15,6 +15,7 @@* so its defineComponent/defineSystem populate the registry this drains. This* entry only owns the runtime + snapshot + asset fetch.*/+import type { ParsedTextureImportSettings } from '../asset/textureImportSettings';import type { App } from '../app/app';import type { ESEngineModule } from '../wasm';import { Audio } from '../audio/Audio';@@ -164,6 +165,27 @@ function manifestBackedSettings(model: ManifestModel): Partial<RuntimeAssetSourc};}+/**+ * A manifest's texture settings for a realm whose refs can be URLs. A material names its textures beside itself, and+ * beside a URL is another URL: one the manifest knows by path or uuid. Without this its maps miss their settings and are+ * decoded as colour, and every value in them bends.+ */+export function playRealmTextureSettings(+ lookup: (ref: string) => ParsedTextureImportSettings | undefined,+ manifest: Record<string, string>,+ assetBaseUrl?: string,+): (ref: string) => ParsedTextureImportSettings | undefined {+ const keyOf = new Map(Object.entries(manifest).map(([key, url]) => [url, key]));+ const base = assetBaseUrl?.replace(/\/$/, '');+ return (ref) => {+ const direct = lookup(ref);+ if (direct) return direct;+ const key = keyOf.get(ref);+ if (key !== undefined) return lookup(key);+ return base && ref.startsWith(`${base}/`) ? lookup(ref.slice(base.length + 1)) : undefined;+ };+}+function createPlayRealmSource(manifest: Record<string, string>,assetBaseUrl?: string,@@ -184,10 +206,15 @@ function createPlayRealmSource(// Sampling, and the spine culling contract, both come off the addressable// manifest — the same fields a cooked build reads, so Play and ship// cannot disagree about what an author promised.- ...(addressable ? manifestBackedSettings(ManifestModel.fromJson(addressable)) : {}),+ ...(addressable ? withUrlSettings(manifestBackedSettings(ManifestModel.fromJson(addressable)), manifest, assetBaseUrl) : {}),};}+function withUrlSettings(settings: Partial<RuntimeAssetSource>, manifest: Record<string, string>, assetBaseUrl?: string): Partial<RuntimeAssetSource> {+ const lookup = settings.textureImportSettings;+ return lookup ? { ...settings, textureImportSettings: playRealmTextureSettings(lookup, manifest, assetBaseUrl) } : settings;+}+/*** Cut the snapshot the way a cook would, or answer null when it is not a world.*diff --git a/sdk/tests/play-realm-texture-settings.test.ts b/sdk/tests/play-realm-texture-settings.test.tsnew file mode 100644index 000000000..8d32d30d0--- /dev/null+++ b/sdk/tests/play-realm-texture-settings.test.ts@@ -0,0 +1,32 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/** A map a material names beside itself reaches a Play realm as a URL, and keeps its import settings there. */+import { describe, expect, it } from 'vitest';+import { indexTextureImportSettings } from '../src/asset/textureImportSettings';+import { playRealmTextureSettings } from '../src/runtime/playRealmRuntime';++const DATA = { srgb: false };+const lookup = indexTextureImportSettings([{ uuid: 'u1', path: 'assets/models/rock_surface.png', settings: DATA }]);+const manifest = { u1: 'estella://project/assets/models/rock_surface.png' };++describe('texture settings in a Play realm', () => {+ it('are found for the URL a material resolves its map to', () => {+ expect(playRealmTextureSettings(lookup, manifest)('estella://project/assets/models/rock_surface.png')).toEqual(DATA);+ });++ it('are found under the realm\'s base for a map the manifest does not list', () => {+ const unlisted = playRealmTextureSettings(lookup, {}, 'estella://project/');+ expect(unlisted('estella://project/assets/models/rock_surface.png')).toEqual(DATA);+ });++ it('still answer by path and by uuid', () => {+ const settings = playRealmTextureSettings(lookup, manifest);+ expect(settings('assets/models/rock_surface.png')).toEqual(DATA);+ expect(settings('@uuid:u1')).toEqual(DATA);+ });++ it('are nothing for a texture nobody said anything about', () => {+ expect(playRealmTextureSettings(lookup, manifest, 'estella://project')('estella://project/assets/other.png')).toBeUndefined();+ expect(playRealmTextureSettings(lookup, manifest)('https://elsewhere/assets/models/rock_surface.png')).toBeUndefined();+ });+});