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): flag required (non-empty) fields in the inspector (C2)
esengine15f94f961506
diff --git a/desktop/src/engine/schema.ts b/desktop/src/engine/schema.tsindex 0f1e6c9ea..ad4154f3b 100644--- a/desktop/src/engine/schema.ts+++ b/desktop/src/engine/schema.ts@@ -213,6 +213,8 @@ export interface UserFieldMeta {tooltip?: string;/** A display name overriding the key-derived label (UE DisplayName). */label?: string;+ /** Must be non-empty (soft — the inspector flags it). Mirrors a future ES_PROPERTY(required). */+ required?: boolean;}const userSchemas = new Map<string, UserComponentSchema>();@@ -353,6 +355,22 @@ export function clampFieldValue(compType: string, key: string, value: unknown):return Math.max(meta.min ?? -Infinity, Math.min(meta.max ?? Infinity, value));}+// Editor-side non-empty (required) fields, until ES_PROPERTY(required) lowers this to+// the SDK like min/max (§7). These are asset-ref fields whose entity is meaningless+// without them — a Sprite with no texture, a SpineAnimation with no skeleton/atlas.+const REQUIRED_FIELDS: Record<string, readonly string[]> = {+ Sprite: ['texture'],+ SpineAnimation: ['skeletonPath', 'atlasPath'],+ AudioSource: ['clip'],+};++/** Whether a field must be non-empty (builtin table, then user schema). Soft — the+ * inspector flags an empty value; nothing blocks the edit. */+export function isRequiredField(compType: string, key: string): boolean {+ if (REQUIRED_FIELDS[compType]?.includes(key)) return true;+ return userSchema(compType)?.fields?.[key]?.required === true;+}+/** The dropdown options for an enum field, or null if the field isn't an enum. */export function enumFieldOptions(compType: string, key: string): EnumOption[] | null {const e = fieldMetaFor(compType, key)?.enum;@@ -434,6 +452,7 @@ function fieldFor(if (field && meta?.category) field.category = meta.category;if (field && meta?.tooltip) field.tooltip = meta.tooltip;if (field && meta?.label) field.label = meta.label;+ if (field && isRequiredField(compType, key)) field.required = true;return field;}diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsxindex 2d0e868b8..58574a3e4 100644--- a/desktop/src/panels/Details.tsx+++ b/desktop/src/panels/Details.tsx@@ -953,9 +953,12 @@ function FieldRow({ entities, comp, field, write }: { entities: EntityId[]; compend();};+ // A required field left empty (no asset / blank string) — flagged, not blocked (soft).+ const invalid = !!field.required && (field.value === 0 || field.value === '' || field.value == null);+return (<div- className={`prop${modified ? ' modified' : ''}${mixed ? ' mixed' : ''}`}+ className={`prop${modified ? ' modified' : ''}${mixed ? ' mixed' : ''}${invalid ? ' invalid' : ''}`}onContextMenu={write? undefineddiff --git a/desktop/src/theme/inspector.css b/desktop/src/theme/inspector.cssindex 6ed2410dc..9545b77e2 100644--- a/desktop/src/theme/inspector.css+++ b/desktop/src/theme/inspector.css@@ -85,6 +85,10 @@.prop-label.scrub:hover { color: var(--text); }.prop.modified .prop-label { color: var(--text); }.prop.modified .prop-label::before { content: ''; position: absolute; left: -6px; top: 50%; transform: translateY(-50%); width: 3px; height: 13px; border-radius: 2px; background: var(--warn); }+/* Required field left empty — a soft flag: red label + asterisk + input outline. */+.prop.invalid .prop-label { color: var(--danger, #e5484d); }+.prop.invalid .prop-label::after { content: ' *'; color: var(--danger, #e5484d); font-weight: 700; }+.prop.invalid .assetref, .prop.invalid .field { border-color: var(--danger, #e5484d); }.prop-value { display: flex; align-items: center; gap: 4px; min-width: 0; }.prop-reset { width: 16px; height: 16px; display: grid; place-items: center; color: var(--warn); opacity: 0; transition: opacity var(--t-fast); justify-self: center; }.prop:hover .prop-reset.show, .prop.modified .prop-reset.show { opacity: .85; }diff --git a/desktop/src/types.ts b/desktop/src/types.tsindex c0c9d0df5..39368bf74 100644--- a/desktop/src/types.ts+++ b/desktop/src/types.ts@@ -119,6 +119,8 @@ export interface InspectorField {category?: string;/** Hover help for the property (UE's UPROPERTY ToolTip). */tooltip?: string;+ /** Must be non-empty; the inspector flags an empty value (soft — doesn't block the edit). */+ required?: boolean;/*** Multi-selection: the selected entities disagree on this field's value. `value`* holds the primary entity's value (shown muted); an edit fans out to all.diff --git a/desktop/tests/field-constraints.test.ts b/desktop/tests/field-constraints.test.tsindex 74a38e535..75846bfcb 100644--- a/desktop/tests/field-constraints.test.ts+++ b/desktop/tests/field-constraints.test.ts@@ -7,7 +7,7 @@* UI; assetTypeAllowed is the drag-drop type guard. Pure TS.*/import { describe, it, expect } from 'vitest';-import { clampFieldValue, setUserSchemas } from '@/engine/schema';+import { clampFieldValue, isRequiredField, setUserSchemas } from '@/engine/schema';import { ProjectStore } from '@/project/ProjectStore';describe('field constraints (C1: write-gate clamp + asset-type guard)', () => {@@ -26,4 +26,14 @@ describe('field constraints (C1: write-gate clamp + asset-type guard)', () => {expect(ProjectStore.assetTypeAllowed('texture', 'assets/thing.esprefab')).toBe(false);expect(ProjectStore.assetTypeAllowed(undefined, 'assets/anything.xyz')).toBe(true); // unconstrained slot});++ it('isRequiredField flags builtin required asset fields + user-schema required (C2)', () => {+ expect(isRequiredField('Sprite', 'texture')).toBe(true);+ expect(isRequiredField('Sprite', 'material')).toBe(false); // optional override+ expect(isRequiredField('SpineAnimation', 'skeletonPath')).toBe(true);+ setUserSchemas([{ name: 'Foo', fields: { title: { required: true } } }] as never);+ expect(isRequiredField('Foo', 'title')).toBe(true);+ expect(isRequiredField('Foo', 'other')).toBe(false);+ setUserSchemas([]);+ });});