Allow overrides in light and sound emitter change functions

This commit is contained in:
2026-04-02 20:19:41 +02:00
parent b30c3f9fa8
commit 77f6c785bd

View File

@@ -1457,7 +1457,7 @@ export function App({ store, initialStatusMessage }: AppProps) {
} }
}; };
const applyPointLightChange = () => { const applyPointLightChange = (overrides: { colorHex?: string } = {}) => {
if (selectedPointLight === null) { if (selectedPointLight === null) {
setStatusMessage("Select a Point Light before editing it."); setStatusMessage("Select a Point Light before editing it.");
return; return;
@@ -1467,7 +1467,7 @@ export function App({ store, initialStatusMessage }: AppProps) {
const nextEntity = createPointLightEntity({ const nextEntity = createPointLightEntity({
id: selectedPointLight.id, id: selectedPointLight.id,
position: snapVec3ToGrid(readVec3Draft(entityPositionDraft, "Point Light position"), DEFAULT_GRID_SIZE), position: snapVec3ToGrid(readVec3Draft(entityPositionDraft, "Point Light position"), DEFAULT_GRID_SIZE),
colorHex: pointLightColorDraft, colorHex: overrides.colorHex ?? pointLightColorDraft,
intensity: readNonNegativeNumberDraft(pointLightIntensityDraft, "Point Light intensity"), intensity: readNonNegativeNumberDraft(pointLightIntensityDraft, "Point Light intensity"),
distance: readPositiveNumberDraft(pointLightDistanceDraft, "Point Light distance") distance: readPositiveNumberDraft(pointLightDistanceDraft, "Point Light distance")
}); });
@@ -1478,7 +1478,7 @@ export function App({ store, initialStatusMessage }: AppProps) {
} }
}; };
const applySpotLightChange = () => { const applySpotLightChange = (overrides: { colorHex?: string } = {}) => {
if (selectedSpotLight === null) { if (selectedSpotLight === null) {
setStatusMessage("Select a Spot Light before editing it."); setStatusMessage("Select a Spot Light before editing it.");
return; return;
@@ -1489,7 +1489,7 @@ export function App({ store, initialStatusMessage }: AppProps) {
id: selectedSpotLight.id, id: selectedSpotLight.id,
position: snapVec3ToGrid(readVec3Draft(entityPositionDraft, "Spot Light position"), DEFAULT_GRID_SIZE), position: snapVec3ToGrid(readVec3Draft(entityPositionDraft, "Spot Light position"), DEFAULT_GRID_SIZE),
direction: readVec3Draft(spotLightDirectionDraft, "Spot Light direction"), direction: readVec3Draft(spotLightDirectionDraft, "Spot Light direction"),
colorHex: spotLightColorDraft, colorHex: overrides.colorHex ?? spotLightColorDraft,
intensity: readNonNegativeNumberDraft(spotLightIntensityDraft, "Spot Light intensity"), intensity: readNonNegativeNumberDraft(spotLightIntensityDraft, "Spot Light intensity"),
distance: readPositiveNumberDraft(spotLightDistanceDraft, "Spot Light distance"), distance: readPositiveNumberDraft(spotLightDistanceDraft, "Spot Light distance"),
angleDegrees: readPositiveNumberDraft(spotLightAngleDraft, "Spot Light angle") angleDegrees: readPositiveNumberDraft(spotLightAngleDraft, "Spot Light angle")
@@ -1531,7 +1531,9 @@ export function App({ store, initialStatusMessage }: AppProps) {
} }
}; };
const applySoundEmitterChange = () => { const applySoundEmitterChange = (
overrides: { audioAssetId?: string | null; autoplay?: boolean; loop?: boolean } = {}
) => {
if (selectedSoundEmitter === null) { if (selectedSoundEmitter === null) {
setStatusMessage("Select a Sound Emitter before editing it."); setStatusMessage("Select a Sound Emitter before editing it.");
return; return;
@@ -1539,15 +1541,21 @@ export function App({ store, initialStatusMessage }: AppProps) {
try { try {
const trimmedAudioAssetId = soundEmitterAudioAssetIdDraft.trim(); const trimmedAudioAssetId = soundEmitterAudioAssetIdDraft.trim();
const nextAudioAssetId =
overrides.audioAssetId !== undefined
? overrides.audioAssetId
: trimmedAudioAssetId.length === 0
? null
: trimmedAudioAssetId;
const nextEntity = createSoundEmitterEntity({ const nextEntity = createSoundEmitterEntity({
id: selectedSoundEmitter.id, id: selectedSoundEmitter.id,
position: snapVec3ToGrid(readVec3Draft(entityPositionDraft, "Sound Emitter position"), DEFAULT_GRID_SIZE), position: snapVec3ToGrid(readVec3Draft(entityPositionDraft, "Sound Emitter position"), DEFAULT_GRID_SIZE),
audioAssetId: trimmedAudioAssetId.length === 0 ? undefined : trimmedAudioAssetId, audioAssetId: nextAudioAssetId,
volume: readNonNegativeNumberDraft(soundEmitterVolumeDraft, "Sound Emitter volume"), volume: readNonNegativeNumberDraft(soundEmitterVolumeDraft, "Sound Emitter volume"),
refDistance: readPositiveNumberDraft(soundEmitterRefDistanceDraft, "Sound Emitter ref distance"), refDistance: readPositiveNumberDraft(soundEmitterRefDistanceDraft, "Sound Emitter ref distance"),
maxDistance: readPositiveNumberDraft(soundEmitterMaxDistanceDraft, "Sound Emitter max distance"), maxDistance: readPositiveNumberDraft(soundEmitterMaxDistanceDraft, "Sound Emitter max distance"),
autoplay: soundEmitterAutoplayDraft, autoplay: overrides.autoplay ?? soundEmitterAutoplayDraft,
loop: soundEmitterLoopDraft loop: overrides.loop ?? soundEmitterLoopDraft
}); });
commitEntityChange(selectedSoundEmitter, nextEntity, "Updated Sound Emitter."); commitEntityChange(selectedSoundEmitter, nextEntity, "Updated Sound Emitter.");
@@ -1602,7 +1610,7 @@ export function App({ store, initialStatusMessage }: AppProps) {
} }
}; };
const applyInteractableChange = () => { const applyInteractableChange = (overrides: { enabled?: boolean } = {}) => {
if (selectedInteractable === null) { if (selectedInteractable === null) {
setStatusMessage("Select an Interactable before editing it."); setStatusMessage("Select an Interactable before editing it.");
return; return;
@@ -1614,7 +1622,7 @@ export function App({ store, initialStatusMessage }: AppProps) {
position: snapVec3ToGrid(readVec3Draft(entityPositionDraft, "Interactable position"), DEFAULT_GRID_SIZE), position: snapVec3ToGrid(readVec3Draft(entityPositionDraft, "Interactable position"), DEFAULT_GRID_SIZE),
radius: readPositiveNumberDraft(interactableRadiusDraft, "Interactable radius"), radius: readPositiveNumberDraft(interactableRadiusDraft, "Interactable radius"),
prompt: readInteractablePromptDraft(interactablePromptDraft), prompt: readInteractablePromptDraft(interactablePromptDraft),
enabled: interactableEnabledDraft enabled: overrides.enabled ?? interactableEnabledDraft
}); });
commitEntityChange(selectedInteractable, nextEntity, "Updated Interactable."); commitEntityChange(selectedInteractable, nextEntity, "Updated Interactable.");
@@ -4286,8 +4294,9 @@ export function App({ store, initialStatusMessage }: AppProps) {
type="color" type="color"
value={pointLightColorDraft} value={pointLightColorDraft}
onChange={(event) => { onChange={(event) => {
setPointLightColorDraft(event.currentTarget.value); const nextColorHex = event.currentTarget.value;
scheduleDraftCommit(applyPointLightChange); setPointLightColorDraft(nextColorHex);
applyPointLightChange({ colorHex: nextColorHex });
}} }}
/> />
</label> </label>
@@ -4345,8 +4354,9 @@ export function App({ store, initialStatusMessage }: AppProps) {
type="color" type="color"
value={spotLightColorDraft} value={spotLightColorDraft}
onChange={(event) => { onChange={(event) => {
setSpotLightColorDraft(event.currentTarget.value); const nextColorHex = event.currentTarget.value;
scheduleDraftCommit(applySpotLightChange); setSpotLightColorDraft(nextColorHex);
applySpotLightChange({ colorHex: nextColorHex });
}} }}
/> />
</label> </label>
@@ -4516,8 +4526,9 @@ export function App({ store, initialStatusMessage }: AppProps) {
className="text-input" className="text-input"
value={soundEmitterAudioAssetIdDraft} value={soundEmitterAudioAssetIdDraft}
onChange={(event) => { onChange={(event) => {
setSoundEmitterAudioAssetIdDraft(event.currentTarget.value); const nextAudioAssetId = event.currentTarget.value.trim();
scheduleDraftCommit(applySoundEmitterChange); setSoundEmitterAudioAssetIdDraft(nextAudioAssetId);
applySoundEmitterChange({ audioAssetId: nextAudioAssetId.length === 0 ? null : nextAudioAssetId });
}} }}
> >
<option value="">— none —</option> <option value="">— none —</option>
@@ -4598,8 +4609,9 @@ export function App({ store, initialStatusMessage }: AppProps) {
type="checkbox" type="checkbox"
checked={soundEmitterAutoplayDraft} checked={soundEmitterAutoplayDraft}
onChange={(event) => { onChange={(event) => {
setSoundEmitterAutoplayDraft(event.currentTarget.checked); const nextAutoplay = event.currentTarget.checked;
scheduleDraftCommit(applySoundEmitterChange); setSoundEmitterAutoplayDraft(nextAutoplay);
applySoundEmitterChange({ autoplay: nextAutoplay });
}} }}
/> />
</label> </label>
@@ -4610,8 +4622,9 @@ export function App({ store, initialStatusMessage }: AppProps) {
type="checkbox" type="checkbox"
checked={soundEmitterLoopDraft} checked={soundEmitterLoopDraft}
onChange={(event) => { onChange={(event) => {
setSoundEmitterLoopDraft(event.currentTarget.checked); const nextLoop = event.currentTarget.checked;
scheduleDraftCommit(applySoundEmitterChange); setSoundEmitterLoopDraft(nextLoop);
applySoundEmitterChange({ loop: nextLoop });
}} }}
/> />
</label> </label>
@@ -4745,8 +4758,9 @@ export function App({ store, initialStatusMessage }: AppProps) {
type="checkbox" type="checkbox"
checked={interactableEnabledDraft} checked={interactableEnabledDraft}
onChange={(event) => { onChange={(event) => {
setInteractableEnabledDraft(event.currentTarget.checked); const nextEnabled = event.currentTarget.checked;
scheduleDraftCommit(applyInteractableChange); setInteractableEnabledDraft(nextEnabled);
applyInteractableChange({ enabled: nextEnabled });
}} }}
/> />
</label> </label>