@novely/core 0.32.0 → 0.33.0-beta.1
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 +20 -1
- package/dist/index.global.js +108 -76
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +108 -76
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -256,6 +256,10 @@ type NovelyScreen = 'mainmenu' | 'game' | 'saves' | 'settings';
|
|
|
256
256
|
type DeepPartial<T> = unknown extends T ? T : T extends object ? {
|
|
257
257
|
[P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]>;
|
|
258
258
|
} : T;
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
*/
|
|
262
|
+
type Assign<A extends object, B extends object> = Pick<A, Exclude<keyof A, keyof B>> & B;
|
|
259
263
|
type NonEmptyRecord<T extends Record<PropertyKey, unknown>> = keyof T extends never ? never : T;
|
|
260
264
|
type CoreData = {
|
|
261
265
|
dataLoaded: boolean;
|
|
@@ -740,4 +744,19 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
740
744
|
getCurrentStorageData: () => StorageData<$Language, $Data> | null;
|
|
741
745
|
};
|
|
742
746
|
|
|
743
|
-
|
|
747
|
+
/**
|
|
748
|
+
* Extens core action with custom actions
|
|
749
|
+
* @param base Actions object you will extend, `engine.action`
|
|
750
|
+
* @param extension Actions object you will extend with
|
|
751
|
+
* @example
|
|
752
|
+
* ```ts
|
|
753
|
+
* const action = extendAction(engine.action, {
|
|
754
|
+
* particles: (options: Parameters<typeof particles>[0]) => {
|
|
755
|
+
* return ['custom', particles(options)]
|
|
756
|
+
* }
|
|
757
|
+
* })
|
|
758
|
+
* ```
|
|
759
|
+
*/
|
|
760
|
+
declare const extendAction: <Part0 extends Record<string, (...args: any[]) => ValidAction>, Part1 extends Record<string, (...args: any[]) => ValidAction>>(base: Part0, extension: Part1) => Readonly<Assign<Part0, Part1>>;
|
|
761
|
+
|
|
762
|
+
export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterHandle, type ConditionParams, type Context, type CoreData, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionableValue, type GetActionParameters, JP, KK, type Lang, type NovelyInit, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type Save, type Stack, type StackHolder, type State, type StateFunction, type Storage, type StorageData, type StorageMeta, type Stored, type Story, type TextContent, type Thenable, type TranslationActions, type TypewriterSpeed, type ValidAction, extendAction, localStorageStorage, novely };
|
package/dist/index.global.js
CHANGED
|
@@ -156,6 +156,7 @@ var Novely = (() => {
|
|
|
156
156
|
JP: () => JP,
|
|
157
157
|
KK: () => KK,
|
|
158
158
|
RU: () => RU,
|
|
159
|
+
extendAction: () => extendAction,
|
|
159
160
|
localStorageStorage: () => localStorageStorage,
|
|
160
161
|
novely: () => novely
|
|
161
162
|
});
|
|
@@ -642,6 +643,90 @@ var Novely = (() => {
|
|
|
642
643
|
return lang;
|
|
643
644
|
}
|
|
644
645
|
};
|
|
646
|
+
var createReferFunction = (story) => {
|
|
647
|
+
const refer = (path) => {
|
|
648
|
+
let current = story;
|
|
649
|
+
let precurrent = story;
|
|
650
|
+
const blocks = [];
|
|
651
|
+
for (const [type, val] of path) {
|
|
652
|
+
if (type === "jump") {
|
|
653
|
+
precurrent = story;
|
|
654
|
+
current = current[val];
|
|
655
|
+
} else if (type === null) {
|
|
656
|
+
precurrent = current;
|
|
657
|
+
current = current[val];
|
|
658
|
+
} else if (type === "choice") {
|
|
659
|
+
blocks.push(precurrent);
|
|
660
|
+
current = current[val + 1][1];
|
|
661
|
+
} else if (type === "condition") {
|
|
662
|
+
blocks.push(precurrent);
|
|
663
|
+
current = current[2][val];
|
|
664
|
+
} else if (type === "block") {
|
|
665
|
+
blocks.push(precurrent);
|
|
666
|
+
current = story[val];
|
|
667
|
+
} else if (type === "block:exit" || type === "choice:exit" || type === "condition:exit") {
|
|
668
|
+
current = blocks.pop();
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return current;
|
|
672
|
+
};
|
|
673
|
+
return refer;
|
|
674
|
+
};
|
|
675
|
+
var exitPath = ({ path, refer, onExitImpossible }) => {
|
|
676
|
+
const last = path.at(-1);
|
|
677
|
+
const ignore = [];
|
|
678
|
+
let wasExitImpossible = false;
|
|
679
|
+
if (!isAction(refer(path))) {
|
|
680
|
+
if (last && isNull(last[0]) && isNumber(last[1])) {
|
|
681
|
+
last[1]--;
|
|
682
|
+
} else {
|
|
683
|
+
path.pop();
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
if (isExitImpossible(path)) {
|
|
687
|
+
const referred = refer(path);
|
|
688
|
+
if (isAction(referred) && isSkippedDuringRestore(referred[0])) {
|
|
689
|
+
onExitImpossible();
|
|
690
|
+
}
|
|
691
|
+
wasExitImpossible = true;
|
|
692
|
+
return {
|
|
693
|
+
exitImpossible: wasExitImpossible
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
for (let i = path.length - 1; i > 0; i--) {
|
|
697
|
+
const [name] = path[i];
|
|
698
|
+
if (isBlockExitStatement(name)) {
|
|
699
|
+
ignore.push(name);
|
|
700
|
+
}
|
|
701
|
+
if (!isBlockStatement(name))
|
|
702
|
+
continue;
|
|
703
|
+
if (ignore.at(-1)?.startsWith(name)) {
|
|
704
|
+
ignore.pop();
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
path.push([`${name}:exit`]);
|
|
708
|
+
const prev = findLastPathItemBeforeItemOfType(path.slice(0, i + 1), name);
|
|
709
|
+
if (prev)
|
|
710
|
+
path.push([null, prev[1] + 1]);
|
|
711
|
+
if (!isAction(refer(path))) {
|
|
712
|
+
path.pop();
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
return {
|
|
718
|
+
exitImpossible: wasExitImpossible
|
|
719
|
+
};
|
|
720
|
+
};
|
|
721
|
+
var nextPath = (path) => {
|
|
722
|
+
const last = path.at(-1);
|
|
723
|
+
if (last && (isNull(last[0]) || last[0] === "jump") && isNumber(last[1])) {
|
|
724
|
+
last[1]++;
|
|
725
|
+
} else {
|
|
726
|
+
path.push([null, 0]);
|
|
727
|
+
}
|
|
728
|
+
return path;
|
|
729
|
+
};
|
|
645
730
|
|
|
646
731
|
// ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/lite/index.mjs
|
|
647
732
|
var has = Object.prototype.hasOwnProperty;
|
|
@@ -1169,10 +1254,12 @@ var Novely = (() => {
|
|
|
1169
1254
|
}
|
|
1170
1255
|
}
|
|
1171
1256
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1257
|
+
if (context.meta.goingBack) {
|
|
1258
|
+
match("clear", [keep, characters2, audio], {
|
|
1259
|
+
ctx: context,
|
|
1260
|
+
data: latest[1]
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1176
1263
|
const lastQueueItem = queue.at(-1) || [];
|
|
1177
1264
|
const lastQueueItemRequiresUserAction = isSkippedDuringRestore(lastQueueItem[0]) || isUserRequiredAction(lastQueueItem);
|
|
1178
1265
|
await run((item) => {
|
|
@@ -1190,32 +1277,7 @@ var Novely = (() => {
|
|
|
1190
1277
|
context.meta.restoring = context.meta.goingBack = false;
|
|
1191
1278
|
render(context);
|
|
1192
1279
|
};
|
|
1193
|
-
const refer = (
|
|
1194
|
-
let current = story;
|
|
1195
|
-
let precurrent = story;
|
|
1196
|
-
const blocks = [];
|
|
1197
|
-
for (const [type, val] of path) {
|
|
1198
|
-
if (type === "jump") {
|
|
1199
|
-
precurrent = story;
|
|
1200
|
-
current = current[val];
|
|
1201
|
-
} else if (type === null) {
|
|
1202
|
-
precurrent = current;
|
|
1203
|
-
current = current[val];
|
|
1204
|
-
} else if (type === "choice") {
|
|
1205
|
-
blocks.push(precurrent);
|
|
1206
|
-
current = current[val + 1][1];
|
|
1207
|
-
} else if (type === "condition") {
|
|
1208
|
-
blocks.push(precurrent);
|
|
1209
|
-
current = current[2][val];
|
|
1210
|
-
} else if (type === "block") {
|
|
1211
|
-
blocks.push(precurrent);
|
|
1212
|
-
current = story[val];
|
|
1213
|
-
} else if (type === "block:exit" || type === "choice:exit" || type === "condition:exit") {
|
|
1214
|
-
current = blocks.pop();
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
return current;
|
|
1218
|
-
};
|
|
1280
|
+
const refer = createReferFunction(story);
|
|
1219
1281
|
const exit = (force = false, saving = true) => {
|
|
1220
1282
|
const ctx = renderer.getContext(MAIN_CONTEXT_KEY);
|
|
1221
1283
|
const stack = useStack(ctx);
|
|
@@ -1340,15 +1402,6 @@ var Novely = (() => {
|
|
|
1340
1402
|
stack.push(current);
|
|
1341
1403
|
save("auto");
|
|
1342
1404
|
};
|
|
1343
|
-
const nextPath = (path) => {
|
|
1344
|
-
const last = path.at(-1);
|
|
1345
|
-
if (last && (isNull(last[0]) || last[0] === "jump") && isNumber(last[1])) {
|
|
1346
|
-
last[1]++;
|
|
1347
|
-
} else {
|
|
1348
|
-
path.push([null, 0]);
|
|
1349
|
-
}
|
|
1350
|
-
return path;
|
|
1351
|
-
};
|
|
1352
1405
|
const next = (ctx) => {
|
|
1353
1406
|
const stack = useStack(ctx);
|
|
1354
1407
|
const path = stack.value[0];
|
|
@@ -1613,49 +1666,19 @@ var Novely = (() => {
|
|
|
1613
1666
|
exit({ ctx, data: data2 }) {
|
|
1614
1667
|
if (ctx.meta.restoring)
|
|
1615
1668
|
return;
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
if (!isAction(refer(path))) {
|
|
1621
|
-
if (last && isNull(last[0]) && isNumber(last[1])) {
|
|
1622
|
-
last[1]--;
|
|
1623
|
-
} else {
|
|
1624
|
-
path.pop();
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
if (isExitImpossible(path)) {
|
|
1628
|
-
const referred = refer(path);
|
|
1629
|
-
if (isAction(referred) && isSkippedDuringRestore(referred[0])) {
|
|
1669
|
+
const { exitImpossible } = exitPath({
|
|
1670
|
+
path: useStack(ctx).value[0],
|
|
1671
|
+
refer,
|
|
1672
|
+
onExitImpossible: () => {
|
|
1630
1673
|
match("end", [], {
|
|
1631
1674
|
ctx,
|
|
1632
1675
|
data: data2
|
|
1633
1676
|
});
|
|
1634
1677
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
const [name] = path[i];
|
|
1639
|
-
if (isBlockExitStatement(name)) {
|
|
1640
|
-
ignore.push(name);
|
|
1641
|
-
}
|
|
1642
|
-
if (!isBlockStatement(name))
|
|
1643
|
-
continue;
|
|
1644
|
-
if (ignore.at(-1)?.startsWith(name)) {
|
|
1645
|
-
ignore.pop();
|
|
1646
|
-
continue;
|
|
1647
|
-
}
|
|
1648
|
-
path.push([`${name}:exit`]);
|
|
1649
|
-
const prev = findLastPathItemBeforeItemOfType(path.slice(0, i + 1), name);
|
|
1650
|
-
if (prev)
|
|
1651
|
-
path.push([null, prev[1] + 1]);
|
|
1652
|
-
if (!isAction(refer(path))) {
|
|
1653
|
-
path.pop();
|
|
1654
|
-
continue;
|
|
1655
|
-
}
|
|
1656
|
-
break;
|
|
1678
|
+
});
|
|
1679
|
+
if (!exitImpossible) {
|
|
1680
|
+
render(ctx);
|
|
1657
1681
|
}
|
|
1658
|
-
render(ctx);
|
|
1659
1682
|
},
|
|
1660
1683
|
preload({ ctx, push }, [source]) {
|
|
1661
1684
|
if (!ctx.meta.goingBack && !ctx.meta.restoring && !PRELOADED_ASSETS.has(source)) {
|
|
@@ -1835,6 +1858,15 @@ var Novely = (() => {
|
|
|
1835
1858
|
};
|
|
1836
1859
|
};
|
|
1837
1860
|
|
|
1861
|
+
// src/extend-actions.ts
|
|
1862
|
+
var extendAction = (base, extension) => {
|
|
1863
|
+
return new Proxy({}, {
|
|
1864
|
+
get(_, key, receiver) {
|
|
1865
|
+
return Reflect.get(key in extension ? extension : base, key, receiver);
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
};
|
|
1869
|
+
|
|
1838
1870
|
// src/translations.ts
|
|
1839
1871
|
var RU = {
|
|
1840
1872
|
NewGame: "\u041D\u043E\u0432\u0430\u044F \u0438\u0433\u0440\u0430",
|