@overmvp/kumi 0.0.0-stage → 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 (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -2
  3. package/animation/color-transition.ts +196 -0
  4. package/animation/cycle.ts +151 -0
  5. package/animation/ease.ts +29 -0
  6. package/animation/index.ts +13 -0
  7. package/animation/package.json +12 -0
  8. package/animation/presets.ts +376 -0
  9. package/animation/spec.ts +197 -0
  10. package/builder/Cargo.lock +192 -0
  11. package/builder/Cargo.toml +7 -0
  12. package/builder/css-v1.mjs +387 -0
  13. package/builder/css-v1.test.mjs +361 -0
  14. package/builder/generated-output.mjs +61 -0
  15. package/builder/generated-output.test.mjs +132 -0
  16. package/builder/jsx-form.mjs +93 -0
  17. package/builder/jsx-form.test.mjs +48 -0
  18. package/builder/jsx-lists.mjs +209 -0
  19. package/builder/link-addon-package.mjs +127 -0
  20. package/builder/lua-assets.mjs +74 -0
  21. package/builder/lua-builtin-values.mjs +57 -0
  22. package/builder/lua-builtin-values.test.mjs +155 -0
  23. package/builder/lua-loop-closures.mjs +183 -0
  24. package/builder/lua-loop-closures.test.mjs +89 -0
  25. package/builder/lua-truthiness.mjs +61 -0
  26. package/builder/lua-truthiness.test.mjs +113 -0
  27. package/builder/module-declarations.mjs +594 -0
  28. package/builder/module-declarations.test.mjs +435 -0
  29. package/builder/native-kernels.mjs +60 -0
  30. package/builder/native-lua.d.ts +57 -0
  31. package/builder/native-routes.mjs +51 -0
  32. package/builder/no-static-ref-read.mjs +93 -0
  33. package/builder/no-static-ref-read.test.mjs +181 -0
  34. package/builder/secure-snippet.mjs +317 -0
  35. package/builder/secure-snippet.test.mjs +101 -0
  36. package/builder/shared-lua-runtime.mjs +150 -0
  37. package/builder/src/addon-link.lua +29 -0
  38. package/builder/src/arrays.lua +260 -0
  39. package/builder/src/assets.rs +177 -0
  40. package/builder/src/classes.lua +75 -0
  41. package/builder/src/collections.lua +190 -0
  42. package/builder/src/compiler.rs +2336 -0
  43. package/builder/src/config.rs +42 -0
  44. package/builder/src/entries.rs +166 -0
  45. package/builder/src/errors.lua +15 -0
  46. package/builder/src/lua_data.rs +231 -0
  47. package/builder/src/main.rs +381 -0
  48. package/builder/src/native_ir.rs +65 -0
  49. package/builder/src/native_signal.rs +83 -0
  50. package/builder/src/numbers.lua +76 -0
  51. package/builder/src/project-front.mjs +3682 -0
  52. package/builder/src/records.lua +75 -0
  53. package/builder/src/routes.rs +124 -0
  54. package/builder/src/setup-store.lua +18 -0
  55. package/builder/src/signal-kernel.fingerprint +1 -0
  56. package/builder/src/strings.lua +103 -0
  57. package/builder/src/ts-lower.mjs +68 -0
  58. package/builder/src/wow-reads.lua +22 -0
  59. package/builder/src/wow_client.rs +253 -0
  60. package/builder/src/wow_types.rs +564 -0
  61. package/builder/style-modules.mjs +93 -0
  62. package/builder/style-states.mjs +100 -0
  63. package/builder/style-states.test.mjs +103 -0
  64. package/builder/vite-assets.mjs +53 -0
  65. package/builder/vite-project.mjs +10 -0
  66. package/config.ts +59 -0
  67. package/eslint.mjs +74 -0
  68. package/form/index.ts +526 -0
  69. package/form/package.json +13 -0
  70. package/motion/index.ts +2 -0
  71. package/motion/package.json +10 -0
  72. package/package.json +26 -4
  73. package/router/index.ts +50 -0
  74. package/router/navigation.ts +22 -0
  75. package/router/package.json +12 -0
  76. package/router/router-view.ts +134 -0
  77. package/router/routes.ts +64 -0
  78. package/scripts/addon-build.mjs +364 -0
  79. package/scripts/addon-project.mjs +78 -0
  80. package/scripts/kumi-cli.mjs +105 -0
  81. package/scripts/link-addons.mjs +61 -0
  82. package/src/bindings.ts +35 -0
  83. package/src/context.ts +15 -0
  84. package/src/css-tokens.ts +239 -0
  85. package/src/css-v1.ts +68 -0
  86. package/src/cvars.ts +91 -0
  87. package/src/element-node.ts +32 -0
  88. package/src/elements.ts +505 -0
  89. package/src/feature-scope.ts +82 -0
  90. package/src/flex-layout.ts +807 -0
  91. package/src/frame-scheduler.ts +336 -0
  92. package/src/grid-tracks.ts +165 -0
  93. package/src/image-imports.d.ts +24 -0
  94. package/src/images.ts +79 -0
  95. package/src/index.ts +29 -0
  96. package/src/jsx-dev-runtime.ts +2 -0
  97. package/src/jsx-runtime.ts +29 -0
  98. package/src/jsx.d.ts +12 -0
  99. package/src/keyed-list.ts +366 -0
  100. package/src/media-query.ts +144 -0
  101. package/src/module-ui.ts +147 -0
  102. package/src/module.ts +311 -0
  103. package/src/node-selectors.ts +114 -0
  104. package/src/owned-collections.ts +52 -0
  105. package/src/providers.ts +241 -0
  106. package/src/reactive-scope.ts +34 -0
  107. package/src/reactivity.ts +275 -0
  108. package/src/result.ts +64 -0
  109. package/src/runtime.ts +52 -0
  110. package/src/scheduler.ts +185 -0
  111. package/src/signal-kernel.ts +63 -0
  112. package/src/style-classes.ts +51 -0
  113. package/src/style-states.ts +134 -0
  114. package/src/style-variables.ts +53 -0
  115. package/src/text-children.ts +42 -0
  116. package/src/theme.ts +50 -0
  117. package/src/transition.ts +18 -0
  118. package/state/index.ts +9 -0
  119. package/state/package.json +12 -0
  120. package/state/setup-store-persistence.ts +206 -0
  121. package/state/setup-store-view.ts +10 -0
  122. package/state/setup-store.ts +342 -0
  123. package/state/store-bindings.ts +25 -0
  124. package/state/store.ts +84 -0
  125. package/styles/_layers.scss +14 -0
  126. package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
  127. package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
  128. package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
  129. package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
  130. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
  131. package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
  132. package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
  133. package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
  134. package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
  135. package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
  136. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
  137. package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
  138. package/templates/addon/AGENTS.md +34 -0
  139. package/templates/addon/Assets/Art/Corner10.tga +0 -0
  140. package/templates/addon/Assets/Art/Corner11.tga +0 -0
  141. package/templates/addon/Assets/Art/Corner12.tga +0 -0
  142. package/templates/addon/Assets/Art/Corner13.tga +0 -0
  143. package/templates/addon/Assets/Art/Corner14.tga +0 -0
  144. package/templates/addon/Assets/Art/Corner15.tga +0 -0
  145. package/templates/addon/Assets/Art/Corner16.tga +0 -0
  146. package/templates/addon/Assets/Art/Corner2.tga +0 -0
  147. package/templates/addon/Assets/Art/Corner3.tga +0 -0
  148. package/templates/addon/Assets/Art/Corner4.tga +0 -0
  149. package/templates/addon/Assets/Art/Corner5.tga +0 -0
  150. package/templates/addon/Assets/Art/Corner6.tga +0 -0
  151. package/templates/addon/Assets/Art/Corner7.tga +0 -0
  152. package/templates/addon/Assets/Art/Corner8.tga +0 -0
  153. package/templates/addon/Assets/Art/Corner9.tga +0 -0
  154. package/templates/addon/Assets/Art/Dot.tga +0 -0
  155. package/templates/addon/Assets/Art/Gear.tga +0 -0
  156. package/templates/addon/Assets/Art/Grip.tga +0 -0
  157. package/templates/addon/Assets/Art/Outline10.tga +0 -0
  158. package/templates/addon/Assets/Art/Outline12.tga +0 -0
  159. package/templates/addon/Assets/Art/Outline13.tga +0 -0
  160. package/templates/addon/Assets/Art/Outline14.tga +0 -0
  161. package/templates/addon/Assets/Art/Outline15.tga +0 -0
  162. package/templates/addon/Assets/Art/Outline2.tga +0 -0
  163. package/templates/addon/Assets/Art/Outline3.tga +0 -0
  164. package/templates/addon/Assets/Art/Outline5.tga +0 -0
  165. package/templates/addon/Assets/Art/Outline7.tga +0 -0
  166. package/templates/addon/Assets/Art/Outline9.tga +0 -0
  167. package/templates/addon/Assets/Art/Round11.tga +0 -0
  168. package/templates/addon/Assets/Art/Round11Border.tga +0 -0
  169. package/templates/addon/Assets/Art/Round4.tga +0 -0
  170. package/templates/addon/Assets/Art/Round4Border.tga +0 -0
  171. package/templates/addon/Assets/Art/Round6.tga +0 -0
  172. package/templates/addon/Assets/Art/Round6Border.tga +0 -0
  173. package/templates/addon/Assets/Art/Round8.tga +0 -0
  174. package/templates/addon/Assets/Art/Round8Border.tga +0 -0
  175. package/templates/addon/Assets/Art/Search.tga +0 -0
  176. package/templates/addon/CLAUDE.md +1 -0
  177. package/templates/addon/README.md +49 -0
  178. package/templates/addon/eslint.config.mjs +6 -0
  179. package/templates/addon/gitignore +9 -0
  180. package/templates/addon/kumi.config.ts +17 -0
  181. package/templates/addon/package.json +20 -0
  182. package/templates/addon/src/app/app.module.ts +18 -0
  183. package/templates/addon/src/app/commands.store.ts +11 -0
  184. package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
  185. package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
  186. package/templates/addon/src/app/main.ts +5 -0
  187. package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
  188. package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
  189. package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
  190. package/templates/addon/src/app/theme.ts +6 -0
  191. package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
  192. package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
  193. package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
  194. package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
  195. package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
  196. package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
  197. package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
  198. package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
  199. package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
  200. package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
  201. package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
  202. package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
  203. package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
  204. package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
  205. package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
  206. package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
  207. package/templates/addon/src/shared/api/native-art.ts +28 -0
  208. package/templates/addon/src/shared/assets/close.png +0 -0
  209. package/templates/addon/src/shared/lib/format.ts +20 -0
  210. package/templates/addon/src/shared/styles/_tokens.scss +12 -0
  211. package/templates/addon/src/shared/ui/Button.tsx +29 -0
  212. package/templates/addon/src/shared/ui/Choice.tsx +34 -0
  213. package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
  214. package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
  215. package/templates/addon/src/shared/ui/Slider.tsx +25 -0
  216. package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
  217. package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
  218. package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
  219. package/templates/addon/tsconfig.json +63 -0
  220. package/translate/index.ts +14 -0
  221. package/translate/package.json +9 -0
  222. package/utils/colors.ts +76 -0
  223. package/utils/format.ts +37 -0
  224. package/utils/index.ts +4 -0
  225. package/utils/number.ts +17 -0
  226. package/utils/package.json +7 -0
  227. package/utils/text.ts +6 -0
  228. package/validate/index.ts +119 -0
  229. package/validate/package.json +9 -0
  230. package/wow/absolute-position.ts +142 -0
  231. package/wow/action-bar-layout.ts +108 -0
  232. package/wow/action-button.ts +219 -0
  233. package/wow/action-catalog.ts +98 -0
  234. package/wow/addon-manifest.ts +36 -0
  235. package/wow/animation.ts +428 -0
  236. package/wow/app-ui.ts +221 -0
  237. package/wow/aura-button.ts +76 -0
  238. package/wow/aura-container.ts +591 -0
  239. package/wow/aura-countdown.ts +201 -0
  240. package/wow/aura-slot.ts +153 -0
  241. package/wow/bar-shade.ts +93 -0
  242. package/wow/borrowed-slot.ts +216 -0
  243. package/wow/button-drag.ts +48 -0
  244. package/wow/cast-clock.ts +153 -0
  245. package/wow/cast-text.ts +83 -0
  246. package/wow/class-colors.ts +126 -0
  247. package/wow/clock.ts +7 -0
  248. package/wow/color-picker.ts +128 -0
  249. package/wow/commands.ts +17 -0
  250. package/wow/contained-frame.ts +128 -0
  251. package/wow/contract.ts +42 -0
  252. package/wow/cooldown-timing.ts +24 -0
  253. package/wow/css-box.ts +144 -0
  254. package/wow/css-color.ts +12 -0
  255. package/wow/css-style.ts +109 -0
  256. package/wow/css-surfaces.ts +603 -0
  257. package/wow/css-text.ts +399 -0
  258. package/wow/cursor.ts +45 -0
  259. package/wow/cvar-schema.ts +32 -0
  260. package/wow/cvars.ts +98 -0
  261. package/wow/dropdown-art.ts +39 -0
  262. package/wow/element-click.ts +20 -0
  263. package/wow/element-event-coordinator.ts +219 -0
  264. package/wow/element-events.ts +317 -0
  265. package/wow/event-dispatcher.ts +151 -0
  266. package/wow/events.ts +50 -0
  267. package/wow/font-cache.ts +92 -0
  268. package/wow/frame-access.ts +53 -0
  269. package/wow/frame-layer.ts +5 -0
  270. package/wow/frame-timing.ts +13 -0
  271. package/wow/frames.ts +236 -0
  272. package/wow/heal-prediction.ts +305 -0
  273. package/wow/hooks.ts +133 -0
  274. package/wow/image-layers.ts +55 -0
  275. package/wow/index.ts +111 -0
  276. package/wow/layout-view.ts +663 -0
  277. package/wow/locale-font.ts +15 -0
  278. package/wow/lua-string.ts +18 -0
  279. package/wow/lua-table.ts +18 -0
  280. package/wow/macro-book.ts +84 -0
  281. package/wow/map-position.ts +27 -0
  282. package/wow/media-query.ts +65 -0
  283. package/wow/module-events.ts +11 -0
  284. package/wow/native-hooks.ts +168 -0
  285. package/wow/native-placement.ts +88 -0
  286. package/wow/native.ts +153 -0
  287. package/wow/number-format.ts +8 -0
  288. package/wow/number-input.ts +10 -0
  289. package/wow/panel-host.ts +97 -0
  290. package/wow/pixel.ts +35 -0
  291. package/wow/plugins.ts +246 -0
  292. package/wow/protect.ts +48 -0
  293. package/wow/protected-layout.ts +133 -0
  294. package/wow/protected-view.ts +103 -0
  295. package/wow/range-art.ts +81 -0
  296. package/wow/readable-api.ts +120 -0
  297. package/wow/reparent-frame.ts +99 -0
  298. package/wow/rounded-texture.ts +183 -0
  299. package/wow/saved-variables.ts +109 -0
  300. package/wow/scroll-view.ts +64 -0
  301. package/wow/secret-ref.ts +14 -0
  302. package/wow/secure-bindings.ts +89 -0
  303. package/wow/secure-clicks.ts +432 -0
  304. package/wow/secure-snippet.ts +235 -0
  305. package/wow/secure-state.ts +130 -0
  306. package/wow/secure-target-visibility.ts +89 -0
  307. package/wow/secure-transaction.ts +331 -0
  308. package/wow/special-window.ts +269 -0
  309. package/wow/spell-cooldown.ts +36 -0
  310. package/wow/start-addon.ts +122 -0
  311. package/wow/state-paint.ts +256 -0
  312. package/wow/transition.ts +86 -0
  313. package/wow/unit-button.ts +39 -0
  314. package/wow/unit-cast.ts +92 -0
  315. package/wow/unit-health-text.ts +47 -0
  316. package/wow/view-nodes.ts +304 -0
  317. package/wow/view.ts +1864 -0
  318. package/wow/visible-frame-job.ts +34 -0
  319. package/wow/width-reserve.ts +108 -0
@@ -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");
@@ -0,0 +1,20 @@
1
+ /** Format seconds as 1:05 or 1:02:05. */
2
+ export function formatDuration(seconds: number): string {
3
+ const total = Math.max(0, Math.floor(seconds));
4
+ const hours = Math.floor(total / 3600);
5
+ const minutes = Math.floor((total % 3600) / 60);
6
+ const rest = total % 60;
7
+ const pad = (value: number) => value < 10 ? "0" + String(value) : String(value);
8
+ return hours > 0 ? String(hours) + ":" + pad(minutes) + ":" + pad(rest) : String(minutes) + ":" + pad(rest);
9
+ }
10
+
11
+ /** Format copper as 12g 34s 56c, leaving out empty leading units. */
12
+ export function formatMoney(copper: number): string {
13
+ const value = Math.max(0, Math.floor(copper));
14
+ const gold = Math.floor(value / 10000);
15
+ const silver = Math.floor((value % 10000) / 100);
16
+ const rest = value % 100;
17
+ if (gold > 0) return String(gold) + "g " + String(silver) + "s " + String(rest) + "c";
18
+ if (silver > 0) return String(silver) + "s " + String(rest) + "c";
19
+ return String(rest) + "c";
20
+ }
@@ -0,0 +1,12 @@
1
+ // Design tokens shared by every stylesheet. Import with `@use "../styles/tokens" as *;`.
2
+ $panel: #101721;
3
+ $header: #17212e;
4
+ $control: #1b2533;
5
+ $raised: #263345;
6
+ $line: #405168;
7
+ $edge: #536682;
8
+ $text: #edf2fb;
9
+ $muted: #a7bdd3;
10
+ $gold: #efbf68;
11
+ $gold-dark: #936222;
12
+ $selected: #483921;
@@ -0,0 +1,29 @@
1
+ import type { Binding, NodeRef, StyleClass, UINode } from "@kumi/core";
2
+ import styles from "@kumi/styles/shared/ui/Controls";
3
+
4
+ interface ButtonProps {
5
+ readonly label?: Binding<string>;
6
+ /** The name screen readers and tooltips use when the button shows only an icon. */
7
+ readonly accessibleLabel?: string;
8
+ readonly checked?: Binding<boolean>;
9
+ readonly disabled?: Binding<boolean>;
10
+ readonly shown?: Binding<boolean>;
11
+ readonly primary?: boolean;
12
+ /** One extra class for this button, added after the base style. */
13
+ readonly className?: string | StyleClass;
14
+ readonly children?: UINode;
15
+ readonly ref?: NodeRef<"button">;
16
+ onClick(this: void): void;
17
+ }
18
+
19
+ /** A text or icon button. Pass `label` for text, or children for an icon. */
20
+ export function Button(props: ButtonProps) {
21
+ const base = props.primary === true ? styles.primary : styles.button;
22
+ const ariaLabel = props.accessibleLabel ?? (typeof props.label === "string" ? props.label : undefined);
23
+ return (
24
+ <button unstyled ariaLabel={ariaLabel} checked={props.checked} disabled={props.disabled} shown={props.shown}
25
+ className={props.className === undefined ? base : [base, props.className]} nodeRef={props.ref} onClick={props.onClick}>
26
+ {props.label === undefined ? props.children : <span className={styles.label} value={props.label} />}
27
+ </button>
28
+ );
29
+ }
@@ -0,0 +1,34 @@
1
+ import type { Binding, FocusRef } from "@kumi/core";
2
+ import { computed, type ReadonlyRef } from "@kumi/state";
3
+ import styles from "@kumi/styles/shared/ui/Controls";
4
+ import { Button } from "./Button";
5
+
6
+ export interface ChoiceOption<Value extends string> {
7
+ readonly value: Value;
8
+ readonly label: string;
9
+ }
10
+
11
+ interface ChoiceProps<Value extends string> {
12
+ readonly options: readonly ChoiceOption<Value>[];
13
+ readonly value: ReadonlyRef<Value>;
14
+ readonly disabled?: Binding<boolean>;
15
+ readonly ref?: FocusRef;
16
+ onChange(this: void, value: Value): void;
17
+ onBlur?(this: void): void;
18
+ }
19
+
20
+ /** A row of buttons for picking one value. */
21
+ export function Choice<Value extends string>(props: ChoiceProps<Value>) {
22
+ function pick(value: Value) {
23
+ props.onChange(value);
24
+ props.onBlur?.();
25
+ }
26
+ return (
27
+ <div className={styles.choice}>
28
+ {props.options.map(option => (
29
+ <Button key={option.value} label={option.label} disabled={props.disabled}
30
+ checked={computed(() => props.value.value === option.value)} onClick={() => pick(option.value)} />
31
+ ))}
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1,93 @@
1
+ @use "../styles/tokens" as *;
2
+
3
+ .button {
4
+ height: 28px;
5
+ min-width: 72px;
6
+ border: 1px solid $line;
7
+ border-radius: 4px;
8
+ background-color: $control;
9
+ font-size: 14px;
10
+ color: $text;
11
+ }
12
+
13
+ .button:hover { background-color: $raised; }
14
+ .button:checked { background-color: $selected; border-color: $gold; }
15
+ .button:disabled { opacity: 0.55; }
16
+
17
+ .primary {
18
+ height: 28px;
19
+ min-width: 96px;
20
+ border: 1px solid $gold;
21
+ border-radius: 4px;
22
+ background-color: $gold-dark;
23
+ font-size: 14px;
24
+ color: $text;
25
+ }
26
+
27
+ .primary:hover { background-color: #ad7528; }
28
+ .primary:disabled { opacity: 0.55; }
29
+
30
+ .label {
31
+ position: absolute;
32
+ inset: 0 6px;
33
+ text-align: center;
34
+ }
35
+
36
+ .glyph {
37
+ width: 16px;
38
+ height: 16px;
39
+ color: $muted;
40
+ }
41
+
42
+ .switch {
43
+ width: 46px;
44
+ height: 22px;
45
+ border: 1px solid $edge;
46
+ border-radius: 11px;
47
+ background-color: $control;
48
+ }
49
+
50
+ .switch:checked { border-color: $gold; background-color: $selected; }
51
+ .switch:disabled { opacity: 0.55; }
52
+
53
+ .knobOff, .knobOn {
54
+ position: absolute;
55
+ top: 3px;
56
+ width: 16px;
57
+ height: 16px;
58
+ }
59
+
60
+ .knobOff { left: 3px; color: $muted; }
61
+ .knobOn { right: 3px; color: $gold; }
62
+
63
+ .choice {
64
+ display: flex;
65
+ gap: 6px;
66
+ }
67
+
68
+ .slider {
69
+ width: 220px;
70
+ height: 24px;
71
+ }
72
+
73
+ .track {
74
+ height: 6px;
75
+ background-color: $line;
76
+ }
77
+
78
+ .fill {
79
+ height: 6px;
80
+ background-color: $gold;
81
+ }
82
+
83
+ .thumb {
84
+ width: 16px;
85
+ height: 16px;
86
+ color: $gold;
87
+ }
88
+
89
+ .sliderCaption {
90
+ text-align: left;
91
+ font-size: 13px;
92
+ color: $muted;
93
+ }
@@ -0,0 +1,18 @@
1
+ import type { ClassNames, NodeRef } from "@kumi/core";
2
+ import styles from "@kumi/styles/shared/ui/Controls";
3
+ import { artwork } from "../api/native-art";
4
+ import closeIcon from "../assets/close.png";
5
+
6
+ export type GlyphName = "Close" | "Gear" | "Grip" | "Dot" | "Search";
7
+
8
+ interface GlyphProps {
9
+ readonly name: GlyphName;
10
+ readonly className?: ClassNames;
11
+ readonly ref?: NodeRef<"image">;
12
+ }
13
+
14
+ /** A small icon from Assets/Art. Size and color it with a class. */
15
+ export function Glyph(props: GlyphProps) {
16
+ const source = props.name === "Close" ? closeIcon : artwork(props.name);
17
+ return <image src={source} className={props.className ?? styles.glyph} nodeRef={props.ref} nativePixelSnap={false} />;
18
+ }
@@ -0,0 +1,25 @@
1
+ import type { Binding, FocusRef } from "@kumi/core";
2
+ import type { ReadonlyRef } from "@kumi/state";
3
+ import styles from "@kumi/styles/shared/ui/Controls";
4
+ import { focusNodeRef } from "./focus-ref";
5
+
6
+ interface SliderProps {
7
+ readonly label: string;
8
+ readonly value: ReadonlyRef<number>;
9
+ readonly min: number;
10
+ readonly max: number;
11
+ readonly step?: number;
12
+ readonly disabled?: Binding<boolean>;
13
+ readonly ref?: FocusRef;
14
+ onChange(this: void, value: number): void;
15
+ onBlur?(this: void): void;
16
+ }
17
+
18
+ /** A range slider. The app theme draws its track and thumb. */
19
+ export function Slider(props: SliderProps) {
20
+ return (
21
+ <input type="range" hideLabel className={styles.slider} label={props.label} min={props.min} max={props.max} step={props.step}
22
+ value={props.value} disabled={props.disabled} nodeRef={focusNodeRef<"range">(props.ref)}
23
+ onChange={props.onChange} onCommit={props.onBlur} />
24
+ );
25
+ }
@@ -0,0 +1,29 @@
1
+ import type { Binding, FocusRef } from "@kumi/core";
2
+ import { computed, type ReadonlyRef } from "@kumi/state";
3
+ import styles from "@kumi/styles/shared/ui/Controls";
4
+ import { artwork } from "../api/native-art";
5
+ import { focusNodeRef } from "./focus-ref";
6
+
7
+ interface ToggleProps {
8
+ readonly label: string;
9
+ readonly value: ReadonlyRef<boolean>;
10
+ readonly disabled?: Binding<boolean>;
11
+ readonly ref?: FocusRef;
12
+ onChange(this: void, value: boolean): void;
13
+ onBlur?(this: void): void;
14
+ }
15
+
16
+ /** An on/off switch. Spread a form field into it: `<Toggle {...register("enabled")} label="Enabled" />`. */
17
+ export function Toggle(props: ToggleProps) {
18
+ function toggle() {
19
+ props.onChange(!props.value.value);
20
+ props.onBlur?.();
21
+ }
22
+ return (
23
+ <button unstyled ariaLabel={props.label} checked={props.value} disabled={props.disabled}
24
+ nodeRef={focusNodeRef<"button">(props.ref)} className={styles.switch} onClick={toggle}>
25
+ <image src={artwork("Dot")} className={styles.knobOff} nativePixelSnap={false} shown={computed(() => !props.value.value)} />
26
+ <image src={artwork("Dot")} className={styles.knobOn} nativePixelSnap={false} shown={props.value} />
27
+ </button>
28
+ );
29
+ }
@@ -0,0 +1,7 @@
1
+ import type { FocusRef, MountedElementKind, NodeRef } from "@kumi/core";
2
+
3
+ /** Turn a form field's focus ref into a node ref for the control that should take focus. */
4
+ export function focusNodeRef<Kind extends MountedElementKind>(ref?: FocusRef): NodeRef<Kind> | undefined {
5
+ if (ref === undefined) return;
6
+ return node => ref(node === undefined ? undefined : { focus: () => node.focus() === true });
7
+ }
@@ -0,0 +1,15 @@
1
+ import type { AppTheme } from "@kumi/wow";
2
+ import styles from "@kumi/styles/shared/ui/Controls";
3
+ import { Glyph } from "./Glyph";
4
+
5
+ /** How range sliders draw their track, fill and thumb. */
6
+ export const rangeSkin: NonNullable<AppTheme["rangeSkin"]> = {
7
+ control: styles.slider,
8
+ caption: styles.sliderCaption,
9
+ thumbSize: 16,
10
+ render: () => ({
11
+ track: <div fullWidth anchor={{ point: "CENTER" }} className={styles.track} />,
12
+ fill: <div fullWidth anchor={{ point: "CENTER" }} className={styles.fill} />,
13
+ thumb: <Glyph name="Dot" className={styles.thumb} />,
14
+ }),
15
+ };