@novely/core 0.41.0 → 0.43.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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/constants.ts
2
- var SKIPPED_DURING_RESTORE = /* @__PURE__ */ new Set(["dialog", "say", "choice", "input", "vibrate", "text"]);
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
5
  var AUDIO_ACTIONS = /* @__PURE__ */ new Set([
@@ -190,13 +190,11 @@ var isAsset = (suspect) => {
190
190
  var matchAction = ({ getContext, onBeforeActionCall, push, forward }, values) => {
191
191
  return (action, props, { ctx, data }) => {
192
192
  const context = typeof ctx === "string" ? getContext(ctx) : ctx;
193
- if (action !== "say") {
194
- onBeforeActionCall({
195
- action,
196
- props,
197
- ctx: context
198
- });
199
- }
193
+ onBeforeActionCall({
194
+ action,
195
+ props,
196
+ ctx: context
197
+ });
200
198
  return values[action]({
201
199
  ctx: context,
202
200
  data,
@@ -1103,6 +1101,14 @@ var huntAssets = ({ volume, lang, mode, characters, action, props, handle }) =>
1103
1101
  }
1104
1102
  return;
1105
1103
  }
1104
+ if (action === "choice") {
1105
+ for (let i = 1; i < props.length; i++) {
1106
+ const data = props[i];
1107
+ if (Array.isArray(data)) {
1108
+ handle(handleImageAsset(data[4]));
1109
+ }
1110
+ }
1111
+ }
1106
1112
  };
1107
1113
 
1108
1114
  // src/novely.ts
@@ -1179,6 +1185,26 @@ var novely = ({
1179
1185
  return renderer.actions[action2];
1180
1186
  }
1181
1187
  return (...props) => {
1188
+ if (action2 === "say") {
1189
+ action2 = "dialog";
1190
+ const [character] = props;
1191
+ if (DEV3 && !characters[character]) {
1192
+ throw new Error(`Attempt to call Say action with unknown character "${character}"`);
1193
+ }
1194
+ } else if (action2 === "choice") {
1195
+ if (props.slice(1).every((choice) => !Array.isArray(choice))) {
1196
+ for (let i = 1; i < props.length; i++) {
1197
+ const choice = props[i];
1198
+ props[i] = [
1199
+ choice.title,
1200
+ choice.children,
1201
+ choice.active,
1202
+ choice.visible,
1203
+ choice.image
1204
+ ];
1205
+ }
1206
+ }
1207
+ }
1182
1208
  if (preloadAssets === "blocking") {
1183
1209
  huntAssets({
1184
1210
  action: action2,
@@ -1688,15 +1714,6 @@ var novely = ({
1688
1714
  forward
1689
1715
  );
1690
1716
  },
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
1717
  function({ ctx, push }, [fn]) {
1701
1718
  const { restoring, goingBack, preview: preview2 } = ctx.meta;
1702
1719
  const result = fn({
@@ -1717,15 +1734,20 @@ var novely = ({
1717
1734
  choices.unshift(question);
1718
1735
  question = "";
1719
1736
  }
1720
- const transformedChoices = choices.map(([content, action2, visible]) => {
1721
- const shown = !visible || visible({
1737
+ const transformedChoices = choices.map(([content, action2, active, visible, image]) => {
1738
+ const activeValue = !active || active({
1739
+ lang: getLanguageFromStore(storageData),
1740
+ state: getStateAtCtx(ctx)
1741
+ });
1742
+ const visibleValue = !visible || visible({
1722
1743
  lang: getLanguageFromStore(storageData),
1723
1744
  state: getStateAtCtx(ctx)
1724
1745
  });
1725
- if (DEV3 && action2.length === 0 && !shown) {
1746
+ const imageValue = image ? handleImageAsset(image) : "";
1747
+ if (DEV3 && action2.length === 0 && (!activeValue && !visibleValue)) {
1726
1748
  console.warn(`Choice children should not be empty, either add content there or make item not selectable`);
1727
1749
  }
1728
- return [templateReplace(content, data2), shown];
1750
+ return [templateReplace(content, data2), activeValue, visibleValue, imageValue];
1729
1751
  });
1730
1752
  if (DEV3 && transformedChoices.length === 0) {
1731
1753
  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]`);