Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions spec/system/renderState/resolveColorIds.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ out:
height: 50
fill: "#112233"
---
case: resolves an own prototype-named color resource
in:
- type: "rect"
width: 100
height: 50
colorId: "constructor"
- colors:
constructor:
hex: "#112233"
out:
type: "rect"
width: 100
height: 50
fill: "#112233"
---
case: resolves nested interaction colorIds for rect elements
in:
- id: "button"
Expand Down Expand Up @@ -105,6 +120,15 @@ in:
- colors: {}
throws: 'Color "missing" not found'
---
case: missing prototype color resource throws clear error
in:
- type: "rect"
width: 100
height: 50
colorId: "constructor"
- colors: {}
throws: 'Color "constructor" not found'
---
case: colorId must resolve to a non-empty string
in:
- type: "rect"
Expand Down
40 changes: 35 additions & 5 deletions spec/system/selectors/selectSection.spec.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
file: "../../../src/stores/system.store.js"
group: systemStore selectors
suites:
[
selectSection,
]
suites: [selectSection]
---
suite: selectSection
exportName: selectSection
Expand Down Expand Up @@ -75,6 +72,39 @@ in:
- sectionId: "nonexistent"
out: __undefined__
---
case: section lookup ignores inherited object properties
in:
- state:
projectData:
story:
scenes:
scene1:
sections:
intro:
lines:
- id: "1"
text: "Hello"
- sectionId: "toString"
out: __undefined__
---
case: section lookup accepts an own prototype-named property
in:
- state:
projectData:
story:
scenes:
scene1:
sections:
toString:
lines:
- id: "1"
text: "Hello"
- sectionId: "toString"
out:
lines:
- id: "1"
text: "Hello"
---
case: empty project data
in:
- state:
Expand Down Expand Up @@ -119,4 +149,4 @@ out:
- id: "line1"
actions: {}
- id: "line2"
actions: {}
actions: {}
7 changes: 5 additions & 2 deletions src/RouteEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createSystemStore } from "./stores/system.store.js";
import { normalizeNamespace } from "./indexedDbPersistence.js";
import {
evaluateRouteCondition,
getOwnProperty,
isComputedVariableConfig,
processActionTemplates,
RUN_STORE_TRANSACTION,
Expand Down Expand Up @@ -1810,8 +1811,10 @@ export default function createRouteEngine(options) {
if (typeof payload.variableId !== "string" || !payload.variableId) {
throw new Error("integer random action requires variableId");
}
const variableConfig =
_canonicalProjectData?.resources?.variables?.[payload.variableId];
const variableConfig = getOwnProperty(
_canonicalProjectData?.resources?.variables,
payload.variableId,
);
if (
!variableConfig ||
variableConfig.type !== "number" ||
Expand Down
10 changes: 7 additions & 3 deletions src/audioIds.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getOwnProperty } from "./util.js";

export const escapeAudioIdComponent = (component) =>
String(component).replaceAll("%", "%25").replaceAll(":", "%3A");

Expand Down Expand Up @@ -41,11 +43,13 @@ export const resolveBgmSoundRenderIds = ({
resources,
previousBgmRender,
}) => {
const sounds = getBgmSounds(bgm).filter(
(sound) => resources.sounds?.[sound.resourceId],
const sounds = getBgmSounds(bgm).filter((sound) =>
getOwnProperty(resources.sounds, sound.resourceId),
);
const previousSounds = getBgmSounds(previousBgmRender?.bgm)
.filter((sound) => previousBgmRender.resources?.sounds?.[sound.resourceId])
.filter((sound) =>
getOwnProperty(previousBgmRender.resources?.sounds, sound.resourceId),
)
.map((sound, index) => ({
sound,
renderId: previousBgmRender.channel?.children[index]?.id,
Expand Down
13 changes: 7 additions & 6 deletions src/resolveAudioEffects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createBgmSoundRenderId } from "./audioIds.js";
import { getOwnProperty } from "./util.js";

const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);

Expand Down Expand Up @@ -55,7 +56,7 @@ const getCanonicalSoundProperty = ({
: bgm?.sounds?.find(
(sound) => createBgmSoundRenderId(bgm, sound) === renderedSound?.id,
);
const resource = resources.sounds?.[sound?.resourceId];
const resource = getOwnProperty(resources.sounds, sound?.resourceId);
return (
sound?.[property] ?? resource?.[property] ?? DEFAULT_AUDIO_VALUES[property]
);
Expand Down Expand Up @@ -272,7 +273,7 @@ export const resolveSoundBoundaryEffect = ({

const resourceId = selection.resourceId;
const resourcePath = `resources.audioEffects.${resourceId}`;
const resource = resources.audioEffects?.[resourceId];
const resource = getOwnProperty(resources.audioEffects, resourceId);
if (!resource) {
throw new Error(
`[${selectionPath}.resourceId]\n[${resourcePath}] Unknown audio effect resource "${resourceId}".`,
Expand Down Expand Up @@ -301,7 +302,7 @@ export const resolveSoundBoundaryEffect = ({

export const applyAudioEffectEndpoints = ({ bgm, resources = {} }) => {
const resourceId = bgm?.audioEffects?.resourceId;
const resource = resources.audioEffects?.[resourceId];
const resource = getOwnProperty(resources.audioEffects, resourceId);
const propertyTracks =
resource?.type === "update"
? resource.tween
Expand Down Expand Up @@ -371,7 +372,7 @@ export const resolveAudioEffect = ({
const actionPath = occurrence.actionPath ?? "bgm";
const resourceId = selection.resourceId;
const resourcePath = `resources.audioEffects.${resourceId}`;
const resource = resources.audioEffects?.[resourceId];
const resource = getOwnProperty(resources.audioEffects, resourceId);
if (!resource) {
throw new Error(
`[${actionPath}.audioEffects.resourceId]\n[${resourcePath}] Unknown audio effect resource "${resourceId}".`,
Expand Down Expand Up @@ -527,8 +528,8 @@ export const resolveAudioEffects = (options) => {
const createSingleSoundBgm = (bgm, resources, channel, sound) => {
if (!Array.isArray(bgm?.sounds)) return bgm;
const index = channel?.children?.indexOf(sound) ?? -1;
const authored = bgm.sounds.filter(
(item) => resources.sounds?.[item.resourceId],
const authored = bgm.sounds.filter((item) =>
getOwnProperty(resources.sounds, item.resourceId),
)[index];
return { ...bgm, sounds: authored ? [authored] : [] };
};
Expand Down
Loading
Loading