@novely/core 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +24 -7
- package/dist/index.global.js +46 -21
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
|
-
var SKIPPED_DURING_RESTORE = /* @__PURE__ */ new Set(["dialog", "
|
|
2
|
+
var SKIPPED_DURING_RESTORE = /* @__PURE__ */ new Set(["dialog", "choice", "input", "vibrate", "text"]);
|
|
3
3
|
var BLOCK_EXIT_STATEMENTS = /* @__PURE__ */ new Set(["choice:exit", "condition:exit", "block:exit"]);
|
|
4
4
|
var BLOCK_STATEMENTS = /* @__PURE__ */ new Set(["choice", "condition", "block"]);
|
|
5
|
+
var VIRTUAL_ACTIONS = /* @__PURE__ */ new Set(["say", "choiceExtended"]);
|
|
5
6
|
var AUDIO_ACTIONS = /* @__PURE__ */ new Set([
|
|
6
7
|
"playMusic",
|
|
7
8
|
"stopMusic",
|
|
@@ -190,13 +191,11 @@ var isAsset = (suspect) => {
|
|
|
190
191
|
var matchAction = ({ getContext, onBeforeActionCall, push, forward }, values) => {
|
|
191
192
|
return (action, props, { ctx, data }) => {
|
|
192
193
|
const context = typeof ctx === "string" ? getContext(ctx) : ctx;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
199
|
-
}
|
|
194
|
+
onBeforeActionCall({
|
|
195
|
+
action,
|
|
196
|
+
props,
|
|
197
|
+
ctx: context
|
|
198
|
+
});
|
|
200
199
|
return values[action]({
|
|
201
200
|
ctx: context,
|
|
202
201
|
data,
|
|
@@ -1103,6 +1102,14 @@ var huntAssets = ({ volume, lang, mode, characters, action, props, handle }) =>
|
|
|
1103
1102
|
}
|
|
1104
1103
|
return;
|
|
1105
1104
|
}
|
|
1105
|
+
if (action === "choice") {
|
|
1106
|
+
for (let i = 1; i < props.length; i++) {
|
|
1107
|
+
const data = props[i];
|
|
1108
|
+
if (Array.isArray(data)) {
|
|
1109
|
+
handle(handleImageAsset(data[4]));
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1106
1113
|
};
|
|
1107
1114
|
|
|
1108
1115
|
// src/novely.ts
|
|
@@ -1179,6 +1186,28 @@ var novely = ({
|
|
|
1179
1186
|
return renderer.actions[action2];
|
|
1180
1187
|
}
|
|
1181
1188
|
return (...props) => {
|
|
1189
|
+
if (VIRTUAL_ACTIONS.has(action2)) {
|
|
1190
|
+
if (action2 === "say") {
|
|
1191
|
+
action2 = "dialog";
|
|
1192
|
+
const [character] = props;
|
|
1193
|
+
if (DEV3 && !characters[character]) {
|
|
1194
|
+
throw new Error(`Attempt to call Say action with unknown character "${character}"`);
|
|
1195
|
+
}
|
|
1196
|
+
} else if (action2 === "choiceExtended") {
|
|
1197
|
+
action2 = "choice";
|
|
1198
|
+
const choices = props[1];
|
|
1199
|
+
const mappedChoices = choices.map((choice) => [
|
|
1200
|
+
choice.title,
|
|
1201
|
+
choice.children,
|
|
1202
|
+
choice.active,
|
|
1203
|
+
choice.visible,
|
|
1204
|
+
choice.image
|
|
1205
|
+
]);
|
|
1206
|
+
for (let i = 0; i < mappedChoices.length; i++) {
|
|
1207
|
+
props[i + 1] = mappedChoices[i];
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1182
1211
|
if (preloadAssets === "blocking") {
|
|
1183
1212
|
huntAssets({
|
|
1184
1213
|
action: action2,
|
|
@@ -1688,15 +1717,6 @@ var novely = ({
|
|
|
1688
1717
|
forward
|
|
1689
1718
|
);
|
|
1690
1719
|
},
|
|
1691
|
-
say({ ctx, data: data2 }, [character, content]) {
|
|
1692
|
-
if (DEV3 && !characters[character]) {
|
|
1693
|
-
throw new Error(`Attempt to call Say action with unknown character "${character}"`);
|
|
1694
|
-
}
|
|
1695
|
-
match("dialog", [character, content], {
|
|
1696
|
-
ctx,
|
|
1697
|
-
data: data2
|
|
1698
|
-
});
|
|
1699
|
-
},
|
|
1700
1720
|
function({ ctx, push }, [fn]) {
|
|
1701
1721
|
const { restoring, goingBack, preview: preview2 } = ctx.meta;
|
|
1702
1722
|
const result = fn({
|
|
@@ -1717,15 +1737,20 @@ var novely = ({
|
|
|
1717
1737
|
choices.unshift(question);
|
|
1718
1738
|
question = "";
|
|
1719
1739
|
}
|
|
1720
|
-
const transformedChoices = choices.map(([content, action2, visible]) => {
|
|
1721
|
-
const
|
|
1740
|
+
const transformedChoices = choices.map(([content, action2, active, visible, image]) => {
|
|
1741
|
+
const activeValue = !active || active({
|
|
1742
|
+
lang: getLanguageFromStore(storageData),
|
|
1743
|
+
state: getStateAtCtx(ctx)
|
|
1744
|
+
});
|
|
1745
|
+
const visibleValue = !visible || visible({
|
|
1722
1746
|
lang: getLanguageFromStore(storageData),
|
|
1723
1747
|
state: getStateAtCtx(ctx)
|
|
1724
1748
|
});
|
|
1725
|
-
|
|
1749
|
+
const imageValue = image ? handleImageAsset(image) : "";
|
|
1750
|
+
if (DEV3 && action2.length === 0 && (!activeValue && !visibleValue)) {
|
|
1726
1751
|
console.warn(`Choice children should not be empty, either add content there or make item not selectable`);
|
|
1727
1752
|
}
|
|
1728
|
-
return [templateReplace(content, data2),
|
|
1753
|
+
return [templateReplace(content, data2), activeValue, visibleValue, imageValue];
|
|
1729
1754
|
});
|
|
1730
1755
|
if (DEV3 && transformedChoices.length === 0) {
|
|
1731
1756
|
throw new Error(`Running choice without variants to choose from, look at how to use Choice action properly [https://novely.pages.dev/guide/actions/choice#usage]`);
|