@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
package/wow/range-art.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { fail, ok } from "../src/result";
|
|
2
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
3
|
+
import { createFrame, type FrameMap, type Texture } from "./frames";
|
|
4
|
+
import { isSecret, reveal } from "./native";
|
|
5
|
+
import { protect } from "./protect";
|
|
6
|
+
|
|
7
|
+
/** Place the skin's hosts on the same travel interval as the native slider thumb. */
|
|
8
|
+
export function mountRangeArt(this: void, slider: FrameMap["Slider"], size: number, scope: RuntimeScope) {
|
|
9
|
+
if (isSecret(size) || !Number.isFinite(size) || size <= 0) return fail("Invalid native slider thumb size");
|
|
10
|
+
|
|
11
|
+
const nativeThumb = slider.CreateTexture(undefined, "OVERLAY");
|
|
12
|
+
let previousThumb: { texture: Texture; shown: boolean } | undefined;
|
|
13
|
+
const cleanup = scope.onDispose(() => {
|
|
14
|
+
if (previousThumb === undefined) {
|
|
15
|
+
nativeThumb.Hide();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const { texture, shown } = previousThumb;
|
|
19
|
+
const current = protect(() => slider.GetThumbTexture());
|
|
20
|
+
if (current.ok && !isSecret(current.value)) {
|
|
21
|
+
if (current.value !== nativeThumb) {
|
|
22
|
+
nativeThumb.Hide();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
protect(() => slider.SetThumbTexture(texture));
|
|
26
|
+
const restored = protect(() => slider.GetThumbTexture());
|
|
27
|
+
if (restored.ok && !isSecret(restored.value) && restored.value === texture) {
|
|
28
|
+
nativeThumb.Hide();
|
|
29
|
+
texture.SetShown(shown);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Keep a visible native thumb when an existing one cannot be restored.
|
|
34
|
+
nativeThumb.SetAlpha(1);
|
|
35
|
+
nativeThumb.Show();
|
|
36
|
+
});
|
|
37
|
+
if (!cleanup.ok) return cleanup;
|
|
38
|
+
nativeThumb.SetTexture("Interface\\Buttons\\WHITE8X8");
|
|
39
|
+
nativeThumb.SetSize(size, size);
|
|
40
|
+
|
|
41
|
+
const track = createFrame("Frame", undefined, slider);
|
|
42
|
+
scope.onDispose(() => track.Hide());
|
|
43
|
+
const fill = createFrame("Frame", undefined, slider);
|
|
44
|
+
scope.onDispose(() => fill.Hide());
|
|
45
|
+
const thumb = createFrame("Frame", undefined, slider);
|
|
46
|
+
scope.onDispose(() => thumb.Hide());
|
|
47
|
+
|
|
48
|
+
const level = reveal(slider.GetFrameLevel());
|
|
49
|
+
if (level !== undefined) {
|
|
50
|
+
track.SetFrameLevel(level + 1);
|
|
51
|
+
fill.SetFrameLevel(level + 2);
|
|
52
|
+
thumb.SetFrameLevel(level + 3);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
track.SetHeight(size);
|
|
56
|
+
track.SetPoint("LEFT", slider, "LEFT", size / 2, 0);
|
|
57
|
+
track.SetPoint("RIGHT", slider, "RIGHT", -size / 2, 0);
|
|
58
|
+
fill.SetHeight(size);
|
|
59
|
+
fill.SetPoint("LEFT", track, "LEFT");
|
|
60
|
+
fill.SetPoint("RIGHT", nativeThumb, "CENTER");
|
|
61
|
+
thumb.SetPoint("TOPLEFT", nativeThumb, "TOPLEFT");
|
|
62
|
+
thumb.SetPoint("BOTTOMRIGHT", nativeThumb, "BOTTOMRIGHT");
|
|
63
|
+
|
|
64
|
+
function installThumb() {
|
|
65
|
+
if (!scope.isActive()) return fail("The reactive scope has been disposed");
|
|
66
|
+
const previous = slider.GetThumbTexture() as Texture | undefined;
|
|
67
|
+
if (isSecret(previous)) return fail("Native slider thumb is unreadable");
|
|
68
|
+
if (previous !== undefined) {
|
|
69
|
+
const shown = reveal(previous.IsShown());
|
|
70
|
+
if (shown === undefined) return fail("Native slider thumb visibility is unreadable");
|
|
71
|
+
previousThumb = { texture: previous, shown };
|
|
72
|
+
}
|
|
73
|
+
slider.SetThumbTexture(nativeThumb);
|
|
74
|
+
const installed = slider.GetThumbTexture();
|
|
75
|
+
if (isSecret(installed) || installed !== nativeThumb) return fail("Native slider thumb was not installed");
|
|
76
|
+
previous?.Hide();
|
|
77
|
+
nativeThumb.SetAlpha(0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return ok({ track, fill, thumb, installThumb });
|
|
81
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { api, reveal, type LuaMultiReturn } from "./native";
|
|
2
|
+
import { readSpellCooldown } from "./spell-cooldown";
|
|
3
|
+
|
|
4
|
+
declare const $multi: (<Values extends unknown[]>(this: void, ...values: Values) => LuaMultiReturn<Values>) & {
|
|
5
|
+
readonly __tstlExtension: "MultiFunction";
|
|
6
|
+
};
|
|
7
|
+
declare function error(this: void, message: string): never;
|
|
8
|
+
declare function setmetatable<View extends object>(
|
|
9
|
+
this: void, view: object,
|
|
10
|
+
meta: { __index: (this: void, view: object, key: keyof View) => unknown; __newindex: (this: void) => never; __metatable: false },
|
|
11
|
+
): View;
|
|
12
|
+
declare function setmetatable<Overrides extends object, Host extends object>(
|
|
13
|
+
this: void, overrides: Overrides, meta: { __index: Host; __newindex?: (this: void) => never; __metatable?: false },
|
|
14
|
+
): Readonly<Omit<Host, keyof Overrides> & Overrides>;
|
|
15
|
+
|
|
16
|
+
function rejectWrite(this: void): never {
|
|
17
|
+
return error("The readable WoW API is read-only");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ReadableSpellApi = Readonly<Omit<typeof api.C_Spell, "GetSpellCooldown"> & {
|
|
21
|
+
GetSpellCooldown: typeof readSpellCooldown;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
function readSpellMember(this: void, _view: object, key: keyof typeof api.C_Spell) {
|
|
25
|
+
if (key === "GetSpellCooldown") return readSpellCooldown;
|
|
26
|
+
return api.C_Spell[key];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const readableSpellApi = setmetatable<ReadableSpellApi>({}, {
|
|
30
|
+
__index: readSpellMember,
|
|
31
|
+
__newindex: rejectWrite,
|
|
32
|
+
__metatable: false,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
type ReadableName = LuaMultiReturn<[name?: string, realm?: string]>;
|
|
36
|
+
type ReadableUnitKind = LuaMultiReturn<[name?: string, token?: string, id?: number]>;
|
|
37
|
+
|
|
38
|
+
const readableMethods = setmetatable({
|
|
39
|
+
C_Spell: readableSpellApi,
|
|
40
|
+
InCombatLockdown(this: void, ...args: Parameters<typeof api.InCombatLockdown>) {
|
|
41
|
+
return reveal(api.InCombatLockdown(...args));
|
|
42
|
+
},
|
|
43
|
+
PlayerHasToy(this: void, ...args: Parameters<typeof api.PlayerHasToy>) {
|
|
44
|
+
return reveal(api.PlayerHasToy(...args));
|
|
45
|
+
},
|
|
46
|
+
GetCursorPosition(this: void): LuaMultiReturn<[x?: number, y?: number]> {
|
|
47
|
+
const [x, y] = api.GetCursorPosition();
|
|
48
|
+
return $multi(reveal(x), reveal(y));
|
|
49
|
+
},
|
|
50
|
+
UnitName(this: void, unit: string): ReadableName {
|
|
51
|
+
const [name, realm] = api.UnitName(unit);
|
|
52
|
+
return $multi(reveal(name), reveal(realm));
|
|
53
|
+
},
|
|
54
|
+
UnitFullName(this: void, unit: string): ReadableName {
|
|
55
|
+
const [name, realm] = api.UnitFullName(unit);
|
|
56
|
+
return $multi(reveal(name), reveal(realm));
|
|
57
|
+
},
|
|
58
|
+
UnitNameFromGUID(this: void, guid: string): ReadableName {
|
|
59
|
+
const [name, realm] = api.UnitNameFromGUID(guid);
|
|
60
|
+
return $multi(reveal(name), reveal(realm));
|
|
61
|
+
},
|
|
62
|
+
UnitNameUnmodified(this: void, unit: string): ReadableName {
|
|
63
|
+
const [name, realm] = api.UnitNameUnmodified(unit);
|
|
64
|
+
return $multi(reveal(name), reveal(realm));
|
|
65
|
+
},
|
|
66
|
+
UnitClass(this: void, unit: string): ReadableUnitKind {
|
|
67
|
+
const [name, token, id] = api.UnitClass(unit);
|
|
68
|
+
return $multi(reveal(name), reveal(token), reveal(id));
|
|
69
|
+
},
|
|
70
|
+
UnitRace(this: void, unit: string): ReadableUnitKind {
|
|
71
|
+
const [name, token, id] = api.UnitRace(unit);
|
|
72
|
+
return $multi(reveal(name), reveal(token), reveal(id));
|
|
73
|
+
},
|
|
74
|
+
UnitGUID(this: void, ...args: Parameters<typeof api.UnitGUID>) {
|
|
75
|
+
return reveal(api.UnitGUID(...args));
|
|
76
|
+
},
|
|
77
|
+
UnitIsUnit(this: void, ...args: Parameters<typeof api.UnitIsUnit>) {
|
|
78
|
+
return reveal(api.UnitIsUnit(...args));
|
|
79
|
+
},
|
|
80
|
+
UnitThreatSituation(this: void, ...args: Parameters<typeof api.UnitThreatSituation>) {
|
|
81
|
+
return reveal(api.UnitThreatSituation(...args));
|
|
82
|
+
},
|
|
83
|
+
UnitGroupRolesAssigned(this: void, ...args: Parameters<typeof api.UnitGroupRolesAssigned>) {
|
|
84
|
+
return reveal(api.UnitGroupRolesAssigned?.(...args));
|
|
85
|
+
},
|
|
86
|
+
UnitInRaid(this: void, ...args: Parameters<typeof api.UnitInRaid>) {
|
|
87
|
+
return reveal(api.UnitInRaid?.(...args));
|
|
88
|
+
},
|
|
89
|
+
UnitIsAFK(this: void, ...args: Parameters<typeof api.UnitIsAFK>) {
|
|
90
|
+
return reveal(api.UnitIsAFK?.(...args));
|
|
91
|
+
},
|
|
92
|
+
UnitPhaseReason(this: void, ...args: Parameters<typeof api.UnitPhaseReason>) {
|
|
93
|
+
return reveal(api.UnitPhaseReason?.(...args));
|
|
94
|
+
},
|
|
95
|
+
UnitSex(this: void, ...args: Parameters<typeof api.UnitSex>) {
|
|
96
|
+
return reveal(api.UnitSex?.(...args));
|
|
97
|
+
},
|
|
98
|
+
UnitSpellTargetClass(this: void, ...args: Parameters<typeof api.UnitSpellTargetClass>) {
|
|
99
|
+
return reveal(api.UnitSpellTargetClass?.(...args));
|
|
100
|
+
},
|
|
101
|
+
UnitHealth(this: void, ...args: Parameters<typeof api.UnitHealth>) {
|
|
102
|
+
return reveal(api.UnitHealth(...args));
|
|
103
|
+
},
|
|
104
|
+
UnitHealthMax(this: void, ...args: Parameters<typeof api.UnitHealthMax>) {
|
|
105
|
+
return reveal(api.UnitHealthMax(...args));
|
|
106
|
+
},
|
|
107
|
+
UnitPower(this: void, ...args: Parameters<typeof api.UnitPower>) {
|
|
108
|
+
return reveal(api.UnitPower(...args));
|
|
109
|
+
},
|
|
110
|
+
UnitPowerMax(this: void, ...args: Parameters<typeof api.UnitPowerMax>) {
|
|
111
|
+
return reveal(api.UnitPowerMax(...args));
|
|
112
|
+
},
|
|
113
|
+
}, { __index: api });
|
|
114
|
+
|
|
115
|
+
/** A read-only view of the WoW API with guarded reads for migrated operations. */
|
|
116
|
+
export const readableApi = setmetatable({}, {
|
|
117
|
+
__index: readableMethods,
|
|
118
|
+
__newindex: rejectWrite,
|
|
119
|
+
__metatable: false,
|
|
120
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ownedArray, type OwnedArray, type OwnedReadonlyArray } from "../src/owned-collections";
|
|
2
|
+
import { fail, ok, type Result } from "../src/result";
|
|
3
|
+
import { canAccessRegion } from "./frame-access";
|
|
4
|
+
import type { Frame } from "./frames";
|
|
5
|
+
import { frameStrata as strata, maximumFrameLevel } from "./frame-layer";
|
|
6
|
+
import { api, isSecret, reveal } from "./native";
|
|
7
|
+
import { protect } from "./protect";
|
|
8
|
+
|
|
9
|
+
const maximumDepth = 13;
|
|
10
|
+
|
|
11
|
+
type LevelFrame = Pick<Frame, "GetChildren" | "GetFrameLevel" | "GetParent" | "IsForbidden" | "IsProtected" | "SetFrameLevel">;
|
|
12
|
+
type Descendant = { frame: LevelFrame; parent: LevelFrame; level: number };
|
|
13
|
+
|
|
14
|
+
function unprotected(frame: LevelFrame): boolean {
|
|
15
|
+
const [protectedState] = frame.IsProtected();
|
|
16
|
+
return reveal(protectedState) === false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readStrata(frame: Frame): number {
|
|
20
|
+
const value = reveal(frame.GetFrameStrata());
|
|
21
|
+
return typeof value === "string" ? (strata as readonly string[] as OwnedReadonlyArray<string>).indexOf(value) : -1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function collectLevels(parent: LevelFrame, levels: OwnedArray<Descendant>, depth: number): boolean {
|
|
25
|
+
if (depth === maximumDepth) return true;
|
|
26
|
+
const children = parent.GetChildren();
|
|
27
|
+
for (const child of children) {
|
|
28
|
+
if (!canAccessRegion(child) || !unprotected(child)) continue;
|
|
29
|
+
const level = reveal(child.GetFrameLevel());
|
|
30
|
+
if (level === undefined) return false;
|
|
31
|
+
levels.push({ frame: child, parent, level });
|
|
32
|
+
if (!collectLevels(child, levels, depth + 1)) return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function reparent(frame: Frame, parent: Frame): Result<void> {
|
|
38
|
+
if (!canAccessRegion(frame) || !canAccessRegion(parent)) return fail("Frame or parent is inaccessible");
|
|
39
|
+
const oldParent = frame.GetParent();
|
|
40
|
+
if (isSecret(oldParent)) return fail("Frame parent is unreadable");
|
|
41
|
+
if (oldParent === parent) return ok(undefined);
|
|
42
|
+
if (frame === parent) return fail("A frame cannot be its own parent");
|
|
43
|
+
|
|
44
|
+
const inCombat = api.InCombatLockdown();
|
|
45
|
+
if (isSecret(inCombat)) return fail("Combat lockdown is unreadable");
|
|
46
|
+
if (inCombat && (!unprotected(frame) || !unprotected(parent))) {
|
|
47
|
+
return fail("Cannot reparent a protected frame in combat");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const frameStrata = readStrata(frame);
|
|
51
|
+
const parentStrata = readStrata(parent);
|
|
52
|
+
const levelBefore = reveal(frame.GetFrameLevel());
|
|
53
|
+
const parentLevel = reveal(parent.GetFrameLevel());
|
|
54
|
+
if (frameStrata < 0 || parentStrata < 0 || levelBefore === undefined || parentLevel === undefined) {
|
|
55
|
+
return fail("Frame or parent layers are unreadable");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Record levels before native SetParent, which can shift descendants on its own.
|
|
59
|
+
const descendants = ownedArray<Descendant>();
|
|
60
|
+
if (!collectLevels(frame, descendants, 0)) return fail("A descendant frame level is unreadable");
|
|
61
|
+
|
|
62
|
+
frame.SetParent(parent);
|
|
63
|
+
if (reveal(frame.GetParent()) !== parent) return fail("The client did not confirm the new frame parent");
|
|
64
|
+
|
|
65
|
+
const targetStrata = Math.max(frameStrata, parentStrata);
|
|
66
|
+
if (readStrata(frame) !== targetStrata) {
|
|
67
|
+
frame.SetFrameStrata(strata[targetStrata]);
|
|
68
|
+
if (readStrata(frame) !== targetStrata) return fail("The client did not apply the new frame strata");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let levelAfter = reveal(frame.GetFrameLevel());
|
|
72
|
+
if (levelAfter !== undefined && levelAfter <= parentLevel) {
|
|
73
|
+
frame.SetFrameLevel(parentLevel + 1);
|
|
74
|
+
levelAfter = reveal(frame.GetFrameLevel());
|
|
75
|
+
}
|
|
76
|
+
if (levelAfter === undefined || levelAfter <= parentLevel) return fail("The client did not confirm the new frame level");
|
|
77
|
+
|
|
78
|
+
const delta = levelAfter - levelBefore;
|
|
79
|
+
for (const descendant of descendants) {
|
|
80
|
+
const child = descendant.frame;
|
|
81
|
+
if (!canAccessRegion(child) || !unprotected(child)) continue;
|
|
82
|
+
if (reveal(child.GetParent()) !== descendant.parent) return fail("A descendant frame changed parent during reparenting");
|
|
83
|
+
const level = reveal(child.GetFrameLevel());
|
|
84
|
+
if (level === undefined) return fail("A descendant frame level is unreadable");
|
|
85
|
+
const target = Math.max(0, Math.min(maximumFrameLevel, descendant.level + delta));
|
|
86
|
+
if (level !== target) {
|
|
87
|
+
child.SetFrameLevel(target);
|
|
88
|
+
if (reveal(child.GetFrameLevel()) !== target) return fail("The client did not apply a descendant frame level");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return ok(undefined);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Move a frame and preserve the relative levels of its accessible, unprotected descendants. */
|
|
96
|
+
export function reparentFrame(frame: Frame, parent: Frame): Result<void> {
|
|
97
|
+
const result = protect(() => reparent(frame, parent));
|
|
98
|
+
return result.ok ? result.value : result;
|
|
99
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { OwnedReadonlyArray } from "../src/owned-collections";
|
|
2
|
+
import type { Frame, StatusBar, Texture } from "./frames";
|
|
3
|
+
|
|
4
|
+
type Layer = Parameters<Frame["CreateTexture"]>[1];
|
|
5
|
+
type FillMask = ReturnType<StatusBar["CreateMaskTexture"]>;
|
|
6
|
+
type SliceTexture = Pick<FillMask, "SetTexture" | "SetTextureSliceMargins" | "SetTextureSliceMode">;
|
|
7
|
+
type TextureAsset = NonNullable<Parameters<SliceTexture["SetTexture"]>[0]>;
|
|
8
|
+
export type RoundedTextureSide = "left" | "right";
|
|
9
|
+
|
|
10
|
+
export interface RoundedBorderCorner {
|
|
11
|
+
readonly asset: string | number;
|
|
12
|
+
/** UV extent of the upper-left cutout. The renderer mirrors it for other corners. */
|
|
13
|
+
readonly extent: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RoundedTextureOptions {
|
|
17
|
+
directory(this: void): string;
|
|
18
|
+
readonly resolveArt?: never;
|
|
19
|
+
fallback(this: void): string;
|
|
20
|
+
readonly radii: readonly number[];
|
|
21
|
+
readonly stretched?: number;
|
|
22
|
+
/** Resolve a sliced outline with a one-texel stroke at the requested physical radius. */
|
|
23
|
+
resolveBorderOutline?(this: void, radius: number): TextureAsset | undefined;
|
|
24
|
+
/** Resolve the inner cutout for a one-texel stroke at an integer display radius. */
|
|
25
|
+
resolveBorderCorner?(this: void, radius: number): RoundedBorderCorner | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RoundedTextureResolverOptions extends Omit<RoundedTextureOptions, "directory" | "resolveArt"> {
|
|
29
|
+
readonly directory?: never;
|
|
30
|
+
/** Resolve an exact variant to a native path or FileID, or return undefined when absent. */
|
|
31
|
+
resolveArt(this: void, radius: number, outline: boolean, side?: RoundedTextureSide): TextureAsset | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface MaskedStatusBarFill {
|
|
35
|
+
setRadius(this: void, radius: number, side?: RoundedTextureSide): FillMask | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RoundedTextures {
|
|
39
|
+
create(this: void, parent: Frame, radius: number, outline?: boolean, layer?: Layer, sublevel?: number,
|
|
40
|
+
side?: RoundedTextureSide): Texture;
|
|
41
|
+
apply(this: void, texture: Texture, radius: number, outline?: boolean, side?: RoundedTextureSide): void;
|
|
42
|
+
/** Install an exact registered radius on a caller-owned mask. */
|
|
43
|
+
applyMask(this: void, mask: FillMask, radius: number): boolean;
|
|
44
|
+
/** Paint an exact solid fill when the client supports native slicing. */
|
|
45
|
+
applyExactFill?(this: void, texture: Texture, radius: number): boolean;
|
|
46
|
+
readonly borderOutline?: {
|
|
47
|
+
readonly stretched: number;
|
|
48
|
+
resolve(this: void, radius: number): TextureAsset | undefined;
|
|
49
|
+
};
|
|
50
|
+
resolveBorderCorner?(this: void, radius: number): RoundedBorderCorner | undefined;
|
|
51
|
+
bindStatusBarFill(this: void, bar: StatusBar, fill: Texture): MaskedStatusBarFill;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const maskWrap = "CLAMPTOBLACKADDITIVE";
|
|
55
|
+
|
|
56
|
+
/** Apply host-supplied Round textures with native nine-slice margins. */
|
|
57
|
+
export function createRoundedTextures(this: void, { directory, resolveArt, fallback, radii, stretched, resolveBorderCorner, resolveBorderOutline }:
|
|
58
|
+
RoundedTextureOptions | RoundedTextureResolverOptions): RoundedTextures {
|
|
59
|
+
const rounded = (radii as OwnedReadonlyArray<number>).filter(radius => radius > 0).sort((left, right) => right - left);
|
|
60
|
+
const square = [0];
|
|
61
|
+
const hasRadiusTwo = rounded.includes(2);
|
|
62
|
+
|
|
63
|
+
function readArt(prefix: string, radius: number, outline: boolean, side?: RoundedTextureSide): TextureAsset | undefined {
|
|
64
|
+
if (resolveArt !== undefined) return resolveArt(radius, outline, side);
|
|
65
|
+
const edge = side === "left" ? "L" : side === "right" ? "R" : "";
|
|
66
|
+
return prefix + radius + edge + (outline ? "Border" : "");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function setArt(texture: SliceTexture, asset: TextureAsset | undefined, margin: number, wrap?: string): boolean {
|
|
70
|
+
if (asset === undefined) return false;
|
|
71
|
+
const found = wrap === undefined ? texture.SetTexture(asset) : texture.SetTexture(asset, wrap, wrap);
|
|
72
|
+
if (found === false) return false;
|
|
73
|
+
if (stretched !== undefined && texture.SetTextureSliceMargins && texture.SetTextureSliceMode) {
|
|
74
|
+
texture.SetTextureSliceMargins(margin, margin, margin, margin);
|
|
75
|
+
texture.SetTextureSliceMode(stretched);
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function tryRound(texture: SliceTexture, radius: number, outline: boolean, side?: RoundedTextureSide, wrap?: string): boolean {
|
|
81
|
+
const candidates = radius <= 0 ? square : rounded;
|
|
82
|
+
let index = candidates.findIndex(candidate => candidate <= radius);
|
|
83
|
+
if (index < 0) index = Math.max(0, candidates.length - 1);
|
|
84
|
+
|
|
85
|
+
const prefix = directory === undefined ? "" : directory() + "Round";
|
|
86
|
+
const first = candidates[index];
|
|
87
|
+
if (first !== undefined && (side === "left" || side === "right")
|
|
88
|
+
&& setArt(texture, readArt(prefix, first, outline, side), first, wrap)) return true;
|
|
89
|
+
|
|
90
|
+
// Keep an outline's faint second pixel outside the stretched center.
|
|
91
|
+
const minimumMargin = outline ? 2 : 1;
|
|
92
|
+
while (index < candidates.length) {
|
|
93
|
+
const candidate = candidates[index];
|
|
94
|
+
if (setArt(texture, readArt(prefix, candidate, outline), Math.max(minimumMargin, candidate), wrap)) return true;
|
|
95
|
+
index++;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Retain the older radius-two fallback after the smallest candidate fails.
|
|
99
|
+
return candidates[candidates.length - 1] === 1 && hasRadiusTwo && setArt(texture, readArt(prefix, 2, outline), 2, wrap);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function setWhite(texture: SliceTexture, wrap?: string): void {
|
|
103
|
+
if (wrap === undefined) texture.SetTexture(fallback());
|
|
104
|
+
else texture.SetTexture(fallback(), wrap, wrap);
|
|
105
|
+
texture.SetTextureSliceMargins?.(0, 0, 0, 0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function apply(this: void, texture: Texture, radius: number, outline = false, side?: RoundedTextureSide): void {
|
|
109
|
+
texture.SetAlpha(1);
|
|
110
|
+
if (tryRound(texture, radius, outline, side)) return;
|
|
111
|
+
setWhite(texture);
|
|
112
|
+
if (outline) texture.SetAlpha(0);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function create(this: void, parent: Frame, radius: number, outline?: boolean, layer: Layer = "BACKGROUND", sublevel?: number,
|
|
116
|
+
side?: RoundedTextureSide): Texture {
|
|
117
|
+
const texture = parent.CreateTexture(undefined, layer, undefined, sublevel);
|
|
118
|
+
apply(texture, radius, outline, side);
|
|
119
|
+
return texture;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function applyExact(texture: SliceTexture, radius: number, wrap?: string): boolean {
|
|
123
|
+
if (stretched === undefined || !rounded.includes(radius) || typeof texture.SetTextureSliceMargins !== "function"
|
|
124
|
+
|| typeof texture.SetTextureSliceMode !== "function") return false;
|
|
125
|
+
const prefix = directory === undefined ? "" : directory() + "Round";
|
|
126
|
+
return setArt(texture, readArt(prefix, radius, false), radius, wrap);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function applyMask(this: void, mask: FillMask, radius: number): boolean {
|
|
130
|
+
return applyExact(mask, radius, maskWrap);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function applyExactFill(this: void, texture: Texture, radius: number): boolean {
|
|
134
|
+
return applyExact(texture, radius);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Keep the mask anchored to the bar while the native fill changes size. */
|
|
138
|
+
function bindStatusBarFill(this: void, bar: StatusBar, fill: Texture): MaskedStatusBarFill {
|
|
139
|
+
let mask: FillMask | undefined;
|
|
140
|
+
let activeMask: FillMask | undefined;
|
|
141
|
+
let previousRadius: number | undefined;
|
|
142
|
+
let previousSide: RoundedTextureSide | undefined;
|
|
143
|
+
|
|
144
|
+
function setRadius(this: void, radius: number, side?: RoundedTextureSide): FillMask | undefined {
|
|
145
|
+
if (radius === previousRadius && side === previousSide) return activeMask;
|
|
146
|
+
previousRadius = radius;
|
|
147
|
+
previousSide = side;
|
|
148
|
+
|
|
149
|
+
if (radius > 0 && stretched !== undefined && typeof bar.CreateMaskTexture === "function"
|
|
150
|
+
&& typeof fill.AddMaskTexture === "function" && typeof fill.RemoveMaskTexture === "function") {
|
|
151
|
+
if (mask === undefined) {
|
|
152
|
+
mask = bar.CreateMaskTexture();
|
|
153
|
+
mask.SetAllPoints(bar);
|
|
154
|
+
}
|
|
155
|
+
if (typeof mask.SetTextureSliceMargins === "function" && typeof mask.SetTextureSliceMode === "function"
|
|
156
|
+
&& tryRound(mask, radius, false, side, maskWrap)) {
|
|
157
|
+
if (activeMask === undefined) {
|
|
158
|
+
setWhite(fill);
|
|
159
|
+
fill.AddMaskTexture(mask);
|
|
160
|
+
activeMask = mask;
|
|
161
|
+
}
|
|
162
|
+
return activeMask;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (activeMask !== undefined) {
|
|
167
|
+
// Overlays can retain the mask until their next refresh.
|
|
168
|
+
setWhite(activeMask, maskWrap);
|
|
169
|
+
fill.RemoveMaskTexture(activeMask);
|
|
170
|
+
activeMask = undefined;
|
|
171
|
+
}
|
|
172
|
+
if (radius > 0) apply(fill, radius, false, side);
|
|
173
|
+
else setWhite(fill);
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return { setRadius };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const borderOutline = stretched === undefined || resolveBorderOutline === undefined
|
|
181
|
+
? undefined : { stretched, resolve: resolveBorderOutline };
|
|
182
|
+
return { create, apply, applyMask, applyExactFill, bindStatusBarFill, resolveBorderCorner, borderOutline };
|
|
183
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { fail, ok, type Result } from "../src/result";
|
|
2
|
+
import { ownedMap, type OwnedLuaArray } from "../src/owned-collections";
|
|
3
|
+
import type { StoreStorage } from "@kumi/state";
|
|
4
|
+
import { rawField, setRawField } from "./lua-table";
|
|
5
|
+
import { api, reveal } from "./native";
|
|
6
|
+
|
|
7
|
+
/** A value WoW can write to a SavedVariables file: text, finite numbers, booleans, lists and records of them. */
|
|
8
|
+
export type SavedValue = string | number | boolean | readonly SavedValue[] | { readonly [key: string]: SavedValue };
|
|
9
|
+
/** A record whose fields are all savable. Interfaces work as well as type literals. */
|
|
10
|
+
export type SavedRecord<State> = { readonly [Key in keyof State]: SavedValue };
|
|
11
|
+
|
|
12
|
+
export interface SavedVariablesOptions<State extends SavedRecord<State>> {
|
|
13
|
+
/** The global named in the TOC's `## SavedVariables` or `## SavedVariablesPerCharacter` line. */
|
|
14
|
+
global: string;
|
|
15
|
+
/** The record inside that global. Use one key per store. */
|
|
16
|
+
key: string;
|
|
17
|
+
/** Field names and their types. Saved fields with another type fall back to these values. */
|
|
18
|
+
defaults: State;
|
|
19
|
+
/** Defaults to "the player is logged in", when WoW has loaded every SavedVariables file of enabled addons. */
|
|
20
|
+
isReady?(this: void): boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const claims = ownedMap<string, string>();
|
|
24
|
+
const MAX_DEPTH = 16;
|
|
25
|
+
|
|
26
|
+
function loggedIn() {
|
|
27
|
+
return reveal(api.IsLoggedIn?.()) === true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Copy only what WoW can serialize and drop protected values, so a reactive list never aliases the saved table.
|
|
31
|
+
function copySaved(value: unknown, depth: number): SavedValue | undefined {
|
|
32
|
+
const plain = reveal(value);
|
|
33
|
+
if (typeof plain === "string" || typeof plain === "boolean") return plain;
|
|
34
|
+
if (typeof plain === "number") return Number.isFinite(plain) ? plain : undefined;
|
|
35
|
+
if (typeof plain !== "object" || plain === null || depth > MAX_DEPTH) return undefined;
|
|
36
|
+
if (Array.isArray(plain)) {
|
|
37
|
+
const items = plain as OwnedLuaArray<unknown>;
|
|
38
|
+
const list: SavedValue[] = [];
|
|
39
|
+
for (let index = 0; index < items.length; index++) {
|
|
40
|
+
const copy = copySaved(items[index], depth + 1);
|
|
41
|
+
if (copy !== undefined) list.push(copy);
|
|
42
|
+
}
|
|
43
|
+
return list;
|
|
44
|
+
}
|
|
45
|
+
const source = plain as Record<string, unknown>;
|
|
46
|
+
const record: Record<string, SavedValue> = {};
|
|
47
|
+
for (const name of Object.keys(source)) {
|
|
48
|
+
const copy = copySaved(source[name], depth + 1);
|
|
49
|
+
if (copy !== undefined) record[name] = copy;
|
|
50
|
+
}
|
|
51
|
+
return record;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function sameShape(value: unknown, fallback: unknown) {
|
|
55
|
+
if (typeof value !== typeof fallback) return false;
|
|
56
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
57
|
+
if (typeof value === "object") return Array.isArray(value) === Array.isArray(fallback);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Open one record of a TOC-declared SavedVariables table for a store. */
|
|
62
|
+
export function savedVariablesStorage<State extends SavedRecord<State>>(
|
|
63
|
+
{ global, key, defaults, isReady = loggedIn }: SavedVariablesOptions<State>,
|
|
64
|
+
): StoreStorage<State> {
|
|
65
|
+
const keys = Object.keys(defaults) as (keyof State & string)[];
|
|
66
|
+
const claim = global + "." + key;
|
|
67
|
+
|
|
68
|
+
function root() {
|
|
69
|
+
if (!isReady()) return fail("SavedVariables " + global + " are not loaded yet. Open the store after the player logs in.");
|
|
70
|
+
const stored = reveal(rawField(api, global));
|
|
71
|
+
if (stored !== undefined && typeof stored !== "object") return fail("Invalid SavedVariables table: " + global);
|
|
72
|
+
return ok(stored);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
claim: owner => {
|
|
77
|
+
const holder = claims.get(claim);
|
|
78
|
+
if (holder !== undefined) return fail("SavedVariables " + claim + " is already used by store " + holder);
|
|
79
|
+
claims.set(claim, owner);
|
|
80
|
+
return ok(() => { if (claims.get(claim) === owner) claims.delete(claim); });
|
|
81
|
+
},
|
|
82
|
+
read: () => {
|
|
83
|
+
const opened = root();
|
|
84
|
+
if (!opened.ok) return opened;
|
|
85
|
+
const stored = reveal(rawField(opened.value, key));
|
|
86
|
+
if (stored === undefined) return ok(undefined);
|
|
87
|
+
if (typeof stored !== "object") return fail("Invalid saved record: " + claim);
|
|
88
|
+
const result: Partial<State> = {};
|
|
89
|
+
for (const field of keys) {
|
|
90
|
+
const value = copySaved(rawField(stored, field), 0);
|
|
91
|
+
if (value !== undefined && sameShape(value, defaults[field])) result[field] = value as State[typeof field];
|
|
92
|
+
}
|
|
93
|
+
return ok(result);
|
|
94
|
+
},
|
|
95
|
+
write: snapshot => {
|
|
96
|
+
const opened = root();
|
|
97
|
+
if (!opened.ok) return opened;
|
|
98
|
+
const record: Record<string, unknown> = {};
|
|
99
|
+
for (const field of keys) {
|
|
100
|
+
const value = copySaved(snapshot[field], 0);
|
|
101
|
+
if (value === undefined || !sameShape(value, defaults[field])) return fail("Invalid saved value: " + claim + "." + field);
|
|
102
|
+
record[field] = value;
|
|
103
|
+
}
|
|
104
|
+
if (opened.value) setRawField(opened.value as object, key, record);
|
|
105
|
+
else setRawField(api, global, { [key]: record });
|
|
106
|
+
return ok(undefined);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { bindValue, type Element, type RuntimeScope } from "../src";
|
|
2
|
+
import type { OwnedRecord } from "../src/owned-collections";
|
|
3
|
+
import { createFrame, type Frame, type FrameMap } from "./frames";
|
|
4
|
+
import { reveal } from "./native";
|
|
5
|
+
|
|
6
|
+
export type ScrollArea = FrameMap["ScrollFrame"] & {
|
|
7
|
+
content: Frame;
|
|
8
|
+
SetContentHeight(this: object, height: number): void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type CreateScrollArea = (this: void, parent: Frame) => ScrollArea;
|
|
12
|
+
|
|
13
|
+
function createDefaultArea(parent: Frame) {
|
|
14
|
+
const viewport = createFrame("ScrollFrame", undefined, parent);
|
|
15
|
+
const content = createFrame("Frame", undefined, viewport);
|
|
16
|
+
content.SetSize(1, 1);
|
|
17
|
+
viewport.SetScrollChild(content);
|
|
18
|
+
viewport.SetScript("OnSizeChanged", (_, width) => {
|
|
19
|
+
const available = reveal(width);
|
|
20
|
+
if (available !== undefined) content.SetWidth(Math.max(1, available));
|
|
21
|
+
});
|
|
22
|
+
viewport.EnableMouseWheel(true);
|
|
23
|
+
viewport.SetScript("OnMouseWheel", (_, raw) => {
|
|
24
|
+
const delta = reveal(raw);
|
|
25
|
+
const current = reveal(viewport.GetVerticalScroll());
|
|
26
|
+
const maximum = reveal(viewport.GetVerticalScrollRange());
|
|
27
|
+
if (delta === undefined || current === undefined || maximum === undefined) return;
|
|
28
|
+
viewport.SetVerticalScroll(Math.max(0, Math.min(maximum, current - delta * 30)));
|
|
29
|
+
});
|
|
30
|
+
return Object.assign(viewport as OwnedRecord<typeof viewport>, {
|
|
31
|
+
content,
|
|
32
|
+
SetContentHeight(this: object, height: number) { content.SetHeight(height); },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function mountScrollView(parent: Frame, scope: RuntimeScope, props: Element<"scrollview">["props"], create?: CreateScrollArea) {
|
|
37
|
+
const frame = create?.(parent) ?? createDefaultArea(parent);
|
|
38
|
+
const failure = bindValue(scope, props.contentHeight, height => {
|
|
39
|
+
const visible = reveal(height);
|
|
40
|
+
if (visible !== undefined && Number.isFinite(visible)) frame.SetContentHeight(Math.max(1, visible));
|
|
41
|
+
});
|
|
42
|
+
if (props.onScroll) frame.HookScript("OnVerticalScroll", (_, raw) => {
|
|
43
|
+
const offset = reveal(raw);
|
|
44
|
+
if (offset !== undefined && scope.isActive()) props.onScroll?.(offset);
|
|
45
|
+
});
|
|
46
|
+
let visible = false;
|
|
47
|
+
const notifyHidden = () => {
|
|
48
|
+
if (!visible) return;
|
|
49
|
+
visible = false;
|
|
50
|
+
props.onHide?.();
|
|
51
|
+
};
|
|
52
|
+
const notifyVisible = () => {
|
|
53
|
+
if (visible || !scope.isActive() || reveal(frame.IsVisible()) !== true) return;
|
|
54
|
+
visible = true;
|
|
55
|
+
props.onShow?.();
|
|
56
|
+
};
|
|
57
|
+
if (props.onShow || props.onHide) {
|
|
58
|
+
frame.HookScript("OnShow", notifyVisible);
|
|
59
|
+
frame.HookScript("OnHide", notifyHidden);
|
|
60
|
+
scope.onDispose(notifyHidden);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return { frame, content: frame.content, failure, notifyVisible };
|
|
64
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ref, type Ref } from "../src/reactivity";
|
|
2
|
+
import { isSecret, type SecretValue } from "./native";
|
|
3
|
+
|
|
4
|
+
/** A secret operand always counts as changed. Compare readable operands normally. */
|
|
5
|
+
export function secretSafeEquals(this: void, previous: unknown, next: unknown): boolean {
|
|
6
|
+
return !isSecret(previous) && !isSecret(next) && previous === next;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const secretRefOptions = { equals: secretSafeEquals };
|
|
10
|
+
|
|
11
|
+
/** Store a client value that may be secret without comparing restricted values. */
|
|
12
|
+
export function nativeRef<T>(this: void, value: T | SecretValue<T>): Ref<T | SecretValue<T>> {
|
|
13
|
+
return ref<T | SecretValue<T>>(value, secretRefOptions);
|
|
14
|
+
}
|