@overmvp/kumi 0.0.0-stage → 0.1.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 +14 -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 +334 -0
- package/builder/css-v1.test.mjs +321 -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 +86 -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 +444 -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 +2164 -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 +367 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +47 -0
- package/builder/src/numbers.lua +62 -0
- package/builder/src/project-front.mjs +3331 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +127 -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_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -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 +17 -0
- package/form/index.ts +522 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +22 -4
- package/router/index.ts +43 -0
- package/router/package.json +12 -0
- package/router/routes.ts +64 -0
- package/scripts/kumi-cli.mjs +70 -0
- package/scripts/link-addons.mjs +51 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +234 -0
- package/src/css-v1.ts +58 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +479 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +334 -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 +28 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +22 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +363 -0
- package/src/media-query.ts +144 -0
- package/src/module.ts +277 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +44 -0
- package/src/providers.ts +235 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +254 -0
- package/src/result.ts +58 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +30 -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 +3 -0
- package/state/package.json +12 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +82 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/README.md +14 -0
- package/templates/addon/__ADDON_NAME__.toc +4 -0
- package/templates/addon/eslint.config.mjs +12 -0
- package/templates/addon/gitignore +8 -0
- package/templates/addon/package.json +21 -0
- package/templates/addon/scripts/build.mjs +25 -0
- package/templates/addon/src/app/main.tsx +13 -0
- package/templates/addon/tsconfig.json +24 -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/animation.ts +428 -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/css-box.ts +110 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +398 -0
- package/wow/css-text.ts +399 -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 +31 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +97 -0
- package/wow/layout-view.ts +651 -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 +135 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/protect.ts +24 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/range-art.ts +74 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +156 -0
- package/wow/saved-variables.ts +60 -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/start-addon.ts +99 -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 +1746 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Element, RuntimeScope } from "../src";
|
|
2
|
+
import type { Button } from "./frames";
|
|
3
|
+
import { api, reveal } from "./native";
|
|
4
|
+
|
|
5
|
+
export function bindButtonDrag(button: Button, scope: RuntimeScope,
|
|
6
|
+
{ onDrag, onDragEnd, onDragCancel }: Element<"button">["props"]) {
|
|
7
|
+
if (!onDrag && !onDragEnd) return;
|
|
8
|
+
let startY: number | undefined;
|
|
9
|
+
|
|
10
|
+
function cursorY() {
|
|
11
|
+
const [, rawY] = api.GetCursorPosition();
|
|
12
|
+
const y = reveal(rawY);
|
|
13
|
+
const scale = reveal(button.GetEffectiveScale());
|
|
14
|
+
if (y !== undefined && scale !== undefined && scale > 0) return y / scale;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function stop() {
|
|
18
|
+
if (startY === undefined) return false;
|
|
19
|
+
startY = undefined;
|
|
20
|
+
button.SetScript("OnUpdate", undefined);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
button.RegisterForDrag("LeftButton");
|
|
25
|
+
button.SetScript("OnDragStart", () => {
|
|
26
|
+
if (!scope.isActive() || !button.IsEnabled()) return;
|
|
27
|
+
startY = cursorY();
|
|
28
|
+
if (startY === undefined || !onDrag) return;
|
|
29
|
+
button.SetScript("OnUpdate", () => {
|
|
30
|
+
const y = cursorY();
|
|
31
|
+
if (startY !== undefined && y !== undefined) onDrag(startY - y);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
button.SetScript("OnDragStop", () => {
|
|
35
|
+
const from = startY;
|
|
36
|
+
const y = cursorY();
|
|
37
|
+
if (!stop()) return;
|
|
38
|
+
if (from !== undefined && y !== undefined && scope.isActive()) onDragEnd?.(from - y);
|
|
39
|
+
else onDragCancel?.();
|
|
40
|
+
});
|
|
41
|
+
const cancel = () => { if (stop()) onDragCancel?.(); };
|
|
42
|
+
button.HookScript("OnHide", cancel);
|
|
43
|
+
scope.onDispose(() => {
|
|
44
|
+
cancel();
|
|
45
|
+
button.SetScript("OnDragStart", undefined);
|
|
46
|
+
button.SetScript("OnDragStop", undefined);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createFrame, type AnimationGroup, type FontString, type Frame, type StatusBar } from "./frames";
|
|
2
|
+
import { api, isSecret, reveal, type SecretValue } from "./native";
|
|
3
|
+
import { protect } from "./protect";
|
|
4
|
+
import { getUnitCastDuration, type UnitCast } from "./unit-cast";
|
|
5
|
+
|
|
6
|
+
type CastTick = (this: void) => void;
|
|
7
|
+
|
|
8
|
+
export interface CastClockOptions {
|
|
9
|
+
view: Frame;
|
|
10
|
+
bar: StatusBar;
|
|
11
|
+
text?: FontString;
|
|
12
|
+
/** Hide the view when a numeric fallback finishes. Defaults to true. */
|
|
13
|
+
hideOnFinish?: boolean;
|
|
14
|
+
/** Called after a numeric fallback finishes and the clock stops. */
|
|
15
|
+
onFinish?: (this: void) => void;
|
|
16
|
+
/** Wrap recurring text and fallback bar updates. */
|
|
17
|
+
wrapTick?: (this: void, tick: CastTick) => CastTick;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ActiveCast =
|
|
21
|
+
| { kind: "native"; cast: UnitCast; showText: boolean }
|
|
22
|
+
| { kind: "fallback"; start: number; end: number; drains: boolean; showText: boolean };
|
|
23
|
+
|
|
24
|
+
type CastBar = StatusBar & { ClearTimerDuration?(this: object): void };
|
|
25
|
+
|
|
26
|
+
const textInterval = 0.1;
|
|
27
|
+
const secondsFormat = "%.1f";
|
|
28
|
+
|
|
29
|
+
function drains(cast: UnitCast) {
|
|
30
|
+
return cast.channel && cast.empowerStages === undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Drive the fill natively when WoW supplies a duration, with a readable timing fallback. */
|
|
34
|
+
export function createCastClock(this: void, { view, bar, text, hideOnFinish = true, onFinish, wrapTick }: CastClockOptions) {
|
|
35
|
+
const clearTimer = (bar as CastBar).ClearTimerDuration;
|
|
36
|
+
const enums = api.Enum;
|
|
37
|
+
const directions = enums?.StatusBarTimerDirection;
|
|
38
|
+
const interpolation = enums === undefined ? undefined : enums.StatusBarInterpolation?.Immediate;
|
|
39
|
+
const formattedText = text?.SetFormattedText as ((this: FontString, format: string, value: number | SecretValue<number>) => void) | undefined;
|
|
40
|
+
let active: ActiveCast | undefined;
|
|
41
|
+
let animation: AnimationGroup | undefined;
|
|
42
|
+
let driver: Frame | undefined;
|
|
43
|
+
let nextTextAt = 0;
|
|
44
|
+
|
|
45
|
+
function pause(this: void) {
|
|
46
|
+
animation?.Stop();
|
|
47
|
+
driver?.Hide();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function stop(this: void) {
|
|
51
|
+
active = undefined;
|
|
52
|
+
pause();
|
|
53
|
+
if (clearTimer) protect(() => clearTimer.call(bar));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function start(this: void, cast: UnitCast, showText = true) {
|
|
57
|
+
const { duration } = cast;
|
|
58
|
+
if (bar.SetTimerDuration && (isSecret(duration) || duration !== undefined)) {
|
|
59
|
+
const direction = drains(cast) ? directions?.RemainingTime : directions?.ElapsedTime;
|
|
60
|
+
const applied = protect(() =>
|
|
61
|
+
bar.SetTimerDuration(duration as Parameters<StatusBar["SetTimerDuration"]>[0], interpolation, direction));
|
|
62
|
+
if (applied.ok) {
|
|
63
|
+
active = { kind: "native", cast, showText };
|
|
64
|
+
driver?.Hide();
|
|
65
|
+
if (!showText) animation?.Stop();
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const start = reveal(cast.startMS);
|
|
70
|
+
const end = reveal(cast.endMS);
|
|
71
|
+
if (start === undefined || end === undefined) {
|
|
72
|
+
stop();
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
stop();
|
|
76
|
+
active = { kind: "fallback", start: start / 1000, end: end / 1000, drains: drains(cast), showText };
|
|
77
|
+
nextTextAt = 0;
|
|
78
|
+
bar.SetMinMaxValues(0, 1);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function tickNative(this: void, cast: UnitCast) {
|
|
83
|
+
if (text === undefined || formattedText === undefined) return;
|
|
84
|
+
const refreshed = getUnitCastDuration(cast.unit, cast.channel, cast.empowerStages !== undefined);
|
|
85
|
+
const duration = isSecret(refreshed) || refreshed !== undefined ? refreshed : cast.duration;
|
|
86
|
+
if (isSecret(duration) || duration !== undefined) {
|
|
87
|
+
const nativeDuration = duration as Parameters<StatusBar["SetTimerDuration"]>[0];
|
|
88
|
+
const remaining = protect(() => formattedText.call(text, secondsFormat, nativeDuration.GetRemainingDuration()));
|
|
89
|
+
if (remaining.ok) return;
|
|
90
|
+
const end = protect(() => reveal(nativeDuration.GetEndTime()));
|
|
91
|
+
if (end.ok && typeof end.value === "number") {
|
|
92
|
+
formattedText.call(text, secondsFormat, Math.max(0, end.value - api.GetTime()));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const end = reveal(cast.endMS);
|
|
97
|
+
if (end === undefined) text.SetText("");
|
|
98
|
+
else formattedText.call(text, secondsFormat, Math.max(0, end / 1000 - api.GetTime()));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function tickFallback(this: void) {
|
|
102
|
+
if (active?.kind !== "fallback") {
|
|
103
|
+
driver?.Hide();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const now = api.GetTime();
|
|
107
|
+
const progress = Math.max(0, Math.min(1, (now - active.start) / Math.max(0.001, active.end - active.start)));
|
|
108
|
+
bar.SetValue(active.drains ? 1 - progress : progress);
|
|
109
|
+
if (active.showText && text !== undefined && formattedText !== undefined && now >= nextTextAt) {
|
|
110
|
+
formattedText.call(text, secondsFormat, Math.max(0, active.end - now));
|
|
111
|
+
nextTextAt = now + textInterval;
|
|
112
|
+
}
|
|
113
|
+
if (now >= active.end) {
|
|
114
|
+
if (hideOnFinish) {
|
|
115
|
+
stop();
|
|
116
|
+
view.Hide();
|
|
117
|
+
} else {
|
|
118
|
+
active = undefined;
|
|
119
|
+
driver?.Hide();
|
|
120
|
+
}
|
|
121
|
+
onFinish?.();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function tickNativeLoop(this: void) {
|
|
126
|
+
if (active?.kind === "native" && active.showText) tickNative(active.cast);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function play(this: void) {
|
|
130
|
+
if (!active || reveal(view.IsVisible()) !== true) return;
|
|
131
|
+
if (active.kind === "fallback") {
|
|
132
|
+
if (driver === undefined) {
|
|
133
|
+
driver = createFrame("Frame", undefined, view);
|
|
134
|
+
driver.SetScript("OnUpdate", wrapTick?.(tickFallback) ?? tickFallback);
|
|
135
|
+
}
|
|
136
|
+
driver.Show();
|
|
137
|
+
tickFallback();
|
|
138
|
+
} else if (active.showText && text !== undefined && formattedText !== undefined) {
|
|
139
|
+
tickNative(active.cast);
|
|
140
|
+
if (animation === undefined) {
|
|
141
|
+
animation = view.CreateAnimationGroup();
|
|
142
|
+
animation.SetLooping("REPEAT");
|
|
143
|
+
animation.CreateAnimation("Animation").SetDuration(textInterval);
|
|
144
|
+
animation.SetScript("OnLoop", wrapTick?.(tickNativeLoop) ?? tickNativeLoop);
|
|
145
|
+
}
|
|
146
|
+
if (reveal(animation.IsPlaying()) !== true) animation.Play();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
view.HookScript("OnShow", play);
|
|
151
|
+
view.HookScript("OnHide", pause);
|
|
152
|
+
return { start, play, stop };
|
|
153
|
+
}
|
package/wow/cast-text.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { FontString, Texture } from "./frames";
|
|
2
|
+
import { luaString } from "./lua-string";
|
|
3
|
+
import { api, isSecret, reveal, type SecretValue } from "./native";
|
|
4
|
+
import { protect } from "./protect";
|
|
5
|
+
import type { UnitCast, UnitCastInterrupter } from "./unit-cast";
|
|
6
|
+
|
|
7
|
+
type Translate = (this: void, key: string) => string;
|
|
8
|
+
|
|
9
|
+
export interface CastSpellDisplay {
|
|
10
|
+
name?: UnitCast["name"];
|
|
11
|
+
icon?: number | string | SecretValue<number | string>;
|
|
12
|
+
spellID?: UnitCast["spellID"];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Render a cast name and icon through protected native setters and report the fallback used. */
|
|
16
|
+
export function paintCastSpell(this: void, name: FontString, icon: Texture | undefined, display: CastSpellDisplay): string {
|
|
17
|
+
const hasSpell = isSecret(display.spellID) || display.spellID !== undefined;
|
|
18
|
+
const spell = display.spellID as number;
|
|
19
|
+
let named = false;
|
|
20
|
+
let nameSource = "name";
|
|
21
|
+
if (isSecret(display.name) || display.name !== undefined) {
|
|
22
|
+
named = protect(() => name.SetText(display.name)).ok;
|
|
23
|
+
}
|
|
24
|
+
if (!named && hasSpell && api.C_Spell?.GetSpellName) {
|
|
25
|
+
named = protect(() => name.SetText(api.C_Spell.GetSpellName(spell))).ok;
|
|
26
|
+
nameSource = "name via spellID";
|
|
27
|
+
}
|
|
28
|
+
if (!named) name.SetText("");
|
|
29
|
+
const report = nameSource + " " + String(named);
|
|
30
|
+
if (icon === undefined) return report;
|
|
31
|
+
|
|
32
|
+
let shown = false;
|
|
33
|
+
if (isSecret(display.icon) || display.icon !== undefined) {
|
|
34
|
+
shown = protect(() => icon.SetTexture(display.icon as string | number)).ok;
|
|
35
|
+
}
|
|
36
|
+
if (!shown && hasSpell && api.C_Spell?.GetSpellTexture) {
|
|
37
|
+
shown = protect(() => {
|
|
38
|
+
const [asset] = api.C_Spell.GetSpellTexture(spell);
|
|
39
|
+
icon.SetTexture(asset);
|
|
40
|
+
}).ok;
|
|
41
|
+
}
|
|
42
|
+
if (!shown) icon.SetTexture(134400);
|
|
43
|
+
return report + ", icon " + String(shown);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Render the interrupting character through the native formatter, including secret names. */
|
|
47
|
+
export function paintCastInterruption(this: void, text: FontString, interrupter: UnitCastInterrupter | undefined,
|
|
48
|
+
translate: Translate): void {
|
|
49
|
+
const fallback = translate("Interrupted");
|
|
50
|
+
if (!isSecret(interrupter) && (interrupter === undefined || interrupter === "")) {
|
|
51
|
+
text.SetText(fallback);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const readName = protect(() => {
|
|
56
|
+
const [name] = api.UnitNameFromGUID(interrupter as string);
|
|
57
|
+
return name;
|
|
58
|
+
});
|
|
59
|
+
const name = readName.ok ? readName.value : undefined;
|
|
60
|
+
if (!isSecret(name) && (typeof name !== "string" || name === "")) {
|
|
61
|
+
text.SetText(fallback);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const classHex = protect(() => {
|
|
66
|
+
const [, classFile] = api.UnitClassFromGUID(interrupter as string);
|
|
67
|
+
const file = reveal(classFile);
|
|
68
|
+
if (file === undefined) return;
|
|
69
|
+
const color = reveal(api.C_ClassColor?.GetClassColor(file)) as { GenerateHexColor?(this: object): string } | undefined;
|
|
70
|
+
if (color && !api.issecrettable?.(color)) return color.GenerateHexColor?.();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const localized = translate("Interrupted by %s");
|
|
74
|
+
const [first, last] = luaString.find(localized, "%s", 1, true);
|
|
75
|
+
const before = first === undefined ? fallback + " " : luaString.sub(localized, 1, first - 1);
|
|
76
|
+
const after = last === undefined ? "" : luaString.sub(localized, last + 1);
|
|
77
|
+
const [prefix] = luaString.gsub(before, "%%", "%%%%");
|
|
78
|
+
const [suffix] = luaString.gsub(after, "%%", "%%%%");
|
|
79
|
+
const hex = classHex.ok ? reveal(classHex.value) : undefined;
|
|
80
|
+
const placeholder = hex === undefined ? "%s" : "|c" + hex + "%s|r";
|
|
81
|
+
const format = text.SetFormattedText as (this: object, format: string, name: string | SecretValue<string>) => void;
|
|
82
|
+
if (!protect(() => format.call(text, prefix + placeholder + suffix, name!)).ok) text.SetText(fallback);
|
|
83
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { RGB } from "../utils/colors";
|
|
2
|
+
import { isFiniteNumber } from "../utils/number";
|
|
3
|
+
import { api, isSecret, reveal, type LuaMultiReturn, type SecretValue } from "./native";
|
|
4
|
+
import { protectNative } from "./protect";
|
|
5
|
+
|
|
6
|
+
declare const $multi: (<const Values extends unknown[]>(this: void, ...values: Values) => LuaMultiReturn<Values>) & {
|
|
7
|
+
readonly __tstlExtension: "MultiFunction";
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type ClassFile = string | SecretValue<string>;
|
|
11
|
+
type Channel = number | SecretValue<number>;
|
|
12
|
+
type ChannelResult = [found: true, red: Channel, green: Channel, blue: Channel] | [found: false];
|
|
13
|
+
type Channels = LuaMultiReturn<ChannelResult>;
|
|
14
|
+
type ClientColor = LuaMultiReturn<[source: "color", red: Channel, green: Channel, blue: Channel] | [source: "missing" | "unavailable"]>;
|
|
15
|
+
|
|
16
|
+
const protectChannels = protectNative as <Value>(
|
|
17
|
+
this: void, run: (this: void, value: Value) => Channels, value: Value
|
|
18
|
+
) => LuaMultiReturn<[success: true, ...ChannelResult] | [success: false, error: unknown]>;
|
|
19
|
+
|
|
20
|
+
interface CachedColor {
|
|
21
|
+
readonly native?: Readonly<RGB>;
|
|
22
|
+
readonly readableFallback?: Readonly<RGB>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ClassColorLookup {
|
|
26
|
+
/** Share a finite, readable class color for arithmetic or comparison. */
|
|
27
|
+
read(this: void, classFile?: ClassFile): Readonly<RGB> | undefined;
|
|
28
|
+
/** Forward native channels as-is to a native API that accepts secret values. */
|
|
29
|
+
native(this: void, classFile?: ClassFile): Channels;
|
|
30
|
+
clear(this: void): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isChannel(this: void, value: unknown): value is Channel {
|
|
34
|
+
return isSecret(value) || isFiniteNumber(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function channels(this: void, value: unknown): Channels {
|
|
38
|
+
if (isSecret(value) || typeof value !== "object" || value === null || api.canaccesstable?.(value) === false) return $multi(false);
|
|
39
|
+
const { r, g, b } = value as { readonly r?: unknown; readonly g?: unknown; readonly b?: unknown };
|
|
40
|
+
if (isChannel(r) && isChannel(g) && isChannel(b)) return $multi(true, r, g, b);
|
|
41
|
+
return $multi(false);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function clientColor(this: void, classFile: ClassFile): ClientColor {
|
|
45
|
+
const lookup = api.C_ClassColor?.GetClassColor as ((this: void, name: ClassFile) => unknown) | undefined;
|
|
46
|
+
if (lookup === undefined) return $multi("missing");
|
|
47
|
+
const [ok, value] = protectNative(lookup, classFile);
|
|
48
|
+
if (!ok) return $multi("unavailable");
|
|
49
|
+
if (!isSecret(value) && value === undefined) return $multi("missing");
|
|
50
|
+
|
|
51
|
+
const [readable, found, r, g, b] = protectChannels(channels, value);
|
|
52
|
+
if (readable && found) return $multi("color", r, g, b);
|
|
53
|
+
return $multi("unavailable");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function raidColor(this: void, name: string): Channels {
|
|
57
|
+
const colors = reveal(api.RAID_CLASS_COLORS);
|
|
58
|
+
if (colors === undefined || api.canaccesstable?.(colors) === false) return $multi(false);
|
|
59
|
+
return channels(colors[name]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function readableRGB(this: void, r: Channel, g: Channel, b: Channel): Readonly<RGB> | undefined {
|
|
63
|
+
const red = reveal(r), green = reveal(g), blue = reveal(b);
|
|
64
|
+
if (isFiniteNumber(red) && isFiniteNumber(green) && isFiniteNumber(blue)) return [red, green, blue];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Own a session cache that can be shared by native and readable class-color consumers. */
|
|
68
|
+
export function createClassColorLookup(this: void): ClassColorLookup {
|
|
69
|
+
const cache = new Map<string, CachedColor>();
|
|
70
|
+
|
|
71
|
+
function read(this: void, classFile?: ClassFile) {
|
|
72
|
+
const name = reveal(classFile);
|
|
73
|
+
if (typeof name !== "string") return;
|
|
74
|
+
const cached = cache.get(name);
|
|
75
|
+
if (cached !== undefined) return cached.native ?? cached.readableFallback;
|
|
76
|
+
|
|
77
|
+
const [source, r, g, b] = clientColor(name);
|
|
78
|
+
const color = source === "color" ? readableRGB(r, g, b) : undefined;
|
|
79
|
+
if (color !== undefined) {
|
|
80
|
+
cache.set(name, { native: color });
|
|
81
|
+
return color;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const [ok, found, red, green, blue] = protectChannels(raidColor, name);
|
|
85
|
+
const fallback = ok && found ? readableRGB(red, green, blue) : undefined;
|
|
86
|
+
if (fallback !== undefined) {
|
|
87
|
+
// The readable fallback must not mask a native color with opaque channels.
|
|
88
|
+
cache.set(name, source === "missing" ? { native: fallback } : { readableFallback: fallback });
|
|
89
|
+
}
|
|
90
|
+
return fallback;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function native(this: void, classFile?: ClassFile): Channels {
|
|
94
|
+
const secret = isSecret(classFile);
|
|
95
|
+
const name = !secret && typeof classFile === "string" ? classFile : undefined;
|
|
96
|
+
if (!secret && name === undefined) return $multi(false);
|
|
97
|
+
|
|
98
|
+
const known = name === undefined ? undefined : cache.get(name)?.native;
|
|
99
|
+
if (known !== undefined) return $multi(true, known[0], known[1], known[2]);
|
|
100
|
+
|
|
101
|
+
const [source, r, g, b] = clientColor(classFile!);
|
|
102
|
+
if (source === "color") {
|
|
103
|
+
if (name !== undefined) {
|
|
104
|
+
const color = readableRGB(r, g, b);
|
|
105
|
+
if (color !== undefined) cache.set(name, { native: color });
|
|
106
|
+
}
|
|
107
|
+
return $multi(true, r, g, b);
|
|
108
|
+
}
|
|
109
|
+
if (source !== "missing" || name === undefined) return $multi(false);
|
|
110
|
+
|
|
111
|
+
const [ok, found, red, green, blue] = protectChannels(raidColor, name);
|
|
112
|
+
if (!ok || !found) return $multi(false);
|
|
113
|
+
const color = readableRGB(red, green, blue);
|
|
114
|
+
if (color !== undefined) cache.set(name, { native: color });
|
|
115
|
+
return $multi(true, red, green, blue);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return { read, native, clear: () => cache.clear() };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let defaultLookup: ClassColorLookup | undefined;
|
|
122
|
+
|
|
123
|
+
/** Returns a shared, readable RGB tuple for a WoW class file token. */
|
|
124
|
+
export function readClassColor(this: void, classFile?: ClassFile): Readonly<RGB> | undefined {
|
|
125
|
+
return (defaultLookup ??= createClassColorLookup()).read(classFile);
|
|
126
|
+
}
|
package/wow/clock.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { fail, type Result } from "../src/result";
|
|
2
|
+
import { copyRGB, type RGB } from "../utils/colors";
|
|
3
|
+
import { rawField } from "./lua-table";
|
|
4
|
+
import { api, isSecret, type LuaMultiReturn } from "./native";
|
|
5
|
+
import { protect } from "./protect";
|
|
6
|
+
|
|
7
|
+
type ColorChange = (this: void, value: RGB) => void;
|
|
8
|
+
|
|
9
|
+
export interface ColorPickerOptions {
|
|
10
|
+
readonly value: Readonly<RGB>;
|
|
11
|
+
readonly onChange: ColorChange;
|
|
12
|
+
readonly onPreview?: ColorChange;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface NativeColorPicker {
|
|
16
|
+
SetupColorPickerAndShow(this: object, options: {
|
|
17
|
+
r: number;
|
|
18
|
+
g: number;
|
|
19
|
+
b: number;
|
|
20
|
+
hasOpacity: false;
|
|
21
|
+
swatchFunc: (this: void) => void;
|
|
22
|
+
cancelFunc: (this: void) => void;
|
|
23
|
+
}): void;
|
|
24
|
+
GetColorRGB(this: object): LuaMultiReturn<RGB>;
|
|
25
|
+
HookScript(this: object, script: "OnHide", callback: (this: void) => void): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ColorPick {
|
|
29
|
+
readonly picker: NativeColorPicker;
|
|
30
|
+
readonly initial: RGB;
|
|
31
|
+
readonly onChange: ColorChange;
|
|
32
|
+
readonly onPreview?: ColorChange;
|
|
33
|
+
pending?: RGB;
|
|
34
|
+
timer?: ReturnType<typeof api.C_Timer.NewTimer>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const quietSeconds = 0.15;
|
|
38
|
+
let hookedPicker: NativeColorPicker | undefined;
|
|
39
|
+
let activePick: ColorPick | undefined;
|
|
40
|
+
let opening = false;
|
|
41
|
+
|
|
42
|
+
function clearTimer(pick: ColorPick) {
|
|
43
|
+
const timer = pick.timer;
|
|
44
|
+
pick.timer = undefined;
|
|
45
|
+
timer?.Cancel();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function flush(pick: ColorPick) {
|
|
49
|
+
const pending = pick.pending;
|
|
50
|
+
pick.pending = undefined;
|
|
51
|
+
clearTimer(pick);
|
|
52
|
+
if (pending !== undefined) pick.onChange(pending);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function report(run: (this: void) => void) {
|
|
56
|
+
const result = protect(run);
|
|
57
|
+
if (!result.ok) api.geterrorhandler()(result.reason);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function close(picker: NativeColorPicker) {
|
|
61
|
+
const pick = activePick;
|
|
62
|
+
if (pick?.picker !== picker) return;
|
|
63
|
+
activePick = undefined;
|
|
64
|
+
report(() => flush(pick));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function preview(picker: NativeColorPicker) {
|
|
68
|
+
const pick = activePick;
|
|
69
|
+
if (pick?.picker !== picker) return;
|
|
70
|
+
report(() => {
|
|
71
|
+
const [red, green, blue] = picker.GetColorRGB();
|
|
72
|
+
const color: RGB = [red, green, blue];
|
|
73
|
+
pick.pending = color;
|
|
74
|
+
clearTimer(pick);
|
|
75
|
+
pick.timer = api.C_Timer.NewTimer(quietSeconds, () => {
|
|
76
|
+
if (activePick !== pick || pick.pending !== color) return;
|
|
77
|
+
pick.timer = undefined;
|
|
78
|
+
report(() => flush(pick));
|
|
79
|
+
});
|
|
80
|
+
pick.onPreview?.(copyRGB(color));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function cancel(picker: NativeColorPicker) {
|
|
85
|
+
const pick = activePick;
|
|
86
|
+
if (pick?.picker !== picker) return;
|
|
87
|
+
activePick = undefined;
|
|
88
|
+
pick.pending = undefined;
|
|
89
|
+
report(() => clearTimer(pick));
|
|
90
|
+
report(() => pick.onPreview?.(copyRGB(pick.initial)));
|
|
91
|
+
report(() => pick.onChange(pick.initial));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function openColorPicker(this: void, options: ColorPickerOptions): Result<void> {
|
|
95
|
+
const { value, onChange, onPreview } = options;
|
|
96
|
+
const [red, green, blue] = value;
|
|
97
|
+
const isChannel = (channel: number) => !isSecret(channel) && Number.isFinite(channel) && channel >= 0 && channel <= 1;
|
|
98
|
+
if (!isChannel(red) || !isChannel(green) || !isChannel(blue)) {
|
|
99
|
+
return fail("Color picker channels must be between 0 and 1");
|
|
100
|
+
}
|
|
101
|
+
if (opening) return fail("The color picker is already opening");
|
|
102
|
+
|
|
103
|
+
const picker = rawField<NativeColorPicker>(api, "ColorPickerFrame");
|
|
104
|
+
if (picker?.SetupColorPickerAndShow === undefined || picker.GetColorRGB === undefined || picker.HookScript === undefined) {
|
|
105
|
+
return fail("The native color picker is unavailable");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
opening = true;
|
|
109
|
+
const result = protect(() => {
|
|
110
|
+
const previous = activePick;
|
|
111
|
+
activePick = undefined;
|
|
112
|
+
if (previous !== undefined) flush(previous);
|
|
113
|
+
if (hookedPicker !== picker) {
|
|
114
|
+
picker.HookScript("OnHide", () => close(picker));
|
|
115
|
+
hookedPicker = picker;
|
|
116
|
+
}
|
|
117
|
+
picker.SetupColorPickerAndShow({
|
|
118
|
+
r: red, g: green, b: blue,
|
|
119
|
+
hasOpacity: false,
|
|
120
|
+
swatchFunc: () => preview(picker),
|
|
121
|
+
cancelFunc: () => cancel(picker),
|
|
122
|
+
});
|
|
123
|
+
// Native setup can invoke the swatch callback while setting the starting color.
|
|
124
|
+
activePick = { picker, initial: [red, green, blue], onChange, onPreview };
|
|
125
|
+
});
|
|
126
|
+
opening = false;
|
|
127
|
+
return result;
|
|
128
|
+
}
|
package/wow/commands.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { api } from "./native";
|
|
2
|
+
|
|
3
|
+
/** Find the registered handler for a localized slash command or alias. */
|
|
4
|
+
export function findSlashCommand(command: string): ((this: void, input: string) => void) | undefined {
|
|
5
|
+
if (!api.SlashCmdList) return undefined;
|
|
6
|
+
const name = command.toLowerCase();
|
|
7
|
+
const globals = api as unknown as Record<string, unknown>;
|
|
8
|
+
for (const [key, handler] of Object.entries(api.SlashCmdList)) {
|
|
9
|
+
if (typeof handler !== "function") continue;
|
|
10
|
+
for (let index = 1; index <= 9; index++) {
|
|
11
|
+
const alias = globals[`SLASH_${key}${index}`];
|
|
12
|
+
if (alias === undefined) break;
|
|
13
|
+
if (typeof alias === "string" && alias.toLowerCase() === name) return handler;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|