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
feat(editor): sorting layers get all 32 nameable slots, not 8
yhh886014799786
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.tsindex f877b97aa..d636775f1 100644--- a/desktop/src/project/ProjectStore.ts+++ b/desktop/src/project/ProjectStore.ts@@ -39,7 +39,7 @@ import { assetTypeOf } from '@/project/assetMeta';import { ASSET_TYPES, assetTypeDef } from '@/project/assetTypes';import { ASSET_SLOTS, metaTypeToSlot } from '@/project/assetSlots';import type { AssetType } from '@/types';-import { resolveLayout, orientationFromDesignResolution, resolveOrientation, cameraScaleModeValue, resolveScripts, DEFAULT_SCRIPTS, WORKSPACE_DIR, PROJECT_MANIFEST_FILE, type OpenedProject, type ProjectFeatures, type ProjectLayout, type ProjectPackaging, type ProjectScripts, type WorkspaceState, type DesignResolution, type ScreenPreset, type ScreenOrientation, type CameraScaleMode, type ExportPlatform } from './format';+import { resolveLayout, orientationFromDesignResolution, resolveOrientation, cameraScaleModeValue, resolveScripts, DEFAULT_SCRIPTS, WORKSPACE_DIR, PROJECT_MANIFEST_FILE, SORTING_LAYER_COUNT, trimSortingLayers, type OpenedProject, type ProjectFeatures, type ProjectLayout, type ProjectPackaging, type ProjectScripts, type WorkspaceState, type DesignResolution, type ScreenPreset, type ScreenOrientation, type CameraScaleMode, type ExportPlatform } from './format';import { useEditorMode } from '@/store/editorModeStore';import { PlayInspect } from '@/engine/PlayInspect';import { useEditorStore } from '@/store/editorStore';@@ -1846,7 +1846,7 @@ class ProjectStoreImpl {renderingFeature(): { sortingLayers: string[]; ySortLayers: number[]; colorSpace: 'gamma' | 'linear'; cameraScaleMode: CameraScaleMode; cameraMatch: number } {const r = this.state?.features?.rendering;return {- sortingLayers: Array.from({ length: 8 }, (_, i) => r?.sortingLayers?.[i] ?? ''),+ sortingLayers: Array.from({ length: SORTING_LAYER_COUNT }, (_, i) => r?.sortingLayers?.[i] ?? ''),ySortLayers: r?.ySortLayers ?? [],colorSpace: r?.colorSpace === 'linear' ? 'linear' : 'gamma',cameraScaleMode: r?.cameraScaleMode ?? 'none',@@ -1889,7 +1889,12 @@ class ProjectStoreImpl {const st = this.state;if (!st) return;const rendering: NonNullable<ProjectFeatures['rendering']> = { ...st.features?.rendering };- if (patch.sortingLayers) rendering.sortingLayers = patch.sortingLayers;+ // An all-empty list means "no named layers" — expressed by ABSENCE, like colorSpace.+ if (patch.sortingLayers) {+ const trimmed = trimSortingLayers(patch.sortingLayers);+ if (trimmed.length) rendering.sortingLayers = trimmed;+ else delete rendering.sortingLayers;+ }if (patch.ySortLayers) rendering.ySortLayers = patch.ySortLayers;// 'gamma' is the default — expressed by ABSENCE so untouched manifests stay untouched.if (patch.colorSpace === 'linear') rendering.colorSpace = 'linear';diff --git a/desktop/src/project/format.ts b/desktop/src/project/format.tsindex ffe8b9cc2..085aa6c41 100644--- a/desktop/src/project/format.ts+++ b/desktop/src/project/format.ts@@ -26,6 +26,26 @@ export const PROJECT_MANIFEST_FILE = 'project.esproject';export const WORKSPACE_DIR = '.esengine';export const WORKSPACE_FILE = 'workspace.json';+/**+ * Nameable render sorting layers. 32 because y-sort is a 32-bit mask over layer+ * indices (DrawList::setYSortMask) — a layer past 31 could be named but never+ * y-sorted. The renderer itself takes any i32 as a `layer`; this bounds only the+ * NAMED slots, and an unnamed project keeps a free-number `layer` field.+ */+export const SORTING_LAYER_COUNT = 32;++/**+ * The stored form of a sorting-layer list: the settings control always hands back+ * a full-width list, most of it empty, but a slot's meaning is its INDEX, so only+ * trailing empties are droppable — an empty slot between two named ones is a real+ * z-order gap and must survive. An all-empty list stores as nothing at all.+ */+export function trimSortingLayers(names: readonly string[]): string[] {+ const out = names.slice(0, SORTING_LAYER_COUNT).map((n) => (typeof n === 'string' ? n : ''));+ while (out.length && out[out.length - 1].trim() === '') out.pop();+ return out;+}+/** Resolved directory layout (relative to project root). */export interface ProjectLayout {scenes: string;@@ -424,11 +444,15 @@ export function parseManifest(raw: unknown): ProjectManifest {const r = f.rendering as Record<string, unknown>;const rendering: NonNullable<ProjectFeatures['rendering']> = {};if (Array.isArray(r.sortingLayers)) {- rendering.sortingLayers = r.sortingLayers.slice(0, 32).map((n) => (typeof n === 'string' ? n : ''));+ rendering.sortingLayers = r.sortingLayers+ .slice(0, SORTING_LAYER_COUNT)+ .map((n) => (typeof n === 'string' ? n : ''));}if (Array.isArray(r.ySortLayers)) {- rendering.ySortLayers = r.ySortLayers- .filter((n): n is number => typeof n === 'number' && Number.isInteger(n) && n >= 0 && n < 32);+ rendering.ySortLayers = r.ySortLayers.filter(+ (n): n is number =>+ typeof n === 'number' && Number.isInteger(n) && n >= 0 && n < SORTING_LAYER_COUNT,+ );}// Only 'linear' persists; 'gamma' (the default) is expressed by absence.if (r.colorSpace === 'linear') rendering.colorSpace = 'linear';diff --git a/desktop/src/settings/projectSettings.ts b/desktop/src/settings/projectSettings.tsindex 5631a5aa8..77118a5ed 100644--- a/desktop/src/settings/projectSettings.ts+++ b/desktop/src/settings/projectSettings.ts@@ -14,7 +14,7 @@ import { rgbaToHex8 } from '@/components/ColorControl';import { EngineHost } from '@/engine/EngineHost';import { Toasts } from '@/store/Toasts';import { useEditorMode } from '@/store/editorModeStore';-import type { ScreenOrientation, CameraScaleMode, ScreenPreset } from '@/project/format';+import { SORTING_LAYER_COUNT, type ScreenOrientation, type CameraScaleMode, type ScreenPreset } from '@/project/format';import { t } from '@/i18n';const ORIENTATION = [@@ -177,9 +177,10 @@ settingsRegistry.register({group: t('set.group.sortingLayers'),label: t('set.project.rendering.sortingLayers'),description: t('set.project.rendering.sortingLayers.desc'),- count: 8,+ layout: 'block',+ count: SORTING_LAYER_COUNT,placeholder: (i) => t('set.layerN', { i }),- default: Array.from({ length: 8 }, () => ''),+ default: Array.from({ length: SORTING_LAYER_COUNT }, () => ''),bind: {get: () => ProjectStore.renderingFeature().sortingLayers,set: (v) => void ProjectStore.setRendering({ sortingLayers: v }),@@ -223,7 +224,7 @@ settingsRegistry.register({group: t('set.group.ySort'),label: t('set.project.rendering.ySortLayers'),description: t('set.project.rendering.ySortLayers.desc'),- count: 8,+ count: SORTING_LAYER_COUNT,labels: () => ProjectStore.renderingFeature().sortingLayers,default: [],bind: {diff --git a/desktop/src/theme/settings.css b/desktop/src/theme/settings.cssindex 30532e093..516e9916a 100644--- a/desktop/src/theme/settings.css+++ b/desktop/src/theme/settings.css@@ -142,7 +142,10 @@vertical-align: middle;}.set-ctrl { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }-.set-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; width: 100%; }+/* Slot count varies (16 collision layers, 32 sorting layers), so the columns are+ fit to the width the row gives us rather than fixed at two — a `block` row goes+ wide and stays a few rows tall instead of becoming a 16-row strip. */+.set-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; width: 100%; }.set-list-item { height: 24px; min-width: 0; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 0 7px; color: var(--text); font-size: var(--fs-xs); outline: none; }.set-list-item:focus { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-soft); }.set-list-item::placeholder { color: var(--text-mute); }@@ -155,7 +158,9 @@.set-matrix th.set-matrix-col span { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }.set-matrix td { text-align: center; padding: 1px 4px; }.set-matrix input[type='checkbox'] { cursor: pointer; }-.set-flaglist { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-xs); color: var(--text-dim); }+/* Wraps rather than stacking: with 32 nameable layers a column would run off the+ page, while a handful of short names still read as a single line. */+.set-flaglist { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-xs); color: var(--text-dim); }.set-flaglist-item { display: flex; align-items: center; gap: 6px; cursor: pointer; }.set-flaglist-item input[type='checkbox'] { cursor: pointer; }.set-str { width: 200px; height: 24px; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 0 7px; color: var(--text); font-size: var(--fs-xs); font-family: var(--mono); outline: none; }diff --git a/desktop/tests/project-rendering.test.ts b/desktop/tests/project-rendering.test.tsindex 240e57a12..3897a4896 100644--- a/desktop/tests/project-rendering.test.ts+++ b/desktop/tests/project-rendering.test.ts@@ -6,7 +6,9 @@* by absence, and junk values are dropped.*/import { describe, it, expect } from 'vitest';-import { parseManifest, cameraScaleModeValue, resolveScreenFit } from '../src/project/format';+import {+ parseManifest, cameraScaleModeValue, resolveScreenFit, trimSortingLayers, SORTING_LAYER_COUNT,+} from '../src/project/format';describe('parseManifest — rendering.colorSpace', () => {it("keeps 'linear'", () => {@@ -34,6 +36,39 @@ describe('parseManifest — rendering.colorSpace', () => {});});+describe('sorting layers — slot count', () => {+ it('names every slot up to the y-sort mask width, and drops the rest', () => {+ const names = Array.from({ length: SORTING_LAYER_COUNT + 4 }, (_, i) => `L${i}`);+ const parsed = parseManifest({ name: 'X', features: { rendering: { sortingLayers: names } } });+ expect(parsed.features?.rendering?.sortingLayers).toHaveLength(SORTING_LAYER_COUNT);+ expect(parsed.features?.rendering?.sortingLayers?.[SORTING_LAYER_COUNT - 1]).toBe(`L${SORTING_LAYER_COUNT - 1}`);+ });++ it('y-sorts the last nameable layer but nothing past it (the mask is 32 bits)', () => {+ const m = parseManifest({+ name: 'X',+ features: { rendering: { ySortLayers: [0, SORTING_LAYER_COUNT - 1, SORTING_LAYER_COUNT, -1] } },+ });+ expect(m.features?.rendering?.ySortLayers).toEqual([0, SORTING_LAYER_COUNT - 1]);+ });+});++describe('trimSortingLayers', () => {+ it('drops trailing empties — the control sends a full-width list', () => {+ expect(trimSortingLayers(['back', 'mid', '', '', ''])).toEqual(['back', 'mid']);+ expect(trimSortingLayers(Array.from({ length: SORTING_LAYER_COUNT }, () => ''))).toEqual([]);+ });++ it('keeps an interior gap — a slot means its index, so the gap is a real z-order step', () => {+ expect(trimSortingLayers(['back', '', 'front', ''])).toEqual(['back', '', 'front']);+ });++ it('never stores more than the nameable slots', () => {+ const names = Array.from({ length: SORTING_LAYER_COUNT + 5 }, (_, i) => `L${i}`);+ expect(trimSortingLayers(names)).toHaveLength(SORTING_LAYER_COUNT);+ });+});+describe('parseManifest — rendering.cameraScaleMode', () => {it('keeps every real fit mode + clamps cameraMatch to 0..1', () => {for (const mode of ['fixed-width', 'fixed-height', 'expand', 'shrink', 'match'] as const) {