@novely/core 0.30.3 → 0.31.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 +44 -16
- package/dist/index.global.js +26 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +26 -2
- 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,7 @@ type TranslationDescription = {
|
|
|
275
276
|
plural?: Record<string, Pluralization>;
|
|
276
277
|
actions?: TranslationActions;
|
|
277
278
|
};
|
|
278
|
-
interface NovelyInit<$Language extends Lang, Characters extends Record<string, Character<NoInfer<$Language>>>,
|
|
279
|
+
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
280
|
/**
|
|
280
281
|
* An object containing the characters in the game.
|
|
281
282
|
* @example
|
|
@@ -294,7 +295,7 @@ interface NovelyInit<$Language extends Lang, Characters extends Record<string, C
|
|
|
294
295
|
* })
|
|
295
296
|
* ```
|
|
296
297
|
*/
|
|
297
|
-
characters: Characters;
|
|
298
|
+
characters: $Characters;
|
|
298
299
|
/**
|
|
299
300
|
* Define default emotions for characters
|
|
300
301
|
* @example
|
|
@@ -323,7 +324,7 @@ interface NovelyInit<$Language extends Lang, Characters extends Record<string, C
|
|
|
323
324
|
* ```
|
|
324
325
|
*/
|
|
325
326
|
defaultEmotions?: {
|
|
326
|
-
[Character in keyof NoInfer
|
|
327
|
+
[Character in keyof NoInfer<$Characters>]?: (keyof NoInfer<$Characters>[Character]['emotions'] & string);
|
|
327
328
|
};
|
|
328
329
|
/**
|
|
329
330
|
* An object that provides access to the game's storage system.
|
|
@@ -337,7 +338,9 @@ interface NovelyInit<$Language extends Lang, Characters extends Record<string, C
|
|
|
337
338
|
/**
|
|
338
339
|
* A function that returns a Renderer object used to display the game's content
|
|
339
340
|
*/
|
|
340
|
-
renderer: (initializationData: RendererInit) => Renderer
|
|
341
|
+
renderer: (initializationData: RendererInit<NoInfer<$Language>, NoInfer<$Characters>>) => Renderer & {
|
|
342
|
+
actions: $Actions;
|
|
343
|
+
};
|
|
341
344
|
/**
|
|
342
345
|
* An optional property that specifies the initial screen to display when the game starts
|
|
343
346
|
*/
|
|
@@ -370,13 +373,13 @@ interface NovelyInit<$Language extends Lang, Characters extends Record<string, C
|
|
|
370
373
|
*
|
|
371
374
|
* State is a local value bound to one save
|
|
372
375
|
*/
|
|
373
|
-
state?:
|
|
376
|
+
state?: $State;
|
|
374
377
|
/**
|
|
375
378
|
* Initial data value
|
|
376
379
|
*
|
|
377
380
|
* Data is a global value shared between saves
|
|
378
381
|
*/
|
|
379
|
-
data?:
|
|
382
|
+
data?: $Data;
|
|
380
383
|
/**
|
|
381
384
|
* Enable autosaves or disable
|
|
382
385
|
* @default true
|
|
@@ -461,6 +464,12 @@ type StateFunction<S extends State> = {
|
|
|
461
464
|
(value: DeepPartial<S> | ((prev: S) => S)): void;
|
|
462
465
|
(): S;
|
|
463
466
|
};
|
|
467
|
+
type TypeEssentials<$Lang extends Lang, $State extends State, $Data extends Data, $Characters extends Record<string, Character<$Lang>>> = {
|
|
468
|
+
readonly l: $Lang | null;
|
|
469
|
+
readonly s: $State | null;
|
|
470
|
+
readonly d: $Data | null;
|
|
471
|
+
readonly c: $Characters | null;
|
|
472
|
+
};
|
|
464
473
|
|
|
465
474
|
type Name<$Lang extends Lang> = string | Record<$Lang, string>;
|
|
466
475
|
type Emotions<Emotion extends string = string> = Record<Emotion, string | string[]>;
|
|
@@ -479,7 +488,10 @@ type TextContent<L extends string, S extends State> = string | ((state: S) => st
|
|
|
479
488
|
type FunctionableValue<T> = T | (() => T);
|
|
480
489
|
type CustomHandlerGetResultDataFunction = (data?: Record<string, unknown>) => Record<string, unknown>;
|
|
481
490
|
type CustomHandlerGetResult<I extends boolean> = {
|
|
482
|
-
|
|
491
|
+
/**
|
|
492
|
+
* Remove's custom handler instance
|
|
493
|
+
*/
|
|
494
|
+
remove: () => void;
|
|
483
495
|
/**
|
|
484
496
|
* Данные
|
|
485
497
|
*/
|
|
@@ -496,6 +508,9 @@ type CustomHandlerGetResult<I extends boolean> = {
|
|
|
496
508
|
* Устанавливает обработчик очистки
|
|
497
509
|
*/
|
|
498
510
|
clear: (fn: () => void) => void;
|
|
511
|
+
__internals: {
|
|
512
|
+
ctx: Context;
|
|
513
|
+
};
|
|
499
514
|
};
|
|
500
515
|
type CustomHandlerFunctionGetFn = <I extends boolean = true>(insert?: I) => CustomHandlerGetResult<I>;
|
|
501
516
|
type CustomHandlerFunctionParameters<L extends string, S extends State> = {
|
|
@@ -621,9 +636,9 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
|
|
|
621
636
|
type DefaultActionProxy = ActionProxy<Record<string, Character>, Lang, State>;
|
|
622
637
|
type GetActionParameters<T extends Capitalize<keyof DefaultActionProxy>> = Parameters<DefaultActionProxy[Uncapitalize<T>]>;
|
|
623
638
|
|
|
624
|
-
type ConditionParams<T> = T extends
|
|
639
|
+
type ConditionParams<T> = T extends TypeEssentials<any, infer $State, any, any> ? $State : never;
|
|
625
640
|
|
|
626
|
-
declare const novely: <$Language extends string, Characters extends Record<string, Character<$Language>>,
|
|
641
|
+
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
642
|
/**
|
|
628
643
|
* Function to set game script
|
|
629
644
|
*
|
|
@@ -649,7 +664,7 @@ declare const novely: <$Language extends string, Characters extends Record<strin
|
|
|
649
664
|
* })
|
|
650
665
|
* ```
|
|
651
666
|
*/
|
|
652
|
-
action: ActionProxy
|
|
667
|
+
action: $Actions & ActionProxy<$Characters, $Language, $State>;
|
|
653
668
|
/**
|
|
654
669
|
* @deprecated Will be removed BUT replaced with state passed into actions as a parameter
|
|
655
670
|
*/
|
|
@@ -670,11 +685,24 @@ declare const novely: <$Language extends string, Characters extends Record<strin
|
|
|
670
685
|
* })
|
|
671
686
|
* ```
|
|
672
687
|
*/
|
|
673
|
-
data: StateFunction
|
|
688
|
+
data: StateFunction<$Data>;
|
|
689
|
+
/**
|
|
690
|
+
* Used in combination with type utilities
|
|
691
|
+
*
|
|
692
|
+
* @example
|
|
693
|
+
* ```ts
|
|
694
|
+
* import type { ConditionParams, StateFunction } from '@novely/core';
|
|
695
|
+
*
|
|
696
|
+
* const conditionCheck = (state: StateFunction<ConditionParams<typeof engine.typeEssintials>>) => {
|
|
697
|
+
* return state.age >= 18;
|
|
698
|
+
* }
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
typeEssentials: TypeEssentials<$Language, $State, $Data, $Characters>;
|
|
674
702
|
/**
|
|
675
703
|
* @deprecated Renamed into `templateReplace`
|
|
676
704
|
*/
|
|
677
|
-
unwrap(content: TextContent<$Language,
|
|
705
|
+
unwrap(content: TextContent<$Language, $Data>): string;
|
|
678
706
|
/**
|
|
679
707
|
* Replaces content inside {{braces}} with using global data
|
|
680
708
|
* @example
|
|
@@ -687,7 +715,7 @@ declare const novely: <$Language extends string, Characters extends Record<strin
|
|
|
687
715
|
* })
|
|
688
716
|
* ```
|
|
689
717
|
*/
|
|
690
|
-
templateReplace(content: TextContent<$Language,
|
|
718
|
+
templateReplace(content: TextContent<$Language, $Data>): string;
|
|
691
719
|
/**
|
|
692
720
|
* Cancel data loading, hide UI, ignore page change events
|
|
693
721
|
* Data updates still will work in case Novely already was loaded
|
package/dist/index.global.js
CHANGED
|
@@ -699,7 +699,7 @@ var Novely = (() => {
|
|
|
699
699
|
return { subscribe, update, set, get };
|
|
700
700
|
};
|
|
701
701
|
|
|
702
|
-
//
|
|
702
|
+
// ../deepmerge/dist/index.js
|
|
703
703
|
var { isArray } = Array;
|
|
704
704
|
var { hasOwnProperty, propertyIsEnumerable, getOwnPropertySymbols } = Object;
|
|
705
705
|
var propertyIsOnObject = (object, property) => {
|
|
@@ -710,7 +710,9 @@ var Novely = (() => {
|
|
|
710
710
|
}
|
|
711
711
|
};
|
|
712
712
|
var propertyIsUnsafe = (target, key) => {
|
|
713
|
-
return propertyIsOnObject(target, key) &&
|
|
713
|
+
return propertyIsOnObject(target, key) && // Properties are safe to merge if they don't exist in the target yet,
|
|
714
|
+
!(hasOwnProperty.call(target, key) && // unsafe if they exist up the prototype chain,
|
|
715
|
+
propertyIsEnumerable.call(target, key));
|
|
714
716
|
};
|
|
715
717
|
var getEnumerableOwnPropertySymbols = (target) => {
|
|
716
718
|
if (!getOwnPropertySymbols)
|
|
@@ -962,6 +964,9 @@ var Novely = (() => {
|
|
|
962
964
|
};
|
|
963
965
|
const action = new Proxy({}, {
|
|
964
966
|
get(_, action2) {
|
|
967
|
+
if (action2 in renderer.actions) {
|
|
968
|
+
return renderer.actions[action2];
|
|
969
|
+
}
|
|
965
970
|
return (...props) => {
|
|
966
971
|
if (preloadAssets === "blocking") {
|
|
967
972
|
if (action2 === "showBackground") {
|
|
@@ -1711,6 +1716,12 @@ var Novely = (() => {
|
|
|
1711
1716
|
});
|
|
1712
1717
|
return void 0;
|
|
1713
1718
|
};
|
|
1719
|
+
const typeEssentials = {
|
|
1720
|
+
l: null,
|
|
1721
|
+
s: null,
|
|
1722
|
+
d: null,
|
|
1723
|
+
c: null
|
|
1724
|
+
};
|
|
1714
1725
|
return {
|
|
1715
1726
|
/**
|
|
1716
1727
|
* Function to set game script
|
|
@@ -1759,6 +1770,19 @@ var Novely = (() => {
|
|
|
1759
1770
|
* ```
|
|
1760
1771
|
*/
|
|
1761
1772
|
data,
|
|
1773
|
+
/**
|
|
1774
|
+
* Used in combination with type utilities
|
|
1775
|
+
*
|
|
1776
|
+
* @example
|
|
1777
|
+
* ```ts
|
|
1778
|
+
* import type { ConditionParams, StateFunction } from '@novely/core';
|
|
1779
|
+
*
|
|
1780
|
+
* const conditionCheck = (state: StateFunction<ConditionParams<typeof engine.typeEssintials>>) => {
|
|
1781
|
+
* return state.age >= 18;
|
|
1782
|
+
* }
|
|
1783
|
+
* ```
|
|
1784
|
+
*/
|
|
1785
|
+
typeEssentials,
|
|
1762
1786
|
/**
|
|
1763
1787
|
* @deprecated Renamed into `templateReplace`
|
|
1764
1788
|
*/
|