@turnipxenon/pineapple 3.0.0-alpha.11 → 3.0.0-alpha.12

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.
@@ -4,8 +4,9 @@
4
4
  import type { DialogDetail } from "../../types/pineapple_fiber/DialogDetail";
5
5
  import { DialogState } from "../../types/pineapple_fiber/DialogState";
6
6
  import { DialogProcessor } from "./DialogProcessor";
7
+ import type { IDialogManager } from "./IDialogManager";
7
8
  export type OnSetDialogChoiceCallback = (newMessage: DialogDetail) => void;
8
- export declare class DialogManager {
9
+ export declare class DialogManager implements IDialogManager {
9
10
  dialogMessageMap: Map<string, DialogDetail>;
10
11
  currentDialogTree: DialogDetail[];
11
12
  fullCurrentMessage: string;
@@ -1,15 +1,2 @@
1
- import { DialogManager } from "./DialogManager";
2
- /**
3
- * strictly must be declared last! or you might receive a weird error that looks like:
4
- *
5
- * 2:04:21 AM [vite] Error when evaluating SSR module /src/lib/components/dialog_manager/DialogManagerStore.ts:
6
- * |- TypeError: Cannot read properties of undefined (reading '0')
7
- * at <instance_members_initializer> (/src/lib/components/dialog_manager/DialogManager.ts:38:67)
8
- * at new DialogManager (/src/lib/components/dialog_manager/DialogManager.ts:53:14)
9
- * at eval (/src/lib/components/dialog_manager/DialogManagerStore.ts:15:23)
10
- * at async instantiateModule (file:///C:/Users/Pumpkin/Projects/Web/pineapple/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:54360:9)
11
- *
12
- * what this means is that one member of dialogManager cannot be initialized. in our case, it was the
13
- * defaultDialogMessage not yet being initialized
14
- */
15
- export declare const dialogManager: DialogManager;
1
+ import type { IDialogManager } from "./IDialogManager";
2
+ export declare const getDialogManager: () => Promise<IDialogManager>;
@@ -1,4 +1,3 @@
1
- import { DialogManager } from "./DialogManager";
2
1
  /**
3
2
  * strictly must be declared last! or you might receive a weird error that looks like:
4
3
  *
@@ -12,4 +11,11 @@ import { DialogManager } from "./DialogManager";
12
11
  * what this means is that one member of dialogManager cannot be initialized. in our case, it was the
13
12
  * defaultDialogMessage not yet being initialized
14
13
  */
15
- export const dialogManager = new DialogManager();
14
+ let _dialogManager = undefined;
15
+ export const getDialogManager = async () => {
16
+ if (_dialogManager === undefined) {
17
+ const dm = await import('./DialogManager');
18
+ _dialogManager = new dm.DialogManager();
19
+ }
20
+ return _dialogManager;
21
+ };
@@ -0,0 +1,39 @@
1
+ import type { DialogDetail } from "../../types/pineapple_fiber/DialogDetail";
2
+ import { type Writable } from "svelte/store";
3
+ import { DialogState } from "../../types/pineapple_fiber/DialogState";
4
+ import { type Tweened } from "svelte/motion";
5
+ import { DialogProcessor } from "./DialogProcessor";
6
+ import type { OnSetDialogChoiceCallback } from "./DialogManager";
7
+ export interface IDialogManager {
8
+ dialogMessageMap: Map<string, DialogDetail>;
9
+ currentDialogTree: DialogDetail[];
10
+ fullCurrentMessage: string;
11
+ currentMessageMeta: DialogDetail;
12
+ currentMessage: Writable<string>;
13
+ currentIndex: number;
14
+ previousTimestamp: number;
15
+ isDoneTransition: boolean;
16
+ currentPortrait: Writable<unknown>;
17
+ portraitMap: Map<string, any>;
18
+ currentState: DialogState;
19
+ currentReadableState: Writable<DialogState>;
20
+ hidePercent: Tweened<number>;
21
+ skipNextActiveTime: number;
22
+ dialogProcessor: DialogProcessor;
23
+ _setDialogChoiceQueue: DialogDetail[];
24
+ _setDialogChoiceMutex: boolean;
25
+ onSetDialogListeners: OnSetDialogChoiceCallback[];
26
+ enableDialogueOverlayCache: boolean;
27
+ skipAnimation: () => void;
28
+ enableDialog: (shouldEnable: boolean) => void;
29
+ setDialogTree: (newDialogTree: DialogDetail[]) => void;
30
+ subscribeToSetDialogChoice: (callback: OnSetDialogChoiceCallback) => void;
31
+ unsubscribeToSetDialogChoice: (callback: OnSetDialogChoiceCallback) => void;
32
+ setDialogChoice: (newMessage: (DialogDetail | undefined)) => void;
33
+ _setDialogChoice: () => void;
34
+ setDialogToDefault: () => void;
35
+ update: (timestamp: number) => void;
36
+ enableDialogOverlay(enable: boolean): void;
37
+ toggleDialogOverlay(): void;
38
+ parseAndSetDialogTree(dialogYarn: string): Promise<DialogDetail[]>;
39
+ }
@@ -0,0 +1,4 @@
1
+ import {} from "svelte/store";
2
+ import { DialogState } from "../../types/pineapple_fiber/DialogState";
3
+ import {} from "svelte/motion";
4
+ import { DialogProcessor } from "./DialogProcessor";
@@ -2,7 +2,10 @@ import type { LineBehaviorNode } from "../../line_core/LineBehaviorNode";
2
2
  import type { LineNodeArguments } from "../../line_core/LineNodeArguments";
3
3
  import type { LineBehaviorResult } from "../../line_core/LineBehaviorResult";
4
4
  import { SetVariableNode } from "../SetVariableNode";
5
+ import type { IDialogManager } from "../../../../..";
5
6
  export declare class JumpCommand implements LineBehaviorNode {
6
7
  setVariableNode: SetVariableNode;
8
+ dialogManager: undefined | IDialogManager;
9
+ constructor();
7
10
  process(nodeArgs: LineNodeArguments): LineBehaviorResult;
8
11
  }
@@ -1,10 +1,22 @@
1
1
  import { BehaviorStatus } from "../../core/BehaviorStatus";
2
2
  import { SetVariableNode } from "../SetVariableNode";
3
3
  import { btreeUtils } from "../../core/BTreeUtils";
4
- import { dialogManager } from "../../../DialogMangerInit";
4
+ import { getDialogManager } from "../../../DialogMangerInit";
5
5
  export class JumpCommand {
6
6
  setVariableNode = new SetVariableNode();
7
+ dialogManager = undefined;
8
+ constructor() {
9
+ getDialogManager().then(dm => this.dialogManager = dm);
10
+ }
7
11
  process(nodeArgs) {
12
+ if (this.dialogManager === undefined) {
13
+ console.error('Dialog Manger not yet initialized');
14
+ return {
15
+ renderedLine: "",
16
+ nextState: nodeArgs.initState,
17
+ status: BehaviorStatus.Failure
18
+ };
19
+ }
8
20
  if (!nodeArgs.line.startsWith("<<jump")) {
9
21
  return {
10
22
  renderedLine: "",
@@ -23,10 +35,10 @@ export class JumpCommand {
23
35
  .slice("<<jump ".length, nodeArgs.line.length - ">>".length)
24
36
  .replace(/^\{/, "") // remove possible " at the start: https://stackoverflow.com/a/2182602
25
37
  .replace(/}$/, ""); // remove possible " at the end: https://stackoverflow.com/a/12249011;
26
- const dialogChoice = dialogManager.dialogMessageMap.get(btreeUtils.simplifyToken(choiceName));
38
+ const dialogChoice = this.dialogManager.dialogMessageMap.get(btreeUtils.simplifyToken(choiceName));
27
39
  if (dialogChoice !== undefined) {
28
40
  // force choice
29
- dialogManager.setDialogChoice(dialogChoice);
41
+ this.dialogManager.setDialogChoice(dialogChoice);
30
42
  }
31
43
  else {
32
44
  console.error(`Unknown jump node at line ${nodeArgs.lineIndex + 1}: ${choiceName} or ${btreeUtils.simplifyToken(choiceName)}`);
@@ -2,37 +2,46 @@
2
2
  import AresHappy from "../../assets/characters/ares/ares_happy.webp";
3
3
  import { onMount } from "svelte";
4
4
  import { DialogState } from "../../types/pineapple_fiber/DialogState";
5
- import { dialogManager } from "../dialog_manager/DialogMangerInit";
5
+ import { getDialogManager } from "../dialog_manager/DialogMangerInit";
6
+ import type { IDialogManager } from "../dialog_manager/IDialogManager";
6
7
 
7
8
  let currentMessage = $state("");
8
- dialogManager.currentMessage.subscribe((value) => {
9
- currentMessage = value;
10
- });
11
-
12
9
  let currentPortrait = $state(AresHappy);
13
- dialogManager.currentPortrait.subscribe((value) => {
14
- if (value) {
15
- currentPortrait = value;
16
- }
17
- });
18
10
 
19
11
  let hidePercent = $state(100);
20
12
  let isHidden = $state(true);
13
+ let dialogManager: IDialogManager | undefined = $state(undefined);
21
14
  onMount(() => {
22
- dialogManager.hidePercent.subscribe((value) => {
23
- hidePercent = value * 0.4;
24
- isHidden = false;
25
- });
15
+ getDialogManager()
16
+ .then(dm => {
17
+ dialogManager = dm;
18
+
19
+ dialogManager.currentMessage.subscribe((value) => {
20
+ currentMessage = value;
21
+ });
22
+
23
+ dialogManager.currentPortrait.subscribe((value) => {
24
+ if (value) {
25
+ currentPortrait = value;
26
+ }
27
+ });
28
+
29
+ dialogManager.hidePercent.subscribe((value) => {
30
+ hidePercent = value * 0.4;
31
+ isHidden = false;
32
+ });
33
+
34
+ dialogManager.currentReadableState.subscribe((value) => {
35
+ isHidden = value === DialogState.Invisible;
36
+ });
26
37
 
27
- dialogManager.currentReadableState.subscribe((value) => {
28
- isHidden = value === DialogState.Invisible;
29
- });
38
+ dialogManager.update(0);
39
+ });
30
40
 
31
- dialogManager.update(0);
32
41
  });
33
42
 
34
43
  const onDialogClick = () => {
35
- dialogManager.skipAnimation();
44
+ dialogManager?.skipAnimation();
36
45
  };
37
46
 
38
47
  </script>
@@ -89,9 +98,9 @@
89
98
  }
90
99
 
91
100
  .dialog-name {
92
- padding-top: 2rem;
93
- padding-left: 4rem;
94
- padding-right: 4rem;
101
+ padding-top: 2rem;
102
+ padding-left: 4rem;
103
+ padding-right: 4rem;
95
104
  position: fixed;
96
105
  }
97
106
 
@@ -20,7 +20,7 @@
20
20
  import Toast from "./toast/Toast.svelte";
21
21
  import DialogOverlay from "../dialog_overlay/DialogOverlay.svelte";
22
22
  import { fade } from "svelte/transition";
23
- import { dialogManager } from "../dialog_manager/DialogMangerInit";
23
+ import { getDialogManager } from "../dialog_manager/DialogMangerInit";
24
24
 
25
25
  interface Props {
26
26
  showDialogByDefault?: boolean;
@@ -77,7 +77,7 @@
77
77
 
78
78
  <!--todo: turn off hidden when it's time-->
79
79
  <button class="fab" onclick={()=>{
80
- dialogManager.toggleDialogOverlay()
80
+ getDialogManager().then(dm => dm.toggleDialogOverlay());
81
81
  }}>
82
82
  {#if (enableDialogueOverlayValue)}
83
83
  <img class="turnip-icon" src={CloseIcon} alt="interactive floating action button represented as a turnip">
package/dist/index.d.ts CHANGED
@@ -11,4 +11,5 @@ export * from "./types/pineapple_fiber/DialogDetail";
11
11
  export * from "./util/util";
12
12
  export * from "./api/index";
13
13
  export * from "./template/seaweed/index";
14
- export { dialogManager } from "./components/dialog_manager/DialogMangerInit";
14
+ export type { IDialogManager } from "./components/dialog_manager/IDialogManager";
15
+ export { getDialogManager } from "./components/dialog_manager/DialogMangerInit";
package/dist/index.js CHANGED
@@ -12,4 +12,4 @@ export * from "./types/pineapple_fiber/DialogDetail";
12
12
  export * from "./util/util";
13
13
  export * from "./api/index";
14
14
  export * from "./template/seaweed/index";
15
- export { dialogManager } from "./components/dialog_manager/DialogMangerInit";
15
+ export { getDialogManager } from "./components/dialog_manager/DialogMangerInit";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turnipxenon/pineapple",
3
3
  "description": "personal package for base styling for other personal projects",
4
- "version": "3.0.0-alpha.11",
4
+ "version": "3.0.0-alpha.12",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build && yarn package",
@@ -21,7 +21,6 @@
21
21
  "@eslint/compat": "^1.2.5",
22
22
  "@eslint/js": "^9.18.0",
23
23
  "@sveltejs/adapter-auto": "^4.0.0",
24
- "@sveltejs/kit": "^2.5.27",
25
24
  "@sveltejs/package": "^2.3.7",
26
25
  "@sveltejs/vite-plugin-svelte": "^4.0.0",
27
26
  "eslint": "^9.18.0",
@@ -44,6 +43,7 @@
44
43
  "@prisma/client": "^5.12.1",
45
44
  "@skeletonlabs/skeleton": "^3.1.0",
46
45
  "@skeletonlabs/skeleton-svelte": "^1.0.0",
46
+ "@sveltejs/kit": "^2.5.27",
47
47
  "@sveltejs/vite-plugin-svelte": "^4.0.0",
48
48
  "@tailwindcss/vite": "^4.0.14",
49
49
  "@types/htmlparser2": "^3.10.7",