@drincs/pixi-vn 0.3.4 → 0.3.6

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Pixi'VN - Pixi Visual Novel Engine
1
+ # Pixi'VN - PixiJS Visual Novel Engine
2
2
 
3
3
  Pixi'VN is a npm package that provides various features for creating visual novels.
4
4
 
@@ -9,6 +9,14 @@ Pixi'VN is based on [Pixi.js](https://pixijs.com/), a modern 2D rendering engine
9
9
  In addition to managing the Pixi.js "Canvas", Pixi'VN offers the possibility of adding an HTML Element with the same dimensions as the "Canvas" to add interactions with the user.
10
10
  This allows the use of systems such as React, Vue, Angular, etc. to create much more complex interfaces with excellent performance.
11
11
 
12
+ ## Why Pixi'VN?
13
+
14
+ The reason why Pixi'VN was born is that current systems for creating a visual novel are based on dated systems and have many shortcomings.
15
+
16
+ ## Pivi'VN Templates
17
+
18
+ * [Pixi’VN template (React + Vite + MUI joy)](https://github.com/DRincs-Productions/pixi-vn-react-template)
19
+
12
20
  ## Get Started
13
21
 
14
22
  ### Installation
@@ -87,7 +95,3 @@ body {
87
95
  ## Wiki
88
96
 
89
97
  For more information, visit the [Wiki](https://pixivn.readthedocs.io/)
90
-
91
- ## Why Pixi'VN?
92
-
93
- The reason why Pixi'VN was born is that current systems for creating a visual novel are based on dated systems and have many shortcomings.
package/dist/index.d.mts CHANGED
@@ -193,7 +193,18 @@ type StepHistoryDataType = string;
193
193
  /**
194
194
  * StepLabel is a function that will be executed as the game continues.
195
195
  */
196
- type StepLabelType = (() => void | Promise<void>);
196
+ type StepLabelType = (() => StepLabelResultType | Promise<StepLabelResultType>);
197
+ /**
198
+ * StepLabelResultType is the return type of the StepLabel function.
199
+ * It can be useful for returning to the information calling function to perform other operations that cannot be performed within the StepLabel.
200
+ */
201
+ type StepLabelResultType = {
202
+ /**
203
+ * The new route to navigate to.
204
+ */
205
+ newRoute?: string;
206
+ [key: string]: any;
207
+ } | void;
197
208
 
198
209
  /**
199
210
  * Label is a class that contains a list of steps, which will be performed as the game continues.
@@ -262,11 +273,11 @@ declare class ChoiceMenuOptionLabel {
262
273
  */
263
274
  constructor(text: string, label: typeof Label, type?: LabelRunModeEnum);
264
275
  }
265
- interface IStoratedChoiceMenuOptionLabel {
276
+ type IStoratedChoiceMenuOptionLabel = {
266
277
  text: string;
267
278
  label: LabelIdType;
268
279
  type: LabelRunModeEnum;
269
- }
280
+ };
270
281
 
271
282
  /**
272
283
  * Munu is a type that contains a list of Label that a player can choose from.
@@ -284,10 +295,12 @@ declare function Pause(duration: number): PauseType;
284
295
  type RepeatType = "Repeat";
285
296
  declare const Repeat: RepeatType;
286
297
 
298
+ type StorageElementPrimaryType = string | number | boolean | undefined | null | StorageElementPrimaryType[];
299
+ type StorageElementInternalType = StorageElementPrimaryType | Record<string | number | symbol, StorageElementPrimaryType> | StorageElementInternalType[];
287
300
  /**
288
301
  * StorageElementType are all the types that can be stored in the storage
289
302
  */
290
- type StorageElementType = string | number | boolean | object | undefined | null;
303
+ type StorageElementType = StorageElementInternalType | Record<string | number | symbol, StorageElementInternalType>;
291
304
 
292
305
  /**
293
306
  * Base class for all dialogue models.
@@ -671,16 +684,33 @@ declare class TickerBase<TArgs extends TickerArgsType> implements ITicker<TArgs>
671
684
  fn(_t: Ticker, _args: TArgs, _tags: string | string[]): void;
672
685
  }
673
686
 
687
+ type TickerFadeAlphaProps = {
688
+ /**
689
+ * The speed of the fade
690
+ */
691
+ speed: number;
692
+ /**
693
+ * The type of the fade
694
+ * @default "hide"
695
+ */
696
+ type?: "hide" | "show";
697
+ /**
698
+ * The limit of the fade
699
+ * @default type === "hide" ? 0 : 1
700
+ */
701
+ limit?: number;
702
+ /**
703
+ * The tag to remove after the fade is done
704
+ */
705
+ tagToRemoveAfter?: string[] | string;
706
+ /**
707
+ * If true, the fade only starts if the canvas element have a texture
708
+ */
709
+ startOnlyIfHaveTexture?: boolean;
710
+ };
711
+
674
712
  /**
675
713
  * A ticker that fades the alpha of the canvas element of the canvas.
676
- * @param args The arguments that are passed to the ticker
677
- * - speed: The speed of the fade
678
- * - type: The type of the fade, default is "hide"
679
- * - limit: The limit of the fade, default is 0 for hide and 1 for show
680
- * - tagToRemoveAfter?: The tag to remove after the fade is done
681
- * - startOnlyIfHaveTexture?: If true, the fade only starts if the canvas element have a texture
682
- * @param duration The duration of the ticker
683
- * @param priority The priority of the ticker
684
714
  * @example
685
715
  * ```typescript
686
716
  * let bunny = addImage("bunny1", "https://pixijs.com/assets/eggHead.png")
@@ -694,13 +724,7 @@ declare class TickerBase<TArgs extends TickerArgsType> implements ITicker<TArgs>
694
724
  * GameWindowManager.addTicker("bunny", ticker)
695
725
  * ```
696
726
  */
697
- declare class TickerFadeAlpha extends TickerBase<{
698
- speed: number;
699
- type?: "hide" | "show";
700
- limit?: number;
701
- tagToRemoveAfter?: string[] | string;
702
- startOnlyIfHaveTexture?: boolean;
703
- }> {
727
+ declare class TickerFadeAlpha extends TickerBase<TickerFadeAlphaProps> {
704
728
  /**
705
729
  * The method that will be called every frame to fade the alpha of the canvas element of the canvas.
706
730
  * @param delta The delta time
@@ -717,114 +741,16 @@ declare class TickerFadeAlpha extends TickerBase<{
717
741
  }
718
742
 
719
743
  type TickerProgrationType = ITickerProgrationLinear | ITickerProgrationExponential;
720
- interface ITickerProgrationLinear {
744
+ type ITickerProgrationLinear = {
721
745
  amt: number;
722
746
  limit?: number;
723
747
  type: "linear";
724
- }
725
- interface ITickerProgrationExponential {
748
+ };
749
+ type ITickerProgrationExponential = {
726
750
  percentage: number;
727
751
  limit?: number;
728
752
  type: "exponential";
729
- }
730
-
731
- /**
732
- * A ticker that rotates the canvas element of the canvas.
733
- * @param args The arguments that are passed to the ticker
734
- * - speed: The speed of the rotation, default is 0.1
735
- * - clockwise: The direction of the rotation, default is true
736
- * - speedProgression: The progression of the speed
737
- * - startOnlyIfHaveTexture?: If true, the rotation only starts if the canvas element have a texture
738
- * @param duration The duration of the ticker
739
- * @param priority The priority of the ticker
740
- * @example
741
- * ```typescript
742
- * let alien = addImage("alien", 'https://pixijs.com/assets/eggHead.png')
743
- * GameWindowManager.addCanvasElement("alien", alien);
744
- * const ticker = new TickerRotate({
745
- * speed: 0.1,
746
- * clockwise: true,
747
- * }),
748
- * GameWindowManager.addTicker("alien", ticker)
749
- */
750
- declare class TickerRotate extends TickerBase<{
751
- speed?: number;
752
- clockwise?: boolean;
753
- speedProgression?: TickerProgrationType;
754
- startOnlyIfHaveTexture?: boolean;
755
- }> {
756
- /**
757
- * The method that will be called every frame to rotate the canvas element of the canvas.
758
- * @param delta The delta time
759
- * @param args The arguments that are passed to the ticker
760
- * @param tags The tags of the canvas element that are connected to this ticker
761
- */
762
- fn(t: Ticker, args: {
763
- speed?: number;
764
- clockwise?: boolean;
765
- speedProgression?: TickerProgrationType;
766
- startOnlyIfHaveTexture?: boolean;
767
- }, tags: string[]): void;
768
- }
769
-
770
- type CanvasElementTagType = string;
771
-
772
- /**
773
- * Is a decorator that register a canvas element in the game.
774
- * @param name Name of the canvas element, by default it will use the class name. If the name is already registered, it will show a warning
775
- * @returns
776
- */
777
- declare function canvasElementDecorator(name?: CanvasElementTagType): (target: typeof CanvasBase<any>) => void;
778
-
779
- /**
780
- * Is a function that saves the character. If the character already exists, it will be overwritten.
781
- * @param character is the character to save
782
- * @returns
783
- * @example
784
- * ```typescript
785
- * export const liam = new CharacterBaseModel('liam', { name: 'Liam'});
786
- * export const alice = new CharacterBaseModel('alice', { name: 'Alice'});
787
- * saveCharacter([liam, alice]);
788
- * ```
789
- */
790
- declare function saveCharacter<T extends CharacterBaseModel = CharacterBaseModel>(character: T | T[]): void;
791
- /**
792
- * is a function that returns the character by the id
793
- * @param id is the id of the character
794
- * @returns the character
795
- * @example
796
- * ```typescript
797
- * const liam = getCharacterById('liam');
798
- * ```
799
- */
800
- declare function getCharacterById<T extends CharacterBaseModel>(id: string): T | undefined;
801
- /**
802
- * is a function that returns all characters
803
- * @returns all characters
804
- * @example
805
- * ```typescript
806
- * const allCharacters = getAllCharacters();
807
- * ```
808
- */
809
- declare function getAllCharacters<T extends CharacterBaseModel>(): T[];
810
-
811
- /**
812
- * Is a decorator that register a event in the game.
813
- * Is a required decorator for use the event in the game.
814
- * Thanks to this decoration the game has the possibility of updating the events to the latest modification and saving the game.
815
- * @param name is th identifier of the event, by default is the name of the class
816
- * @returns
817
- */
818
- declare function eventDecorator(name?: EventIdType): (target: typeof CanvasEvent<any>) => void;
819
-
820
- /**
821
- * Is a decorator that register a label in the game.
822
- * Is a required decorator for use the label in the game.
823
- * Thanks to this decoration the game has the possibility of updating the labels to the latest modification and saving the game.
824
- * @param name is th identifier of the label, by default is the name of the class
825
- * @returns
826
- */
827
- declare function labelDecorator(name?: LabelIdType): (target: typeof Label) => void;
753
+ };
828
754
 
829
755
  /**
830
756
  * is a string that represents a ticker id.
@@ -832,15 +758,6 @@ declare function labelDecorator(name?: LabelIdType): (target: typeof Label) => v
832
758
  */
833
759
  type TickerIdType = string;
834
760
 
835
- /**
836
- * Is a decorator that register a ticker in the game.
837
- * Is a required decorator for use the ticker in the game.
838
- * Thanks to this decoration the game has the possibility of updating the tickers to the latest modification and saving the game.
839
- * @param name is th identifier of the label, by default is the name of the class
840
- * @returns
841
- */
842
- declare function tickerDecorator(name?: TickerIdType): (target: typeof TickerBase<any>) => void;
843
-
844
761
  /**
845
762
  * IClassWithArgsHistory is a class that contains the name of a class and the arguments that were used to create it.
846
763
  */
@@ -996,6 +913,122 @@ interface ITickersSteps {
996
913
  steps: (ITickersStep<any> | RepeatType | PauseType)[];
997
914
  }
998
915
 
916
+ type TickerRotateProps = {
917
+ /**
918
+ * The speed of the rotation
919
+ * @default 0.1
920
+ */
921
+ speed?: number;
922
+ /**
923
+ * The direction of the rotation
924
+ * @default true
925
+ */
926
+ clockwise?: boolean;
927
+ /**
928
+ * The progression of the speed
929
+ */
930
+ speedProgression?: TickerProgrationType;
931
+ /**
932
+ * If true, the rotation only starts if the canvas element have a texture
933
+ */
934
+ startOnlyIfHaveTexture?: boolean;
935
+ };
936
+
937
+ /**
938
+ * A ticker that rotates the canvas element of the canvas.
939
+ * @example
940
+ * ```typescript
941
+ * let alien = addImage("alien", 'https://pixijs.com/assets/eggHead.png')
942
+ * GameWindowManager.addCanvasElement("alien", alien);
943
+ * const ticker = new TickerRotate({
944
+ * speed: 0.1,
945
+ * clockwise: true,
946
+ * }),
947
+ * GameWindowManager.addTicker("alien", ticker)
948
+ */
949
+ declare class TickerRotate extends TickerBase<TickerRotateProps> {
950
+ /**
951
+ * The method that will be called every frame to rotate the canvas element of the canvas.
952
+ * @param delta The delta time
953
+ * @param args The arguments that are passed to the ticker
954
+ * @param tags The tags of the canvas element that are connected to this ticker
955
+ */
956
+ fn(t: Ticker, args: {
957
+ speed?: number;
958
+ clockwise?: boolean;
959
+ speedProgression?: TickerProgrationType;
960
+ startOnlyIfHaveTexture?: boolean;
961
+ }, tags: string[]): void;
962
+ }
963
+
964
+ type CanvasElementTagType = string;
965
+
966
+ /**
967
+ * Is a decorator that register a canvas element in the game.
968
+ * @param name Name of the canvas element, by default it will use the class name. If the name is already registered, it will show a warning
969
+ * @returns
970
+ */
971
+ declare function canvasElementDecorator(name?: CanvasElementTagType): (target: typeof CanvasBase<any>) => void;
972
+
973
+ /**
974
+ * Is a function that saves the character. If the character already exists, it will be overwritten.
975
+ * @param character is the character to save
976
+ * @returns
977
+ * @example
978
+ * ```typescript
979
+ * export const liam = new CharacterBaseModel('liam', { name: 'Liam'});
980
+ * export const alice = new CharacterBaseModel('alice', { name: 'Alice'});
981
+ * saveCharacter([liam, alice]);
982
+ * ```
983
+ */
984
+ declare function saveCharacter<T extends CharacterBaseModel = CharacterBaseModel>(character: T | T[]): void;
985
+ /**
986
+ * is a function that returns the character by the id
987
+ * @param id is the id of the character
988
+ * @returns the character
989
+ * @example
990
+ * ```typescript
991
+ * const liam = getCharacterById('liam');
992
+ * ```
993
+ */
994
+ declare function getCharacterById<T extends CharacterBaseModel>(id: string): T | undefined;
995
+ /**
996
+ * is a function that returns all characters
997
+ * @returns all characters
998
+ * @example
999
+ * ```typescript
1000
+ * const allCharacters = getAllCharacters();
1001
+ * ```
1002
+ */
1003
+ declare function getAllCharacters<T extends CharacterBaseModel>(): T[];
1004
+
1005
+ /**
1006
+ * Is a decorator that register a event in the game.
1007
+ * Is a required decorator for use the event in the game.
1008
+ * Thanks to this decoration the game has the possibility of updating the events to the latest modification and saving the game.
1009
+ * @param name is th identifier of the event, by default is the name of the class
1010
+ * @returns
1011
+ */
1012
+ declare function eventDecorator(name?: EventIdType): (target: typeof CanvasEvent<any>) => void;
1013
+
1014
+ /**
1015
+ * Is a decorator that register a label in the game.
1016
+ * Is a required decorator for use the label in the game.
1017
+ * Thanks to this decoration the game has the possibility of updating the labels to the latest modification and saving the game.
1018
+ * @param name is th identifier of the label, by default is the name of the class
1019
+ * @returns
1020
+ */
1021
+ declare function labelDecorator(name?: LabelIdType): (target: typeof Label) => void;
1022
+
1023
+ /**
1024
+ * Is a decorator that register a ticker in the game.
1025
+ * Is a required decorator for use the ticker in the game.
1026
+ * Thanks to this decoration the game has the possibility of updating the tickers to the latest modification and saving the game.
1027
+ * @param name is th identifier of the label, by default is the name of the class
1028
+ * @returns
1029
+ */
1030
+ declare function tickerDecorator(name?: TickerIdType): (target: typeof TickerBase<any>) => void;
1031
+
999
1032
  /**
1000
1033
  * Set the dialogue to be shown in the game
1001
1034
  * @param text Text of the dialogue
@@ -1239,15 +1272,18 @@ declare class GameStepManager {
1239
1272
  private static increaseCurrentStepIndex;
1240
1273
  /**
1241
1274
  * Execute the next step and add it to the history.
1242
- * @returns
1275
+ * @returns StepLabelResultType or undefined.
1243
1276
  * @example
1244
1277
  * ```typescript
1245
1278
  * function nextOnClick() {
1246
1279
  * setLoading(true)
1247
1280
  * GameStepManager.runNextStep()
1248
- * .then(() => {
1281
+ * .then((result) => {
1249
1282
  * setUpdate((p) => p + 1)
1250
1283
  * setLoading(false)
1284
+ * if (result) {
1285
+ * // your code
1286
+ * }
1251
1287
  * })
1252
1288
  * .catch((e) => {
1253
1289
  * setLoading(false)
@@ -1256,34 +1292,56 @@ declare class GameStepManager {
1256
1292
  * }
1257
1293
  * ```
1258
1294
  */
1259
- static runNextStep(): Promise<void>;
1295
+ static runNextStep(): Promise<StepLabelResultType>;
1260
1296
  /**
1261
1297
  * Execute the current step and add it to the history.
1262
- * @returns
1298
+ * @returns StepLabelResultType or undefined.
1263
1299
  */
1264
1300
  private static runCurrentStep;
1265
1301
  /**
1266
1302
  * Execute the label and add it to the history.
1267
1303
  * Is a call function in Ren'Py.
1268
1304
  * @param label The label to execute.
1269
- * @returns
1305
+ * @returns StepLabelResultType or undefined.
1306
+ * @example
1307
+ * ```typescript
1308
+ * GameStepManager.callLabel(StartLabel).then((result) => {
1309
+ * if (result) {
1310
+ * // your code
1311
+ * }
1312
+ * })
1313
+ * ```
1270
1314
  * @example
1271
1315
  * ```typescript
1272
- * GameStepManager.callLabel(StartLabel)
1316
+ * // if you use it in a step label you should return the result.
1317
+ * return GameStepManager.callLabel(StartLabel).then((result) => {
1318
+ * return result
1319
+ * })
1273
1320
  * ```
1274
1321
  */
1275
- static callLabel(label: typeof Label | Label): Promise<void>;
1322
+ static callLabel(label: typeof Label | Label): Promise<StepLabelResultType>;
1276
1323
  /**
1277
1324
  * Execute the label, close all labels and add them to the history.
1278
1325
  * Is a jump function in Ren'Py.
1279
- * @param label
1280
- * @returns
1326
+ * @param label The label to execute.
1327
+ * @returns StepLabelResultType or undefined.
1281
1328
  * @example
1282
1329
  * ```typescript
1283
- * GameStepManager.jumpLabel(StartLabel)
1330
+ * GameStepManager.jumpLabel(StartLabel).then((result) => {
1331
+ * if (result) {
1332
+ * // your code
1333
+ * }
1334
+ * })
1335
+ * ```
1336
+ * @example
1337
+ * ```typescript
1338
+ * // if you use it in a step label you should return the result.
1339
+ * return GameStepManager.jumpLabel(StartLabel).then((result) => {
1340
+ * return result
1341
+ * })
1284
1342
  * ```
1285
1343
  */
1286
- static jumpLabel(label: typeof Label | Label): Promise<void>;
1344
+ static jumpLabel(label: typeof Label | Label): Promise<StepLabelResultType>;
1287
1345
  /**
1288
1346
  * Go back to the last step and add it to the history.
1289
1347
  * @param navigate The navigate function.
@@ -1621,4 +1679,4 @@ declare class GameWindowManager {
1621
1679
  static import(data: object): void;
1622
1680
  }
1623
1681
 
1624
- export { CanvasBase, CanvasContainer, CanvasEvent, type CanvasEventNamesType, CanvasImage, CanvasSprite, CanvasText, CharacterBaseModel, type CharacterBaseModelProps, ChoiceMenuOptionLabel, type ChoiceMenuOptionsType, DialogueBaseModel, type ExportedCanvas, type ExportedStep, type ExportedStorage, GameStepManager, GameStorageManager, GameWindowManager, type ICanvasBaseMemory, type ICanvasContainerMemory, type ICanvasImageMemory, type ICanvasSpriteBaseMemory, type ICanvasSpriteMemory, type ICanvasTextMemory as ICanvasTextTextMemory, type IClassWithArgsHistory, type IClassWithArgsHistoryForExport, type IDialogueHistory, type IHistoryStep, type IHistoryStepData, type IOpenedLabel, type ISaveData, type ITextureMemory, type ITicker, type ITickersSteps, Label, LabelRunModeEnum, Pause, type PauseType, PauseValueType, Repeat, type RepeatType, type StepLabelType, type StorageElementType, StoredClassModel, TickerBase, TickerFadeAlpha, type TickerProgrationType, TickerRotate, addImage, canvasElementDecorator, clearAllGameDatas, clearChoiceMenuOptions, clearDialogue, eventDecorator, getAllCharacters, getCharacterById, getChoiceMenuOptions, getDialogue, getDialogueHistory, getFlag, getSaveData, getSaveJson, getTexture, labelDecorator, loadSaveData, loadSaveJson, removeCanvasElement, saveCharacter, setChoiceMenuOptions, setDialogue, setFlag, showCanvasImages, showImageWithDissolveTransition, tickerDecorator };
1682
+ export { CanvasBase, CanvasContainer, CanvasEvent, type CanvasEventNamesType, CanvasImage, CanvasSprite, CanvasText, CharacterBaseModel, type CharacterBaseModelProps, ChoiceMenuOptionLabel, type ChoiceMenuOptionsType, DialogueBaseModel, type ExportedCanvas, type ExportedStep, type ExportedStorage, GameStepManager, GameStorageManager, GameWindowManager, type ICanvasBaseMemory, type ICanvasContainerMemory, type ICanvasImageMemory, type ICanvasSpriteBaseMemory, type ICanvasSpriteMemory, type ICanvasTextMemory as ICanvasTextTextMemory, type IClassWithArgsHistory, type IClassWithArgsHistoryForExport, type IDialogueHistory, type IHistoryStep, type IHistoryStepData, type IOpenedLabel, type ISaveData, type ITextureMemory, type ITicker, type ITickersSteps, Label, LabelRunModeEnum, Pause, type PauseType, PauseValueType, Repeat, type RepeatType, type StepLabelResultType, type StepLabelType, type StorageElementType, StoredClassModel, TickerBase, TickerFadeAlpha, type TickerFadeAlphaProps, type TickerProgrationType, TickerRotate, type TickerRotateProps, addImage, canvasElementDecorator, clearAllGameDatas, clearChoiceMenuOptions, clearDialogue, eventDecorator, getAllCharacters, getCharacterById, getChoiceMenuOptions, getDialogue, getDialogueHistory, getFlag, getSaveData, getSaveJson, getTexture, labelDecorator, loadSaveData, loadSaveJson, removeCanvasElement, saveCharacter, setChoiceMenuOptions, setDialogue, setFlag, showCanvasImages, showImageWithDissolveTransition, tickerDecorator };