@novely/core 0.41.0 → 0.42.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 +24 -7
- package/dist/index.global.js +46 -21
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ type Context = {
|
|
|
101
101
|
character: (character: string) => CharacterHandle;
|
|
102
102
|
background: (background: Record<string, string>) => void;
|
|
103
103
|
dialog: (content: string, name: string, character: string | undefined, emotion: string | undefined, resolve: () => void) => void;
|
|
104
|
-
choices: (question: string, choices: [name: string, active: boolean][], resolve: (selected: number) => void) => void;
|
|
104
|
+
choices: (question: string, choices: [name: string, active: boolean, visible: boolean, image: string][], resolve: (selected: number) => void) => void;
|
|
105
105
|
input: (question: string, onInput: (meta: ActionInputOnInputMeta<Lang, State>) => void, setup: ActionInputSetup, resolve: () => void) => void;
|
|
106
106
|
clear: (keep: Set<keyof DefaultActionProxy>, keepCharacters: Set<string>, keepAudio: {
|
|
107
107
|
music: Set<string>;
|
|
@@ -560,10 +560,10 @@ type Character<$Lang extends Lang = string> = {
|
|
|
560
560
|
emotions: Emotions;
|
|
561
561
|
};
|
|
562
562
|
|
|
563
|
-
type ValidAction = ['choice',
|
|
563
|
+
type ValidAction = ['choice', string | undefined, ...[string, unknown[], (() => boolean)?, (() => boolean)?, string?][]] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
|
|
564
564
|
music: Set<string>;
|
|
565
565
|
sounds: Set<string>;
|
|
566
|
-
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['
|
|
566
|
+
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['end'] | ['showBackground', string | NovelyAsset | BackgroundImage] | ['playMusic', string | NovelyAsset] | ['stopMusic', string | NovelyAsset] | ['pauseMusic', string | NovelyAsset] | ['playSound', audio: string | NovelyAsset, loop?: boolean] | ['pauseSound', string | NovelyAsset] | ['stopSound', string | NovelyAsset] | ['voice', string | NovelyAsset | Record<string, string | NovelyAsset>] | ['stopVoice'] | ['jump', string] | ['showCharacter', string, keyof Character['emotions'], string?, string?] | ['hideCharacter', string, string?, string?, number?] | ['animateCharacter', string, number, ...string[]] | ['wait', (number | ((state: State) => number))] | ['function', FunctionAction<string, State>] | ['input', string, (meta: ActionInputOnInputMeta<string, State>) => void, ActionInputSetup?] | ['custom', CustomHandler<string, State>] | ['vibrate', ...number[]] | ['next'] | ['text', ...TextContent<string, State>[]] | ['exit'] | ['preload', string] | ['block', string] | ValidAction[];
|
|
567
567
|
type Story = Record<string, ValidAction[]>;
|
|
568
568
|
type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
|
|
569
569
|
type FunctionableValue<T> = T | (() => T);
|
|
@@ -733,10 +733,24 @@ type ActionInputSetupCleanup = () => void;
|
|
|
733
733
|
type ActionInputSetup = (input: HTMLInputElement) => ActionInputSetupCleanup | void;
|
|
734
734
|
type BackgroundImage = Record<string, string | NovelyAsset>;
|
|
735
735
|
type VoiceAction<L extends Lang> = (params: string | NovelyAsset | Partial<Record<L, string | NovelyAsset>>) => ValidAction;
|
|
736
|
+
type ActionChoiceExtendedChoice<Languages extends Lang, S extends State> = {
|
|
737
|
+
title: TextContent<Languages, S>;
|
|
738
|
+
children: ValidAction[];
|
|
739
|
+
active?: ChoiceCheckFunction<Languages, S>;
|
|
740
|
+
visible?: ChoiceCheckFunction<Languages, S>;
|
|
741
|
+
image?: string | NovelyAsset;
|
|
742
|
+
};
|
|
743
|
+
type ActionChoiceChoice<Languages extends Lang, S extends State> = [
|
|
744
|
+
title: TextContent<Languages, S>,
|
|
745
|
+
actions: ValidAction[],
|
|
746
|
+
active?: ChoiceCheckFunction<Languages, S>,
|
|
747
|
+
visible?: ChoiceCheckFunction<Languages, S>,
|
|
748
|
+
image?: string | NovelyAsset
|
|
749
|
+
];
|
|
736
750
|
type ActionProxy<Characters extends Record<string, Character>, Languages extends Lang, S extends State> = {
|
|
737
751
|
choice: {
|
|
738
|
-
(...choices:
|
|
739
|
-
(question: TextContent<Languages, S>, ...choices:
|
|
752
|
+
(...choices: ActionChoiceChoice<Languages, S>[]): ValidAction;
|
|
753
|
+
(question: TextContent<Languages, S>, ...choices: ActionChoiceChoice<Languages, S>[]): ValidAction;
|
|
740
754
|
};
|
|
741
755
|
clear: (keep?: Set<keyof DefaultActionProxy>, keepCharacters?: Set<string>, keepAudio?: {
|
|
742
756
|
music: Set<string>;
|
|
@@ -749,7 +763,6 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
|
|
|
749
763
|
(character: undefined, content: TextContent<Languages, S>, emotion?: undefined): ValidAction;
|
|
750
764
|
(character: string, content: TextContent<Languages, S>, emotion?: undefined): ValidAction;
|
|
751
765
|
};
|
|
752
|
-
say: (character: keyof Characters, content: TextContent<Languages, S>) => ValidAction;
|
|
753
766
|
end: () => ValidAction;
|
|
754
767
|
showBackground: {
|
|
755
768
|
(background: string | NovelyAsset): ValidAction;
|
|
@@ -795,6 +808,10 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
|
|
|
795
808
|
};
|
|
796
809
|
type DefaultActionProxy = ActionProxy<Record<string, Character>, Lang, State>;
|
|
797
810
|
type GetActionParameters<T extends Capitalize<keyof DefaultActionProxy>> = Parameters<DefaultActionProxy[Uncapitalize<T>]>;
|
|
811
|
+
type VirtualActions<Characters extends Record<string, Character>, Languages extends Lang, S extends State> = {
|
|
812
|
+
choiceExtended: (question: TextContent<Languages, S>, choices: ActionChoiceExtendedChoice<Languages, State>[]) => ValidAction;
|
|
813
|
+
say: (character: keyof Characters, content: TextContent<Languages, S>) => ValidAction;
|
|
814
|
+
};
|
|
798
815
|
|
|
799
816
|
type ConditionParams<T> = T extends TypeEssentials<any, infer $State, any, any> ? $State : never;
|
|
800
817
|
type ChoiceParams<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? ChoiceCheckFunctionProps<$Lang, $State> : never;
|
|
@@ -827,7 +844,7 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
827
844
|
* })
|
|
828
845
|
* ```
|
|
829
846
|
*/
|
|
830
|
-
action: $Actions & ActionProxy<$Characters, $Language, $State>;
|
|
847
|
+
action: $Actions & ActionProxy<$Characters, $Language, $State> & VirtualActions<$Characters, $Language, $State>;
|
|
831
848
|
/**
|
|
832
849
|
* @deprecated Will be removed BUT replaced with state passed into actions as a parameter
|
|
833
850
|
*/
|
package/dist/index.global.js
CHANGED
|
@@ -32,9 +32,10 @@ var Novely = (() => {
|
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
// src/constants.ts
|
|
35
|
-
var SKIPPED_DURING_RESTORE = /* @__PURE__ */ new Set(["dialog", "
|
|
35
|
+
var SKIPPED_DURING_RESTORE = /* @__PURE__ */ new Set(["dialog", "choice", "input", "vibrate", "text"]);
|
|
36
36
|
var BLOCK_EXIT_STATEMENTS = /* @__PURE__ */ new Set(["choice:exit", "condition:exit", "block:exit"]);
|
|
37
37
|
var BLOCK_STATEMENTS = /* @__PURE__ */ new Set(["choice", "condition", "block"]);
|
|
38
|
+
var VIRTUAL_ACTIONS = /* @__PURE__ */ new Set(["say", "choiceExtended"]);
|
|
38
39
|
var AUDIO_ACTIONS = /* @__PURE__ */ new Set([
|
|
39
40
|
"playMusic",
|
|
40
41
|
"stopMusic",
|
|
@@ -262,13 +263,11 @@ var Novely = (() => {
|
|
|
262
263
|
var matchAction = ({ getContext, onBeforeActionCall, push, forward }, values) => {
|
|
263
264
|
return (action, props, { ctx, data }) => {
|
|
264
265
|
const context = typeof ctx === "string" ? getContext(ctx) : ctx;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
});
|
|
271
|
-
}
|
|
266
|
+
onBeforeActionCall({
|
|
267
|
+
action,
|
|
268
|
+
props,
|
|
269
|
+
ctx: context
|
|
270
|
+
});
|
|
272
271
|
return values[action]({
|
|
273
272
|
ctx: context,
|
|
274
273
|
data,
|
|
@@ -1346,6 +1345,14 @@ var Novely = (() => {
|
|
|
1346
1345
|
}
|
|
1347
1346
|
return;
|
|
1348
1347
|
}
|
|
1348
|
+
if (action === "choice") {
|
|
1349
|
+
for (let i = 1; i < props.length; i++) {
|
|
1350
|
+
const data = props[i];
|
|
1351
|
+
if (Array.isArray(data)) {
|
|
1352
|
+
handle(handleImageAsset(data[4]));
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1349
1356
|
};
|
|
1350
1357
|
|
|
1351
1358
|
// src/novely.ts
|
|
@@ -1422,6 +1429,28 @@ var Novely = (() => {
|
|
|
1422
1429
|
return renderer.actions[action2];
|
|
1423
1430
|
}
|
|
1424
1431
|
return (...props) => {
|
|
1432
|
+
if (VIRTUAL_ACTIONS.has(action2)) {
|
|
1433
|
+
if (action2 === "say") {
|
|
1434
|
+
action2 = "dialog";
|
|
1435
|
+
const [character] = props;
|
|
1436
|
+
if (DEV && !characters[character]) {
|
|
1437
|
+
throw new Error(`Attempt to call Say action with unknown character "${character}"`);
|
|
1438
|
+
}
|
|
1439
|
+
} else if (action2 === "choiceExtended") {
|
|
1440
|
+
action2 = "choice";
|
|
1441
|
+
const choices = props[1];
|
|
1442
|
+
const mappedChoices = choices.map((choice) => [
|
|
1443
|
+
choice.title,
|
|
1444
|
+
choice.children,
|
|
1445
|
+
choice.active,
|
|
1446
|
+
choice.visible,
|
|
1447
|
+
choice.image
|
|
1448
|
+
]);
|
|
1449
|
+
for (let i = 0; i < mappedChoices.length; i++) {
|
|
1450
|
+
props[i + 1] = mappedChoices[i];
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1425
1454
|
if (preloadAssets === "blocking") {
|
|
1426
1455
|
huntAssets({
|
|
1427
1456
|
action: action2,
|
|
@@ -1931,15 +1960,6 @@ var Novely = (() => {
|
|
|
1931
1960
|
forward
|
|
1932
1961
|
);
|
|
1933
1962
|
},
|
|
1934
|
-
say({ ctx, data: data2 }, [character, content]) {
|
|
1935
|
-
if (DEV && !characters[character]) {
|
|
1936
|
-
throw new Error(`Attempt to call Say action with unknown character "${character}"`);
|
|
1937
|
-
}
|
|
1938
|
-
match("dialog", [character, content], {
|
|
1939
|
-
ctx,
|
|
1940
|
-
data: data2
|
|
1941
|
-
});
|
|
1942
|
-
},
|
|
1943
1963
|
function({ ctx, push }, [fn]) {
|
|
1944
1964
|
const { restoring, goingBack, preview: preview2 } = ctx.meta;
|
|
1945
1965
|
const result = fn({
|
|
@@ -1960,15 +1980,20 @@ var Novely = (() => {
|
|
|
1960
1980
|
choices.unshift(question);
|
|
1961
1981
|
question = "";
|
|
1962
1982
|
}
|
|
1963
|
-
const transformedChoices = choices.map(([content, action2, visible]) => {
|
|
1964
|
-
const
|
|
1983
|
+
const transformedChoices = choices.map(([content, action2, active, visible, image]) => {
|
|
1984
|
+
const activeValue = !active || active({
|
|
1985
|
+
lang: getLanguageFromStore(storageData),
|
|
1986
|
+
state: getStateAtCtx(ctx)
|
|
1987
|
+
});
|
|
1988
|
+
const visibleValue = !visible || visible({
|
|
1965
1989
|
lang: getLanguageFromStore(storageData),
|
|
1966
1990
|
state: getStateAtCtx(ctx)
|
|
1967
1991
|
});
|
|
1968
|
-
|
|
1992
|
+
const imageValue = image ? handleImageAsset(image) : "";
|
|
1993
|
+
if (DEV && action2.length === 0 && (!activeValue && !visibleValue)) {
|
|
1969
1994
|
console.warn(`Choice children should not be empty, either add content there or make item not selectable`);
|
|
1970
1995
|
}
|
|
1971
|
-
return [templateReplace(content, data2),
|
|
1996
|
+
return [templateReplace(content, data2), activeValue, visibleValue, imageValue];
|
|
1972
1997
|
});
|
|
1973
1998
|
if (DEV && transformedChoices.length === 0) {
|
|
1974
1999
|
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]`);
|