diff --git a/src/app/App.tsx b/src/app/App.tsx index c6247d7a..2a8a619e 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -5268,6 +5268,41 @@ export function App({ store, initialStatusMessage }: AppProps) { } }; + const applyNpcChange = ( + overrides: { + modelAssetId?: string | null; + } = {} + ) => { + if (selectedNpc === null) { + setStatusMessage("Select an NPC before editing it."); + return; + } + + try { + const trimmedModelAssetId = npcModelAssetIdDraft.trim(); + const nextEntity = createNpcEntity({ + id: selectedNpc.id, + name: selectedNpc.name, + actorId: npcActorIdDraft, + position: snapVec3ToGrid( + readVec3Draft(entityPositionDraft, "NPC position"), + DEFAULT_GRID_SIZE + ), + yawDegrees: readYawDegreesDraft(npcYawDraft), + modelAssetId: + overrides.modelAssetId !== undefined + ? overrides.modelAssetId + : trimmedModelAssetId.length === 0 + ? null + : trimmedModelAssetId + }); + + commitEntityChange(selectedNpc, nextEntity, "Updated NPC."); + } catch (error) { + setStatusMessage(getErrorMessage(error)); + } + }; + const applyPointLightChange = (overrides: { colorHex?: string } = {}) => { if (selectedPointLight === null) { setStatusMessage("Select a Point Light before editing it."); @@ -5360,6 +5395,9 @@ export function App({ store, initialStatusMessage }: AppProps) { case "sceneEntry": applySceneEntryChange(); break; + case "npc": + applyNpcChange(); + break; case "soundEmitter": applySoundEmitterChange(); break;