@overmvp/kumi 0.1.0 → 0.3.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.
Files changed (175) hide show
  1. package/README.md +59 -6
  2. package/builder/css-v1.mjs +54 -1
  3. package/builder/css-v1.test.mjs +40 -0
  4. package/builder/link-addon-package.mjs +47 -6
  5. package/builder/module-declarations.test.mjs +9 -18
  6. package/builder/native-kernels.mjs +1 -1
  7. package/builder/src/compiler.rs +180 -8
  8. package/builder/src/main.rs +19 -5
  9. package/builder/src/native_ir.rs +1 -1
  10. package/builder/src/native_signal.rs +46 -10
  11. package/builder/src/numbers.lua +14 -0
  12. package/builder/src/project-front.mjs +385 -34
  13. package/builder/src/routes.rs +11 -14
  14. package/builder/src/setup-store.lua +18 -0
  15. package/builder/src/signal-kernel.fingerprint +1 -1
  16. package/builder/src/ts-lower.mjs +2 -2
  17. package/builder/src/wow-reads.lua +22 -0
  18. package/builder/style-modules.mjs +93 -0
  19. package/config.ts +56 -14
  20. package/eslint.mjs +74 -0
  21. package/form/index.ts +15 -11
  22. package/package.json +11 -7
  23. package/router/index.ts +9 -2
  24. package/router/navigation.ts +22 -0
  25. package/router/router-view.ts +134 -0
  26. package/scripts/addon-build.mjs +364 -0
  27. package/scripts/addon-project.mjs +78 -0
  28. package/scripts/kumi-cli.mjs +52 -17
  29. package/scripts/link-addons.mjs +12 -2
  30. package/src/bindings.ts +2 -2
  31. package/src/css-tokens.ts +16 -11
  32. package/src/css-v1.ts +10 -0
  33. package/src/elements.ts +26 -0
  34. package/src/frame-scheduler.ts +3 -1
  35. package/src/index.ts +1 -0
  36. package/src/jsx-runtime.ts +8 -1
  37. package/src/keyed-list.ts +8 -5
  38. package/src/module-ui.ts +147 -0
  39. package/src/module.ts +42 -8
  40. package/src/owned-collections.ts +8 -0
  41. package/src/providers.ts +7 -1
  42. package/src/reactive-scope.ts +3 -3
  43. package/src/reactivity.ts +28 -7
  44. package/src/result.ts +6 -0
  45. package/src/signal-kernel.ts +35 -2
  46. package/state/index.ts +6 -0
  47. package/state/setup-store-persistence.ts +206 -0
  48. package/state/setup-store-view.ts +10 -0
  49. package/state/setup-store.ts +342 -0
  50. package/state/store.ts +2 -0
  51. package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
  52. package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
  53. package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
  54. package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
  55. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
  56. package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
  57. package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
  58. package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
  59. package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
  60. package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
  61. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
  62. package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
  63. package/templates/addon/AGENTS.md +34 -0
  64. package/templates/addon/Assets/Art/Corner10.tga +0 -0
  65. package/templates/addon/Assets/Art/Corner11.tga +0 -0
  66. package/templates/addon/Assets/Art/Corner12.tga +0 -0
  67. package/templates/addon/Assets/Art/Corner13.tga +0 -0
  68. package/templates/addon/Assets/Art/Corner14.tga +0 -0
  69. package/templates/addon/Assets/Art/Corner15.tga +0 -0
  70. package/templates/addon/Assets/Art/Corner16.tga +0 -0
  71. package/templates/addon/Assets/Art/Corner2.tga +0 -0
  72. package/templates/addon/Assets/Art/Corner3.tga +0 -0
  73. package/templates/addon/Assets/Art/Corner4.tga +0 -0
  74. package/templates/addon/Assets/Art/Corner5.tga +0 -0
  75. package/templates/addon/Assets/Art/Corner6.tga +0 -0
  76. package/templates/addon/Assets/Art/Corner7.tga +0 -0
  77. package/templates/addon/Assets/Art/Corner8.tga +0 -0
  78. package/templates/addon/Assets/Art/Corner9.tga +0 -0
  79. package/templates/addon/Assets/Art/Dot.tga +0 -0
  80. package/templates/addon/Assets/Art/Gear.tga +0 -0
  81. package/templates/addon/Assets/Art/Grip.tga +0 -0
  82. package/templates/addon/Assets/Art/Outline10.tga +0 -0
  83. package/templates/addon/Assets/Art/Outline12.tga +0 -0
  84. package/templates/addon/Assets/Art/Outline13.tga +0 -0
  85. package/templates/addon/Assets/Art/Outline14.tga +0 -0
  86. package/templates/addon/Assets/Art/Outline15.tga +0 -0
  87. package/templates/addon/Assets/Art/Outline2.tga +0 -0
  88. package/templates/addon/Assets/Art/Outline3.tga +0 -0
  89. package/templates/addon/Assets/Art/Outline5.tga +0 -0
  90. package/templates/addon/Assets/Art/Outline7.tga +0 -0
  91. package/templates/addon/Assets/Art/Outline9.tga +0 -0
  92. package/templates/addon/Assets/Art/Round11.tga +0 -0
  93. package/templates/addon/Assets/Art/Round11Border.tga +0 -0
  94. package/templates/addon/Assets/Art/Round4.tga +0 -0
  95. package/templates/addon/Assets/Art/Round4Border.tga +0 -0
  96. package/templates/addon/Assets/Art/Round6.tga +0 -0
  97. package/templates/addon/Assets/Art/Round6Border.tga +0 -0
  98. package/templates/addon/Assets/Art/Round8.tga +0 -0
  99. package/templates/addon/Assets/Art/Round8Border.tga +0 -0
  100. package/templates/addon/Assets/Art/Search.tga +0 -0
  101. package/templates/addon/CLAUDE.md +1 -0
  102. package/templates/addon/README.md +42 -7
  103. package/templates/addon/eslint.config.mjs +3 -9
  104. package/templates/addon/gitignore +1 -0
  105. package/templates/addon/kumi.config.ts +17 -0
  106. package/templates/addon/package.json +4 -5
  107. package/templates/addon/src/app/app.module.ts +18 -0
  108. package/templates/addon/src/app/commands.store.ts +11 -0
  109. package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
  110. package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
  111. package/templates/addon/src/app/main.ts +5 -0
  112. package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
  113. package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
  114. package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
  115. package/templates/addon/src/app/theme.ts +6 -0
  116. package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
  117. package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
  118. package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
  119. package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
  120. package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
  121. package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
  122. package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
  123. package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
  124. package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
  125. package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
  126. package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
  127. package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
  128. package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
  129. package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
  130. package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
  131. package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
  132. package/templates/addon/src/shared/api/native-art.ts +28 -0
  133. package/templates/addon/src/shared/assets/close.png +0 -0
  134. package/templates/addon/src/shared/lib/format.ts +20 -0
  135. package/templates/addon/src/shared/styles/_tokens.scss +12 -0
  136. package/templates/addon/src/shared/ui/Button.tsx +29 -0
  137. package/templates/addon/src/shared/ui/Choice.tsx +34 -0
  138. package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
  139. package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
  140. package/templates/addon/src/shared/ui/Slider.tsx +25 -0
  141. package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
  142. package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
  143. package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
  144. package/templates/addon/tsconfig.json +49 -10
  145. package/wow/action-bar-layout.ts +108 -0
  146. package/wow/action-button.ts +219 -0
  147. package/wow/action-catalog.ts +98 -0
  148. package/wow/addon-manifest.ts +36 -0
  149. package/wow/app-ui.ts +221 -0
  150. package/wow/cooldown-timing.ts +24 -0
  151. package/wow/css-box.ts +40 -6
  152. package/wow/css-surfaces.ts +229 -24
  153. package/wow/cursor.ts +45 -0
  154. package/wow/frame-access.ts +23 -1
  155. package/wow/frame-timing.ts +13 -0
  156. package/wow/hooks.ts +133 -0
  157. package/wow/index.ts +18 -4
  158. package/wow/layout-view.ts +26 -14
  159. package/wow/locale-font.ts +15 -0
  160. package/wow/native.ts +18 -0
  161. package/wow/panel-host.ts +97 -0
  162. package/wow/pixel.ts +35 -0
  163. package/wow/plugins.ts +246 -0
  164. package/wow/protect.ts +27 -3
  165. package/wow/protected-view.ts +103 -0
  166. package/wow/range-art.ts +7 -0
  167. package/wow/readable-api.ts +120 -0
  168. package/wow/rounded-texture.ts +33 -6
  169. package/wow/saved-variables.ts +67 -18
  170. package/wow/spell-cooldown.ts +36 -0
  171. package/wow/start-addon.ts +31 -8
  172. package/wow/view.ts +201 -83
  173. package/templates/addon/__ADDON_NAME__.toc +0 -4
  174. package/templates/addon/scripts/build.mjs +0 -25
  175. package/templates/addon/src/app/main.tsx +0 -13
@@ -0,0 +1,5 @@
1
+ import { startAddon } from "@kumi/wow";
2
+ import { AppModule } from "./app.module";
3
+ import { theme } from "./theme";
4
+
5
+ export const addon = startAddon(AppModule, { theme });
@@ -0,0 +1,8 @@
1
+ import { GreetingOverview } from "../../../../modules/greeting/widgets/GreetingOverview";
2
+
3
+ export const title = "Home";
4
+ export const order = 0;
5
+
6
+ export default function HomePage() {
7
+ return <GreetingOverview />;
8
+ }
@@ -0,0 +1,38 @@
1
+ import { computed, ref, storeToRefs } from "@kumi/state";
2
+ import styles from "@kumi/styles/app/layout/AppWindow";
3
+ import { usePlugins, type PluginInfo } from "@kumi/wow";
4
+ import { Button } from "../../../../shared/ui/Button";
5
+ import { Toggle } from "../../../../shared/ui/Toggle";
6
+
7
+ export const title = "Plugins";
8
+ export const order = 90;
9
+
10
+ const STATUS: Record<PluginInfo["status"], string> = {
11
+ off: "Off",
12
+ waiting: "Starts after a reload",
13
+ loading: "Loading",
14
+ ready: "Running",
15
+ error: "Failed",
16
+ };
17
+
18
+ /** Turn plugins on or off. Kumi changes the addon list and asks for a reload. */
19
+ export default function PluginsPage() {
20
+ const plugins = usePlugins();
21
+ const { list, reloadRequired } = storeToRefs(plugins);
22
+ return (
23
+ <div className={styles.list}>
24
+ {list.value.map(plugin => (
25
+ <div key={plugin.id} className={styles.listRow}>
26
+ <div className={styles.listText}>
27
+ <span className={styles.listTitle} value={plugin.title} />
28
+ <span className={styles.listNote} value={plugin.error ?? STATUS[plugin.status] + (plugin.notes === "" ? "" : " · " + plugin.notes)} />
29
+ </div>
30
+ <Toggle label={plugin.title} value={ref(plugin.enabled)}
31
+ onChange={enabled => { plugins.setEnabled(plugin.id, enabled); }} />
32
+ </div>
33
+ ))}
34
+ <span className={styles.listNote} shown={computed(() => list.value.length === 0)} value="This addon has no plugins." />
35
+ <Button primary label="Reload UI" shown={reloadRequired} onClick={plugins.reload} />
36
+ </div>
37
+ );
38
+ }
@@ -0,0 +1,8 @@
1
+ import { GreetingSettings } from "../../../../modules/greeting/widgets/GreetingSettings";
2
+
3
+ export const title = "Settings";
4
+ export const order = 10;
5
+
6
+ export default function SettingsPage() {
7
+ return <GreetingSettings />;
8
+ }
@@ -0,0 +1,6 @@
1
+ import type { AppTheme } from "@kumi/wow";
2
+ import { rounded, uiFont } from "../shared/api/native-art";
3
+ import { rangeSkin } from "../shared/ui/range-skin";
4
+
5
+ /** Textures, fonts and control skins for every view and window of the addon. */
6
+ export const theme: AppTheme = { rounded, fontSize: uiFont, rangeSkin };
@@ -0,0 +1,29 @@
1
+ import { api, readableApi, reveal } from "@kumi/wow";
2
+
3
+ // The api/ layer is the only place that calls WoW. Each function returns plain values.
4
+
5
+ /** The player's name. Undefined while the client keeps it hidden. */
6
+ export function readPlayerName(): string | undefined {
7
+ const [name] = readableApi.UnitName("player");
8
+ return name;
9
+ }
10
+
11
+ export function readPlayerLevel(): number {
12
+ return api.UnitLevel("player");
13
+ }
14
+
15
+ /** The player's money in copper. */
16
+ export function readMoney(): number {
17
+ return api.GetMoney();
18
+ }
19
+
20
+ /** Play an emote such as "WAVE", like typing /wave. False when the game does not allow it right now. */
21
+ export function performEmote(emote: string): boolean {
22
+ const perform = api.C_ChatInfo?.PerformEmote;
23
+ if (typeof perform === "function") return reveal(perform(emote)) === true;
24
+ // Clients without C_ChatInfo.PerformEmote still have the older global.
25
+ const legacy = (api as { DoEmote?: (this: void, token: string) => void }).DoEmote;
26
+ if (typeof legacy !== "function") return false;
27
+ legacy(emote);
28
+ return true;
29
+ }
@@ -0,0 +1,18 @@
1
+ import { Module, ModuleType } from "@kumi/core";
2
+ import { useGreetingStore } from "./model/greeting.store";
3
+ import { GreetingService } from "./services/greeting.service";
4
+ import { GreetingHud } from "./widgets/GreetingHud";
5
+
6
+ // The module file is the feature's public API: what it provides, owns, shows and exports.
7
+ export { useGreetingStore } from "./model/greeting.store";
8
+
9
+ const metadata = {
10
+ id: "greeting",
11
+ providers: [GreetingService],
12
+ stores: [useGreetingStore],
13
+ views: [GreetingHud],
14
+ exports: { greeting: GreetingService },
15
+ } as const;
16
+
17
+ @Module(metadata)
18
+ export class GreetingModule extends ModuleType<typeof metadata> {}
@@ -0,0 +1,81 @@
1
+ import { fail, ok, type Result } from "@kumi/core";
2
+ import { batch, computed, defineStore, inject, readonly, ref } from "@kumi/state";
3
+ import { useEvent } from "@kumi/wow";
4
+ import { formatMoney } from "../../../shared/lib/format";
5
+ import { GreetingService, type GreetingStyle } from "../services/greeting.service";
6
+
7
+ export type { GreetingStyle };
8
+
9
+ export interface GreetingSettings {
10
+ style: GreetingStyle;
11
+ showHud: boolean;
12
+ opacity: number;
13
+ }
14
+
15
+ export const GREETING_DEFAULTS: GreetingSettings = { style: "friendly", showHud: true, opacity: 100 };
16
+ export const OPACITY_RANGE = { min: 30, max: 100 } as const;
17
+
18
+ /**
19
+ * The greeting feature's state. Other modules use it through `useGreetingStore()`.
20
+ * Settings and the HUD position are saved in SavedVariables under "greeting".
21
+ */
22
+ export const useGreetingStore = defineStore("greeting", () => {
23
+ const greetings = inject(GreetingService);
24
+ const style = ref<GreetingStyle>(GREETING_DEFAULTS.style);
25
+ const showHud = ref(GREETING_DEFAULTS.showHud);
26
+ const opacity = ref(GREETING_DEFAULTS.opacity);
27
+ const waves = ref(0);
28
+ const x = ref(0);
29
+ const y = ref(-160);
30
+ const player = ref(greetings.player());
31
+ const copper = ref(greetings.money());
32
+ const notice = ref("");
33
+
34
+ // WoW events update the store while it is alive.
35
+ useEvent("PLAYER_MONEY", () => { copper.value = greetings.money(); });
36
+ useEvent("PLAYER_LEVEL_UP", () => { player.value = greetings.player(); });
37
+
38
+ const message = computed(() => greetings.message(style.value, player.value, waves.value));
39
+ const money = computed(() => formatMoney(copper.value));
40
+
41
+ /** Play the /wave emote and count it. */
42
+ function wave(this: void): Result<void> {
43
+ if (!greetings.wave()) {
44
+ notice.value = "You can't wave right now.";
45
+ return fail(notice.value);
46
+ }
47
+ notice.value = "";
48
+ waves.value += 1;
49
+ return ok(undefined);
50
+ }
51
+
52
+ function updateSettings(this: void, values: Partial<GreetingSettings>): Result<void> {
53
+ const next = values.opacity;
54
+ if (next !== undefined && (next < OPACITY_RANGE.min || next > OPACITY_RANGE.max)) return fail("Opacity is out of range");
55
+ // A batch saves every changed field once and restores them all if saving fails.
56
+ return batch(() => {
57
+ if (values.style !== undefined) style.value = values.style;
58
+ if (values.showHud !== undefined) showHud.value = values.showHud;
59
+ if (next !== undefined) opacity.value = Math.floor(next);
60
+ });
61
+ }
62
+
63
+ function moveHud(this: void, nextX: number, nextY: number): Result<void> {
64
+ return batch(() => {
65
+ x.value = Math.floor(nextX);
66
+ y.value = Math.floor(nextY);
67
+ });
68
+ }
69
+
70
+ function resetHud(this: void): Result<void> {
71
+ const reset = moveHud(0, -160);
72
+ return reset.ok ? updateSettings(GREETING_DEFAULTS) : reset;
73
+ }
74
+
75
+ return {
76
+ style: readonly(style), showHud: readonly(showHud), opacity: readonly(opacity), waves: readonly(waves),
77
+ x: readonly(x), y: readonly(y), player: readonly(player), notice: readonly(notice),
78
+ message, money, wave, updateSettings, moveHud, resetHud,
79
+ };
80
+ }, { persist: { pick: ["style", "showHud", "opacity", "waves", "x", "y"] } });
81
+
@@ -0,0 +1,38 @@
1
+ import { Injectable } from "@kumi/core";
2
+ import { performEmote, readMoney, readPlayerLevel, readPlayerName } from "../api/player.api";
3
+
4
+ export type GreetingStyle = "friendly" | "formal" | "pirate";
5
+
6
+ export interface Player {
7
+ readonly name: string;
8
+ readonly level: number;
9
+ }
10
+
11
+ const OPENERS: Record<GreetingStyle, string> = {
12
+ friendly: "Hi",
13
+ formal: "Good day",
14
+ pirate: "Ahoy",
15
+ };
16
+
17
+ /** Logic of the greeting feature. Stores call it; it calls the feature's api/ for WoW data. */
18
+ @Injectable()
19
+ export class GreetingService {
20
+ player(): Player {
21
+ return { name: readPlayerName() ?? "adventurer", level: readPlayerLevel() };
22
+ }
23
+
24
+ money(): number {
25
+ return readMoney();
26
+ }
27
+
28
+ /** Wave at everyone nearby. False when the game does not allow emotes right now. */
29
+ wave(): boolean {
30
+ return performEmote("WAVE");
31
+ }
32
+
33
+ message(style: GreetingStyle, player: Player, waves: number): string {
34
+ const greeting = OPENERS[style] + ", " + player.name + "!";
35
+ if (waves === 0) return greeting + " Press Wave to wave at everyone nearby.";
36
+ return greeting + " You waved " + String(waves) + (waves === 1 ? " time." : " times.");
37
+ }
38
+ }
@@ -0,0 +1,105 @@
1
+ @use "../../../shared/styles/tokens" as *;
2
+
3
+ .card {
4
+ display: flex;
5
+ flex-direction: column;
6
+ gap: 6px;
7
+ }
8
+
9
+ // Room for two lines, so the panel keeps its height when the text gets shorter.
10
+ .message {
11
+ height: 36px;
12
+ font-size: 15px;
13
+ text-align: left;
14
+ color: $text;
15
+ }
16
+
17
+ .money {
18
+ font-size: 13px;
19
+ text-align: left;
20
+ color: $gold;
21
+ }
22
+
23
+ .notice {
24
+ font-size: 12px;
25
+ text-align: left;
26
+ color: $muted;
27
+ }
28
+
29
+ .hud {
30
+ display: flex;
31
+ flex-direction: column;
32
+ gap: 10px;
33
+ width: 280px;
34
+ padding: 10px 12px 12px;
35
+ background-color: $panel;
36
+ border: 1px solid $line;
37
+ border-radius: 8px;
38
+ }
39
+
40
+ .hudHeader {
41
+ display: flex;
42
+ align-items: center;
43
+ gap: 8px;
44
+ height: 24px;
45
+ }
46
+
47
+ .hudTitle {
48
+ flex-grow: 1;
49
+ font-size: 14px;
50
+ text-align: left;
51
+ color: $muted;
52
+ }
53
+
54
+ .iconButton {
55
+ width: 26px;
56
+ min-width: 26px;
57
+ height: 24px;
58
+ }
59
+
60
+ .grip {
61
+ width: 20px;
62
+ height: 20px;
63
+ }
64
+
65
+ .footer {
66
+ display: flex;
67
+ align-items: center;
68
+ gap: 8px;
69
+ }
70
+
71
+ .spacer { flex-grow: 1; }
72
+
73
+ .settings {
74
+ display: flex;
75
+ flex-direction: column;
76
+ gap: 14px;
77
+ padding: 16px;
78
+ }
79
+
80
+ .row {
81
+ display: flex;
82
+ align-items: center;
83
+ gap: 12px;
84
+ height: 32px;
85
+ }
86
+
87
+ .rowLabel {
88
+ width: 120px;
89
+ font-size: 14px;
90
+ text-align: left;
91
+ color: $text;
92
+ }
93
+
94
+ .hint {
95
+ font-size: 13px;
96
+ text-align: left;
97
+ color: $muted;
98
+ }
99
+
100
+ .overview {
101
+ display: flex;
102
+ flex-direction: column;
103
+ gap: 14px;
104
+ padding: 16px;
105
+ }
@@ -0,0 +1,29 @@
1
+ import type { Binding, NodeRef } from "@kumi/core";
2
+ import { presets } from "@kumi/animation";
3
+ import { computed, watch, type ReadonlyRef } from "@kumi/state";
4
+ import styles from "@kumi/styles/modules/greeting/ui/Greeting";
5
+ import { useAnimation } from "@kumi/wow";
6
+
7
+ interface GreetingCardProps {
8
+ readonly message: Binding<string>;
9
+ readonly money: Binding<string>;
10
+ /** A short note under the money, such as why an action did not work. Hidden while empty. */
11
+ readonly notice: ReadonlyRef<string>;
12
+ /** Each change fades the message in again. */
13
+ readonly waves: ReadonlyRef<number>;
14
+ readonly ref?: NodeRef<"frame">;
15
+ }
16
+
17
+ /** The greeting text and the player's money. */
18
+ export function GreetingCard(props: GreetingCardProps) {
19
+ // Fade the new text in. Text uses alpha, not scale: scaling a font string stretches its glyphs.
20
+ const refresh = useAnimation(presets.fadeIn({ from: 0.25, duration: 0.3 }));
21
+ watch(() => props.waves.value, () => { refresh.play(); });
22
+ return (
23
+ <div className={styles.card} nodeRef={props.ref}>
24
+ <span className={styles.message} value={props.message} ref={refresh.ref} />
25
+ <span className={styles.money} value={props.money} />
26
+ <span className={styles.notice} value={props.notice} shown={computed(() => props.notice.value !== "")} />
27
+ </div>
28
+ );
29
+ }
@@ -0,0 +1,54 @@
1
+ import { Extensions } from "@kumi/core";
2
+ import { computed, ref, storeToRefs } from "@kumi/state";
3
+ import styles from "@kumi/styles/modules/greeting/ui/Greeting";
4
+ import { useWindow } from "@kumi/wow";
5
+ import { Button } from "../../../shared/ui/Button";
6
+ import { Glyph } from "../../../shared/ui/Glyph";
7
+ import { useGreetingStore } from "../model/greeting.store";
8
+ import { GreetingCard } from "../ui/GreetingCard";
9
+
10
+ /**
11
+ * The on-screen panel. The greeting module lists it in `views`, so Kumi mounts it while the module runs.
12
+ * Plugins add rows to its footer through the "hud.footer" extension point.
13
+ */
14
+ export function GreetingHud() {
15
+ const greeting = useGreetingStore();
16
+ const window = useWindow();
17
+ const { message, money, notice, opacity, showHud, waves, x, y } = storeToRefs(greeting);
18
+ const dragging = ref<{ x: number; y: number } | undefined>(undefined);
19
+
20
+ function move(dx: number, dy: number) {
21
+ dragging.value = { x: greeting.x + dx, y: greeting.y + dy };
22
+ }
23
+
24
+ function drop(dx: number, dy: number) {
25
+ dragging.value = undefined;
26
+ greeting.moveHud(greeting.x + dx, greeting.y + dy);
27
+ }
28
+
29
+ const anchor = computed(() => {
30
+ const preview = dragging.value;
31
+ return { point: "TOP" as const, x: preview?.x ?? x.value, y: preview?.y ?? y.value };
32
+ });
33
+
34
+ return (
35
+ <div className={styles.hud} anchor={anchor} shown={showHud} opacity={computed(() => opacity.value / 100)}>
36
+ <div className={styles.hudHeader}>
37
+ <button unstyled className={styles.grip} ariaLabel="Move" onMove={move} onMoveEnd={drop}
38
+ onMoveCancel={() => { dragging.value = undefined; }}>
39
+ <Glyph name="Grip" />
40
+ </button>
41
+ <span className={styles.hudTitle} value="__ADDON_NAME__" />
42
+ <Button className={styles.iconButton} accessibleLabel="Settings" onClick={() => { window.toggle(); }}>
43
+ <Glyph name="Gear" />
44
+ </Button>
45
+ </div>
46
+ <GreetingCard message={message} money={money} waves={waves} notice={notice} />
47
+ <div className={styles.footer}>
48
+ <Button primary label="Wave" onClick={greeting.wave} />
49
+ <div className={styles.spacer} />
50
+ <Extensions name="hud.footer" />
51
+ </div>
52
+ </div>
53
+ );
54
+ }
@@ -0,0 +1,18 @@
1
+ import { storeToRefs } from "@kumi/state";
2
+ import styles from "@kumi/styles/modules/greeting/ui/Greeting";
3
+ import { Button } from "../../../shared/ui/Button";
4
+ import { useGreetingStore } from "../model/greeting.store";
5
+ import { GreetingCard } from "../ui/GreetingCard";
6
+
7
+ /** The window's home page content. */
8
+ export function GreetingOverview() {
9
+ const greeting = useGreetingStore();
10
+ const { message, money, notice, waves } = storeToRefs(greeting);
11
+ return (
12
+ <div className={styles.overview}>
13
+ <GreetingCard message={message} money={money} waves={waves} notice={notice} />
14
+ <Button primary label="Wave" onClick={greeting.wave} />
15
+ <span className={styles.hint} value="Drag the grip on the panel to move it. Type /__ADDON_SLASH__ to open this window." />
16
+ </div>
17
+ );
18
+ }
@@ -0,0 +1,56 @@
1
+ import { Form, useForm, type FormIssue } from "@kumi/form";
2
+ import { computed } from "@kumi/state";
3
+ import styles from "@kumi/styles/modules/greeting/ui/Greeting";
4
+ import { Button } from "../../../shared/ui/Button";
5
+ import { Choice } from "../../../shared/ui/Choice";
6
+ import { Slider } from "../../../shared/ui/Slider";
7
+ import { Toggle } from "../../../shared/ui/Toggle";
8
+ import { GREETING_DEFAULTS, OPACITY_RANGE, useGreetingStore, type GreetingSettings as Settings, type GreetingStyle } from "../model/greeting.store";
9
+
10
+ const STYLES: readonly { value: GreetingStyle; label: string }[] = [
11
+ { value: "friendly", label: "Friendly" },
12
+ { value: "formal", label: "Formal" },
13
+ { value: "pirate", label: "Pirate" },
14
+ ];
15
+
16
+ function validate(this: void, values: Readonly<Settings>): readonly FormIssue[] {
17
+ const issues: FormIssue[] = [];
18
+ if (values.opacity < OPACITY_RANGE.min || values.opacity > OPACITY_RANGE.max) {
19
+ issues.push({ path: ["opacity"], message: "Opacity must be between " + OPACITY_RANGE.min + " and " + OPACITY_RANGE.max + "." });
20
+ }
21
+ return issues;
22
+ }
23
+
24
+ /** Settings bound to the greeting store. Each valid change saves right away. */
25
+ export function GreetingSettings() {
26
+ const greeting = useGreetingStore();
27
+ const form = useForm<Settings>({
28
+ defaultValues: GREETING_DEFAULTS,
29
+ values: greeting,
30
+ commit: greeting.updateSettings,
31
+ validate,
32
+ });
33
+ const status = computed(() => form.issues.value[0]?.message ?? "Changes are saved as you make them.");
34
+ return (
35
+ <Form form={form}>
36
+ {() => (
37
+ <div className={styles.settings}>
38
+ <div className={styles.row}>
39
+ <span className={styles.rowLabel} value="Greeting" />
40
+ <Choice {...form.register("style")} options={STYLES} />
41
+ </div>
42
+ <div className={styles.row}>
43
+ <span className={styles.rowLabel} value="Show panel" />
44
+ <Toggle {...form.register("showHud")} label="Show panel" />
45
+ </div>
46
+ <div className={styles.row}>
47
+ <span className={styles.rowLabel} value="Opacity" />
48
+ <Slider {...form.register("opacity")} label="Opacity" min={OPACITY_RANGE.min} max={OPACITY_RANGE.max} step={5} />
49
+ </div>
50
+ <span className={styles.hint} value={status} />
51
+ <Button label="Reset panel" onClick={() => { greeting.resetHud(); form.revert(); }} />
52
+ </div>
53
+ )}
54
+ </Form>
55
+ );
56
+ }
@@ -0,0 +1,6 @@
1
+ import { api } from "@kumi/wow";
2
+
3
+ /** Seconds since the client started. Differences measure elapsed time. */
4
+ export function readGameTime(): number {
5
+ return api.GetTime();
6
+ }
@@ -0,0 +1,19 @@
1
+ import { computed, defineStore, inject, readonly, ref } from "@kumi/state";
2
+ import { useEvent, useNow } from "@kumi/wow";
3
+ import { PlaytimeService } from "../services/playtime.service";
4
+
5
+ export const usePlaytimeStore = defineStore("playtime", () => {
6
+ const clock = inject(PlaytimeService);
7
+ const start = clock.now();
8
+ const now = useNow(1);
9
+ const longest = ref(0);
10
+ // Inside a setup, computed values hold a Result. Share plain functions between them instead.
11
+ const elapsed = () => clock.elapsed(start, now.value);
12
+ const session = computed(elapsed);
13
+ const best = computed(() => clock.record(longest.value, elapsed()));
14
+
15
+ // Save the record when the player logs out or reloads, not every second.
16
+ useEvent("PLAYER_LOGOUT", () => { longest.value = clock.record(longest.value, elapsed()); });
17
+
18
+ return { session, best, longest: readonly(longest) };
19
+ }, { persist: { pick: ["longest"] } });
@@ -0,0 +1,18 @@
1
+ import { Module, ModuleType } from "@kumi/core";
2
+ import { usePlaytimeStore } from "./model/playtime.store";
3
+ import { PlaytimeService } from "./services/playtime.service";
4
+ import { PlaytimeBadge } from "./ui/PlaytimeBadge";
5
+ import { PlaytimePage } from "./widgets/PlaytimePage";
6
+
7
+ // A plugin: kumi.config.ts lists this module under plugins, so it builds as its own addon.
8
+ const metadata = {
9
+ id: "playtime",
10
+ providers: [PlaytimeService],
11
+ stores: [usePlaytimeStore],
12
+ extensions: { "hud.footer": PlaytimeBadge },
13
+ pages: [{ path: "/playtime", title: "Playtime", component: PlaytimePage, order: 20 }],
14
+ exports: {},
15
+ } as const;
16
+
17
+ @Module(metadata)
18
+ export class PlaytimeModule extends ModuleType<typeof metadata> {}
@@ -0,0 +1,18 @@
1
+ import { Injectable } from "@kumi/core";
2
+ import { readGameTime } from "../api/clock.api";
3
+
4
+ @Injectable()
5
+ export class PlaytimeService {
6
+ now(): number {
7
+ return readGameTime();
8
+ }
9
+
10
+ elapsed(start: number, now: number): number {
11
+ return Math.max(0, now - start);
12
+ }
13
+
14
+ /** The longer of the saved record and this session. */
15
+ record(longest: number, session: number): number {
16
+ return Math.max(longest, Math.floor(session));
17
+ }
18
+ }
@@ -0,0 +1,25 @@
1
+ @use "../../../shared/styles/tokens" as *;
2
+
3
+ .badge {
4
+ font-size: 13px;
5
+ color: $muted;
6
+ }
7
+
8
+ .page {
9
+ display: flex;
10
+ flex-direction: column;
11
+ gap: 10px;
12
+ padding: 16px;
13
+ }
14
+
15
+ .big {
16
+ font-size: 28px;
17
+ text-align: left;
18
+ color: $gold;
19
+ }
20
+
21
+ .note {
22
+ font-size: 13px;
23
+ text-align: left;
24
+ color: $muted;
25
+ }
@@ -0,0 +1,10 @@
1
+ import { computed } from "@kumi/state";
2
+ import styles from "@kumi/styles/modules/playtime/ui/Playtime";
3
+ import { formatDuration } from "../../../shared/lib/format";
4
+ import { usePlaytimeStore } from "../model/playtime.store";
5
+
6
+ /** Session time, shown in the greeting panel's footer. */
7
+ export function PlaytimeBadge() {
8
+ const playtime = usePlaytimeStore();
9
+ return <span className={styles.badge} value={computed(() => formatDuration(playtime.session))} />;
10
+ }
@@ -0,0 +1,16 @@
1
+ import { computed } from "@kumi/state";
2
+ import styles from "@kumi/styles/modules/playtime/ui/Playtime";
3
+ import { formatDuration } from "../../../shared/lib/format";
4
+ import { usePlaytimeStore } from "../model/playtime.store";
5
+
6
+ /** A window page added by the plugin. It disappears when the plugin is turned off. */
7
+ export function PlaytimePage() {
8
+ const playtime = usePlaytimeStore();
9
+ return (
10
+ <div className={styles.page}>
11
+ <span className={styles.note} value="This session" />
12
+ <span className={styles.big} value={computed(() => formatDuration(playtime.session))} />
13
+ <span className={styles.note} value={computed(() => "Longest session: " + formatDuration(playtime.best))} />
14
+ </div>
15
+ );
16
+ }
@@ -0,0 +1,28 @@
1
+ import { api, createLocaleFont, createRoundedTextures } from "@kumi/wow";
2
+
3
+ // Textures shipped in Assets/Art. The build copies the folder next to the addon's Lua.
4
+ const base = "Interface\\AddOns\\__ADDON_NAME__\\Assets\\Art\\";
5
+ const white = "Interface\\Buttons\\WHITE8X8";
6
+
7
+ export function artwork(name: string) {
8
+ return { path: base + name + ".tga" };
9
+ }
10
+
11
+ /** Rounded corners and borders drawn from the art in Assets/Art. */
12
+ export const rounded = createRoundedTextures({
13
+ resolveArt: (radius, border) => radius === 0 ? (border ? undefined : white)
14
+ : artwork("Round" + String(radius) + (border ? "Border" : "")).path,
15
+ resolveBorderOutline(radius) {
16
+ if (radius < 2 || radius > 15) return undefined;
17
+ return artwork(radius === 4 || radius === 6 || radius === 8 || radius === 11
18
+ ? "Round" + String(radius) + "Border" : "Outline" + String(radius)).path;
19
+ },
20
+ resolveBorderCorner: radius => radius >= 2 && radius <= 16
21
+ ? { asset: artwork("Corner" + String(radius)).path, extent: radius / 32 } : undefined,
22
+ fallback: () => white,
23
+ radii: [4, 6, 8, 11],
24
+ stretched: api.Enum.UITextureSliceMode.Stretched,
25
+ });
26
+
27
+ /** The UI font, with the right glyphs for the client's locale. */
28
+ export const uiFont = createLocaleFont("Fonts\\ARIALN.TTF");