@overmvp/kumi 0.1.0 → 0.4.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/README.md +59 -6
- package/animation/index.ts +4 -0
- package/animation/motion-policy.ts +20 -0
- package/animation/slide.ts +61 -0
- package/animation/spring.ts +75 -0
- package/animation/staggered-reveal.ts +34 -0
- package/builder/css-gradients.mjs +74 -0
- package/builder/css-mask-assets.mjs +52 -0
- package/builder/css-mask-assets.test.mjs +31 -0
- package/builder/css-v1.mjs +127 -23
- package/builder/css-v1.test.mjs +82 -2
- package/builder/link-addon-package.mjs +47 -6
- package/builder/module-declarations.test.mjs +9 -18
- package/builder/native-kernels.mjs +1 -1
- package/builder/src/compiler.rs +205 -8
- package/builder/src/lua_upvalues.rs +641 -0
- package/builder/src/main.rs +20 -5
- package/builder/src/native_ir.rs +1 -1
- package/builder/src/native_signal.rs +46 -10
- package/builder/src/numbers.lua +14 -0
- package/builder/src/project-front.mjs +385 -34
- package/builder/src/routes.rs +11 -14
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -1
- package/builder/src/ts-lower.mjs +2 -2
- package/builder/src/wow-reads.lua +22 -0
- package/builder/style-modules.mjs +111 -0
- package/builder/style-modules.test.mjs +24 -0
- package/builder/style-states.mjs +6 -4
- package/config.ts +56 -14
- package/eslint.mjs +74 -0
- package/form/index.ts +15 -11
- package/package.json +11 -7
- package/router/index.ts +10 -2
- package/router/link.tsx +32 -0
- package/router/navigation.ts +22 -0
- package/router/router-view.ts +134 -0
- package/scripts/addon-build.mjs +377 -0
- package/scripts/addon-project.mjs +89 -0
- package/scripts/kumi-cli.mjs +52 -17
- package/scripts/link-addons.mjs +12 -2
- package/src/bindings.ts +12 -6
- package/src/context.ts +31 -7
- package/src/css-tokens.ts +27 -13
- package/src/css-v1.ts +13 -0
- package/src/elements.ts +35 -0
- package/src/flex-layout.ts +26 -5
- package/src/frame-scheduler.ts +6 -2
- package/src/index.ts +2 -1
- package/src/jsx-runtime.ts +8 -1
- package/src/keyed-list.ts +17 -11
- package/src/module-ui.ts +163 -0
- package/src/module.ts +51 -8
- package/src/owned-collections.ts +8 -0
- package/src/providers.ts +7 -1
- package/src/reactive-scope.ts +3 -3
- package/src/reactivity.ts +42 -8
- package/src/result.ts +6 -0
- package/src/signal-kernel.ts +35 -2
- package/src/style-classes.ts +22 -1
- package/src/style-states.ts +13 -6
- package/state/index.ts +6 -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.ts +2 -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 +42 -7
- package/templates/addon/eslint.config.mjs +3 -9
- package/templates/addon/gitignore +1 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +4 -5
- 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.css +90 -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.css +103 -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.css +23 -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.css +13 -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.css +91 -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 +49 -10
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +244 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +38 -0
- package/wow/animation.ts +3 -14
- package/wow/app-ui.ts +230 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-background-image.ts +75 -0
- package/wow/css-box.ts +46 -10
- package/wow/css-image-mask.ts +32 -0
- package/wow/css-surfaces.ts +295 -43
- package/wow/cursor.ts +45 -0
- package/wow/element-events.ts +33 -13
- package/wow/frame-access.ts +23 -1
- package/wow/frame-timing.ts +13 -0
- package/wow/heal-prediction.ts +2 -4
- package/wow/hooks.ts +133 -0
- package/wow/index.ts +19 -4
- package/wow/layout-view.ts +44 -23
- package/wow/locale-font.ts +15 -0
- package/wow/module-replacements.ts +103 -0
- package/wow/native.ts +18 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/pointer-click.ts +35 -0
- package/wow/protect.ts +27 -3
- package/wow/protected-view.ts +139 -0
- package/wow/range-art.ts +7 -0
- package/wow/readable-api.ts +120 -0
- package/wow/rounded-texture.ts +38 -6
- package/wow/saved-variables.ts +67 -18
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +31 -8
- package/wow/state-paint.ts +5 -14
- package/wow/texture-fill.ts +10 -0
- package/wow/unit-cast.ts +6 -4
- package/wow/view.ts +458 -228
- package/templates/addon/__ADDON_NAME__.toc +0 -4
- package/templates/addon/scripts/build.mjs +0 -25
- package/templates/addon/src/app/main.tsx +0 -13
package/wow/css-surfaces.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import type { CssBorder, CssSide } from "../src/css-v1";
|
|
2
|
-
import type { OwnedArray } from "../src/owned-collections";
|
|
1
|
+
import type { CssBorder, CssBorderPaintPlan, CssSide, CssV1Style } from "../src/css-v1";
|
|
2
|
+
import type { OwnedArray, OwnedReadonlyArray } from "../src/owned-collections";
|
|
3
3
|
import { ref } from "../src/reactivity";
|
|
4
4
|
import { fail, ok, type Result } from "../src/result";
|
|
5
5
|
import type { RuntimeScope } from "../src/runtime";
|
|
6
6
|
import type { StatePaint } from "../src/style-states";
|
|
7
7
|
import { resolveStyleValue, type StyleEnvironment } from "../src/style-variables";
|
|
8
8
|
import type { RGBA } from "../utils/colors";
|
|
9
|
+
import { createBackgroundPainter } from "./css-background-image";
|
|
9
10
|
import { readCssColor } from "./css-color";
|
|
11
|
+
import { mountImageMask } from "./css-image-mask";
|
|
10
12
|
import type { Frame, MaskTexture, Texture } from "./frames";
|
|
11
13
|
import { isSecret, reveal } from "./native";
|
|
12
|
-
import
|
|
14
|
+
import { physicalPixelScale, snapPixel } from "./pixel";
|
|
15
|
+
import type { RoundedBorderCorner, RoundedTextures } from "./rounded-texture";
|
|
13
16
|
|
|
14
17
|
type Insets = readonly [top: number, right: number, bottom: number, left: number];
|
|
15
18
|
type BackgroundImage = StatePaint["backgroundImage"];
|
|
@@ -19,6 +22,7 @@ interface SurfaceTexture {
|
|
|
19
22
|
texture: Texture;
|
|
20
23
|
shown: boolean;
|
|
21
24
|
masked: boolean;
|
|
25
|
+
cutout?: RoundedBorderCorner["asset"];
|
|
22
26
|
red?: number;
|
|
23
27
|
green?: number;
|
|
24
28
|
blue?: number;
|
|
@@ -31,15 +35,29 @@ interface NativeBorder {
|
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export interface CssSurfaceOptions {
|
|
34
|
-
readonly rounded?: Pick<RoundedTextures, "applyMask"> & Partial<Pick<RoundedTextures, "apply">>;
|
|
38
|
+
readonly rounded?: Pick<RoundedTextures, "applyMask"> & Partial<Pick<RoundedTextures, "apply" | "applyExactFill" | "resolveBorderCorner" | "borderOutline">>;
|
|
35
39
|
readonly nativeRoundedArt?: boolean;
|
|
36
40
|
readonly environment?: StyleEnvironment;
|
|
37
41
|
readonly color?: boolean;
|
|
38
42
|
readonly image?: boolean;
|
|
43
|
+
readonly maskImage?: CssV1Style["maskImage"];
|
|
39
44
|
readonly borderState?: boolean;
|
|
45
|
+
/** Fixed authored border. Its widths still follow the physical display scale. */
|
|
46
|
+
readonly fixedBorder?: CssBorder;
|
|
47
|
+
/** Immutable solid fill, without an image or a border to clip. */
|
|
48
|
+
readonly fixedFillRadius?: number;
|
|
49
|
+
readonly fixedBorderRadius?: number;
|
|
50
|
+
/** A live style can select sliced art whenever its current border is uniform. */
|
|
51
|
+
readonly liveOutline?: boolean;
|
|
52
|
+
readonly borderPaint?: CssBorderPaintPlan;
|
|
53
|
+
readonly pixelSize?: (this: void) => number;
|
|
40
54
|
}
|
|
41
55
|
|
|
42
56
|
export interface CssSurface {
|
|
57
|
+
readonly responsiveBorder?: {
|
|
58
|
+
resize(this: void, width: number, height: number): boolean;
|
|
59
|
+
useFallback(this: void): void;
|
|
60
|
+
};
|
|
43
61
|
setBorder(this: void, border?: CssBorder, radius?: number): Result<void>;
|
|
44
62
|
readonly borderPaint?: {
|
|
45
63
|
readonly sides?: readonly CssSide[];
|
|
@@ -47,11 +65,13 @@ export interface CssSurface {
|
|
|
47
65
|
write(this: void, side: CssSide, red: number, green: number, blue: number, alpha: number): void;
|
|
48
66
|
};
|
|
49
67
|
setBackgroundColor(this: void, r: number, g: number, b: number, a: number): void;
|
|
50
|
-
setBackgroundImage(this: void, image?: BackgroundImage): void
|
|
68
|
+
setBackgroundImage(this: void, image?: BackgroundImage): Result<void>;
|
|
51
69
|
}
|
|
52
70
|
|
|
53
71
|
export const borderSides = ["top", "right", "bottom", "left"] as const;
|
|
72
|
+
const singlePaintSide: readonly CssSide[] = ["top"];
|
|
54
73
|
const zeroInsets: Insets = [0, 0, 0, 0];
|
|
74
|
+
const onePixelInsets: Insets = [1, 1, 1, 1];
|
|
55
75
|
const white = "Interface\\Buttons\\WHITE8X8";
|
|
56
76
|
const maskWrap = "CLAMPTOBLACKADDITIVE";
|
|
57
77
|
|
|
@@ -64,8 +84,27 @@ export function borderInsets(this: void, border?: CssBorder): Insets {
|
|
|
64
84
|
return [width(border.top?.width), width(border.right?.width), width(border.bottom?.width), width(border.left?.width)];
|
|
65
85
|
}
|
|
66
86
|
|
|
87
|
+
function readUniformBorder(border: CssBorder | undefined, plan: CssBorderPaintPlan | undefined): Result<NativeBorder> | undefined {
|
|
88
|
+
if (border === undefined) return;
|
|
89
|
+
const literal = reveal(border.top?.color);
|
|
90
|
+
if (typeof literal !== "string") return;
|
|
91
|
+
for (const side of borderSides) {
|
|
92
|
+
const edge = border[side];
|
|
93
|
+
if (edge === undefined || reveal(edge.color) !== literal) return;
|
|
94
|
+
}
|
|
95
|
+
const insets = borderInsets(border);
|
|
96
|
+
if (insets[0] === 0 || insets[1] === 0 || insets[2] === 0 || insets[3] === 0) return;
|
|
97
|
+
// The final style can override the compiled border. Reuse its decoded color only when it still matches.
|
|
98
|
+
const matches = plan !== undefined && plan.literal === literal && insets[0] === plan.width
|
|
99
|
+
&& insets[1] === plan.width && insets[2] === plan.width && insets[3] === plan.width;
|
|
100
|
+
const rgba = matches ? plan.rgba : readCssColor(literal);
|
|
101
|
+
if (rgba === undefined) return;
|
|
102
|
+
return ok({ insets, colors: { top: { literal, rgba } } });
|
|
103
|
+
}
|
|
104
|
+
|
|
67
105
|
function readBorder(border: CssBorder | undefined, environment: StyleEnvironment | undefined): Result<NativeBorder> {
|
|
68
106
|
const colors: NativeBorder["colors"] = {};
|
|
107
|
+
let previous: NativeBorder["colors"][CssSide];
|
|
69
108
|
for (const side of borderSides) {
|
|
70
109
|
const edge = border?.[side];
|
|
71
110
|
if (edge === undefined) continue;
|
|
@@ -77,9 +116,14 @@ function readBorder(border: CssBorder | undefined, environment: StyleEnvironment
|
|
|
77
116
|
const resolved = resolveStyleValue(color, environment);
|
|
78
117
|
if (!resolved.ok) return resolved;
|
|
79
118
|
const literal = reveal(resolved.value);
|
|
119
|
+
if (previous !== undefined && previous.literal === literal) {
|
|
120
|
+
colors[side] = previous;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
80
123
|
const rgba = typeof literal === "string" ? readCssColor(literal) : undefined;
|
|
81
124
|
if (literal === undefined || rgba === undefined) return fail(`Invalid ${side} border color`);
|
|
82
|
-
|
|
125
|
+
previous = { literal, rgba };
|
|
126
|
+
colors[side] = previous;
|
|
83
127
|
}
|
|
84
128
|
return ok({ insets: borderInsets(border), colors });
|
|
85
129
|
}
|
|
@@ -95,6 +139,10 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
95
139
|
if (options.nativeRoundedArt === true && (artwork === undefined || options.color !== true || options.image === true)) {
|
|
96
140
|
return fail("Native rounded art requires a host texture port and a CSS color fill");
|
|
97
141
|
}
|
|
142
|
+
const uniformBorder = artwork === undefined ? readUniformBorder(options.fixedBorder, options.borderPaint) : undefined;
|
|
143
|
+
const combined = uniformBorder !== undefined;
|
|
144
|
+
const paintSides = combined || artwork !== undefined ? singlePaintSide : undefined;
|
|
145
|
+
const painted = (paintSides ?? borderSides) as OwnedReadonlyArray<CssSide>;
|
|
98
146
|
const layers: SurfaceTexture[] = [];
|
|
99
147
|
const edges: Record<CssSide, SurfaceTexture[]> = { top: [], right: [], bottom: [], left: [] };
|
|
100
148
|
const used: Record<CssSide, number> = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
@@ -110,6 +158,43 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
110
158
|
let previousInsets = zeroInsets;
|
|
111
159
|
let previousRadius = 0;
|
|
112
160
|
let artworkRadius: number | undefined;
|
|
161
|
+
let slicedFill = false;
|
|
162
|
+
const fixedOutline = options.fixedBorderRadius !== undefined && uniformBorder?.ok === true
|
|
163
|
+
&& sameInsets(uniformBorder.value.insets, onePixelInsets);
|
|
164
|
+
const nativeOutline = artwork === undefined && options.image !== true && options.pixelSize !== undefined
|
|
165
|
+
&& (fixedOutline || options.liveOutline === true) ? options.rounded?.borderOutline : undefined;
|
|
166
|
+
let canSlice = nativeOutline !== undefined && canPlaceOutline() && typeof frame.GetSize === "function"
|
|
167
|
+
&& typeof frame.HasScript === "function" && typeof frame.HookScript === "function"
|
|
168
|
+
&& reveal(frame.HasScript("OnSizeChanged")) === true;
|
|
169
|
+
let sliceUnavailable = false;
|
|
170
|
+
let sliceActive = false;
|
|
171
|
+
let sliceRadius: number | undefined, sliceScale: number | undefined;
|
|
172
|
+
let sliceFillRadius: number | undefined;
|
|
173
|
+
let lastSizeWidth: number | undefined, lastSizeHeight: number | undefined;
|
|
174
|
+
let minOutlineSize: number | undefined;
|
|
175
|
+
|
|
176
|
+
function outlineFits() {
|
|
177
|
+
if (minOutlineSize === undefined || lastSizeWidth === undefined || lastSizeHeight === undefined) return "fallback";
|
|
178
|
+
if (lastSizeWidth <= 0 || lastSizeHeight <= 0) return "pending";
|
|
179
|
+
return lastSizeWidth >= minOutlineSize && lastSizeHeight >= minOutlineSize ? "ready" : "fallback";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function borderSizeChanged(this: void, width: number, height: number) {
|
|
183
|
+
const previous = outlineFits();
|
|
184
|
+
const shortSide = lastSizeWidth === undefined || lastSizeHeight === undefined ? undefined : Math.min(lastSizeWidth, lastSizeHeight);
|
|
185
|
+
lastSizeWidth = reveal(width);
|
|
186
|
+
lastSizeHeight = reveal(height);
|
|
187
|
+
return !sliceUnavailable && minOutlineSize !== undefined && (outlineFits() !== previous
|
|
188
|
+
|| nativeOutline?.resolveFill !== undefined && lastSizeWidth !== undefined && lastSizeHeight !== undefined
|
|
189
|
+
&& Math.min(lastSizeWidth, lastSizeHeight) !== shortSide);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function canPlaceOutline() {
|
|
193
|
+
if (typeof frame.IsProtected !== "function" || typeof frame.IsForbidden !== "function"
|
|
194
|
+
|| reveal(frame.IsForbidden()) !== false) return false;
|
|
195
|
+
const [protectedState, explicit] = frame.IsProtected();
|
|
196
|
+
return reveal(protectedState) === false && reveal(explicit) === false;
|
|
197
|
+
}
|
|
113
198
|
|
|
114
199
|
function shown(layer: SurfaceTexture, visible: boolean) {
|
|
115
200
|
if (layer.shown === visible) return;
|
|
@@ -140,13 +225,13 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
140
225
|
}
|
|
141
226
|
}
|
|
142
227
|
|
|
143
|
-
function makeLayer(layer: "BACKGROUND" | "BORDER", level: number, solid: boolean) {
|
|
228
|
+
function makeLayer(layer: "BACKGROUND" | "BORDER", level: number, solid: boolean, maskable = true) {
|
|
144
229
|
const texture = frame.CreateTexture(undefined, layer, undefined, level);
|
|
145
230
|
const entry: SurfaceTexture = { texture, shown: true, masked: false };
|
|
146
231
|
layers.push(entry);
|
|
147
232
|
shown(entry, false);
|
|
148
233
|
if (solid) texture.SetColorTexture(1, 1, 1, 1);
|
|
149
|
-
if (mask !== undefined && maskRadius !== undefined) attach(entry, mask);
|
|
234
|
+
if (maskable && mask !== undefined && maskRadius !== undefined) attach(entry, mask);
|
|
150
235
|
return entry;
|
|
151
236
|
}
|
|
152
237
|
|
|
@@ -179,26 +264,36 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
179
264
|
target.SetAllPoints(frame);
|
|
180
265
|
hasMaskAnchor = true;
|
|
181
266
|
}
|
|
182
|
-
for (const layer of layers) attach(layer, target);
|
|
267
|
+
for (const layer of layers) if (layer !== outline) attach(layer, target);
|
|
183
268
|
maskRadius = radius;
|
|
184
269
|
return ok(undefined);
|
|
185
270
|
}
|
|
186
271
|
|
|
187
|
-
function nextPart(side: CssSide): SurfaceTexture {
|
|
272
|
+
function nextPart(side: CssSide, solid = true): SurfaceTexture {
|
|
188
273
|
const index = used[side]++;
|
|
189
274
|
const parts = edges[side] as OwnedArray<SurfaceTexture>;
|
|
190
275
|
let part = parts[index];
|
|
191
276
|
if (part === undefined) {
|
|
192
|
-
part = makeLayer("BORDER", -8,
|
|
277
|
+
part = makeLayer("BORDER", -8, solid);
|
|
278
|
+
if (options.pixelSize !== undefined) {
|
|
279
|
+
part.texture.SetSnapToPixelGrid?.(false);
|
|
280
|
+
part.texture.SetTexelSnappingBias?.(0);
|
|
281
|
+
}
|
|
193
282
|
parts.push(part);
|
|
283
|
+
} else {
|
|
284
|
+
part.texture.ClearAllPoints();
|
|
285
|
+
if (solid && part.cutout !== undefined) {
|
|
286
|
+
part.texture.SetColorTexture(1, 1, 1, 1);
|
|
287
|
+
part.cutout = undefined;
|
|
288
|
+
part.red = undefined;
|
|
289
|
+
}
|
|
194
290
|
}
|
|
195
|
-
part.texture.ClearAllPoints();
|
|
196
291
|
return part;
|
|
197
292
|
}
|
|
198
293
|
|
|
199
294
|
function band(side: CssSide, inset: number, start: Point, end: Point, first: number, last: number, horizontal: boolean) {
|
|
200
295
|
if (inset === 0) return;
|
|
201
|
-
const part = nextPart(side).texture;
|
|
296
|
+
const part = nextPart(combined ? "top" : side).texture;
|
|
202
297
|
part.SetPoint(start, frame, start, horizontal ? first : 0, horizontal ? 0 : -first);
|
|
203
298
|
part.SetPoint(end, frame, end, horizontal ? -last : 0, horizontal ? 0 : last);
|
|
204
299
|
if (horizontal) part.SetHeight(inset);
|
|
@@ -222,6 +317,11 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
222
317
|
}
|
|
223
318
|
|
|
224
319
|
function paint(top: number, bottom: number, limit: number) {
|
|
320
|
+
// The neighboring spans share a tint and sum to the same masked row.
|
|
321
|
+
if (combined) {
|
|
322
|
+
patch("top", 0, top, limit, bottom - top);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
225
325
|
const split = height === 0 ? limit : Math.min(limit, (top + bottom) * width / (2 * height));
|
|
226
326
|
patch(vertical, 0, top, split, bottom - top);
|
|
227
327
|
patch(horizontal, split, top, limit - split, bottom - top);
|
|
@@ -239,7 +339,24 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
239
339
|
}
|
|
240
340
|
}
|
|
241
341
|
|
|
242
|
-
function
|
|
342
|
+
function bakedCorner(point: Point, radius: number, art: RoundedBorderCorner): boolean {
|
|
343
|
+
const part = nextPart("top", false);
|
|
344
|
+
const texture = part.texture;
|
|
345
|
+
if (part.cutout !== art.asset) {
|
|
346
|
+
part.cutout = art.asset;
|
|
347
|
+
part.red = undefined;
|
|
348
|
+
if (texture.SetTexture(art.asset) === false) return false;
|
|
349
|
+
}
|
|
350
|
+
const { extent } = art;
|
|
351
|
+
const right = point === "TOPRIGHT" || point === "BOTTOMRIGHT";
|
|
352
|
+
const bottom = point === "BOTTOMLEFT" || point === "BOTTOMRIGHT";
|
|
353
|
+
texture.SetTexCoord(right ? extent : 0, right ? 0 : extent, bottom ? extent : 0, bottom ? 0 : extent);
|
|
354
|
+
texture.SetPoint(point, frame, point, 0, 0);
|
|
355
|
+
texture.SetSize(radius, radius);
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function geometry(insets: Insets, radius: number, art?: RoundedBorderCorner) {
|
|
243
360
|
const [top, right, bottom, left] = insets;
|
|
244
361
|
const startX = radius > 0 ? Math.max(radius, left) : 0;
|
|
245
362
|
const endX = radius > 0 ? Math.max(radius, right) : 0;
|
|
@@ -250,21 +367,120 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
250
367
|
band("bottom", bottom, "BOTTOMLEFT", "BOTTOMRIGHT", startX, endX, true);
|
|
251
368
|
band("left", left, "TOPLEFT", "BOTTOMLEFT", startY, endY, false);
|
|
252
369
|
band("right", right, "TOPRIGHT", "BOTTOMRIGHT", startY, endY, false);
|
|
370
|
+
if (art !== undefined) {
|
|
371
|
+
const bands = used.top;
|
|
372
|
+
if (bakedCorner("TOPLEFT", radius, art) && bakedCorner("TOPRIGHT", radius, art)
|
|
373
|
+
&& bakedCorner("BOTTOMLEFT", radius, art) && bakedCorner("BOTTOMRIGHT", radius, art)) return;
|
|
374
|
+
used.top = bands;
|
|
375
|
+
}
|
|
253
376
|
corner("TOPLEFT", "top", "left", top, left, radius);
|
|
254
377
|
corner("TOPRIGHT", "top", "right", top, right, radius);
|
|
255
378
|
corner("BOTTOMLEFT", "bottom", "left", bottom, left, radius);
|
|
256
379
|
corner("BOTTOMRIGHT", "bottom", "right", bottom, right, radius);
|
|
257
380
|
}
|
|
258
381
|
|
|
382
|
+
function supportsPixelOutline(texture: Texture) {
|
|
383
|
+
return typeof texture.SetTextureSliceMargins === "function" && typeof texture.SetTextureSliceMode === "function"
|
|
384
|
+
&& typeof texture.SetIgnoreParentScale === "function" && typeof texture.SetScale === "function"
|
|
385
|
+
&& typeof texture.SetSnapToPixelGrid === "function" && typeof texture.SetTexelSnappingBias === "function";
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function restoreFill() {
|
|
389
|
+
if (color === undefined || sliceFillRadius === undefined) return;
|
|
390
|
+
const texture = color.texture;
|
|
391
|
+
texture.SetIgnoreParentScale(false);
|
|
392
|
+
texture.SetScale(1);
|
|
393
|
+
texture.SetTextureSliceMargins(0, 0, 0, 0);
|
|
394
|
+
texture.SetColorTexture(1, 1, 1, 1);
|
|
395
|
+
if (colorR !== undefined && colorG !== undefined && colorB !== undefined && colorA !== undefined) {
|
|
396
|
+
texture.SetVertexColor(colorR, colorG, colorB, colorA);
|
|
397
|
+
}
|
|
398
|
+
sliceFillRadius = undefined;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function setPixelFill(deviceRadius: number, scale: number) {
|
|
402
|
+
if (color === undefined || nativeOutline === undefined) return;
|
|
403
|
+
const texture = color.texture;
|
|
404
|
+
if (sliceFillRadius !== deviceRadius) {
|
|
405
|
+
const asset = nativeOutline.resolveFill?.(deviceRadius);
|
|
406
|
+
if (asset === undefined || texture.SetTexture(asset) === false) return restoreFill();
|
|
407
|
+
texture.SetIgnoreParentScale(true);
|
|
408
|
+
texture.SetTexelSnappingBias(0);
|
|
409
|
+
texture.SetSnapToPixelGrid(true);
|
|
410
|
+
texture.SetTextureSliceMargins(deviceRadius, deviceRadius, deviceRadius, deviceRadius);
|
|
411
|
+
texture.SetTextureSliceMode(nativeOutline.stretched);
|
|
412
|
+
if (colorR !== undefined && colorG !== undefined && colorB !== undefined && colorA !== undefined) {
|
|
413
|
+
texture.SetVertexColor(colorR, colorG, colorB, colorA);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (sliceFillRadius !== deviceRadius || sliceScale !== scale) texture.SetScale(scale);
|
|
417
|
+
sliceFillRadius = deviceRadius;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function setPixelOutline(pixel: number, radius: number) {
|
|
421
|
+
minOutlineSize = undefined;
|
|
422
|
+
if (nativeOutline === undefined || sliceUnavailable || radius <= pixel || !canPlaceOutline()) return false;
|
|
423
|
+
const scale = physicalPixelScale();
|
|
424
|
+
if (scale === undefined) return false;
|
|
425
|
+
let deviceRadius = Math.round(radius / pixel);
|
|
426
|
+
if (lastSizeWidth === undefined || lastSizeHeight === undefined) {
|
|
427
|
+
const [width, height] = frame.GetSize();
|
|
428
|
+
lastSizeWidth = reveal(width);
|
|
429
|
+
lastSizeHeight = reveal(height);
|
|
430
|
+
}
|
|
431
|
+
// A small surface can share a slightly smaller radius between fill and outline.
|
|
432
|
+
if (nativeOutline.resolveFill !== undefined && lastSizeWidth !== undefined && lastSizeHeight !== undefined
|
|
433
|
+
&& lastSizeWidth > 0 && lastSizeHeight > 0) {
|
|
434
|
+
const shortSide = Math.min(lastSizeWidth, lastSizeHeight);
|
|
435
|
+
deviceRadius = Math.min(deviceRadius, Math.floor((shortSide / pixel - 1) / 2));
|
|
436
|
+
}
|
|
437
|
+
// Both caps must fit even after the client rounds the vertices to display pixels.
|
|
438
|
+
minOutlineSize = (2 * Math.max(2, deviceRadius) + 1) * pixel;
|
|
439
|
+
const fit = outlineFits();
|
|
440
|
+
if (fit !== "ready") return fit === "pending";
|
|
441
|
+
const asset = nativeOutline.resolve(deviceRadius);
|
|
442
|
+
if (asset === undefined) return false;
|
|
443
|
+
|
|
444
|
+
if (outline === undefined) {
|
|
445
|
+
outline = makeLayer("BORDER", -8, false, false);
|
|
446
|
+
const texture = outline.texture;
|
|
447
|
+
if (color === undefined && !supportsPixelOutline(texture)) {
|
|
448
|
+
sliceUnavailable = true;
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
texture.SetIgnoreParentScale(true);
|
|
452
|
+
texture.SetTexelSnappingBias(0);
|
|
453
|
+
texture.SetSnapToPixelGrid(true);
|
|
454
|
+
texture.SetAllPoints(frame);
|
|
455
|
+
}
|
|
456
|
+
const texture = outline.texture;
|
|
457
|
+
if (sliceRadius !== deviceRadius) {
|
|
458
|
+
sliceRadius = undefined;
|
|
459
|
+
if (texture.SetTexture(asset) === false) return false;
|
|
460
|
+
texture.SetTextureSliceMargins(deviceRadius, deviceRadius, deviceRadius, deviceRadius);
|
|
461
|
+
texture.SetTextureSliceMode(nativeOutline.stretched);
|
|
462
|
+
sliceRadius = deviceRadius;
|
|
463
|
+
}
|
|
464
|
+
setPixelFill(deviceRadius, scale);
|
|
465
|
+
if (sliceScale !== scale) {
|
|
466
|
+
texture.SetScale(scale);
|
|
467
|
+
sliceScale = scale;
|
|
468
|
+
}
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
|
|
259
472
|
function setBorder(border?: CssBorder, radius = 0): Result<void> {
|
|
260
473
|
if (!scope.isActive()) return fail("CSS surface scope is disposed");
|
|
261
474
|
if (isSecret(radius) || !Number.isFinite(radius) || radius < 0) return fail("Invalid CSS border radius");
|
|
262
|
-
|
|
475
|
+
if (slicedFill) {
|
|
476
|
+
return border === undefined && radius === options.fixedFillRadius ? ok(undefined) : fail("A fixed CSS fill cannot change shape");
|
|
477
|
+
}
|
|
478
|
+
const read = uniformBorder ?? readBorder(border, options.environment);
|
|
263
479
|
if (!read.ok) return read;
|
|
264
|
-
const { insets, colors } = read.value;
|
|
480
|
+
const { insets: logical, colors } = read.value;
|
|
265
481
|
if (artwork !== undefined) {
|
|
266
482
|
const edge = colors.top;
|
|
267
|
-
if (border !== undefined && (!
|
|
483
|
+
if (border !== undefined && (!logical.every(amount => amount === 1) || edge === undefined
|
|
268
484
|
|| !borderSides.every(side => colors[side]?.literal === edge.literal))) {
|
|
269
485
|
return fail("Native rounded art requires a uniform 1px CSS border");
|
|
270
486
|
}
|
|
@@ -290,15 +506,49 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
290
506
|
});
|
|
291
507
|
return configured;
|
|
292
508
|
}
|
|
509
|
+
const pixel = border === undefined && uniformBorder === undefined ? undefined : options.pixelSize?.();
|
|
510
|
+
const snap = (value: number) => value === 0 || pixel === undefined ? value
|
|
511
|
+
: value === 1 ? pixel : Math.max(pixel, snapPixel(value, pixel));
|
|
512
|
+
const insets: Insets = pixel === undefined ? logical : [snap(logical[0]), snap(logical[1]), snap(logical[2]), snap(logical[3])];
|
|
293
513
|
const configured = scope.protect(() => {
|
|
294
|
-
|
|
514
|
+
const edge = colors.top;
|
|
515
|
+
const uniform = edge !== undefined && (combined
|
|
516
|
+
|| borderSides.every(side => colors[side]?.literal === edge.literal));
|
|
517
|
+
if (canSlice && pixel !== undefined && edge !== undefined && uniform && sameInsets(logical, onePixelInsets)) {
|
|
518
|
+
const sliced = scope.protect(() => setPixelOutline(pixel, radius));
|
|
519
|
+
if (!sliced.ok) sliceUnavailable = true;
|
|
520
|
+
if (sliced.ok && sliced.value) {
|
|
521
|
+
const masked = setMask(color === undefined || sliceFillRadius !== undefined ? undefined : radius);
|
|
522
|
+
if (!masked.ok) return masked;
|
|
523
|
+
if (!sliceActive) {
|
|
524
|
+
for (const side of borderSides) for (const part of edges[side] as OwnedArray<SurfaceTexture>) shown(part, false);
|
|
525
|
+
}
|
|
526
|
+
sliceActive = true;
|
|
527
|
+
if (outline !== undefined) {
|
|
528
|
+
const [r, g, b, a] = borderState?.drawn.top ?? edge.rgba;
|
|
529
|
+
tint(outline, r, g, b, a);
|
|
530
|
+
shown(outline, true);
|
|
531
|
+
}
|
|
532
|
+
if (borderState !== undefined) borderState.base.value = colors;
|
|
533
|
+
return ok(undefined);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
const switching = sliceActive;
|
|
537
|
+
if (switching && outline !== undefined) shown(outline, false);
|
|
538
|
+
restoreFill();
|
|
539
|
+
sliceActive = false;
|
|
540
|
+
if (switching || radius !== previousRadius || !sameInsets(previousInsets, insets)) {
|
|
295
541
|
const masked = setMask(radius > 0 ? radius : insets.some(value => value > 0) ? 0 : undefined);
|
|
296
542
|
if (!masked.ok) return masked;
|
|
297
|
-
|
|
543
|
+
// Keep the side bands and outer mask. The corner texture provides only the inner cutout.
|
|
544
|
+
const onePixel = pixel !== undefined && pixel > 0 && radius > pixel && combined && options.borderPaint?.width === 1
|
|
545
|
+
&& logical[0] === 1 && logical[1] === 1 && logical[2] === 1 && logical[3] === 1;
|
|
546
|
+
const art = onePixel ? options.rounded?.resolveBorderCorner?.(Math.round(radius / pixel)) : undefined;
|
|
547
|
+
geometry(insets, radius, art);
|
|
298
548
|
previousRadius = radius;
|
|
299
549
|
previousInsets = insets;
|
|
300
550
|
}
|
|
301
|
-
for (const side of
|
|
551
|
+
for (const side of painted) {
|
|
302
552
|
const base = colors[side];
|
|
303
553
|
if (base === undefined && borderState !== undefined) borderState.drawn[side] = undefined;
|
|
304
554
|
const drawn = base === undefined || borderState === undefined ? undefined : borderState.drawn[side];
|
|
@@ -320,7 +570,7 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
320
570
|
}
|
|
321
571
|
|
|
322
572
|
const borderPaint: CssSurface["borderPaint"] = borderState === undefined ? undefined : {
|
|
323
|
-
sides:
|
|
573
|
+
sides: paintSides,
|
|
324
574
|
read: side => borderState.base.value[side]?.literal,
|
|
325
575
|
write(this: void, side, red, green, blue, alpha) {
|
|
326
576
|
if (!scope.isActive() || borderState.base.value[side] === undefined) return;
|
|
@@ -329,8 +579,8 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
329
579
|
drawn[1] = green;
|
|
330
580
|
drawn[2] = blue;
|
|
331
581
|
drawn[3] = alpha;
|
|
332
|
-
if (
|
|
333
|
-
tint(outline, red, green, blue, alpha);
|
|
582
|
+
if (sliceActive || artwork !== undefined) {
|
|
583
|
+
if (outline !== undefined && side === "top") tint(outline, red, green, blue, alpha);
|
|
334
584
|
return;
|
|
335
585
|
}
|
|
336
586
|
const parts = edges[side] as OwnedArray<SurfaceTexture>;
|
|
@@ -349,24 +599,6 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
349
599
|
colorA = a;
|
|
350
600
|
}
|
|
351
601
|
|
|
352
|
-
let path: string | undefined, atlas: string | undefined;
|
|
353
|
-
function setBackgroundImage(next?: BackgroundImage) {
|
|
354
|
-
if (!scope.isActive() || image === undefined) return;
|
|
355
|
-
const nextPath = next !== undefined && "path" in next ? next.path : undefined;
|
|
356
|
-
const nextAtlas = next !== undefined && "atlas" in next ? next.atlas : undefined;
|
|
357
|
-
if (path === nextPath && atlas === nextAtlas) return;
|
|
358
|
-
if (nextPath !== undefined) {
|
|
359
|
-
const local = nextPath.startsWith("./") ? nextPath.slice(2) : nextPath;
|
|
360
|
-
if (atlas !== undefined) image.texture.SetTexCoord(0, 1, 0, 1);
|
|
361
|
-
shown(image, image.texture.SetTexture(local.split("/").join("\\")) !== false);
|
|
362
|
-
} else if (nextAtlas !== undefined) {
|
|
363
|
-
image.texture.SetAtlas(nextAtlas, false);
|
|
364
|
-
shown(image, true);
|
|
365
|
-
} else shown(image, false);
|
|
366
|
-
path = nextPath;
|
|
367
|
-
atlas = nextAtlas;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
602
|
function release() {
|
|
371
603
|
for (const layer of layers) {
|
|
372
604
|
shown(layer, false);
|
|
@@ -377,8 +609,14 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
377
609
|
|
|
378
610
|
const created = scope.protect(() => {
|
|
379
611
|
if (options.color === true) {
|
|
380
|
-
|
|
612
|
+
const fill = options.fixedFillRadius;
|
|
613
|
+
color = makeLayer("BACKGROUND", -8, artwork === undefined && fill === undefined);
|
|
381
614
|
color.texture.SetAllPoints(frame);
|
|
615
|
+
if (canSlice && !supportsPixelOutline(color.texture)) canSlice = false;
|
|
616
|
+
if (fill !== undefined) {
|
|
617
|
+
slicedFill = options.rounded?.applyExactFill?.(color.texture, fill) === true;
|
|
618
|
+
if (!slicedFill) color.texture.SetColorTexture(1, 1, 1, 1);
|
|
619
|
+
}
|
|
382
620
|
}
|
|
383
621
|
if (options.image === true) {
|
|
384
622
|
image = makeLayer("BACKGROUND", -7, false);
|
|
@@ -394,5 +632,19 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
394
632
|
scope.protect(release);
|
|
395
633
|
return cleanup;
|
|
396
634
|
}
|
|
397
|
-
|
|
635
|
+
const background = image;
|
|
636
|
+
const paintImage = background === undefined ? undefined
|
|
637
|
+
: createBackgroundPainter(background.texture, visible => shown(background, visible), options.environment);
|
|
638
|
+
if (background !== undefined && options.maskImage !== undefined) {
|
|
639
|
+
const applied = mountImageMask(scope, frame, background.texture, options.maskImage);
|
|
640
|
+
if (!applied.ok) return applied;
|
|
641
|
+
}
|
|
642
|
+
function setBackgroundImage(next?: BackgroundImage): Result<void> {
|
|
643
|
+
return scope.isActive() && paintImage !== undefined ? paintImage(next) : ok(undefined);
|
|
644
|
+
}
|
|
645
|
+
const responsiveBorder = canSlice ? {
|
|
646
|
+
resize: borderSizeChanged,
|
|
647
|
+
useFallback: () => { canSlice = false; },
|
|
648
|
+
} : undefined;
|
|
649
|
+
return ok({ responsiveBorder, setBorder, borderPaint, setBackgroundColor, setBackgroundImage });
|
|
398
650
|
}
|
package/wow/cursor.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { api, reveal, type LuaMultiReturn } from "./native";
|
|
2
|
+
|
|
3
|
+
declare const $multi: (<const Values extends unknown[]>(this: void, ...values: Values) => LuaMultiReturn<Values>) & {
|
|
4
|
+
readonly __tstlExtension: "MultiFunction";
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/** Read the cursor's first result when the client exposes it. */
|
|
8
|
+
export function readCursorKind(this: void): string | undefined {
|
|
9
|
+
const read = api.GetCursorInfo;
|
|
10
|
+
if (read === undefined) return undefined;
|
|
11
|
+
return reveal(read()[0]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A spell, bag item, or collected toy carried by the WoW cursor. */
|
|
15
|
+
export type CursorAction = { readonly kind: "spell" | "item" | "toy"; readonly id: number };
|
|
16
|
+
|
|
17
|
+
function readCursorActionParts(this: void): LuaMultiReturn<[] | [kind: CursorAction["kind"], id: number]> {
|
|
18
|
+
const read = api.GetCursorInfo;
|
|
19
|
+
if (read === undefined) return $multi();
|
|
20
|
+
// WoW returns the spellbook index first and the spell ID last.
|
|
21
|
+
const [rawKind, first, , spell] = read();
|
|
22
|
+
const kind = reveal(rawKind);
|
|
23
|
+
if (kind !== "spell" && kind !== "item" && kind !== "toy") return $multi();
|
|
24
|
+
let rawId = first;
|
|
25
|
+
if (kind === "spell") rawId = spell;
|
|
26
|
+
const id = reveal(rawId);
|
|
27
|
+
if (typeof id !== "number" || !(id > 0 && id <= 2147483647 && Math.floor(id) === id)) return $multi();
|
|
28
|
+
return $multi(kind, id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Check whether the cursor carries an assignable action without resolving toy ownership. */
|
|
32
|
+
export function hasCursorAction(this: void): boolean {
|
|
33
|
+
return readCursorActionParts()[0] !== undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Read an action suitable for assignment to a secure action slot. */
|
|
37
|
+
export function readCursorAction(this: void): CursorAction | undefined {
|
|
38
|
+
const [kind, id] = readCursorActionParts();
|
|
39
|
+
if (kind === undefined) return undefined;
|
|
40
|
+
if (kind === "item") {
|
|
41
|
+
const ownsToy = api.PlayerHasToy;
|
|
42
|
+
if (ownsToy !== undefined && reveal(ownsToy(id)) === true) return { kind: "toy", id };
|
|
43
|
+
}
|
|
44
|
+
return { kind, id };
|
|
45
|
+
}
|