@turnipxenon/pineapple 5.0.0-alpha.2 → 5.0.0-alpha.20

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.
Files changed (189) hide show
  1. package/dist/api/GetLatestBlogs.js +13 -4
  2. package/dist/components/dialog_manager/DialogManager.js +226 -215
  3. package/dist/components/dialog_manager/DialogProcessor.js +24 -26
  4. package/dist/components/dialog_manager/DialogUtils.js +6 -4
  5. package/dist/components/dialog_manager/behavior_tree/core/BTreeUtils.js +32 -30
  6. package/dist/components/dialog_manager/behavior_tree/core/SelectorNode.js +0 -1
  7. package/dist/components/dialog_manager/behavior_tree/expression/ExpressionEvaluator.js +188 -186
  8. package/dist/components/dialog_manager/behavior_tree/expression/ExpressionSelectorNode.js +8 -8
  9. package/dist/components/dialog_manager/behavior_tree/expression/commands/CommandMap.js +7 -7
  10. package/dist/components/dialog_manager/behavior_tree/expression/commands/RandomRangeCommand.js +20 -17
  11. package/dist/components/dialog_manager/behavior_tree/expression/commands/VisitedCommand.js +20 -17
  12. package/dist/components/dialog_manager/behavior_tree/expression/commands/VisitedCountCommand.js +18 -15
  13. package/dist/components/dialog_manager/behavior_tree/expression/operators/AndOperator.js +14 -11
  14. package/dist/components/dialog_manager/behavior_tree/expression/operators/EqualityOperator.js +14 -11
  15. package/dist/components/dialog_manager/behavior_tree/expression/operators/GreaterThanEqualOperator.js +12 -9
  16. package/dist/components/dialog_manager/behavior_tree/expression/operators/GreaterThanOperator.js +12 -9
  17. package/dist/components/dialog_manager/behavior_tree/expression/operators/InequalityOperator.js +12 -9
  18. package/dist/components/dialog_manager/behavior_tree/expression/operators/LessThanEqualOperator.js +12 -9
  19. package/dist/components/dialog_manager/behavior_tree/expression/operators/LessThanOperator.js +12 -9
  20. package/dist/components/dialog_manager/behavior_tree/expression/operators/NegationOperator.js +12 -9
  21. package/dist/components/dialog_manager/behavior_tree/expression/operators/OperatorMap.js +7 -7
  22. package/dist/components/dialog_manager/behavior_tree/expression/operators/OrOperator.js +12 -9
  23. package/dist/components/dialog_manager/behavior_tree/expression/operators/XorOperator.js +16 -13
  24. package/dist/components/dialog_manager/behavior_tree/expression/operators/arithmetic/DivisionOperator.js +14 -11
  25. package/dist/components/dialog_manager/behavior_tree/expression/operators/arithmetic/MinusOperator.js +14 -11
  26. package/dist/components/dialog_manager/behavior_tree/expression/operators/arithmetic/MultiplicationOperator.js +12 -9
  27. package/dist/components/dialog_manager/behavior_tree/expression/operators/arithmetic/PlusOperator.js +14 -11
  28. package/dist/components/dialog_manager/behavior_tree/expression/operators/arithmetic/RemainderDivisionOperator.js +14 -11
  29. package/dist/components/dialog_manager/behavior_tree/line_core/LineSelectorNode.js +7 -7
  30. package/dist/components/dialog_manager/behavior_tree/line_processors/BehaviorState.js +4 -2
  31. package/dist/components/dialog_manager/behavior_tree/line_processors/commands/DeclareCommand.js +3 -1
  32. package/dist/components/dialog_manager/behavior_tree/line_processors/commands/JumpCommand.js +1 -2
  33. package/dist/components/reveal-info/RevealInfo.svelte.d.ts +12 -14
  34. package/dist/components/reveal-info/RevealInfo.svelte.d.ts.map +1 -1
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -0
  38. package/dist/modules/overrideable_meta/OverridableMeta.svelte.d.ts +10 -14
  39. package/dist/modules/overrideable_meta/OverridableMeta.svelte.d.ts.map +1 -1
  40. package/dist/modules/parsnip/ParsnipBlockChildren.svelte.d.ts +7 -13
  41. package/dist/modules/parsnip/ParsnipBlockChildren.svelte.d.ts.map +1 -1
  42. package/dist/modules/parsnip/ParsnipEmbedWikilink.svelte.d.ts +13 -12
  43. package/dist/modules/parsnip/ParsnipEmbedWikilink.svelte.d.ts.map +1 -1
  44. package/dist/modules/parsnip/ParsnipHeading.svelte.d.ts +6 -13
  45. package/dist/modules/parsnip/ParsnipHeading.svelte.d.ts.map +1 -1
  46. package/dist/modules/parsnip/ParsnipList.svelte.d.ts +6 -13
  47. package/dist/modules/parsnip/ParsnipList.svelte.d.ts.map +1 -1
  48. package/dist/modules/parsnip/ParsnipParagraph.svelte.d.ts +6 -13
  49. package/dist/modules/parsnip/ParsnipParagraph.svelte.d.ts.map +1 -1
  50. package/dist/modules/parsnip/ParsnipPhrasingChildren.svelte.d.ts +6 -13
  51. package/dist/modules/parsnip/ParsnipPhrasingChildren.svelte.d.ts.map +1 -1
  52. package/dist/modules/parsnip/ParsnipWikilink.svelte.d.ts +14 -12
  53. package/dist/modules/parsnip/ParsnipWikilink.svelte.d.ts.map +1 -1
  54. package/dist/modules/parsnip/route-util/ParsnipBlog.svelte.d.ts +6 -13
  55. package/dist/modules/parsnip/route-util/ParsnipBlog.svelte.d.ts.map +1 -1
  56. package/dist/modules/parsnip/route-util/getSlugEntries.js +13 -7
  57. package/dist/modules/parsnip/route-util/menuPageServerLoad.js +13 -7
  58. package/dist/modules/parsnip/route-util/slugPageServerLoad.js +15 -9
  59. package/dist/remoteIndex.remote.d.ts +2 -0
  60. package/dist/remoteIndex.remote.d.ts.map +1 -0
  61. package/dist/remoteIndex.remote.js +2 -0
  62. package/dist/scripts/pineapple_fiber/PineappleFiberParser.js +14 -5
  63. package/dist/scripts/pineapple_fiber/PineappleWeaver.js +12 -3
  64. package/dist/styles/app.css +0 -82
  65. package/dist/styles/tailwind.css +0 -12
  66. package/dist/styles/turnip-theme.css +1 -0
  67. package/dist/types/BlogBlurbMeta.js +11 -9
  68. package/dist/types/api/CreateUrl.js +4 -3
  69. package/dist/ui/components/FourPartCard.svelte +5 -0
  70. package/dist/ui/components/FourPartCard.svelte.d.ts +9 -13
  71. package/dist/ui/components/FourPartCard.svelte.d.ts.map +1 -1
  72. package/dist/ui/components/MeltToaster/MeltToaster.svelte +64 -61
  73. package/dist/ui/components/MeltToaster/MeltToaster.svelte.d.ts +3 -14
  74. package/dist/ui/components/MeltToaster/MeltToaster.svelte.d.ts.map +1 -1
  75. package/dist/ui/components/ModalBase.svelte.d.ts +9 -13
  76. package/dist/ui/components/ModalBase.svelte.d.ts.map +1 -1
  77. package/dist/ui/components/NestedNavigation.svelte +105 -106
  78. package/dist/ui/components/NestedNavigation.svelte.d.ts +11 -14
  79. package/dist/ui/components/NestedNavigation.svelte.d.ts.map +1 -1
  80. package/dist/ui/components/SocialSection.svelte.d.ts +10 -13
  81. package/dist/ui/components/SocialSection.svelte.d.ts.map +1 -1
  82. package/dist/ui/components/accordion/PinyaAccordion.svelte.d.ts +4 -14
  83. package/dist/ui/components/accordion/PinyaAccordion.svelte.d.ts.map +1 -1
  84. package/dist/ui/components/accordion/PinyaAccordionItem.svelte.d.ts +4 -14
  85. package/dist/ui/components/accordion/PinyaAccordionItem.svelte.d.ts.map +1 -1
  86. package/dist/ui/components/randomized-background/RandomizedBackground.svelte.d.ts +5 -13
  87. package/dist/ui/components/randomized-background/RandomizedBackground.svelte.d.ts.map +1 -1
  88. package/dist/ui/components/randomized-background/RandomizedImage.svelte.d.ts +6 -13
  89. package/dist/ui/components/randomized-background/RandomizedImage.svelte.d.ts.map +1 -1
  90. package/dist/ui/components/randomized-background/getSocialSection.remote.js +11 -2
  91. package/dist/ui/elements/CodeBlock/CodeBlock.svelte +161 -18
  92. package/dist/ui/elements/CodeBlock/CodeBlock.svelte.d.ts +4 -14
  93. package/dist/ui/elements/CodeBlock/CodeBlock.svelte.d.ts.map +1 -1
  94. package/dist/ui/elements/ElementVisibilityDetector.svelte.d.ts +7 -13
  95. package/dist/ui/elements/ElementVisibilityDetector.svelte.d.ts.map +1 -1
  96. package/dist/ui/elements/ImageIcon.svelte.d.ts +6 -14
  97. package/dist/ui/elements/ImageIcon.svelte.d.ts.map +1 -1
  98. package/dist/ui/elements/PineappleSwitch.svelte.d.ts +9 -13
  99. package/dist/ui/elements/PineappleSwitch.svelte.d.ts.map +1 -1
  100. package/dist/ui/elements/PinyaAnchorButton/PinyaAnchorButton.svelte.d.ts +4 -14
  101. package/dist/ui/elements/PinyaAnchorButton/PinyaAnchorButton.svelte.d.ts.map +1 -1
  102. package/dist/ui/elements/PinyaButton/PinyaButton.svelte.d.ts +4 -14
  103. package/dist/ui/elements/PinyaButton/PinyaButton.svelte.d.ts.map +1 -1
  104. package/dist/ui/elements/PinyaButtonCommon/createButtonClass.js +4 -4
  105. package/dist/ui/elements/PinyaCard/PinyaCard.svelte.d.ts +4 -14
  106. package/dist/ui/elements/PinyaCard/PinyaCard.svelte.d.ts.map +1 -1
  107. package/dist/ui/elements/Placeholder.svelte.d.ts +8 -14
  108. package/dist/ui/elements/Placeholder.svelte.d.ts.map +1 -1
  109. package/dist/ui/elements/TextChip/TextChip.svelte.d.ts +4 -14
  110. package/dist/ui/elements/TextChip/TextChip.svelte.d.ts.map +1 -1
  111. package/dist/ui/elements/TextLink.svelte.d.ts +4 -14
  112. package/dist/ui/elements/TextLink.svelte.d.ts.map +1 -1
  113. package/dist/ui/elements/pinya-combobox/PinyaCombobox.svelte +4 -4
  114. package/dist/ui/elements/pinya-combobox/PinyaCombobox.svelte.d.ts +23 -12
  115. package/dist/ui/elements/pinya-combobox/PinyaCombobox.svelte.d.ts.map +1 -1
  116. package/dist/ui/modules/NavigationMenu/NavigationControl.svelte.d.ts +7 -13
  117. package/dist/ui/modules/NavigationMenu/NavigationControl.svelte.d.ts.map +1 -1
  118. package/dist/ui/modules/NavigationMenu/NavigationMenu.svelte.d.ts +21 -13
  119. package/dist/ui/modules/NavigationMenu/NavigationMenu.svelte.d.ts.map +1 -1
  120. package/dist/ui/modules/NavigationMenu/PageMeta.js +10 -7
  121. package/dist/ui/modules/modals/general-settings/GeneralSettingsModal.svelte.d.ts +4 -14
  122. package/dist/ui/modules/modals/general-settings/GeneralSettingsModal.svelte.d.ts.map +1 -1
  123. package/dist/ui/modules/modals/general-settings/LanguagePicker.svelte.d.ts +3 -14
  124. package/dist/ui/modules/modals/general-settings/LanguagePicker.svelte.d.ts.map +1 -1
  125. package/dist/ui/modules/modals/general-settings/NavigationModal.svelte +1 -5
  126. package/dist/ui/modules/modals/general-settings/NavigationModal.svelte.d.ts +4 -14
  127. package/dist/ui/modules/modals/general-settings/NavigationModal.svelte.d.ts.map +1 -1
  128. package/dist/ui/modules/projects/Hepcat.svelte.d.ts +16 -11
  129. package/dist/ui/modules/projects/Hepcat.svelte.d.ts.map +1 -1
  130. package/dist/ui/modules/projects/Pengi.svelte.d.ts +16 -11
  131. package/dist/ui/modules/projects/Pengi.svelte.d.ts.map +1 -1
  132. package/dist/ui/modules/projects/Soulwork.svelte.d.ts +16 -11
  133. package/dist/ui/modules/projects/Soulwork.svelte.d.ts.map +1 -1
  134. package/dist/ui/modules/projects/ThisWebpage.svelte +9 -0
  135. package/dist/ui/modules/projects/ThisWebpage.svelte.d.ts +16 -11
  136. package/dist/ui/modules/projects/ThisWebpage.svelte.d.ts.map +1 -1
  137. package/dist/ui/modules/universal-overlay/DialogPanel.svelte.d.ts +3 -14
  138. package/dist/ui/modules/universal-overlay/DialogPanel.svelte.d.ts.map +1 -1
  139. package/dist/ui/modules/universal-overlay/SettingsPanel.svelte +30 -26
  140. package/dist/ui/modules/universal-overlay/SettingsPanel.svelte.d.ts +3 -14
  141. package/dist/ui/modules/universal-overlay/SettingsPanel.svelte.d.ts.map +1 -1
  142. package/dist/ui/modules/universal-overlay/UniversalOverlay.svelte +7 -2
  143. package/dist/ui/modules/universal-overlay/UniversalOverlay.svelte.d.ts +3 -14
  144. package/dist/ui/modules/universal-overlay/UniversalOverlay.svelte.d.ts.map +1 -1
  145. package/dist/ui/templates/PinyaPageLayout/PinyaPageLayout.svelte +33 -22
  146. package/dist/ui/templates/PinyaPageLayout/PinyaPageLayout.svelte.d.ts +9 -13
  147. package/dist/ui/templates/PinyaPageLayout/PinyaPageLayout.svelte.d.ts.map +1 -1
  148. package/dist/ui/templates/PinyaPageLayout/pinyaPageLayoutRunes.svelte.d.ts.map +1 -1
  149. package/dist/ui/templates/SeaweedLayout/ChumBucket.svelte.d.ts +3 -14
  150. package/dist/ui/templates/SeaweedLayout/ChumBucket.svelte.d.ts.map +1 -1
  151. package/dist/ui/templates/SeaweedLayout/CreateUrlForm.svelte.d.ts +5 -13
  152. package/dist/ui/templates/SeaweedLayout/CreateUrlForm.svelte.d.ts.map +1 -1
  153. package/dist/ui/templates/SeaweedLayout/EntryGroup.svelte.d.ts +4 -14
  154. package/dist/ui/templates/SeaweedLayout/EntryGroup.svelte.d.ts.map +1 -1
  155. package/dist/ui/templates/SeaweedLayout/EntryOrderConfig.svelte.d.ts +8 -13
  156. package/dist/ui/templates/SeaweedLayout/EntryOrderConfig.svelte.d.ts.map +1 -1
  157. package/dist/ui/templates/SeaweedLayout/ProjectGroupConfig.svelte.d.ts +10 -13
  158. package/dist/ui/templates/SeaweedLayout/ProjectGroupConfig.svelte.d.ts.map +1 -1
  159. package/dist/ui/templates/SeaweedLayout/SeaweedLayout.svelte.d.ts +4 -14
  160. package/dist/ui/templates/SeaweedLayout/SeaweedLayout.svelte.d.ts.map +1 -1
  161. package/dist/ui/templates/blog_template/BlogTemplate.svelte +6 -3
  162. package/dist/ui/templates/blog_template/BlogTemplate.svelte.d.ts +11 -13
  163. package/dist/ui/templates/blog_template/BlogTemplate.svelte.d.ts.map +1 -1
  164. package/dist/ui/templates/blog_template/BlogTemplateInner.svelte.d.ts +7 -13
  165. package/dist/ui/templates/blog_template/BlogTemplateInner.svelte.d.ts.map +1 -1
  166. package/dist/ui/templates/confirmation-modal/component.svelte.d.ts +4 -14
  167. package/dist/ui/templates/confirmation-modal/component.svelte.d.ts.map +1 -1
  168. package/dist/ui/templates/pinya-base/PinyaBase.svelte +45 -4
  169. package/dist/ui/templates/pinya-base/PinyaBase.svelte.d.ts +16 -13
  170. package/dist/ui/templates/pinya-base/PinyaBase.svelte.d.ts.map +1 -1
  171. package/dist/ui/templates/pinya-base/menuPageServerLoadRemote.remote.svelte +1 -0
  172. package/dist/ui/templates/pinya-base/menuPageServerLoadRemote.remote.svelte.d.ts +27 -0
  173. package/dist/ui/templates/pinya-base/menuPageServerLoadRemote.remote.svelte.d.ts.map +1 -0
  174. package/dist/ui/templates/pinya-base/pinyaBaseRunes.svelte.js +1 -1
  175. package/dist/util/context/PineappleBaseContext.svelte +18 -6
  176. package/dist/util/context/PineappleBaseContext.svelte.d.ts +5 -14
  177. package/dist/util/context/PineappleBaseContext.svelte.d.ts.map +1 -1
  178. package/dist/util/context/{pineappleBaseContextDefinitions.d.ts → pineappleBaseContextDefinitions.svelte.d.ts} +18 -4
  179. package/dist/util/context/pineappleBaseContextDefinitions.svelte.d.ts.map +1 -0
  180. package/dist/util/context/{pineappleBaseContextDefinitions.js → pineappleBaseContextDefinitions.svelte.js} +14 -1
  181. package/dist/util/env-getter.js +5 -4
  182. package/dist/util/getParsnipData.remote.d.ts +12 -0
  183. package/dist/util/getParsnipData.remote.d.ts.map +1 -0
  184. package/dist/util/getParsnipData.remote.js +3 -0
  185. package/dist/util/localStore.svelte.js +8 -10
  186. package/dist/util/util.js +1 -1
  187. package/package.json +72 -53
  188. package/src/lib/styles/app.css +0 -82
  189. package/dist/util/context/pineappleBaseContextDefinitions.d.ts.map +0 -1
@@ -1,7 +1,16 @@
1
- export const GetLatestBlogs = async () => {
2
- const resp = await fetch("http://turnipxenon.com/api/get-latest-blogs");
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export const GetLatestBlogs = () => __awaiter(void 0, void 0, void 0, function* () {
11
+ const resp = yield fetch("http://turnipxenon.com/api/get-latest-blogs");
3
12
  if (!resp.ok) {
4
13
  return new Response(JSON.stringify([]));
5
14
  }
6
- return new Response(JSON.stringify(await resp.json()));
7
- };
15
+ return new Response(JSON.stringify(yield resp.json()));
16
+ });
@@ -1,6 +1,15 @@
1
1
  /**
2
2
  * DialogManager is the object we want to interact with in Svelte
3
3
  */
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
4
13
  import { writable } from "svelte/store";
5
14
  import { DialogState } from "../../types/pineapple_fiber/DialogState";
6
15
  import { tweened } from "svelte/motion";
@@ -20,34 +29,216 @@ import { DialogProcessor } from "./DialogProcessor";
20
29
  import { parseYarn } from "../../scripts/pineapple_fiber/PineappleFiberParser";
21
30
  const shouldDebugYarn = false;
22
31
  export class DialogManager {
23
- dialogMessageMap = new Map();
24
- currentDialogTree = [];
25
- fullCurrentMessage = defaultDialogMessage[0].textContent;
26
- currentMessageMeta = defaultDialogMessage[0];
27
- currentMessage = writable("");
28
- currentIndex = 0;
29
- previousTimestamp = 0;
30
- isDoneTransition = false;
31
- currentPortrait = writable("");
32
- portraitMap = new Map();
33
- currentState = DialogState.Visible;
34
- currentReadableState = writable(this.currentState);
35
- hidePercent = tweened(100, {
36
- duration: 400,
37
- easing: backOut
38
- });
39
- hidePercentLinear = tweened(100, {
40
- duration: 150,
41
- easing: linear
42
- });
43
- skipNextActiveTime = 0;
44
- dialogProcessor;
45
- // for queueing actions
46
- _setDialogChoiceQueue = [];
47
- _setDialogChoiceMutex = false;
48
- onSetDialogListeners = [];
49
- enableDialogueOverlayCache = false;
50
32
  constructor() {
33
+ this.dialogMessageMap = new Map();
34
+ this.currentDialogTree = [];
35
+ this.fullCurrentMessage = defaultDialogMessage[0].textContent;
36
+ this.currentMessageMeta = defaultDialogMessage[0];
37
+ this.currentMessage = writable("");
38
+ this.currentIndex = 0;
39
+ this.previousTimestamp = 0;
40
+ this.isDoneTransition = false;
41
+ this.currentPortrait = writable("");
42
+ this.portraitMap = new Map();
43
+ this.currentState = DialogState.Visible;
44
+ this.currentReadableState = writable(this.currentState);
45
+ this.hidePercent = tweened(100, {
46
+ duration: 400,
47
+ easing: backOut
48
+ });
49
+ this.hidePercentLinear = tweened(100, {
50
+ duration: 150,
51
+ easing: linear
52
+ });
53
+ this.skipNextActiveTime = 0;
54
+ // for queueing actions
55
+ this._setDialogChoiceQueue = [];
56
+ this._setDialogChoiceMutex = false;
57
+ this.onSetDialogListeners = [];
58
+ this.enableDialogueOverlayCache = false;
59
+ /**
60
+ * when users interact with the dialog, they can skip the transition like in a game
61
+ * note that there is a cool down to this, check out skipNextActiveTime
62
+ */
63
+ this.skipAnimation = () => {
64
+ if (this.previousTimestamp > this.skipNextActiveTime &&
65
+ this.currentState == DialogState.Visible &&
66
+ !this.isDoneTransition // crucial for dynamic links!
67
+ ) {
68
+ this.currentIndex = this.fullCurrentMessage.length - 1;
69
+ this.currentMessage.update(() => this.fullCurrentMessage.slice(0, this.currentIndex));
70
+ }
71
+ };
72
+ /**
73
+ * hides or shows the dialog UI
74
+ * @param shouldEnable
75
+ */
76
+ this.enableDialog = (shouldEnable) => {
77
+ enableUniversalOverlaySvelte4.update(() => shouldEnable);
78
+ };
79
+ /**
80
+ * sets the possible dialog that might appear on the Dialog UI
81
+ * note that it overwrites the previous tree and does not append on it due to the possibility
82
+ * of node name conflicts
83
+ * @param newDialogTree
84
+ */
85
+ this.setDialogTree = (newDialogTree) => {
86
+ this.currentDialogTree = newDialogTree;
87
+ this.dialogMessageMap.clear();
88
+ newDialogTree.map((value) => {
89
+ if (value.dialogId) {
90
+ this.dialogMessageMap.set(value.dialogId, value);
91
+ }
92
+ });
93
+ // lazy load map
94
+ if (this.portraitMap.size == 0) {
95
+ this.portraitMap.set(PortraitType.AresHappy.toString(), AresHappy);
96
+ this.portraitMap.set(PortraitType.AresBlushing.toString(), AresBlushing);
97
+ this.portraitMap.set(PortraitType.AresDisappointed.toString(), AresDisappointed);
98
+ this.portraitMap.set(PortraitType.AresLetsGo.toString(), AresLetsGo);
99
+ this.portraitMap.set(PortraitType.AresMad.toString(), AresMad);
100
+ this.portraitMap.set(PortraitType.AresNeutral.toString(), AresNeutral);
101
+ this.portraitMap.set(PortraitType.AresSlightlyMad.toString(), AresSlightlyMad);
102
+ this.portraitMap.set(PortraitType.AresSurprised.toString(), AresSurprised);
103
+ this.portraitMap.set(PortraitType.AresYay.toString(), AresYay);
104
+ }
105
+ this.setDialogChoice(newDialogTree[0]);
106
+ };
107
+ /**
108
+ * Remember to call this before SetDialogTree
109
+ * and unsubscribe during onDestroy
110
+ * @param callback
111
+ */
112
+ this.subscribeToSetDialogChoice = (callback) => {
113
+ this.onSetDialogListeners.push(callback);
114
+ };
115
+ /**
116
+ * Remember to call this during onDestroy
117
+ * @param callback
118
+ * todo: double check if this works???
119
+ */
120
+ this.unsubscribeToSetDialogChoice = (callback) => {
121
+ // from: https://stackoverflow.com/a/5767357/17836168
122
+ const index = this.onSetDialogListeners.indexOf(callback);
123
+ if (index > -1) {
124
+ // only splice array when item is found
125
+ this.onSetDialogListeners.splice(index, 1); // 2nd parameter means remove one item only
126
+ }
127
+ };
128
+ /**
129
+ * Sets the next dialog to show depending on which special choice a href link the user
130
+ * has interacted with
131
+ * @param newMessage
132
+ *
133
+ * you can listen to this!
134
+ */
135
+ this.setDialogChoice = (newMessage) => {
136
+ if (!newMessage || !newMessage.textContent) {
137
+ return;
138
+ }
139
+ this._setDialogChoiceQueue.push(newMessage);
140
+ if (!this._setDialogChoiceMutex) {
141
+ this._setDialogChoiceMutex = true; // not a true mutex but this will do
142
+ this._setDialogChoice();
143
+ }
144
+ };
145
+ this._setDialogChoice = () => {
146
+ var _a, _b;
147
+ const newMessage = this._setDialogChoiceQueue.shift();
148
+ if (newMessage === undefined) {
149
+ this._setDialogChoiceMutex = false; // set it free!
150
+ this.onSetDialogListeners.forEach((listener) => {
151
+ listener(this.currentMessageMeta);
152
+ });
153
+ return;
154
+ }
155
+ this.currentMessageMeta = newMessage;
156
+ // set the portrait
157
+ let portraitValue = AresHappy;
158
+ if (this.currentMessageMeta.portraitType) {
159
+ portraitValue = (_b = this.portraitMap.get((_a = this.currentMessageMeta.portraitType) !== null && _a !== void 0 ? _a : AresHappy)) !== null && _b !== void 0 ? _b : '';
160
+ }
161
+ if (portraitValue) {
162
+ this.currentPortrait.update(() => portraitValue);
163
+ }
164
+ // process the dialogue here line-by-line
165
+ this.fullCurrentMessage = this.dialogProcessor.processDialog(this.currentMessageMeta);
166
+ this.currentMessage.update(() => "");
167
+ this.currentIndex = 0;
168
+ this.skipNextActiveTime = this.previousTimestamp + 1000; // guard
169
+ this.isDoneTransition = false; // must be after the guard
170
+ if (shouldDebugYarn) {
171
+ console.info(`Currently processing node: ${this.currentMessageMeta.dialogId}`);
172
+ }
173
+ // save that we visited AND processed the node
174
+ if (this.currentMessageMeta.dialogId) {
175
+ const key = `+${this.currentMessageMeta.dialogId}`;
176
+ const value = Number(dialogVariableStore.getItem(key));
177
+ if (isNaN(value)) {
178
+ dialogVariableStore.setItem(key, "1");
179
+ }
180
+ else {
181
+ dialogVariableStore.setItem(key, `${value + 1}`);
182
+ }
183
+ }
184
+ // reloop this to process all messages
185
+ this._setDialogChoice();
186
+ };
187
+ this.setDialogToDefault = () => {
188
+ this.setDialogTree(defaultDialogMessage);
189
+ };
190
+ /**
191
+ * updates the information and detail frame by frame
192
+ * you can think of this like the main game loop
193
+ *
194
+ * @param timestamp
195
+ *
196
+ * todo: this might be too big we might want to refactor this method for better readability
197
+ * ISSUE #81 https://github.com/TurnipXenon/pineapple/issues/81
198
+ */
199
+ this.update = (timestamp) => {
200
+ if (this.currentState == DialogState.Invisible || this.currentState == DialogState.Busy) {
201
+ window.requestAnimationFrame(this.update);
202
+ return;
203
+ }
204
+ // if visible
205
+ // text transition loop
206
+ if (!this.isDoneTransition && this.currentIndex > this.fullCurrentMessage.length) {
207
+ const elementList = document.getElementsByClassName("dialog-choice");
208
+ for (const el of elementList) {
209
+ el.addEventListener("click", () => {
210
+ // todo: make more robust; for now we're assuming first class is our choice
211
+ const choice = el.classList[0].split("-")[1];
212
+ this.setDialogChoice(this.dialogMessageMap.get(choice));
213
+ });
214
+ }
215
+ this.isDoneTransition = true;
216
+ }
217
+ // guard: skip if done or if not yet time to update
218
+ if (this.currentIndex > this.fullCurrentMessage.length ||
219
+ this.previousTimestamp + updateRate > timestamp) {
220
+ window.requestAnimationFrame(this.update);
221
+ return;
222
+ }
223
+ this.previousTimestamp = timestamp;
224
+ // check if valid text
225
+ // there is an assumption that previous character is valid
226
+ // let validCharacterIndex = this.currentLength - 1;
227
+ // validCharacterIndex++;
228
+ // the code above is just to show you how it looks like but let's assume
229
+ // that currentLength = validCharacter + 1
230
+ while (this.fullCurrentMessage[this.currentIndex] == "<" &&
231
+ this.currentIndex + 1 < this.fullCurrentMessage.length) {
232
+ // find valid character, trap with closing
233
+ this.currentIndex = this.fullCurrentMessage.indexOf(">", this.currentIndex) + 1;
234
+ // normalize
235
+ this.currentIndex = Math.min(this.currentIndex, this.fullCurrentMessage.length - 1);
236
+ }
237
+ this.currentMessage.update(() => this.fullCurrentMessage.slice(0, this.currentIndex));
238
+ // increment
239
+ ++this.currentIndex;
240
+ window.requestAnimationFrame(this.update);
241
+ };
51
242
  this.dialogProcessor = new DialogProcessor(this);
52
243
  enableUniversalOverlaySvelte4.subscribe((value) => {
53
244
  // todo: investigate why we cant put setDialogDefault inside the then clause
@@ -70,188 +261,6 @@ export class DialogManager {
70
261
  }
71
262
  });
72
263
  }
73
- /**
74
- * when users interact with the dialog, they can skip the transition like in a game
75
- * note that there is a cool down to this, check out skipNextActiveTime
76
- */
77
- skipAnimation = () => {
78
- if (this.previousTimestamp > this.skipNextActiveTime &&
79
- this.currentState == DialogState.Visible &&
80
- !this.isDoneTransition // crucial for dynamic links!
81
- ) {
82
- this.currentIndex = this.fullCurrentMessage.length - 1;
83
- this.currentMessage.update(() => this.fullCurrentMessage.slice(0, this.currentIndex));
84
- }
85
- };
86
- /**
87
- * hides or shows the dialog UI
88
- * @param shouldEnable
89
- */
90
- enableDialog = (shouldEnable) => {
91
- enableUniversalOverlaySvelte4.update(() => shouldEnable);
92
- };
93
- /**
94
- * sets the possible dialog that might appear on the Dialog UI
95
- * note that it overwrites the previous tree and does not append on it due to the possibility
96
- * of node name conflicts
97
- * @param newDialogTree
98
- */
99
- setDialogTree = (newDialogTree) => {
100
- this.currentDialogTree = newDialogTree;
101
- this.dialogMessageMap.clear();
102
- newDialogTree.map((value) => {
103
- if (value.dialogId) {
104
- this.dialogMessageMap.set(value.dialogId, value);
105
- }
106
- });
107
- // lazy load map
108
- if (this.portraitMap.size == 0) {
109
- this.portraitMap.set(PortraitType.AresHappy.toString(), AresHappy);
110
- this.portraitMap.set(PortraitType.AresBlushing.toString(), AresBlushing);
111
- this.portraitMap.set(PortraitType.AresDisappointed.toString(), AresDisappointed);
112
- this.portraitMap.set(PortraitType.AresLetsGo.toString(), AresLetsGo);
113
- this.portraitMap.set(PortraitType.AresMad.toString(), AresMad);
114
- this.portraitMap.set(PortraitType.AresNeutral.toString(), AresNeutral);
115
- this.portraitMap.set(PortraitType.AresSlightlyMad.toString(), AresSlightlyMad);
116
- this.portraitMap.set(PortraitType.AresSurprised.toString(), AresSurprised);
117
- this.portraitMap.set(PortraitType.AresYay.toString(), AresYay);
118
- }
119
- this.setDialogChoice(newDialogTree[0]);
120
- };
121
- /**
122
- * Remember to call this before SetDialogTree
123
- * and unsubscribe during onDestroy
124
- * @param callback
125
- */
126
- subscribeToSetDialogChoice = (callback) => {
127
- this.onSetDialogListeners.push(callback);
128
- };
129
- /**
130
- * Remember to call this during onDestroy
131
- * @param callback
132
- * todo: double check if this works???
133
- */
134
- unsubscribeToSetDialogChoice = (callback) => {
135
- // from: https://stackoverflow.com/a/5767357/17836168
136
- const index = this.onSetDialogListeners.indexOf(callback);
137
- if (index > -1) {
138
- // only splice array when item is found
139
- this.onSetDialogListeners.splice(index, 1); // 2nd parameter means remove one item only
140
- }
141
- };
142
- /**
143
- * Sets the next dialog to show depending on which special choice a href link the user
144
- * has interacted with
145
- * @param newMessage
146
- *
147
- * you can listen to this!
148
- */
149
- setDialogChoice = (newMessage) => {
150
- if (!newMessage || !newMessage.textContent) {
151
- return;
152
- }
153
- this._setDialogChoiceQueue.push(newMessage);
154
- if (!this._setDialogChoiceMutex) {
155
- this._setDialogChoiceMutex = true; // not a true mutex but this will do
156
- this._setDialogChoice();
157
- }
158
- };
159
- _setDialogChoice = () => {
160
- const newMessage = this._setDialogChoiceQueue.shift();
161
- if (newMessage === undefined) {
162
- this._setDialogChoiceMutex = false; // set it free!
163
- this.onSetDialogListeners.forEach((listener) => {
164
- listener(this.currentMessageMeta);
165
- });
166
- return;
167
- }
168
- this.currentMessageMeta = newMessage;
169
- // set the portrait
170
- let portraitValue = AresHappy;
171
- if (this.currentMessageMeta.portraitType) {
172
- portraitValue = this.portraitMap.get(this.currentMessageMeta.portraitType ?? AresHappy) ?? '';
173
- }
174
- if (portraitValue) {
175
- this.currentPortrait.update(() => portraitValue);
176
- }
177
- // process the dialogue here line-by-line
178
- this.fullCurrentMessage = this.dialogProcessor.processDialog(this.currentMessageMeta);
179
- this.currentMessage.update(() => "");
180
- this.currentIndex = 0;
181
- this.skipNextActiveTime = this.previousTimestamp + 1000; // guard
182
- this.isDoneTransition = false; // must be after the guard
183
- if (shouldDebugYarn) {
184
- console.info(`Currently processing node: ${this.currentMessageMeta.dialogId}`);
185
- }
186
- // save that we visited AND processed the node
187
- if (this.currentMessageMeta.dialogId) {
188
- const key = `+${this.currentMessageMeta.dialogId}`;
189
- const value = Number(dialogVariableStore.getItem(key));
190
- if (isNaN(value)) {
191
- dialogVariableStore.setItem(key, "1");
192
- }
193
- else {
194
- dialogVariableStore.setItem(key, `${value + 1}`);
195
- }
196
- }
197
- // reloop this to process all messages
198
- this._setDialogChoice();
199
- };
200
- setDialogToDefault = () => {
201
- this.setDialogTree(defaultDialogMessage);
202
- };
203
- /**
204
- * updates the information and detail frame by frame
205
- * you can think of this like the main game loop
206
- *
207
- * @param timestamp
208
- *
209
- * todo: this might be too big we might want to refactor this method for better readability
210
- * ISSUE #81 https://github.com/TurnipXenon/pineapple/issues/81
211
- */
212
- update = (timestamp) => {
213
- if (this.currentState == DialogState.Invisible || this.currentState == DialogState.Busy) {
214
- window.requestAnimationFrame(this.update);
215
- return;
216
- }
217
- // if visible
218
- // text transition loop
219
- if (!this.isDoneTransition && this.currentIndex > this.fullCurrentMessage.length) {
220
- const elementList = document.getElementsByClassName("dialog-choice");
221
- for (const el of elementList) {
222
- el.addEventListener("click", () => {
223
- // todo: make more robust; for now we're assuming first class is our choice
224
- const choice = el.classList[0].split("-")[1];
225
- this.setDialogChoice(this.dialogMessageMap.get(choice));
226
- });
227
- }
228
- this.isDoneTransition = true;
229
- }
230
- // guard: skip if done or if not yet time to update
231
- if (this.currentIndex > this.fullCurrentMessage.length ||
232
- this.previousTimestamp + updateRate > timestamp) {
233
- window.requestAnimationFrame(this.update);
234
- return;
235
- }
236
- this.previousTimestamp = timestamp;
237
- // check if valid text
238
- // there is an assumption that previous character is valid
239
- // let validCharacterIndex = this.currentLength - 1;
240
- // validCharacterIndex++;
241
- // the code above is just to show you how it looks like but let's assume
242
- // that currentLength = validCharacter + 1
243
- while (this.fullCurrentMessage[this.currentIndex] == "<" &&
244
- this.currentIndex + 1 < this.fullCurrentMessage.length) {
245
- // find valid character, trap with closing
246
- this.currentIndex = this.fullCurrentMessage.indexOf(">", this.currentIndex) + 1;
247
- // normalize
248
- this.currentIndex = Math.min(this.currentIndex, this.fullCurrentMessage.length - 1);
249
- }
250
- this.currentMessage.update(() => this.fullCurrentMessage.slice(0, this.currentIndex));
251
- // increment
252
- ++this.currentIndex;
253
- window.requestAnimationFrame(this.update);
254
- };
255
264
  enableDialogOverlay(enable) {
256
265
  enableUniversalOverlaySvelte4.set(enable);
257
266
  }
@@ -259,12 +268,14 @@ export class DialogManager {
259
268
  enableUniversalOverlaySvelte4.set(!this.enableDialogueOverlayCache);
260
269
  }
261
270
  ;
262
- async parseAndSetDialogTree(dialogYarn) {
263
- return parseYarn(dialogYarn)
264
- .then((dialogTree) => {
265
- console.log(dialogTree);
266
- this.setDialogTree(dialogTree);
267
- return dialogTree;
271
+ parseAndSetDialogTree(dialogYarn) {
272
+ return __awaiter(this, void 0, void 0, function* () {
273
+ return parseYarn(dialogYarn)
274
+ .then((dialogTree) => {
275
+ console.log(dialogTree);
276
+ this.setDialogTree(dialogTree);
277
+ return dialogTree;
278
+ });
268
279
  });
269
280
  }
270
281
  }
@@ -17,9 +17,31 @@ import { UnvisitCommand } from "./behavior_tree/line_processors/commands/Unvisit
17
17
  * DialogProcessor processes dialogs
18
18
  */
19
19
  export class DialogProcessor {
20
- dialogManager;
21
- processingTree;
22
20
  constructor(dialogManager) {
21
+ /**
22
+ * process the dialog line by line and return a presentable string
23
+ * @param dialogDetail
24
+ */
25
+ this.processDialog = (dialogDetail) => {
26
+ if (!browser) {
27
+ return ""; // don't process any line in the server
28
+ }
29
+ let currentState = new BehaviorState();
30
+ // split each yarn line
31
+ return dialogDetail.textContent
32
+ .trim()
33
+ .split("\n")
34
+ .map((line_, index) => {
35
+ const result = this.processingTree.process({
36
+ initState: currentState,
37
+ line: line_.trim(),
38
+ lineIndex: index
39
+ });
40
+ currentState = result.nextState;
41
+ return result.renderedLine;
42
+ })
43
+ .join("\n"); // combine all processed lines
44
+ };
23
45
  this.dialogManager = dialogManager;
24
46
  this.processingTree = new LineSelectorNode([
25
47
  /*region comment based formats*/
@@ -40,28 +62,4 @@ export class DialogProcessor {
40
62
  new NormalLineProcessorNode()
41
63
  ]);
42
64
  }
43
- /**
44
- * process the dialog line by line and return a presentable string
45
- * @param dialogDetail
46
- */
47
- processDialog = (dialogDetail) => {
48
- if (!browser) {
49
- return ""; // don't process any line in the server
50
- }
51
- let currentState = new BehaviorState();
52
- // split each yarn line
53
- return dialogDetail.textContent
54
- .trim()
55
- .split("\n")
56
- .map((line_, index) => {
57
- const result = this.processingTree.process({
58
- initState: currentState,
59
- line: line_.trim(),
60
- lineIndex: index
61
- });
62
- currentState = result.nextState;
63
- return result.renderedLine;
64
- })
65
- .join("\n"); // combine all processed lines
66
- };
67
65
  }
@@ -1,8 +1,10 @@
1
1
  import { dialogVariableStore } from "./DialogManagerStore";
2
2
  class _DialogUtils {
3
- isNodeVisited = (dialogId) => {
4
- const value = Number(dialogVariableStore.getItem(`+${dialogId}`));
5
- return !isNaN(value) && value > 0;
6
- };
3
+ constructor() {
4
+ this.isNodeVisited = (dialogId) => {
5
+ const value = Number(dialogVariableStore.getItem(`+${dialogId}`));
6
+ return !isNaN(value) && value > 0;
7
+ };
8
+ }
7
9
  }
8
10
  export const DialogUtils = new _DialogUtils();
@@ -1,34 +1,36 @@
1
1
  class BTreeUtils {
2
- /**
3
- * peek the top of a stack object with the assumption it's not an empty stack
4
- * todo: add possible protection like an assertion
5
- * @param stack
6
- * @return top of the stack
7
- */
8
- peek = (stack) => {
9
- return stack[stack.length - 1];
10
- };
11
- removeQuotes = (value) => {
12
- return value
13
- .replace(/^"/, "") // remove possible " at the start: https://stackoverflow.com/a/2182602
14
- .replace(/"$/, ""); // remove possible " at the end: https://stackoverflow.com/a/12249011
15
- };
16
- simplifyToken = (oldToken) => {
17
- if (oldToken[0] == "$") {
18
- const value = localStorage.getItem(oldToken);
19
- if (value) {
20
- return value;
2
+ constructor() {
3
+ /**
4
+ * peek the top of a stack object with the assumption it's not an empty stack
5
+ * todo: add possible protection like an assertion
6
+ * @param stack
7
+ * @return top of the stack
8
+ */
9
+ this.peek = (stack) => {
10
+ return stack[stack.length - 1];
11
+ };
12
+ this.removeQuotes = (value) => {
13
+ return value
14
+ .replace(/^"/, "") // remove possible " at the start: https://stackoverflow.com/a/2182602
15
+ .replace(/"$/, ""); // remove possible " at the end: https://stackoverflow.com/a/12249011
16
+ };
17
+ this.simplifyToken = (oldToken) => {
18
+ if (oldToken[0] == "$") {
19
+ const value = localStorage.getItem(oldToken);
20
+ if (value) {
21
+ return value;
22
+ }
23
+ console.error(`Value obtained in local storage false: ${oldToken}`);
24
+ return "";
21
25
  }
22
- console.error(`Value obtained in local storage false: ${oldToken}`);
23
- return "";
24
- }
25
- return btreeUtils.removeQuotes(oldToken);
26
- };
27
- isTrue = (value) => {
28
- return value.trim().toLowerCase() === "true";
29
- };
30
- isFalse = (value) => {
31
- return value.trim().toLowerCase() === "false";
32
- };
26
+ return btreeUtils.removeQuotes(oldToken);
27
+ };
28
+ this.isTrue = (value) => {
29
+ return value.trim().toLowerCase() === "true";
30
+ };
31
+ this.isFalse = (value) => {
32
+ return value.trim().toLowerCase() === "false";
33
+ };
34
+ }
33
35
  }
34
36
  export const btreeUtils = new BTreeUtils();
@@ -4,7 +4,6 @@ import { BehaviorStatus } from "./BehaviorStatus";
4
4
  * finds a non-failing node
5
5
  */
6
6
  export class SelectorNode {
7
- nodeList;
8
7
  constructor(nodeList) {
9
8
  this.nodeList = nodeList;
10
9
  }