@novely/core 0.30.3 → 0.31.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 +44 -19
- package/dist/index.global.js +29 -10
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +29 -10
- package/dist/index.js.map +1 -1
- package/package.json +63 -63
package/dist/index.d.ts
CHANGED
|
@@ -176,18 +176,19 @@ type Renderer = {
|
|
|
176
176
|
unmount(): void;
|
|
177
177
|
};
|
|
178
178
|
};
|
|
179
|
+
actions: Record<string, (...args: any[]) => ValidAction>;
|
|
179
180
|
getContext: (context: string) => Context;
|
|
180
181
|
removeContext: (context: string) => void;
|
|
181
182
|
};
|
|
182
|
-
type RendererInit = {
|
|
183
|
-
characters:
|
|
183
|
+
type RendererInit<$Language extends Lang, $Characters extends Record<string, Character<$Language>>> = {
|
|
184
|
+
characters: $Characters;
|
|
184
185
|
set: (save: Save<State>) => Promise<void>;
|
|
185
186
|
restore: (save?: Save<State>) => Promise<void>;
|
|
186
187
|
save: (type: Save<State>[2][1]) => void;
|
|
187
188
|
newGame: () => void;
|
|
188
189
|
exit: (force?: boolean) => void;
|
|
189
190
|
back: () => Promise<void>;
|
|
190
|
-
languages:
|
|
191
|
+
languages: $Language[];
|
|
191
192
|
/**
|
|
192
193
|
* Translation function
|
|
193
194
|
*/
|
|
@@ -275,7 +276,10 @@ type TranslationDescription = {
|
|
|
275
276
|
plural?: Record<string, Pluralization>;
|
|
276
277
|
actions?: TranslationActions;
|
|
277
278
|
};
|
|
278
|
-
|
|
279
|
+
type DefaultEmotions<$Characters extends Record<string, Character<Lang>>> = {
|
|
280
|
+
[Character in keyof $Characters]?: (keyof $Characters[Character]['emotions'] & string);
|
|
281
|
+
};
|
|
282
|
+
interface NovelyInit<$Language extends Lang, $Characters extends Record<string, Character<NoInfer<$Language>>>, $State extends State, $Data extends Data, $Actions extends Record<string, (...args: any[]) => ValidAction>> {
|
|
279
283
|
/**
|
|
280
284
|
* An object containing the characters in the game.
|
|
281
285
|
* @example
|
|
@@ -294,7 +298,7 @@ interface NovelyInit<$Language extends Lang, Characters extends Record<string, C
|
|
|
294
298
|
* })
|
|
295
299
|
* ```
|
|
296
300
|
*/
|
|
297
|
-
characters: Characters;
|
|
301
|
+
characters: $Characters;
|
|
298
302
|
/**
|
|
299
303
|
* Define default emotions for characters
|
|
300
304
|
* @example
|
|
@@ -322,9 +326,7 @@ interface NovelyInit<$Language extends Lang, Characters extends Record<string, C
|
|
|
322
326
|
* })
|
|
323
327
|
* ```
|
|
324
328
|
*/
|
|
325
|
-
defaultEmotions?:
|
|
326
|
-
[Character in keyof NoInfer<Characters>]?: (keyof NoInfer<Characters>[Character]['emotions'] & string);
|
|
327
|
-
};
|
|
329
|
+
defaultEmotions?: DefaultEmotions<NoInfer<$Characters>>;
|
|
328
330
|
/**
|
|
329
331
|
* An object that provides access to the game's storage system.
|
|
330
332
|
* @default localStorage // at key `novely-game-storage`
|
|
@@ -337,7 +339,9 @@ interface NovelyInit<$Language extends Lang, Characters extends Record<string, C
|
|
|
337
339
|
/**
|
|
338
340
|
* A function that returns a Renderer object used to display the game's content
|
|
339
341
|
*/
|
|
340
|
-
renderer: (initializationData: RendererInit) => Renderer
|
|
342
|
+
renderer: (initializationData: RendererInit<NoInfer<$Language>, NoInfer<$Characters>>) => Renderer & {
|
|
343
|
+
actions: $Actions;
|
|
344
|
+
};
|
|
341
345
|
/**
|
|
342
346
|
* An optional property that specifies the initial screen to display when the game starts
|
|
343
347
|
*/
|
|
@@ -370,13 +374,13 @@ interface NovelyInit<$Language extends Lang, Characters extends Record<string, C
|
|
|
370
374
|
*
|
|
371
375
|
* State is a local value bound to one save
|
|
372
376
|
*/
|
|
373
|
-
state?:
|
|
377
|
+
state?: $State;
|
|
374
378
|
/**
|
|
375
379
|
* Initial data value
|
|
376
380
|
*
|
|
377
381
|
* Data is a global value shared between saves
|
|
378
382
|
*/
|
|
379
|
-
data?:
|
|
383
|
+
data?: $Data;
|
|
380
384
|
/**
|
|
381
385
|
* Enable autosaves or disable
|
|
382
386
|
* @default true
|
|
@@ -461,6 +465,12 @@ type StateFunction<S extends State> = {
|
|
|
461
465
|
(value: DeepPartial<S> | ((prev: S) => S)): void;
|
|
462
466
|
(): S;
|
|
463
467
|
};
|
|
468
|
+
type TypeEssentials<$Lang extends Lang, $State extends State, $Data extends Data, $Characters extends Record<string, Character<$Lang>>> = {
|
|
469
|
+
readonly l: $Lang | null;
|
|
470
|
+
readonly s: $State | null;
|
|
471
|
+
readonly d: $Data | null;
|
|
472
|
+
readonly c: $Characters | null;
|
|
473
|
+
};
|
|
464
474
|
|
|
465
475
|
type Name<$Lang extends Lang> = string | Record<$Lang, string>;
|
|
466
476
|
type Emotions<Emotion extends string = string> = Record<Emotion, string | string[]>;
|
|
@@ -479,7 +489,10 @@ type TextContent<L extends string, S extends State> = string | ((state: S) => st
|
|
|
479
489
|
type FunctionableValue<T> = T | (() => T);
|
|
480
490
|
type CustomHandlerGetResultDataFunction = (data?: Record<string, unknown>) => Record<string, unknown>;
|
|
481
491
|
type CustomHandlerGetResult<I extends boolean> = {
|
|
482
|
-
|
|
492
|
+
/**
|
|
493
|
+
* Remove's custom handler instance
|
|
494
|
+
*/
|
|
495
|
+
remove: () => void;
|
|
483
496
|
/**
|
|
484
497
|
* Данные
|
|
485
498
|
*/
|
|
@@ -496,6 +509,9 @@ type CustomHandlerGetResult<I extends boolean> = {
|
|
|
496
509
|
* Устанавливает обработчик очистки
|
|
497
510
|
*/
|
|
498
511
|
clear: (fn: () => void) => void;
|
|
512
|
+
__internals: {
|
|
513
|
+
ctx: Context;
|
|
514
|
+
};
|
|
499
515
|
};
|
|
500
516
|
type CustomHandlerFunctionGetFn = <I extends boolean = true>(insert?: I) => CustomHandlerGetResult<I>;
|
|
501
517
|
type CustomHandlerFunctionParameters<L extends string, S extends State> = {
|
|
@@ -621,9 +637,9 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
|
|
|
621
637
|
type DefaultActionProxy = ActionProxy<Record<string, Character>, Lang, State>;
|
|
622
638
|
type GetActionParameters<T extends Capitalize<keyof DefaultActionProxy>> = Parameters<DefaultActionProxy[Uncapitalize<T>]>;
|
|
623
639
|
|
|
624
|
-
type ConditionParams<T> = T extends
|
|
640
|
+
type ConditionParams<T> = T extends TypeEssentials<any, infer $State, any, any> ? $State : never;
|
|
625
641
|
|
|
626
|
-
declare const novely: <$Language extends string, Characters extends Record<string, Character<$Language>>,
|
|
642
|
+
declare const novely: <$Language extends string, $Characters extends Record<string, Character<$Language>>, $State extends State, $Data extends Data, $Actions extends Record<string, (...args: any[]) => ValidAction>>({ characters, defaultEmotions, storage, storageDelay, renderer: createRenderer, initialScreen, translation, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, parallelAssetsDownloadLimit, fetch: request, saveOnUnload, startKey }: NovelyInit<$Language, $Characters, $State, $Data, $Actions>) => {
|
|
627
643
|
/**
|
|
628
644
|
* Function to set game script
|
|
629
645
|
*
|
|
@@ -649,7 +665,7 @@ declare const novely: <$Language extends string, Characters extends Record<strin
|
|
|
649
665
|
* })
|
|
650
666
|
* ```
|
|
651
667
|
*/
|
|
652
|
-
action: ActionProxy
|
|
668
|
+
action: $Actions & ActionProxy<$Characters, $Language, $State>;
|
|
653
669
|
/**
|
|
654
670
|
* @deprecated Will be removed BUT replaced with state passed into actions as a parameter
|
|
655
671
|
*/
|
|
@@ -670,11 +686,20 @@ declare const novely: <$Language extends string, Characters extends Record<strin
|
|
|
670
686
|
* })
|
|
671
687
|
* ```
|
|
672
688
|
*/
|
|
673
|
-
data: StateFunction
|
|
689
|
+
data: StateFunction<$Data>;
|
|
674
690
|
/**
|
|
675
|
-
*
|
|
691
|
+
* Used in combination with type utilities
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* ```ts
|
|
695
|
+
* import type { ConditionParams, StateFunction } from '@novely/core';
|
|
696
|
+
*
|
|
697
|
+
* const conditionCheck = (state: StateFunction<ConditionParams<typeof engine.typeEssintials>>) => {
|
|
698
|
+
* return state.age >= 18;
|
|
699
|
+
* }
|
|
700
|
+
* ```
|
|
676
701
|
*/
|
|
677
|
-
|
|
702
|
+
typeEssentials: TypeEssentials<$Language, $State, $Data, $Characters>;
|
|
678
703
|
/**
|
|
679
704
|
* Replaces content inside {{braces}} with using global data
|
|
680
705
|
* @example
|
|
@@ -687,7 +712,7 @@ declare const novely: <$Language extends string, Characters extends Record<strin
|
|
|
687
712
|
* })
|
|
688
713
|
* ```
|
|
689
714
|
*/
|
|
690
|
-
templateReplace(content: TextContent<$Language,
|
|
715
|
+
templateReplace(content: TextContent<$Language, $Data>): string;
|
|
691
716
|
/**
|
|
692
717
|
* Cancel data loading, hide UI, ignore page change events
|
|
693
718
|
* Data updates still will work in case Novely already was loaded
|
package/dist/index.global.js
CHANGED
|
@@ -462,7 +462,9 @@ var Novely = (() => {
|
|
|
462
462
|
const next = (i) => queue.slice(i + 1);
|
|
463
463
|
for (const [i, item] of queue.entries()) {
|
|
464
464
|
const [action, ...params] = item;
|
|
465
|
-
|
|
465
|
+
if (isUserRequiredAction(item) && !queue.slice(0, i + 1).some((action2) => isUserRequiredAction(action2))) {
|
|
466
|
+
keep.add(action);
|
|
467
|
+
}
|
|
466
468
|
if (options.skip.has(item) && item !== options.skipPreserve) {
|
|
467
469
|
continue;
|
|
468
470
|
}
|
|
@@ -699,7 +701,7 @@ var Novely = (() => {
|
|
|
699
701
|
return { subscribe, update, set, get };
|
|
700
702
|
};
|
|
701
703
|
|
|
702
|
-
//
|
|
704
|
+
// ../deepmerge/dist/index.js
|
|
703
705
|
var { isArray } = Array;
|
|
704
706
|
var { hasOwnProperty, propertyIsEnumerable, getOwnPropertySymbols } = Object;
|
|
705
707
|
var propertyIsOnObject = (object, property) => {
|
|
@@ -710,7 +712,9 @@ var Novely = (() => {
|
|
|
710
712
|
}
|
|
711
713
|
};
|
|
712
714
|
var propertyIsUnsafe = (target, key) => {
|
|
713
|
-
return propertyIsOnObject(target, key) &&
|
|
715
|
+
return propertyIsOnObject(target, key) && // Properties are safe to merge if they don't exist in the target yet,
|
|
716
|
+
!(hasOwnProperty.call(target, key) && // unsafe if they exist up the prototype chain,
|
|
717
|
+
propertyIsEnumerable.call(target, key));
|
|
714
718
|
};
|
|
715
719
|
var getEnumerableOwnPropertySymbols = (target) => {
|
|
716
720
|
if (!getOwnPropertySymbols)
|
|
@@ -962,6 +966,9 @@ var Novely = (() => {
|
|
|
962
966
|
};
|
|
963
967
|
const action = new Proxy({}, {
|
|
964
968
|
get(_, action2) {
|
|
969
|
+
if (action2 in renderer.actions) {
|
|
970
|
+
return renderer.actions[action2];
|
|
971
|
+
}
|
|
965
972
|
return (...props) => {
|
|
966
973
|
if (preloadAssets === "blocking") {
|
|
967
974
|
if (action2 === "showBackground") {
|
|
@@ -1144,11 +1151,10 @@ var Novely = (() => {
|
|
|
1144
1151
|
const [path] = stack.value = latest;
|
|
1145
1152
|
renderer.ui.showScreen("game");
|
|
1146
1153
|
const { queue, skip, skipPreserve } = getActionsFromPath(story, path, false);
|
|
1147
|
-
const
|
|
1154
|
+
const { run, keep: { keep, characters: characters2, audio } } = createQueueProcessor(queue, {
|
|
1148
1155
|
skip,
|
|
1149
1156
|
skipPreserve
|
|
1150
1157
|
});
|
|
1151
|
-
const { keep, characters: characters2, audio } = processor.keep;
|
|
1152
1158
|
if (previous) {
|
|
1153
1159
|
const { queue: prevQueue } = getActionsFromPath(story, previous[0], false);
|
|
1154
1160
|
for (let i = prevQueue.length - 1; i > queue.length - 1; i--) {
|
|
@@ -1168,7 +1174,7 @@ var Novely = (() => {
|
|
|
1168
1174
|
});
|
|
1169
1175
|
const lastQueueItem = queue.at(-1) || [];
|
|
1170
1176
|
const lastQueueItemRequiresUserAction = isSkippedDuringRestore(lastQueueItem[0]) || isUserRequiredAction(lastQueueItem);
|
|
1171
|
-
await
|
|
1177
|
+
await run((item) => {
|
|
1172
1178
|
if (!latest)
|
|
1173
1179
|
return;
|
|
1174
1180
|
if (lastQueueItem === item && lastQueueItemRequiresUserAction) {
|
|
@@ -1711,6 +1717,12 @@ var Novely = (() => {
|
|
|
1711
1717
|
});
|
|
1712
1718
|
return void 0;
|
|
1713
1719
|
};
|
|
1720
|
+
const typeEssentials = {
|
|
1721
|
+
l: null,
|
|
1722
|
+
s: null,
|
|
1723
|
+
d: null,
|
|
1724
|
+
c: null
|
|
1725
|
+
};
|
|
1714
1726
|
return {
|
|
1715
1727
|
/**
|
|
1716
1728
|
* Function to set game script
|
|
@@ -1760,11 +1772,18 @@ var Novely = (() => {
|
|
|
1760
1772
|
*/
|
|
1761
1773
|
data,
|
|
1762
1774
|
/**
|
|
1763
|
-
*
|
|
1775
|
+
* Used in combination with type utilities
|
|
1776
|
+
*
|
|
1777
|
+
* @example
|
|
1778
|
+
* ```ts
|
|
1779
|
+
* import type { ConditionParams, StateFunction } from '@novely/core';
|
|
1780
|
+
*
|
|
1781
|
+
* const conditionCheck = (state: StateFunction<ConditionParams<typeof engine.typeEssintials>>) => {
|
|
1782
|
+
* return state.age >= 18;
|
|
1783
|
+
* }
|
|
1784
|
+
* ```
|
|
1764
1785
|
*/
|
|
1765
|
-
|
|
1766
|
-
return templateReplace(content);
|
|
1767
|
-
},
|
|
1786
|
+
typeEssentials,
|
|
1768
1787
|
/**
|
|
1769
1788
|
* Replaces content inside {{braces}} with using global data
|
|
1770
1789
|
* @example
|