@turnipxenon/pineapple 3.1.0-alpha.5 → 3.1.0-alpha.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.
@@ -16,7 +16,7 @@ export declare class DialogManager implements IDialogManager {
16
16
  previousTimestamp: number;
17
17
  isDoneTransition: boolean;
18
18
  currentPortrait: import("svelte/store").Writable<string>;
19
- portraitMap: Map<string, any>;
19
+ portraitMap: Map<string, string>;
20
20
  currentState: DialogState;
21
21
  currentReadableState: import("svelte/store").Writable<DialogState>;
22
22
  hidePercent: import("svelte/motion").Tweened<number>;
@@ -80,3 +80,4 @@ export declare class DialogManager implements IDialogManager {
80
80
  toggleDialogOverlay(): void;
81
81
  parseAndSetDialogTree(dialogYarn: string): Promise<DialogDetail[]>;
82
82
  }
83
+ export declare const dialogManager: DialogManager;
@@ -37,13 +37,14 @@ export class DialogManager {
37
37
  easing: backOut
38
38
  }); // 100 = 100%
39
39
  skipNextActiveTime = 0;
40
- dialogProcessor = new DialogProcessor();
40
+ dialogProcessor;
41
41
  // for queueing actions
42
42
  _setDialogChoiceQueue = [];
43
43
  _setDialogChoiceMutex = false;
44
44
  onSetDialogListeners = [];
45
45
  enableDialogueOverlayCache = false;
46
46
  constructor() {
47
+ this.dialogProcessor = new DialogProcessor(this);
47
48
  enableDialogueOverlay.subscribe((value) => {
48
49
  // todo: investigate why we cant put setDialogDefault inside the then clause
49
50
  // ISSUE #82 https://github.com/TurnipXenon/pineapple/issues/82
@@ -162,7 +163,7 @@ export class DialogManager {
162
163
  // set the portrait
163
164
  let portraitValue = AresHappy;
164
165
  if (this.currentMessageMeta.portraitType) {
165
- portraitValue = this.portraitMap.get(this.currentMessageMeta.portraitType);
166
+ portraitValue = this.portraitMap.get(this.currentMessageMeta.portraitType ?? AresHappy);
166
167
  }
167
168
  if (portraitValue) {
168
169
  this.currentPortrait.update(() => portraitValue);
@@ -212,7 +213,7 @@ export class DialogManager {
212
213
  if (!this.isDoneTransition && this.currentIndex > this.fullCurrentMessage.length) {
213
214
  const elementList = document.getElementsByClassName("dialog-choice");
214
215
  for (const el of elementList) {
215
- el.addEventListener("click", (event) => {
216
+ el.addEventListener("click", () => {
216
217
  // todo: make more robust; for now we're assuming first class is our choice
217
218
  const choice = el.classList[0].split("-")[1];
218
219
  this.setDialogChoice(this.dialogMessageMap.get(choice));
@@ -261,3 +262,4 @@ export class DialogManager {
261
262
  });
262
263
  }
263
264
  }
265
+ export const dialogManager = new DialogManager();
@@ -1,10 +1,12 @@
1
1
  import type { DialogDetail } from "../../types/pineapple_fiber/DialogDetail";
2
- import { LineSelectorNode } from "./behavior_tree/line_core/LineSelectorNode";
2
+ import type { IDialogManager } from "../..";
3
3
  /**
4
4
  * DialogProcessor processes dialogs
5
5
  */
6
6
  export declare class DialogProcessor {
7
- processingTree: LineSelectorNode;
7
+ private readonly dialogManager;
8
+ private processingTree;
9
+ constructor(dialogManager: IDialogManager);
8
10
  /**
9
11
  * process the dialog line by line and return a presentable string
10
12
  * @param dialogDetail
@@ -17,24 +17,29 @@ import { UnvisitCommand } from "./behavior_tree/line_processors/commands/Unvisit
17
17
  * DialogProcessor processes dialogs
18
18
  */
19
19
  export class DialogProcessor {
20
- processingTree = new LineSelectorNode([
21
- /*region comment based formats*/
22
- new IgnoreJumpNode(), // must be prioritized above line comment node
23
- new LineCommentNode(),
24
- /*endregion commend based formats*/
25
- new EndIfNode(),
26
- new ElseIfNode(),
27
- new ElseNode(),
28
- new IfNode(),
29
- new IgnoreGuardNode(),
30
- /*region commands*/
31
- new SetVariableNode(),
32
- new DeclareCommand(),
33
- new JumpCommand(),
34
- new UnvisitCommand(),
35
- /*endregion commands*/
36
- new NormalLineProcessorNode()
37
- ]);
20
+ dialogManager;
21
+ processingTree;
22
+ constructor(dialogManager) {
23
+ this.dialogManager = dialogManager;
24
+ this.processingTree = new LineSelectorNode([
25
+ /*region comment based formats*/
26
+ new IgnoreJumpNode(), // must be prioritized above line comment node
27
+ new LineCommentNode(),
28
+ /*endregion commend based formats*/
29
+ new EndIfNode(),
30
+ new ElseIfNode(),
31
+ new ElseNode(),
32
+ new IfNode(),
33
+ new IgnoreGuardNode(),
34
+ /*region commands*/
35
+ new SetVariableNode(),
36
+ new DeclareCommand(),
37
+ new JumpCommand(this.dialogManager),
38
+ new UnvisitCommand(),
39
+ /*endregion commands*/
40
+ new NormalLineProcessorNode()
41
+ ]);
42
+ }
38
43
  /**
39
44
  * process the dialog line by line and return a presentable string
40
45
  * @param dialogDetail
@@ -7,7 +7,6 @@ import type { OnSetDialogChoiceCallback } from "./DialogManager";
7
7
  export interface IDialogManager {
8
8
  dialogMessageMap: Map<string, DialogDetail>;
9
9
  currentDialogTree: DialogDetail[];
10
- fullCurrentMessage: string;
11
10
  currentMessageMeta: DialogDetail;
12
11
  currentMessage: Writable<string>;
13
12
  currentIndex: number;
@@ -5,7 +5,7 @@ import { SetVariableNode } from "../SetVariableNode";
5
5
  import type { IDialogManager } from "../../../IDialogManager";
6
6
  export declare class JumpCommand implements LineBehaviorNode {
7
7
  setVariableNode: SetVariableNode;
8
- dialogManager: undefined | IDialogManager;
9
- constructor();
8
+ dialogManager: IDialogManager;
9
+ constructor(dialogManager: IDialogManager);
10
10
  process(nodeArgs: LineNodeArguments): LineBehaviorResult;
11
11
  }
@@ -1,16 +1,15 @@
1
1
  import { BehaviorStatus } from "../../core/BehaviorStatus";
2
2
  import { SetVariableNode } from "../SetVariableNode";
3
3
  import { btreeUtils } from "../../core/BTreeUtils";
4
- import { getDialogManager } from "../../../DialogMangerInit";
5
4
  export class JumpCommand {
6
5
  setVariableNode = new SetVariableNode();
7
- dialogManager = undefined;
8
- constructor() {
9
- getDialogManager().then(dm => this.dialogManager = dm);
6
+ dialogManager;
7
+ constructor(dialogManager) {
8
+ this.dialogManager = dialogManager;
10
9
  }
11
10
  process(nodeArgs) {
12
11
  if (this.dialogManager === undefined) {
13
- console.warn('Dialog Manger not yet initialized');
12
+ console.warn("Dialog Manger not yet initialized");
14
13
  return {
15
14
  renderedLine: "",
16
15
  nextState: nodeArgs.initState,
@@ -2,8 +2,7 @@
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 { getDialogManager } from "../dialog_manager/DialogMangerInit";
6
- import type { IDialogManager } from "../dialog_manager/IDialogManager";
5
+ import { dialogManager } from "../dialog_manager/DialogManager";
7
6
  import PinyaCard from "../../ui/elements/PinyaCard/PinyaCard.svelte";
8
7
  import { appState } from "../../ui/templates/index";
9
8
  import CloseIcon from "../../assets/icons/close.svg";
@@ -18,34 +17,31 @@
18
17
 
19
18
  let hidePercent = $state(100);
20
19
  let isHidden = $state(true);
21
- let dialogManager: IDialogManager | undefined = $state(undefined);
22
20
  onMount(() => {
23
- getDialogManager()
24
- .then(dm => {
25
- dialogManager = dm;
26
21
 
27
- dialogManager.currentMessage.subscribe((value) => {
28
- currentMessage = value;
29
- });
22
+ dialogManager.currentMessage.subscribe((value) => {
23
+ currentMessage = value;
24
+ });
30
25
 
31
- dialogManager.currentPortrait.subscribe((value) => {
32
- if (value) {
33
- currentPortrait = value;
34
- }
35
- });
26
+ dialogManager.currentPortrait.subscribe((value) => {
27
+ console.log("sub value", value);
28
+ if (value) {
29
+ currentPortrait = value;
30
+ }
31
+ });
36
32
 
37
- dialogManager.hidePercent.subscribe((value) => {
38
- hidePercent = value * 0.4;
39
- isHidden = false;
40
- });
33
+ dialogManager.hidePercent.subscribe((value) => {
34
+ hidePercent = value * 0.4;
35
+ isHidden = false;
36
+ });
41
37
 
42
- dialogManager.currentReadableState.subscribe((value) => {
43
- isHidden = value === DialogState.Invisible;
44
- });
38
+ dialogManager.currentReadableState.subscribe((value) => {
39
+ isHidden = value === DialogState.Invisible;
40
+ });
45
41
 
46
- dialogManager.update(0);
47
- isMounted = true;
48
- });
42
+ console.log("CAlling update");
43
+ dialogManager.update(0);
44
+ isMounted = true;
49
45
 
50
46
  });
51
47
 
@@ -103,9 +99,8 @@
103
99
  <div class="fab-container" in:slide>
104
100
  <PinyaButton
105
101
  classes="fab"
106
- onclick={()=>{
107
- getDialogManager().then(dm => dm.toggleDialogOverlay());
108
- }}>
102
+ onclick={()=>{dialogManager.toggleDialogOverlay();}}
103
+ >
109
104
  {#if (enableDialogueOverlayValue)}
110
105
  <img class="turnip-icon" src={CloseIcon} alt="interactive floating action button represented as a turnip">
111
106
  {:else }
@@ -224,7 +219,7 @@
224
219
 
225
220
  .fab-container {
226
221
  position: fixed;
227
- bottom: 0;
222
+ bottom: 0;
228
223
  }
229
224
 
230
225
  .fab-container:dir(ltr) {
@@ -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 { getDialogManager } from "../dialog_manager/DialogMangerInit";
23
+ import { dialogManager } from "../dialog_manager/DialogManager";
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
- getDialogManager().then(dm => dm.toggleDialogOverlay());
80
+ dialogManager.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,4 @@ export * from "./types/pineapple_fiber/DialogDetail";
11
11
  export * from "./util/util";
12
12
  export * from "./api/index";
13
13
  export type { IDialogManager } from "./components/dialog_manager/IDialogManager";
14
- export { getDialogManager } from "./components/dialog_manager/DialogMangerInit";
14
+ export { dialogManager } from "./components/dialog_manager/DialogManager";
package/dist/index.js CHANGED
@@ -11,4 +11,4 @@ export * from "./types/pineapple_fiber/PortraitType";
11
11
  export * from "./types/pineapple_fiber/DialogDetail";
12
12
  export * from "./util/util";
13
13
  export * from "./api/index";
14
- export { getDialogManager } from "./components/dialog_manager/DialogMangerInit";
14
+ export { dialogManager } from "./components/dialog_manager/DialogManager";
@@ -44,7 +44,7 @@ const pineappleWeaverRun = () => {
44
44
  const template = `// this file was generated by PineappleWeaver.ts
45
45
  // do not edit!
46
46
 
47
- import { type DialogDetail, getDialogManager, PortraitType } from "@turnipxenon/pineapple";
47
+ import { type DialogDetail, dialogManager, PortraitType } from "@turnipxenon/pineapple";
48
48
 
49
49
  class _${fileName}Yarn {
50
50
  dialogList: DialogDetail[] = [
@@ -53,7 +53,7 @@ ${dialogDetailListToString(dialogDetailList)}
53
53
 
54
54
  /* Remember to call DialogManager.subscribeToSetDialogChoice before calling this in Svelte */
55
55
  setDialogTree = () => {
56
- getDialogManager().then((dm) => dm?.setDialogTree(this.dialogList));
56
+ dialogManager.setDialogTree(this.dialogList);
57
57
  };
58
58
  }
59
59
 
@@ -22,13 +22,15 @@ html {
22
22
  height: calc(var(--dialog-box-height) + 4em);
23
23
  }
24
24
 
25
- a.dialog-choice {
25
+ .dialog-box a {
26
26
  font-size: inherit;
27
+ }
28
+
29
+ a.dialog-choice {
27
30
  cursor: url("$pkg/assets/icons/chat-cursor.svg"), auto;
28
31
  }
29
32
 
30
33
  a.external-link {
31
- font-size: inherit;
32
34
  cursor: url("$pkg/assets/icons/external-link.svg"), auto;
33
35
  }
34
36
 
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.1.0-alpha.5",
4
+ "version": "3.1.0-alpha.6",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build && yarn package",
@@ -22,13 +22,15 @@ html {
22
22
  height: calc(var(--dialog-box-height) + 4em);
23
23
  }
24
24
 
25
- a.dialog-choice {
25
+ .dialog-box a {
26
26
  font-size: inherit;
27
+ }
28
+
29
+ a.dialog-choice {
27
30
  cursor: url("$pkg/assets/icons/chat-cursor.svg"), auto;
28
31
  }
29
32
 
30
33
  a.external-link {
31
- font-size: inherit;
32
34
  cursor: url("$pkg/assets/icons/external-link.svg"), auto;
33
35
  }
34
36
 
@@ -1,2 +0,0 @@
1
- import type { IDialogManager } from "./IDialogManager";
2
- export declare const getDialogManager: () => Promise<IDialogManager>;
@@ -1,21 +0,0 @@
1
- /**
2
- * strictly must be declared last! or you might receive a weird error that looks like:
3
- *
4
- * 2:04:21 AM [vite] Error when evaluating SSR module /src/lib/components/dialog_manager/DialogManagerStore.ts:
5
- * |- TypeError: Cannot read properties of undefined (reading '0')
6
- * at <instance_members_initializer> (/src/lib/components/dialog_manager/DialogManager.ts:38:67)
7
- * at new DialogManager (/src/lib/components/dialog_manager/DialogManager.ts:53:14)
8
- * at eval (/src/lib/components/dialog_manager/DialogManagerStore.ts:15:23)
9
- * at async instantiateModule (file:///C:/Users/Pumpkin/Projects/Web/pineapple/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:54360:9)
10
- *
11
- * what this means is that one member of dialogManager cannot be initialized. in our case, it was the
12
- * defaultDialogMessage not yet being initialized
13
- */
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
- };
@@ -1 +0,0 @@
1
- export * from "./DialogMangerInit";
@@ -1 +0,0 @@
1
- export * from "./DialogMangerInit";