@novely/core 0.31.3 → 0.33.0-beta.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 +13 -2
- package/dist/index.global.js +105 -77
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +105 -77
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -478,6 +478,90 @@ var getIntlLanguageDisplayName = (lang) => {
|
|
|
478
478
|
return lang;
|
|
479
479
|
}
|
|
480
480
|
};
|
|
481
|
+
var createReferFunction = (story) => {
|
|
482
|
+
const refer = (path) => {
|
|
483
|
+
let current = story;
|
|
484
|
+
let precurrent = story;
|
|
485
|
+
const blocks = [];
|
|
486
|
+
for (const [type, val] of path) {
|
|
487
|
+
if (type === "jump") {
|
|
488
|
+
precurrent = story;
|
|
489
|
+
current = current[val];
|
|
490
|
+
} else if (type === null) {
|
|
491
|
+
precurrent = current;
|
|
492
|
+
current = current[val];
|
|
493
|
+
} else if (type === "choice") {
|
|
494
|
+
blocks.push(precurrent);
|
|
495
|
+
current = current[val + 1][1];
|
|
496
|
+
} else if (type === "condition") {
|
|
497
|
+
blocks.push(precurrent);
|
|
498
|
+
current = current[2][val];
|
|
499
|
+
} else if (type === "block") {
|
|
500
|
+
blocks.push(precurrent);
|
|
501
|
+
current = story[val];
|
|
502
|
+
} else if (type === "block:exit" || type === "choice:exit" || type === "condition:exit") {
|
|
503
|
+
current = blocks.pop();
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return current;
|
|
507
|
+
};
|
|
508
|
+
return refer;
|
|
509
|
+
};
|
|
510
|
+
var exitPath = ({ path, refer, onExitImpossible }) => {
|
|
511
|
+
const last = path.at(-1);
|
|
512
|
+
const ignore = [];
|
|
513
|
+
let wasExitImpossible = false;
|
|
514
|
+
if (!isAction(refer(path))) {
|
|
515
|
+
if (last && isNull(last[0]) && isNumber(last[1])) {
|
|
516
|
+
last[1]--;
|
|
517
|
+
} else {
|
|
518
|
+
path.pop();
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (isExitImpossible(path)) {
|
|
522
|
+
const referred = refer(path);
|
|
523
|
+
if (isAction(referred) && isSkippedDuringRestore(referred[0])) {
|
|
524
|
+
onExitImpossible();
|
|
525
|
+
}
|
|
526
|
+
wasExitImpossible = true;
|
|
527
|
+
return {
|
|
528
|
+
exitImpossible: wasExitImpossible
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
for (let i = path.length - 1; i > 0; i--) {
|
|
532
|
+
const [name] = path[i];
|
|
533
|
+
if (isBlockExitStatement(name)) {
|
|
534
|
+
ignore.push(name);
|
|
535
|
+
}
|
|
536
|
+
if (!isBlockStatement(name))
|
|
537
|
+
continue;
|
|
538
|
+
if (ignore.at(-1)?.startsWith(name)) {
|
|
539
|
+
ignore.pop();
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
path.push([`${name}:exit`]);
|
|
543
|
+
const prev = findLastPathItemBeforeItemOfType(path.slice(0, i + 1), name);
|
|
544
|
+
if (prev)
|
|
545
|
+
path.push([null, prev[1] + 1]);
|
|
546
|
+
if (!isAction(refer(path))) {
|
|
547
|
+
path.pop();
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
exitImpossible: wasExitImpossible
|
|
554
|
+
};
|
|
555
|
+
};
|
|
556
|
+
var nextPath = (path) => {
|
|
557
|
+
const last = path.at(-1);
|
|
558
|
+
if (last && (isNull(last[0]) || last[0] === "jump") && isNumber(last[1])) {
|
|
559
|
+
last[1]++;
|
|
560
|
+
} else {
|
|
561
|
+
path.push([null, 0]);
|
|
562
|
+
}
|
|
563
|
+
return path;
|
|
564
|
+
};
|
|
481
565
|
|
|
482
566
|
// src/novely.ts
|
|
483
567
|
import { dequal } from "dequal/lite";
|
|
@@ -977,10 +1061,12 @@ var novely = ({
|
|
|
977
1061
|
}
|
|
978
1062
|
}
|
|
979
1063
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1064
|
+
if (context.meta.goingBack) {
|
|
1065
|
+
match("clear", [keep, characters2, audio], {
|
|
1066
|
+
ctx: context,
|
|
1067
|
+
data: latest[1]
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
984
1070
|
const lastQueueItem = queue.at(-1) || [];
|
|
985
1071
|
const lastQueueItemRequiresUserAction = isSkippedDuringRestore(lastQueueItem[0]) || isUserRequiredAction(lastQueueItem);
|
|
986
1072
|
await run((item) => {
|
|
@@ -998,32 +1084,7 @@ var novely = ({
|
|
|
998
1084
|
context.meta.restoring = context.meta.goingBack = false;
|
|
999
1085
|
render(context);
|
|
1000
1086
|
};
|
|
1001
|
-
const refer = (
|
|
1002
|
-
let current = story;
|
|
1003
|
-
let precurrent = story;
|
|
1004
|
-
const blocks = [];
|
|
1005
|
-
for (const [type, val] of path) {
|
|
1006
|
-
if (type === "jump") {
|
|
1007
|
-
precurrent = story;
|
|
1008
|
-
current = current[val];
|
|
1009
|
-
} else if (type === null) {
|
|
1010
|
-
precurrent = current;
|
|
1011
|
-
current = current[val];
|
|
1012
|
-
} else if (type === "choice") {
|
|
1013
|
-
blocks.push(precurrent);
|
|
1014
|
-
current = current[val + 1][1];
|
|
1015
|
-
} else if (type === "condition") {
|
|
1016
|
-
blocks.push(precurrent);
|
|
1017
|
-
current = current[2][val];
|
|
1018
|
-
} else if (type === "block") {
|
|
1019
|
-
blocks.push(precurrent);
|
|
1020
|
-
current = story[val];
|
|
1021
|
-
} else if (type === "block:exit" || type === "choice:exit" || type === "condition:exit") {
|
|
1022
|
-
current = blocks.pop();
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
return current;
|
|
1026
|
-
};
|
|
1087
|
+
const refer = createReferFunction(story);
|
|
1027
1088
|
const exit = (force = false, saving = true) => {
|
|
1028
1089
|
const ctx = renderer.getContext(MAIN_CONTEXT_KEY);
|
|
1029
1090
|
const stack = useStack(ctx);
|
|
@@ -1148,15 +1209,6 @@ var novely = ({
|
|
|
1148
1209
|
stack.push(current);
|
|
1149
1210
|
save("auto");
|
|
1150
1211
|
};
|
|
1151
|
-
const nextPath = (path) => {
|
|
1152
|
-
const last = path.at(-1);
|
|
1153
|
-
if (last && (isNull(last[0]) || last[0] === "jump") && isNumber(last[1])) {
|
|
1154
|
-
last[1]++;
|
|
1155
|
-
} else {
|
|
1156
|
-
path.push([null, 0]);
|
|
1157
|
-
}
|
|
1158
|
-
return path;
|
|
1159
|
-
};
|
|
1160
1212
|
const next = (ctx) => {
|
|
1161
1213
|
const stack = useStack(ctx);
|
|
1162
1214
|
const path = stack.value[0];
|
|
@@ -1213,7 +1265,13 @@ var novely = ({
|
|
|
1213
1265
|
push();
|
|
1214
1266
|
},
|
|
1215
1267
|
voice({ ctx, push }, [source]) {
|
|
1216
|
-
|
|
1268
|
+
const [lang] = storageData.get().meta;
|
|
1269
|
+
const audioSource = isString(source) ? source : source[lang];
|
|
1270
|
+
if (!audioSource) {
|
|
1271
|
+
push();
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
ctx.audio.voice(audioSource);
|
|
1217
1275
|
push();
|
|
1218
1276
|
},
|
|
1219
1277
|
stopVoice({ ctx, push }) {
|
|
@@ -1415,49 +1473,19 @@ var novely = ({
|
|
|
1415
1473
|
exit({ ctx, data: data2 }) {
|
|
1416
1474
|
if (ctx.meta.restoring)
|
|
1417
1475
|
return;
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
if (!isAction(refer(path))) {
|
|
1423
|
-
if (last && isNull(last[0]) && isNumber(last[1])) {
|
|
1424
|
-
last[1]--;
|
|
1425
|
-
} else {
|
|
1426
|
-
path.pop();
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
if (isExitImpossible(path)) {
|
|
1430
|
-
const referred = refer(path);
|
|
1431
|
-
if (isAction(referred) && isSkippedDuringRestore(referred[0])) {
|
|
1476
|
+
const { exitImpossible } = exitPath({
|
|
1477
|
+
path: useStack(ctx).value[0],
|
|
1478
|
+
refer,
|
|
1479
|
+
onExitImpossible: () => {
|
|
1432
1480
|
match("end", [], {
|
|
1433
1481
|
ctx,
|
|
1434
1482
|
data: data2
|
|
1435
1483
|
});
|
|
1436
1484
|
}
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
const [name] = path[i];
|
|
1441
|
-
if (isBlockExitStatement(name)) {
|
|
1442
|
-
ignore.push(name);
|
|
1443
|
-
}
|
|
1444
|
-
if (!isBlockStatement(name))
|
|
1445
|
-
continue;
|
|
1446
|
-
if (ignore.at(-1)?.startsWith(name)) {
|
|
1447
|
-
ignore.pop();
|
|
1448
|
-
continue;
|
|
1449
|
-
}
|
|
1450
|
-
path.push([`${name}:exit`]);
|
|
1451
|
-
const prev = findLastPathItemBeforeItemOfType(path.slice(0, i + 1), name);
|
|
1452
|
-
if (prev)
|
|
1453
|
-
path.push([null, prev[1] + 1]);
|
|
1454
|
-
if (!isAction(refer(path))) {
|
|
1455
|
-
path.pop();
|
|
1456
|
-
continue;
|
|
1457
|
-
}
|
|
1458
|
-
break;
|
|
1485
|
+
});
|
|
1486
|
+
if (!exitImpossible) {
|
|
1487
|
+
render(ctx);
|
|
1459
1488
|
}
|
|
1460
|
-
render(ctx);
|
|
1461
1489
|
},
|
|
1462
1490
|
preload({ ctx, push }, [source]) {
|
|
1463
1491
|
if (!ctx.meta.goingBack && !ctx.meta.restoring && !PRELOADED_ASSETS.has(source)) {
|