@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.
- package/LICENSE +21 -0
- package/README.md +67 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +387 -0
- package/builder/css-v1.test.mjs +361 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +127 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +435 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2336 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +381 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +83 -0
- package/builder/src/numbers.lua +76 -0
- package/builder/src/project-front.mjs +3682 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +124 -0
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow-reads.lua +22 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-modules.mjs +93 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +59 -0
- package/eslint.mjs +74 -0
- package/form/index.ts +526 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +26 -4
- package/router/index.ts +50 -0
- package/router/navigation.ts +22 -0
- package/router/package.json +12 -0
- package/router/router-view.ts +134 -0
- package/router/routes.ts +64 -0
- package/scripts/addon-build.mjs +364 -0
- package/scripts/addon-project.mjs +78 -0
- package/scripts/kumi-cli.mjs +105 -0
- package/scripts/link-addons.mjs +61 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +239 -0
- package/src/css-v1.ts +68 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +505 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +336 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +29 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +29 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +366 -0
- package/src/media-query.ts +144 -0
- package/src/module-ui.ts +147 -0
- package/src/module.ts +311 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +52 -0
- package/src/providers.ts +241 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +275 -0
- package/src/result.ts +64 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +63 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +9 -0
- package/state/package.json +12 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +84 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +49 -0
- package/templates/addon/eslint.config.mjs +6 -0
- package/templates/addon/gitignore +9 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +20 -0
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/_tokens.scss +12 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +63 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +219 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +36 -0
- package/wow/animation.ts +428 -0
- package/wow/app-ui.ts +221 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-box.ts +144 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +603 -0
- package/wow/css-text.ts +399 -0
- package/wow/cursor.ts +45 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +53 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frame-timing.ts +13 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/hooks.ts +133 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +111 -0
- package/wow/layout-view.ts +663 -0
- package/wow/locale-font.ts +15 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +153 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/protect.ts +48 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/protected-view.ts +103 -0
- package/wow/range-art.ts +81 -0
- package/wow/readable-api.ts +120 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +183 -0
- package/wow/saved-variables.ts +109 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +122 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1864 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { bindValue } from "../src/bindings";
|
|
2
|
+
import type { ActionSlot, Binding, Element } from "../src/elements";
|
|
3
|
+
import { withReactiveScope } from "../src/reactive-scope";
|
|
4
|
+
import { fail, formatFailure, type Failure, type Result } from "../src/result";
|
|
5
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
6
|
+
import type { Cancel } from "../src/scheduler";
|
|
7
|
+
import { hasCursorAction } from "./cursor";
|
|
8
|
+
import { createEventDispatcher } from "./event-dispatcher";
|
|
9
|
+
import type { Button } from "./frames";
|
|
10
|
+
import { readLayoutValue } from "./layout-view";
|
|
11
|
+
import { api, isSecret, reveal } from "./native";
|
|
12
|
+
import { createProtectedLayoutUpdate } from "./protected-layout";
|
|
13
|
+
import { readableApi } from "./readable-api";
|
|
14
|
+
|
|
15
|
+
type Receive = (this: void) => Result<boolean> | void;
|
|
16
|
+
type DropButton = Button & {
|
|
17
|
+
SetScript(this: object, event: "OnReceiveDrag", receive?: (this: void) => void): void;
|
|
18
|
+
};
|
|
19
|
+
type SecureButton = DropButton & {
|
|
20
|
+
SetAttribute(this: object, key: string, value?: string | number | boolean): void;
|
|
21
|
+
};
|
|
22
|
+
const events = createEventDispatcher();
|
|
23
|
+
|
|
24
|
+
export function unlockedActionSlot(): boolean {
|
|
25
|
+
return reveal(api.InCombatLockdown()) === false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function report(failure: Failure) {
|
|
29
|
+
api.geterrorhandler()(formatFailure(failure));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function showText(button: Button, text: string) {
|
|
33
|
+
const tooltip = api.GameTooltip;
|
|
34
|
+
if (tooltip === undefined) return;
|
|
35
|
+
tooltip.SetOwner(button, "ANCHOR_TOP");
|
|
36
|
+
tooltip.SetText(text);
|
|
37
|
+
tooltip.Show();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function listenForDrop(button: Button, scope: RuntimeScope, receive?: Receive) {
|
|
41
|
+
if (receive === undefined) return;
|
|
42
|
+
const target = button as DropButton;
|
|
43
|
+
button.RegisterForDrag("LeftButton");
|
|
44
|
+
target.SetScript("OnReceiveDrag", () => {
|
|
45
|
+
if (!scope.isActive() || !unlockedActionSlot()) return;
|
|
46
|
+
const attempt = scope.protect(receive);
|
|
47
|
+
if (!attempt.ok) report(attempt);
|
|
48
|
+
else if (attempt.value?.ok === false) showText(button, attempt.value.reason);
|
|
49
|
+
});
|
|
50
|
+
const cleanup = scope.onDispose(() => { target.SetScript("OnReceiveDrag", undefined); });
|
|
51
|
+
return cleanup.ok ? undefined : cleanup;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function sameAction(previous: ActionSlot | undefined, next: ActionSlot | undefined) {
|
|
55
|
+
return previous?.kind === next?.kind && previous?.id === next?.id;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function bindSecureAction(button: Button, scope: RuntimeScope, source: Binding<ActionSlot | undefined>, receive?: Receive) {
|
|
59
|
+
const target = button as SecureButton;
|
|
60
|
+
target.SetAttribute("useOnKeyDown", false);
|
|
61
|
+
button.RegisterForClicks("LeftButtonUp");
|
|
62
|
+
let applied: ActionSlot | undefined;
|
|
63
|
+
let pending: ActionSlot | undefined;
|
|
64
|
+
const protectedWrite = createProtectedLayoutUpdate(() => {
|
|
65
|
+
const next = pending;
|
|
66
|
+
if (sameAction(applied, next)) return;
|
|
67
|
+
if (applied !== undefined && applied.kind !== next?.kind) target.SetAttribute(applied.kind, undefined);
|
|
68
|
+
if (next !== undefined) target.SetAttribute(next.kind, next.kind === "item" ? "item:" + String(next.id) : next.id);
|
|
69
|
+
if (applied?.kind !== next?.kind) target.SetAttribute("type", next?.kind);
|
|
70
|
+
applied = next;
|
|
71
|
+
}, { scope, label: "Secure action button" });
|
|
72
|
+
if (!protectedWrite.ok) return protectedWrite;
|
|
73
|
+
const write = protectedWrite.value.request;
|
|
74
|
+
const binding = bindValue(scope, source, value => {
|
|
75
|
+
if (isSecret(value) || isSecret(value?.kind) || isSecret(value?.id)) return;
|
|
76
|
+
if (value !== undefined && (value.kind !== "item" && value.kind !== "spell" && value.kind !== "toy"
|
|
77
|
+
|| !(value.id > 0 && value.id <= 2147483647 && Math.floor(value.id) === value.id))) return;
|
|
78
|
+
pending = value;
|
|
79
|
+
const result = write();
|
|
80
|
+
if (!result.ok) report(result);
|
|
81
|
+
}, (previous, next) => !isSecret(previous) && !isSecret(next)
|
|
82
|
+
&& !isSecret(previous?.kind) && !isSecret(next?.kind) && !isSecret(previous?.id) && !isSecret(next?.id)
|
|
83
|
+
&& sameAction(previous, next));
|
|
84
|
+
if (binding !== undefined) return binding;
|
|
85
|
+
|
|
86
|
+
let unwatch: Cancel | undefined;
|
|
87
|
+
function tooltip() {
|
|
88
|
+
const gameTooltip = api.GameTooltip;
|
|
89
|
+
if (gameTooltip === undefined) return;
|
|
90
|
+
if (receive !== undefined && unlockedActionSlot() && hasCursorAction()) {
|
|
91
|
+
showText(button, "Drop to assign");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const action = applied;
|
|
95
|
+
if (action === undefined) {
|
|
96
|
+
showText(button, "Empty slot. Drag an action here.");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
gameTooltip.SetOwner(button, "ANCHOR_TOP");
|
|
100
|
+
if (action.kind === "spell") gameTooltip.SetSpellByID(action.id);
|
|
101
|
+
else if (action.kind === "toy" && gameTooltip.SetToyByItemID !== undefined) gameTooltip.SetToyByItemID(action.id);
|
|
102
|
+
else gameTooltip.SetItemByID(action.id);
|
|
103
|
+
gameTooltip.Show();
|
|
104
|
+
}
|
|
105
|
+
function leave() {
|
|
106
|
+
if (unwatch === undefined) return;
|
|
107
|
+
unwatch();
|
|
108
|
+
unwatch = undefined;
|
|
109
|
+
api.GameTooltip?.Hide();
|
|
110
|
+
}
|
|
111
|
+
button.HookScript("OnEnter", () => {
|
|
112
|
+
if (!scope.isActive()) return;
|
|
113
|
+
tooltip();
|
|
114
|
+
if (unwatch !== undefined) return;
|
|
115
|
+
const watch = events.on(scope, "CURSOR_CHANGED", tooltip);
|
|
116
|
+
if (watch.ok) unwatch = watch.value;
|
|
117
|
+
else report(watch);
|
|
118
|
+
});
|
|
119
|
+
button.HookScript("OnLeave", leave);
|
|
120
|
+
const cleanup = scope.onDispose(leave);
|
|
121
|
+
if (!cleanup.ok) return cleanup;
|
|
122
|
+
return listenForDrop(button, scope, receive);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function bindActionVisibility(button: Button, scope: RuntimeScope, source: Binding<boolean>,
|
|
126
|
+
mount: (this: void, owner: RuntimeScope) => Failure | undefined): Failure | undefined {
|
|
127
|
+
let desired = false;
|
|
128
|
+
let visible: boolean | undefined;
|
|
129
|
+
let mounted = false;
|
|
130
|
+
const update = createProtectedLayoutUpdate(() => {
|
|
131
|
+
const next = desired;
|
|
132
|
+
if (next === visible) return;
|
|
133
|
+
if (next && !mounted) {
|
|
134
|
+
const owner = scope.fork();
|
|
135
|
+
const created = withReactiveScope(owner, () => mount(owner));
|
|
136
|
+
const failure = created.ok ? created.value : created;
|
|
137
|
+
if (failure !== undefined) {
|
|
138
|
+
owner.dispose();
|
|
139
|
+
return failure;
|
|
140
|
+
}
|
|
141
|
+
if (!owner.isActive()) return fail("Action content disposed during mount");
|
|
142
|
+
mounted = true;
|
|
143
|
+
}
|
|
144
|
+
button.SetShown(next);
|
|
145
|
+
visible = next;
|
|
146
|
+
}, { scope, label: "Secure action visibility" });
|
|
147
|
+
if (!update.ok) return update;
|
|
148
|
+
|
|
149
|
+
// watch runs the change callback outside the source's observer. Mounting the body must not track into it.
|
|
150
|
+
const observed = scope.watch(() => readLayoutValue(source), next => {
|
|
151
|
+
if (!next.ok) return next;
|
|
152
|
+
if (typeof next.value !== "boolean") return fail("Secure action visibility requires a readable boolean");
|
|
153
|
+
desired = next.value;
|
|
154
|
+
const applied = update.value.request();
|
|
155
|
+
if (!applied.ok) return applied;
|
|
156
|
+
}, true);
|
|
157
|
+
return observed.ok ? undefined : observed;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface DragStart {
|
|
161
|
+
readonly x: number;
|
|
162
|
+
readonly y: number;
|
|
163
|
+
readonly scale: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function bindButtonMove(button: Button, scope: RuntimeScope,
|
|
167
|
+
{ onMove, onMoveEnd, onMoveCancel }: Element<"button">["props"]) {
|
|
168
|
+
if (onMove === undefined && onMoveEnd === undefined) return;
|
|
169
|
+
let start: DragStart | undefined;
|
|
170
|
+
|
|
171
|
+
function stop() {
|
|
172
|
+
const previous = start;
|
|
173
|
+
if (previous === undefined) return undefined;
|
|
174
|
+
start = undefined;
|
|
175
|
+
button.SetScript("OnUpdate", undefined);
|
|
176
|
+
return previous;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function cancel() {
|
|
180
|
+
if (stop() !== undefined && scope.isActive()) onMoveCancel?.();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
button.RegisterForDrag("LeftButton");
|
|
184
|
+
button.SetScript("OnDragStart", () => {
|
|
185
|
+
if (!scope.isActive() || !unlockedActionSlot() || reveal(button.IsEnabled()) !== true) return;
|
|
186
|
+
const [x, y] = readableApi.GetCursorPosition();
|
|
187
|
+
const scale = reveal(button.GetEffectiveScale());
|
|
188
|
+
if (x === undefined || y === undefined || scale === undefined || scale <= 0) return;
|
|
189
|
+
start = { x, y, scale };
|
|
190
|
+
if (onMove === undefined) return;
|
|
191
|
+
button.SetScript("OnUpdate", () => {
|
|
192
|
+
const origin = start;
|
|
193
|
+
if (origin === undefined || !unlockedActionSlot()) return;
|
|
194
|
+
const [nextX, nextY] = readableApi.GetCursorPosition();
|
|
195
|
+
if (nextX !== undefined && nextY !== undefined) onMove((nextX - origin.x) / origin.scale, (nextY - origin.y) / origin.scale);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
button.SetScript("OnDragStop", () => {
|
|
199
|
+
const origin = stop();
|
|
200
|
+
if (origin === undefined) return;
|
|
201
|
+
if (scope.isActive() && unlockedActionSlot()) {
|
|
202
|
+
const [x, y] = readableApi.GetCursorPosition();
|
|
203
|
+
if (x !== undefined && y !== undefined) {
|
|
204
|
+
onMoveEnd?.((x - origin.x) / origin.scale, (y - origin.y) / origin.scale);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
onMoveCancel?.();
|
|
209
|
+
});
|
|
210
|
+
button.HookScript("OnHide", cancel);
|
|
211
|
+
const combat = events.on(scope, "PLAYER_REGEN_DISABLED", cancel);
|
|
212
|
+
if (!combat.ok) return combat;
|
|
213
|
+
const cleanup = scope.onDispose(() => {
|
|
214
|
+
cancel();
|
|
215
|
+
button.SetScript("OnDragStart", undefined);
|
|
216
|
+
button.SetScript("OnDragStop", undefined);
|
|
217
|
+
});
|
|
218
|
+
return cleanup.ok ? undefined : cleanup;
|
|
219
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { api, reveal, type SecretValue } from "./native";
|
|
2
|
+
|
|
3
|
+
type VisitAction = (this: void, id: number, label?: string) => boolean;
|
|
4
|
+
|
|
5
|
+
function validId(id: number | undefined): id is number {
|
|
6
|
+
return typeof id === "number" && id > 0 && id <= 2147483647 && Math.floor(id) === id;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function readCount(value: number | SecretValue<number> | undefined): number {
|
|
10
|
+
const count = reveal(value);
|
|
11
|
+
return typeof count === "number" && Number.isFinite(count) && count > 0 ? Math.floor(count) : 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function readTable<Table extends object>(input: Table | SecretValue<Table> | undefined): Table | undefined {
|
|
15
|
+
const table = reveal(input);
|
|
16
|
+
if (table === undefined || typeof table !== "object") return undefined;
|
|
17
|
+
const canAccess = api.canaccesstable;
|
|
18
|
+
if (canAccess !== undefined) return canAccess(table) ? table : undefined;
|
|
19
|
+
const isRestricted = api.issecrettable;
|
|
20
|
+
return isRestricted !== undefined && isRestricted(table) ? undefined : table;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Resolve an item without loading uncached item details. */
|
|
24
|
+
export function readItemId(this: void, item: string | number): number | undefined {
|
|
25
|
+
const id = reveal(api.C_Item.GetItemInfoInstant(item)[0]);
|
|
26
|
+
return validId(id) ? id : undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Visit readable bag items in slot order. Return false from the visitor to stop. */
|
|
30
|
+
export function visitBagItems(this: void, visit: (this: void, id: number, link?: string) => boolean): void {
|
|
31
|
+
const containers = api.C_Container;
|
|
32
|
+
const bagLimit = reveal(api.NUM_TOTAL_EQUIPPED_BAG_SLOTS);
|
|
33
|
+
const lastBag = bagLimit !== undefined && Number.isFinite(bagLimit) ? bagLimit : 5;
|
|
34
|
+
for (let bag = 0; bag <= lastBag; bag += 1) {
|
|
35
|
+
const slots = readCount(containers.GetContainerNumSlots(bag));
|
|
36
|
+
for (let slot = 1; slot <= slots; slot += 1) {
|
|
37
|
+
const item = readTable(containers.GetContainerItemInfo(bag, slot));
|
|
38
|
+
if (item === undefined) continue;
|
|
39
|
+
const id = reveal(item.itemID);
|
|
40
|
+
if (validId(id) && !visit(id, reveal(item.hyperlink))) return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Visit collected toys currently listed by the client's Toy Box filter. */
|
|
46
|
+
export function visitCollectedToys(this: void, visit: VisitAction): void {
|
|
47
|
+
const book = api.C_ToyBox;
|
|
48
|
+
if (book === undefined) return;
|
|
49
|
+
const count = readCount(book.GetNumFilteredToys());
|
|
50
|
+
for (let index = 1; index <= count; index += 1) {
|
|
51
|
+
const id = reveal(book.GetToyFromIndex(index));
|
|
52
|
+
if (!validId(id) || reveal(api.PlayerHasToy(id)) !== true) continue;
|
|
53
|
+
const [, name] = book.GetToyInfo(id);
|
|
54
|
+
if (!visit(id, reveal(name))) return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function visitFlyout(id: number, visit: VisitAction): boolean {
|
|
59
|
+
const readInfo = api.GetFlyoutInfo;
|
|
60
|
+
const readSlot = api.GetFlyoutSlotInfo;
|
|
61
|
+
if (readInfo === undefined || readSlot === undefined) return true;
|
|
62
|
+
const [, , size, known] = readInfo(id);
|
|
63
|
+
if (reveal(known) !== true) return true;
|
|
64
|
+
const count = readCount(size);
|
|
65
|
+
for (let slot = 1; slot <= count; slot += 1) {
|
|
66
|
+
const [spell, override, learned, name] = readSlot(id, slot);
|
|
67
|
+
if (reveal(learned) !== true) continue;
|
|
68
|
+
const spellId = reveal(override) ?? reveal(spell);
|
|
69
|
+
if (validId(spellId) && !visit(spellId, reveal(name))) return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Visit visible, active player spellbook entries and learned flyout spells. */
|
|
75
|
+
export function visitPlayerSpells(this: void, visit: VisitAction): void {
|
|
76
|
+
const book = api.C_SpellBook;
|
|
77
|
+
const bank = api.Enum.SpellBookSpellBank.Player;
|
|
78
|
+
const types = api.Enum.SpellBookItemType;
|
|
79
|
+
const lines = readCount(book.GetNumSpellBookSkillLines());
|
|
80
|
+
for (let line = 1; line <= lines; line += 1) {
|
|
81
|
+
const info = readTable(book.GetSpellBookSkillLineInfo(line));
|
|
82
|
+
if (info === undefined || reveal(info.shouldHide) === true) continue;
|
|
83
|
+
const offset = reveal(info.itemIndexOffset) ?? 0;
|
|
84
|
+
const count = readCount(info.numSpellBookItems);
|
|
85
|
+
for (let index = 1; index <= count; index += 1) {
|
|
86
|
+
const entry = readTable(book.GetSpellBookItemInfo(offset + index, bank));
|
|
87
|
+
if (entry === undefined || reveal(entry.isOffSpec) === true || reveal(entry.isPassive) === true) continue;
|
|
88
|
+
const type = reveal(entry.itemType);
|
|
89
|
+
if (type === types.Spell) {
|
|
90
|
+
const spell = reveal(entry.spellID);
|
|
91
|
+
if (validId(spell) && !visit(spell, reveal(entry.name))) return;
|
|
92
|
+
} else if (type === types.Flyout) {
|
|
93
|
+
const flyout = reveal(entry.actionID);
|
|
94
|
+
if (validId(flyout) && !visitFlyout(flyout, visit)) return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { OwnedLuaArray } from "../src/owned-collections";
|
|
2
|
+
import { rawField } from "./lua-table";
|
|
3
|
+
|
|
4
|
+
// The compiler binds this to the addon's private table: the second value WoW passes to each addon file.
|
|
5
|
+
declare const kumiAddonTable: object | undefined;
|
|
6
|
+
|
|
7
|
+
export interface PluginManifest {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
/** The plugin's addon folder, `<addon>_<id>`. */
|
|
10
|
+
readonly addon: string;
|
|
11
|
+
readonly title: string;
|
|
12
|
+
readonly notes: string;
|
|
13
|
+
readonly load: "startup" | "demand";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @internal What kumi build wrote to KumiAddon.lua for this addon. */
|
|
17
|
+
export interface AddonManifest {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly savedVariables?: string;
|
|
20
|
+
readonly savedVariablesPerCharacter?: string;
|
|
21
|
+
readonly pluginState: "account" | "character";
|
|
22
|
+
/** A Lua list written by KumiAddon.lua. Read it with an index loop. */
|
|
23
|
+
readonly plugins: OwnedLuaArray<PluginManifest>;
|
|
24
|
+
/** Plugin modules registered by their generated entries, by plugin ID. */
|
|
25
|
+
readonly registered: Record<string, object | undefined>;
|
|
26
|
+
/** Errors raised while a plugin's file ran, by plugin ID. */
|
|
27
|
+
readonly failures: Record<string, string | undefined>;
|
|
28
|
+
started: boolean;
|
|
29
|
+
/** The demand plugin whose files WoW is loading right now. */
|
|
30
|
+
loading?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @internal The manifest of the running addon, or undefined when the addon was not built by kumi build. */
|
|
34
|
+
export function addonManifest(this: void): AddonManifest | undefined {
|
|
35
|
+
return rawField<AddonManifest>(kumiAddonTable, "KumiAddon");
|
|
36
|
+
}
|