@overmvp/kumi 0.1.0 → 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/README.md +59 -6
- package/builder/css-v1.mjs +54 -1
- package/builder/css-v1.test.mjs +40 -0
- 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 +180 -8
- package/builder/src/main.rs +19 -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 +93 -0
- 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 +9 -2
- package/router/navigation.ts +22 -0
- package/router/router-view.ts +134 -0
- package/scripts/addon-build.mjs +364 -0
- package/scripts/addon-project.mjs +78 -0
- package/scripts/kumi-cli.mjs +52 -17
- package/scripts/link-addons.mjs +12 -2
- package/src/bindings.ts +2 -2
- package/src/css-tokens.ts +16 -11
- package/src/css-v1.ts +10 -0
- package/src/elements.ts +26 -0
- package/src/frame-scheduler.ts +3 -1
- package/src/index.ts +1 -0
- package/src/jsx-runtime.ts +8 -1
- package/src/keyed-list.ts +8 -5
- package/src/module-ui.ts +147 -0
- package/src/module.ts +42 -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 +28 -7
- package/src/result.ts +6 -0
- package/src/signal-kernel.ts +35 -2
- 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.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 +49 -10
- 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/app-ui.ts +221 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-box.ts +40 -6
- package/wow/css-surfaces.ts +229 -24
- package/wow/cursor.ts +45 -0
- package/wow/frame-access.ts +23 -1
- package/wow/frame-timing.ts +13 -0
- package/wow/hooks.ts +133 -0
- package/wow/index.ts +18 -4
- package/wow/layout-view.ts +26 -14
- package/wow/locale-font.ts +15 -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/protect.ts +27 -3
- package/wow/protected-view.ts +103 -0
- package/wow/range-art.ts +7 -0
- package/wow/readable-api.ts +120 -0
- package/wow/rounded-texture.ts +33 -6
- package/wow/saved-variables.ts +67 -18
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +31 -8
- package/wow/view.ts +201 -83
- 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/index.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { WoWApi } from "./contract";
|
|
2
2
|
import { api, isSecret, reveal } from "./native";
|
|
3
3
|
import { cvars } from "./cvars";
|
|
4
|
-
import { frameTiming } from "./
|
|
4
|
+
import { frameTiming } from "./frame-timing";
|
|
5
5
|
export { api, isSecret, reveal } from "./native";
|
|
6
|
+
export { readableApi } from "./readable-api";
|
|
7
|
+
export { hasCursorAction, readCursorAction, readCursorKind, type CursorAction } from "./cursor";
|
|
8
|
+
export type { ReadableSpellCooldown } from "./spell-cooldown";
|
|
6
9
|
export { nativeRef, secretSafeEquals } from "./secret-ref";
|
|
7
10
|
export type { LuaMultiReturn, SecretValue, UnitToken, WoWGlobals } from "./native";
|
|
8
11
|
export { createFrame, smoothStatusBarValue } from "./frames";
|
|
9
12
|
export { createFontCache, type FontCache, type FontCacheOptions, type FontObject, type FontOutline } from "./font-cache";
|
|
10
|
-
export {
|
|
13
|
+
export { createLocaleFont } from "./locale-font";
|
|
14
|
+
export { createRoundedTextures, type MaskedStatusBarFill, type RoundedBorderCorner, type RoundedTextureOptions, type RoundedTextureResolverOptions, type RoundedTextures, type RoundedTextureSide } from "./rounded-texture";
|
|
11
15
|
export { createBarShade, type BarShade, type BarShadeOptions, type BarShadeStyle } from "./bar-shade";
|
|
12
16
|
export { reparentFrame } from "./reparent-frame";
|
|
13
17
|
export { bindContainedFrame, createContainedFrame } from "./contained-frame";
|
|
@@ -25,15 +29,21 @@ export { secureChildUpdateSnippet, secureSnippet, secureStateSnippet, wrapSecure
|
|
|
25
29
|
export type { SecureFrameHandle, SecureSnippet, SecureSnippetEvent, SecureSnippetOptions, SecureSnippetValue, WrapSecureSnippetOptions } from "./secure-snippet";
|
|
26
30
|
export type { SecureButton, SecureFrame, SecureInstallation, SecureOptions } from "./secure-transaction";
|
|
27
31
|
export { createProtectedLayoutUpdate, type ProtectedLayoutOptions, type ProtectedLayoutUpdate } from "./protected-layout";
|
|
32
|
+
export { mountProtectedView } from "./protected-view";
|
|
33
|
+
export { useActionBarLayout, type ActionBarLayoutOptions, type ActionBarPosition } from "./action-bar-layout";
|
|
34
|
+
export { createNativePanel } from "./panel-host";
|
|
28
35
|
export { scheduleVisibleFrameUpdate } from "./visible-frame-job";
|
|
29
36
|
export { castInterrupter, castNotInterruptible, getUnitCastDuration, readUnitCast } from "./unit-cast";
|
|
30
37
|
export type { UnitCast, UnitCastDuration, UnitCastEvent, UnitCastInterrupter } from "./unit-cast";
|
|
31
38
|
export { createCastClock, type CastClockOptions } from "./cast-clock";
|
|
39
|
+
export { readCooldownTiming, type CooldownTiming } from "./cooldown-timing";
|
|
32
40
|
export { paintCastInterruption, paintCastSpell, type CastSpellDisplay } from "./cast-text";
|
|
33
41
|
export { renderUnitHealthText, type UnitHealthTextMode, type UnitHealthTextOptions } from "./unit-health-text";
|
|
34
42
|
export type { AnimationGroup, NativeAnimationKind, NativeAnimationOf, BackdropFrame, BackdropInfo, Button, FontString, Frame, FrameEventRegistration, FrameMap, MaskTexture, FrameType, FrameParent, MinimapFrame,
|
|
35
43
|
Region, StatusBar, Texture } from "./frames";
|
|
36
|
-
export { asTexture, canAccessRegion,
|
|
44
|
+
export { asTexture, canAccessRegion, readFontPath, readFrameHeight, readFrameScale, readFrameShown, readFrameWidth,
|
|
45
|
+
setFrameEventListening } from "./frame-access";
|
|
46
|
+
export { readItemId, visitBagItems, visitCollectedToys, visitPlayerSpells } from "./action-catalog";
|
|
37
47
|
export { createEvents } from "./events";
|
|
38
48
|
export { createEventDispatcher, type EventDispatcherFrame } from "./event-dispatcher";
|
|
39
49
|
export { addonRuntime, frameDriver, frameTiming, startAddon, type AddonContext, type AddonStart, type AddonStartOptions } from "./start-addon";
|
|
@@ -67,11 +77,15 @@ export type { FrameStrata } from "./frame-layer";
|
|
|
67
77
|
export type { CreateScrollArea, ScrollArea } from "./scroll-view";
|
|
68
78
|
export { protect } from "./protect";
|
|
69
79
|
export { luaString } from "./lua-string";
|
|
80
|
+
export { physicalPixel, snapPixel, watchDisplayMetrics } from "./pixel";
|
|
70
81
|
export { formatWoWNumber } from "./number-format";
|
|
71
82
|
export { clampWoWNumber } from "./number-input";
|
|
72
83
|
export { formatMapCoordinates, readPlayerMapPosition } from "./map-position";
|
|
73
84
|
export { rawField, setRawField, weakKeys } from "./lua-table";
|
|
74
|
-
export { savedVariablesStorage, type SavedVariablesOptions } from "./saved-variables";
|
|
85
|
+
export { savedVariablesStorage, type SavedRecord, type SavedValue, type SavedVariablesOptions } from "./saved-variables";
|
|
86
|
+
export { usePlugins, type KumiPlugins, type PluginId, type PluginInfo, type PluginServices, type PluginStatus } from "./plugins";
|
|
87
|
+
export { useViewHost, useWindow, type AppTheme } from "./app-ui";
|
|
88
|
+
export { onCleanup, useCombat, useEvent, useNow, useSlashCommand } from "./hooks";
|
|
75
89
|
export type { EventApi, EventOptions, EventScope, WoWEvent, WoWEventMap } from "./contract";
|
|
76
90
|
|
|
77
91
|
declare const DoReadyCheck: ((this: void) => void) | undefined;
|
package/wow/layout-view.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { canAccessRegion } from "./frame-access";
|
|
|
8
8
|
import type { FontString, Frame, FrameParent } from "./frames";
|
|
9
9
|
import { api, isSecret, reveal } from "./native";
|
|
10
10
|
import { hookScript } from "./native-hooks";
|
|
11
|
+
import { physicalPixel, watchDisplayMetrics } from "./pixel";
|
|
11
12
|
import { protect } from "./protect";
|
|
12
13
|
import { createProtectedLayoutUpdate, type ProtectedLayoutUpdate } from "./protected-layout";
|
|
13
14
|
|
|
@@ -265,12 +266,13 @@ export class NativeLayoutItem {
|
|
|
265
266
|
const shown = props.style?.display === "none" ? ok(false) : readLayoutValue(props.shown);
|
|
266
267
|
if (!shown.ok) return shown;
|
|
267
268
|
const visible = shown.value !== false;
|
|
268
|
-
|
|
269
|
-
|
|
269
|
+
const changed = this.style === undefined || !sameLayoutValue(this.style, next.value);
|
|
270
|
+
if (visible === this.shown && !changed) return;
|
|
271
|
+
const visibilityChanged = visible !== this.shown;
|
|
270
272
|
this.style = next.value;
|
|
271
273
|
this.shown = visible;
|
|
272
|
-
if (
|
|
273
|
-
this.group.enqueue();
|
|
274
|
+
if (visibilityChanged && (!visible || !this.inFlow && !changed)) this.updateVisibility();
|
|
275
|
+
if (changed || this.inFlow) this.group.enqueue();
|
|
274
276
|
});
|
|
275
277
|
if (!sub.ok) return sub;
|
|
276
278
|
this.region.SetShown(false);
|
|
@@ -509,22 +511,27 @@ function createTextMeasurer(root: Frame, retry: (this: void) => void, pixel: (th
|
|
|
509
511
|
};
|
|
510
512
|
}
|
|
511
513
|
|
|
512
|
-
function
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
514
|
+
export function isAbsoluteFill(this: void, props: Layout): boolean {
|
|
515
|
+
const { style } = props;
|
|
516
|
+
return props.anchor === undefined && style?.position === "absolute"
|
|
517
|
+
&& style.top === 0 && style.right === 0 && style.bottom === 0 && style.left === 0 && style.autoMargin === undefined
|
|
518
|
+
&& props.width === undefined && style.width === undefined && props.height === undefined && style.height === undefined;
|
|
516
519
|
}
|
|
517
520
|
|
|
518
521
|
export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, props: Layout, scope: RuntimeScope,
|
|
519
522
|
diagnostics?: NativeLayoutDiagnostics, stageInitial?: StageInitialLayout): Result<NativeLayoutItem> {
|
|
520
|
-
// The root keeps its own anchors
|
|
523
|
+
// The root keeps its own anchors. A zero-inset absolute root gets both axes from its containing block.
|
|
521
524
|
const supported = acceptParent(parent, "ancestor");
|
|
522
525
|
if (!supported.ok) return supported;
|
|
523
526
|
const safe = acceptRegion(frame);
|
|
524
527
|
if (!safe.ok) return safe;
|
|
525
528
|
const owner = supported.value;
|
|
526
529
|
const key = {};
|
|
527
|
-
|
|
530
|
+
const fillsParent = isAbsoluteFill(props);
|
|
531
|
+
const readWidth = fillsParent || props.fullWidth === true;
|
|
532
|
+
const measured = readWidth ? readSize(owner) : empty;
|
|
533
|
+
let availableWidth = readWidth ? measured.width : undefined;
|
|
534
|
+
let availableHeight = fillsParent ? measured.height : undefined;
|
|
528
535
|
let scale = reveal(frame.GetEffectiveScale());
|
|
529
536
|
let committing = false;
|
|
530
537
|
let waiting = false;
|
|
@@ -567,8 +574,8 @@ export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, p
|
|
|
567
574
|
const safe = acceptRegion(item.region);
|
|
568
575
|
if (!safe.ok) return safe;
|
|
569
576
|
}
|
|
570
|
-
pixel =
|
|
571
|
-
const result = solveLayout(tree.node, { width: availableWidth });
|
|
577
|
+
pixel = physicalPixel(frame);
|
|
578
|
+
const result = solveLayout(tree.node, { width: availableWidth, height: availableHeight });
|
|
572
579
|
if (!finiteLayout(result)) return fail("Layout resolved nonfinite geometry");
|
|
573
580
|
committing = true;
|
|
574
581
|
const moved = [] as NativeLayoutItem[] as OwnedArray<NativeLayoutItem>;
|
|
@@ -618,14 +625,19 @@ export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, p
|
|
|
618
625
|
if (!cleanup.ok) return cleanup;
|
|
619
626
|
const resize = hookScript(owner, "OnSizeChanged", () => {
|
|
620
627
|
if (committing) return;
|
|
621
|
-
const
|
|
628
|
+
const size = readWidth ? readSize(owner) : empty;
|
|
629
|
+
const width = readWidth ? size.width : undefined;
|
|
630
|
+
const height = fillsParent ? size.height : undefined;
|
|
622
631
|
const currentScale = reveal(frame.GetEffectiveScale());
|
|
623
|
-
if (width === availableWidth && currentScale === scale) return;
|
|
632
|
+
if (width === availableWidth && height === availableHeight && currentScale === scale) return;
|
|
624
633
|
availableWidth = width;
|
|
634
|
+
availableHeight = height;
|
|
625
635
|
scale = currentScale;
|
|
626
636
|
enqueue();
|
|
627
637
|
}, scope);
|
|
628
638
|
if (!resize.ok) return resize;
|
|
639
|
+
const metrics = watchDisplayMetrics(scope, enqueue);
|
|
640
|
+
if (!metrics.ok) return metrics;
|
|
629
641
|
const installed = root.bind(props, scope);
|
|
630
642
|
return installed.ok ? ok(root) : installed;
|
|
631
643
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { readFontPath } from "./frame-access";
|
|
2
|
+
import type { FontString, FrameMap } from "./frames";
|
|
3
|
+
import { api } from "./native";
|
|
4
|
+
|
|
5
|
+
/** Apply a UI family while keeping Blizzard's existing glyph coverage in localized clients. */
|
|
6
|
+
export function createLocaleFont(this: void, family: string) {
|
|
7
|
+
return (target: FontString | FrameMap["EditBox"], size: number) => {
|
|
8
|
+
const previous = readFontPath(target);
|
|
9
|
+
const locale = api.GetLocale();
|
|
10
|
+
const path = locale === "ruRU" || locale === "koKR" || locale === "zhCN" || locale === "zhTW"
|
|
11
|
+
? previous ?? family : family;
|
|
12
|
+
if (!target.SetFont(path, size, "") && previous !== undefined && path !== previous) target.SetFont(previous, size, "");
|
|
13
|
+
target.SetShadowOffset(0, 0);
|
|
14
|
+
};
|
|
15
|
+
}
|
package/wow/native.ts
CHANGED
|
@@ -28,6 +28,24 @@ interface MerchantApi {
|
|
|
28
28
|
|
|
29
29
|
// Native globals omitted by Blizzard's generated API documentation.
|
|
30
30
|
interface LegacyGlobals {
|
|
31
|
+
GetCursorInfo(this: void): LuaMultiReturn<[kind?: string, first?: number, detail?: unknown, spellId?: number]>;
|
|
32
|
+
PlayerHasToy(this: void, itemID: number): boolean;
|
|
33
|
+
readonly C_ToyBox?: {
|
|
34
|
+
GetNumFilteredToys(this: void): number;
|
|
35
|
+
GetToyFromIndex(this: void, index: number): number;
|
|
36
|
+
GetToyInfo(this: void, itemID: number): LuaMultiReturn<[id?: number, name?: string, icon?: number]>;
|
|
37
|
+
};
|
|
38
|
+
GetFlyoutInfo?(this: void, flyoutID: number): LuaMultiReturn<[name?: string, description?: string, slots?: number, known?: boolean]>;
|
|
39
|
+
GetFlyoutSlotInfo?(this: void, flyoutID: number, index: number): LuaMultiReturn<[id?: number, override?: number, known?: boolean, name?: string]>;
|
|
40
|
+
readonly GameTooltip?: {
|
|
41
|
+
SetOwner(this: object, owner: FrameParent, anchor: string): void;
|
|
42
|
+
SetItemByID(this: object, itemId: number): void;
|
|
43
|
+
SetSpellByID(this: object, spellId: number): void;
|
|
44
|
+
SetToyByItemID?(this: object, itemId: number): boolean;
|
|
45
|
+
SetText(this: object, text: string): void;
|
|
46
|
+
Show(this: object): void;
|
|
47
|
+
Hide(this: object): void;
|
|
48
|
+
};
|
|
31
49
|
CreateFont(this: void, name: string): SimpleFont;
|
|
32
50
|
CreateColor?(this: void, red: number, green: number, blue: number, alpha: number): unknown;
|
|
33
51
|
readonly CurveConstants?: { readonly ScaleTo100?: Parameters<WoWGlobals["UnitHealthPercent"]>[2] };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
2
|
+
import { fail, ok, type Result } from "../src/result";
|
|
3
|
+
import type { Runtime, RuntimeScope } from "../src/runtime";
|
|
4
|
+
import type { UIElement } from "../src/elements";
|
|
5
|
+
import type { EventApi } from "./contract";
|
|
6
|
+
import type { FrameStrata } from "./frame-layer";
|
|
7
|
+
import { readFrameHeight, readFrameShown, readFrameWidth } from "./frame-access";
|
|
8
|
+
import { createFrame, type Frame } from "./frames";
|
|
9
|
+
import { api } from "./native";
|
|
10
|
+
import { physicalPixel, snapPixel } from "./pixel";
|
|
11
|
+
import { unlockedActionSlot } from "./action-button";
|
|
12
|
+
import { mountNative, type NativeViewOptions } from "./view";
|
|
13
|
+
|
|
14
|
+
interface NativePanel {
|
|
15
|
+
readonly locked: ReadonlyRef<boolean>;
|
|
16
|
+
show(this: void): void;
|
|
17
|
+
hide(this: void): void;
|
|
18
|
+
isShown(this: void): boolean;
|
|
19
|
+
mount(this: void, runtime: Runtime, render: (this: void, scope: RuntimeScope) => UIElement,
|
|
20
|
+
options: NativeViewOptions): ReturnType<typeof mountNative>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Own a native parent from the first mount and center it on display metric changes. */
|
|
24
|
+
export function createNativePanel(this: void, scope: RuntimeScope, events: EventApi, width: number, height: number,
|
|
25
|
+
strata: FrameStrata, offsetY: number): Result<NativePanel> {
|
|
26
|
+
const locked = ref(!unlockedActionSlot());
|
|
27
|
+
const refreshCombat = () => { locked.value = !unlockedActionSlot(); };
|
|
28
|
+
const lockedEvent = events.on(scope, "PLAYER_REGEN_DISABLED", refreshCombat);
|
|
29
|
+
if (!lockedEvent.ok) return lockedEvent;
|
|
30
|
+
const unlockedEvent = events.on(scope, "PLAYER_REGEN_ENABLED", refreshCombat);
|
|
31
|
+
if (!unlockedEvent.ok) return unlockedEvent;
|
|
32
|
+
|
|
33
|
+
const parent = api.UIParent as Frame;
|
|
34
|
+
let host: Frame | undefined;
|
|
35
|
+
let panelWidth = width;
|
|
36
|
+
let anchorX: number | undefined, anchorY: number | undefined;
|
|
37
|
+
let centered: boolean | undefined;
|
|
38
|
+
function place(panel: Frame) {
|
|
39
|
+
const pixel = physicalPixel(panel);
|
|
40
|
+
const screenWidth = readFrameWidth(parent);
|
|
41
|
+
const screenHeight = readFrameHeight(parent);
|
|
42
|
+
const availableWidth = screenWidth === undefined || screenWidth <= 0 ? width : Math.min(width, screenWidth);
|
|
43
|
+
if (panelWidth !== availableWidth) {
|
|
44
|
+
panelWidth = availableWidth;
|
|
45
|
+
panel.SetWidth(panelWidth);
|
|
46
|
+
}
|
|
47
|
+
const center = screenWidth === undefined || screenHeight === undefined;
|
|
48
|
+
const x = center ? 0 : snapPixel((screenWidth - panelWidth) / 2, pixel);
|
|
49
|
+
const y = center ? offsetY : snapPixel((screenHeight - height) / 2 + offsetY, pixel);
|
|
50
|
+
if (center === centered && x === anchorX && y === anchorY) return;
|
|
51
|
+
const point = center ? "CENTER" : "BOTTOMLEFT";
|
|
52
|
+
panel.ClearAllPoints();
|
|
53
|
+
panel.SetPoint(point, parent, point, x, y);
|
|
54
|
+
centered = center;
|
|
55
|
+
anchorX = x;
|
|
56
|
+
anchorY = y;
|
|
57
|
+
}
|
|
58
|
+
function ensureHost(): Result<Frame> {
|
|
59
|
+
if (host !== undefined) return ok(host);
|
|
60
|
+
return scope.protect(() => {
|
|
61
|
+
const panel = createFrame("Frame", undefined, parent);
|
|
62
|
+
panel.Hide();
|
|
63
|
+
panel.SetFrameStrata(strata);
|
|
64
|
+
panel.SetClampedToScreen(true);
|
|
65
|
+
panel.SetSize(width, height);
|
|
66
|
+
panelWidth = width;
|
|
67
|
+
place(panel);
|
|
68
|
+
host = panel;
|
|
69
|
+
return panel;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function refreshPosition() {
|
|
73
|
+
if (host !== undefined) place(host);
|
|
74
|
+
}
|
|
75
|
+
const zoom = events.on(scope, "UI_SCALE_CHANGED", refreshPosition);
|
|
76
|
+
if (!zoom.ok) return zoom;
|
|
77
|
+
const screen = events.on(scope, "DISPLAY_SIZE_CHANGED", refreshPosition);
|
|
78
|
+
if (!screen.ok) return screen;
|
|
79
|
+
const cleanup = scope.onDispose(() => { host?.Hide(); });
|
|
80
|
+
if (!cleanup.ok) return cleanup;
|
|
81
|
+
return ok({
|
|
82
|
+
locked,
|
|
83
|
+
show: () => {
|
|
84
|
+
if (!scope.isActive()) return;
|
|
85
|
+
const ready = ensureHost();
|
|
86
|
+
if (ready.ok) ready.value.Show();
|
|
87
|
+
else api.geterrorhandler()(ready.reason);
|
|
88
|
+
},
|
|
89
|
+
hide: () => { host?.Hide(); },
|
|
90
|
+
isShown: () => host !== undefined && readFrameShown(host) === true,
|
|
91
|
+
mount: (runtime, render, options) => {
|
|
92
|
+
if (!scope.isActive()) return fail("Cannot mount a disposed panel");
|
|
93
|
+
const ready = ensureHost();
|
|
94
|
+
return ready.ok ? mountNative(ready.value, runtime, render, options) : ready;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
package/wow/pixel.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ok } from "../src/result";
|
|
2
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
3
|
+
import { createEventDispatcher } from "./event-dispatcher";
|
|
4
|
+
import type { Frame } from "./frames";
|
|
5
|
+
import { api, reveal } from "./native";
|
|
6
|
+
|
|
7
|
+
const display = createEventDispatcher();
|
|
8
|
+
|
|
9
|
+
/** Effective scale for a native region whose local unit is one display pixel. */
|
|
10
|
+
export function physicalPixelScale(this: void): number | undefined {
|
|
11
|
+
const [, height] = api.GetPhysicalScreenSize();
|
|
12
|
+
const screen = reveal(height);
|
|
13
|
+
return typeof screen === "number" && Number.isFinite(screen) && screen > 0 ? 768 / screen : undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Local UI units occupied by a single physical display pixel. */
|
|
17
|
+
export function physicalPixel(this: void, frame: Pick<Frame, "GetEffectiveScale">): number {
|
|
18
|
+
const [, height] = api.GetPhysicalScreenSize();
|
|
19
|
+
const scale = reveal(frame.GetEffectiveScale());
|
|
20
|
+
const screen = reveal(height);
|
|
21
|
+
return typeof scale === "number" && Number.isFinite(scale) && scale > 0
|
|
22
|
+
&& typeof screen === "number" && Number.isFinite(screen) && screen > 0 ? 768 / screen / scale : 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function snapPixel(this: void, value: number, unit: number): number {
|
|
26
|
+
return Math.floor(value / unit + 0.5) * unit;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function watchDisplayMetrics(this: void, scope: RuntimeScope, refresh: (this: void) => void) {
|
|
30
|
+
const scale = display.on(scope, "UI_SCALE_CHANGED", refresh);
|
|
31
|
+
if (!scale.ok) return scale;
|
|
32
|
+
const size = display.on(scope, "DISPLAY_SIZE_CHANGED", refresh);
|
|
33
|
+
if (!size.ok) { scale.value(); return size; }
|
|
34
|
+
return ok(undefined);
|
|
35
|
+
}
|
package/wow/plugins.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { ModuleContainer, ModuleDeclaration, ModuleInput, ModuleReference } from "../src/module";
|
|
2
|
+
import { computed } from "../src/reactive-scope";
|
|
3
|
+
import { ref, type SignalRef } from "../src/reactivity";
|
|
4
|
+
import { fail, ok, type Failure, type Result } from "../src/result";
|
|
5
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
6
|
+
import { ownedMap, type OwnedMap } from "../src/owned-collections";
|
|
7
|
+
import { defineStore, readonly } from "../state/setup-store";
|
|
8
|
+
import { addonManifest, type AddonManifest, type PluginManifest } from "./addon-manifest";
|
|
9
|
+
import { api, reveal } from "./native";
|
|
10
|
+
import { protect } from "./protect";
|
|
11
|
+
|
|
12
|
+
type LoadableModule = Exclude<ModuleReference<object>, ModuleInput<object>>;
|
|
13
|
+
type ModuleExports<Module> = Module extends ModuleReference<infer Value> ? Value : never;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The plugins declared in kumi.config.ts, keyed by ID. `kumi check` and `kumi build` fill this in from
|
|
17
|
+
* `build/kumi/plugins.d.ts`, so `usePlugins().load("history")` knows the plugin's services.
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
20
|
+
export interface KumiPlugins {}
|
|
21
|
+
|
|
22
|
+
/** A plugin ID from kumi.config.ts. Any string until the project declares plugins. */
|
|
23
|
+
export type PluginId = [keyof KumiPlugins] extends [never] ? string : Extract<keyof KumiPlugins, string>;
|
|
24
|
+
/** The public services of a plugin's module. */
|
|
25
|
+
export type PluginServices<Id extends string> = Id extends keyof KumiPlugins ? Readonly<ModuleExports<KumiPlugins[Id]>> : Readonly<object>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* - `"off"`: turned off in the addon list.
|
|
29
|
+
* - `"waiting"`: turned on but not running yet. A demand plugin waits for `load()`, a startup plugin for a reload.
|
|
30
|
+
* - `"loading"`, `"ready"`, `"error"`: the plugin is starting, running, or failed with `error`.
|
|
31
|
+
*/
|
|
32
|
+
export type PluginStatus = "off" | "waiting" | "loading" | "ready" | "error";
|
|
33
|
+
|
|
34
|
+
export interface PluginInfo {
|
|
35
|
+
readonly id: PluginId;
|
|
36
|
+
readonly addon: string;
|
|
37
|
+
readonly title: string;
|
|
38
|
+
readonly notes: string;
|
|
39
|
+
readonly load: "startup" | "demand";
|
|
40
|
+
/** The saved choice in the addon list. A change applies after `/reload`, or at `load()` for a demand plugin. */
|
|
41
|
+
readonly enabled: boolean;
|
|
42
|
+
readonly status: PluginStatus;
|
|
43
|
+
readonly error?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PluginState {
|
|
47
|
+
readonly manifest: PluginManifest;
|
|
48
|
+
readonly enabled: SignalRef<boolean>;
|
|
49
|
+
readonly status: SignalRef<PluginStatus>;
|
|
50
|
+
readonly error: SignalRef<string | undefined>;
|
|
51
|
+
/** Whether the plugin's code was running when the UI loaded. */
|
|
52
|
+
readonly running: boolean;
|
|
53
|
+
services?: object;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface PluginHost {
|
|
57
|
+
readonly modules: ModuleContainer;
|
|
58
|
+
readonly scope: RuntimeScope;
|
|
59
|
+
readonly manifest: AddonManifest;
|
|
60
|
+
readonly states: OwnedMap<string, PluginState>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let host: PluginHost | undefined;
|
|
64
|
+
|
|
65
|
+
function playerName() {
|
|
66
|
+
const read = api.UnitName;
|
|
67
|
+
if (typeof read !== "function") return undefined;
|
|
68
|
+
const [name] = read("player");
|
|
69
|
+
const value = reveal(name);
|
|
70
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function savedEnabled(addon: string) {
|
|
74
|
+
const state = reveal(api.C_AddOns?.GetAddOnEnableState?.(addon, playerName() ?? ""));
|
|
75
|
+
return typeof state === "number" ? state > 0 : true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function inCombat() {
|
|
79
|
+
return reveal(api.InCombatLockdown?.()) === true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function activate(state: PluginState, modules: ModuleContainer, manifest: AddonManifest): Result<object> {
|
|
83
|
+
const module = manifest.registered[state.manifest.id] as LoadableModule | undefined;
|
|
84
|
+
if (module === undefined) {
|
|
85
|
+
const failure = manifest.failures[state.manifest.id];
|
|
86
|
+
return fail(failure === undefined ? "Plugin " + state.manifest.id + " did not register its module"
|
|
87
|
+
: "Plugin " + state.manifest.id + " failed while its file loaded: " + failure + ". Reload the UI after updating it.");
|
|
88
|
+
}
|
|
89
|
+
const attempted = protect(() => modules.resolve(module));
|
|
90
|
+
const resolved = attempted.ok ? attempted.value : attempted;
|
|
91
|
+
if (!resolved.ok) return resolved;
|
|
92
|
+
return ok(resolved.value);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function settle(state: PluginState, result: Result<object>) {
|
|
96
|
+
if (result.ok) {
|
|
97
|
+
state.services = result.value;
|
|
98
|
+
state.error.value = undefined;
|
|
99
|
+
state.status.value = "ready";
|
|
100
|
+
} else {
|
|
101
|
+
state.error.value = result.reason;
|
|
102
|
+
state.status.value = "error";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @internal Called by a plugin's generated entry when WoW runs its file. */
|
|
107
|
+
export function registerPlugin(this: void, id: string, module: LoadableModule): void {
|
|
108
|
+
const manifest = addonManifest();
|
|
109
|
+
if (manifest === undefined) throw new Error("Plugin " + id + " needs the Kumi manifest of its addon");
|
|
110
|
+
if ((module as ModuleDeclaration<object>).kind !== "module") throw new Error("Plugin " + id + " must export a Kumi module");
|
|
111
|
+
if (manifest.registered[id] !== undefined) throw new Error("Plugin " + id + " registered twice");
|
|
112
|
+
manifest.registered[id] = module;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @internal Start the startup plugins once the root module is active. One failing plugin does not stop the others. */
|
|
116
|
+
export function startPlugins(this: void, modules: ModuleContainer, scope: RuntimeScope, report: (this: void, failure: Failure) => void): void {
|
|
117
|
+
const manifest = addonManifest();
|
|
118
|
+
if (manifest === undefined) return;
|
|
119
|
+
manifest.started = true;
|
|
120
|
+
const states = ownedMap<string, PluginState>();
|
|
121
|
+
for (let index = 0; index < manifest.plugins.length; index++) {
|
|
122
|
+
const plugin = manifest.plugins[index];
|
|
123
|
+
const registered = manifest.registered[plugin.id] !== undefined || manifest.failures[plugin.id] !== undefined;
|
|
124
|
+
const enabled = savedEnabled(plugin.addon);
|
|
125
|
+
states.set(plugin.id, {
|
|
126
|
+
manifest: plugin,
|
|
127
|
+
enabled: ref(enabled),
|
|
128
|
+
status: ref<PluginStatus>(enabled ? "waiting" : "off"),
|
|
129
|
+
error: ref<string | undefined>(undefined),
|
|
130
|
+
running: registered,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
host = { modules, scope, manifest, states };
|
|
134
|
+
for (let index = 0; index < manifest.plugins.length; index++) {
|
|
135
|
+
const plugin = manifest.plugins[index];
|
|
136
|
+
const state = states.get(plugin.id);
|
|
137
|
+
if (state === undefined || plugin.load !== "startup" || !state.running) continue;
|
|
138
|
+
settle(state, activate(state, modules, manifest));
|
|
139
|
+
if (state.status.value === "error") report(fail("Plugin " + plugin.id + ": " + (state.error.value ?? "failed")));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function loadPlugin(id: string): Result<object> {
|
|
144
|
+
const current = host;
|
|
145
|
+
if (current === undefined) return fail("Plugins are available after the addon starts");
|
|
146
|
+
if (!current.scope.isActive()) return fail("The addon has stopped");
|
|
147
|
+
const state = current.states.get(id);
|
|
148
|
+
if (state === undefined) return fail("Unknown plugin " + id + ". Declare it in kumi.config.ts.");
|
|
149
|
+
const status = state.status.value;
|
|
150
|
+
if (status === "ready" && state.services !== undefined) return ok(state.services);
|
|
151
|
+
if (status === "loading") return fail("Plugin " + id + " is already loading");
|
|
152
|
+
if (!state.enabled.value) return fail("Plugin " + id + " is turned off. Turn it on in the plugin list.");
|
|
153
|
+
if (state.manifest.load === "startup" && !state.running) return fail("Plugin " + id + " starts after a UI reload");
|
|
154
|
+
if (inCombat()) return fail("Plugin " + id + " can load after combat");
|
|
155
|
+
const { manifest, modules } = current;
|
|
156
|
+
state.status.value = "loading";
|
|
157
|
+
state.error.value = undefined;
|
|
158
|
+
if (manifest.registered[id] === undefined && manifest.failures[id] === undefined) {
|
|
159
|
+
const loader = api.C_AddOns?.LoadAddOn;
|
|
160
|
+
if (typeof loader !== "function") {
|
|
161
|
+
settle(state, fail("This client cannot load addons on demand"));
|
|
162
|
+
return fail(state.error.value ?? "");
|
|
163
|
+
}
|
|
164
|
+
// WoW reports errors from the plugin's files to its error handler. LoadAddOn itself returns a status.
|
|
165
|
+
manifest.loading = state.manifest.addon;
|
|
166
|
+
const [success, reason] = loader(state.manifest.addon);
|
|
167
|
+
manifest.loading = undefined;
|
|
168
|
+
if (reveal(success) !== true) {
|
|
169
|
+
const failure = fail("Could not load " + state.manifest.addon + ": " + (reveal(reason) ?? "unknown reason"));
|
|
170
|
+
settle(state, failure);
|
|
171
|
+
return failure;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const result = activate(state, modules, manifest);
|
|
175
|
+
settle(state, result);
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function setPluginEnabled(id: string, enabled: boolean, reload: SignalRef<boolean>): Result<void> {
|
|
180
|
+
const current = host;
|
|
181
|
+
const state = current?.states.get(id);
|
|
182
|
+
if (current === undefined || state === undefined) return fail("Unknown plugin " + id + ". Declare it in kumi.config.ts.");
|
|
183
|
+
if (state.enabled.value === enabled) return ok(undefined);
|
|
184
|
+
const addons = api.C_AddOns;
|
|
185
|
+
const write = enabled ? addons?.EnableAddOn : addons?.DisableAddOn;
|
|
186
|
+
if (typeof write !== "function") return fail("This client cannot change the addon list");
|
|
187
|
+
const character = current.manifest.pluginState === "character" ? playerName() : undefined;
|
|
188
|
+
const written = protect(() => {
|
|
189
|
+
if (character === undefined) write(state.manifest.addon);
|
|
190
|
+
else write(state.manifest.addon, character);
|
|
191
|
+
addons?.SaveAddOns?.();
|
|
192
|
+
});
|
|
193
|
+
if (!written.ok) return written;
|
|
194
|
+
state.enabled.value = enabled;
|
|
195
|
+
if (state.status.value === "off" || state.status.value === "waiting") state.status.value = enabled ? "waiting" : "off";
|
|
196
|
+
// A running plugin stops only after a reload. A startup plugin also starts only after one.
|
|
197
|
+
const running = state.status.value === "ready" || state.status.value === "error" || state.running;
|
|
198
|
+
if (running !== enabled && (running || state.manifest.load === "startup")) reload.value = true;
|
|
199
|
+
return ok(undefined);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The addon's plugins and their state. Use it to build a plugin list:
|
|
204
|
+
* `plugins.list` is reactive, `setEnabled` changes the addon list, and `reload()` applies the change.
|
|
205
|
+
*/
|
|
206
|
+
export const usePlugins = defineStore("kumi/plugins", () => {
|
|
207
|
+
const reloadRequired = ref(false);
|
|
208
|
+
const list = computed(() => {
|
|
209
|
+
const rows: PluginInfo[] = [];
|
|
210
|
+
const current = host;
|
|
211
|
+
if (current === undefined) return rows;
|
|
212
|
+
for (let index = 0; index < current.manifest.plugins.length; index++) {
|
|
213
|
+
const plugin = current.manifest.plugins[index];
|
|
214
|
+
const state = current.states.get(plugin.id);
|
|
215
|
+
if (state === undefined) continue;
|
|
216
|
+
rows.push({
|
|
217
|
+
id: plugin.id as PluginId, addon: plugin.addon, title: plugin.title, notes: plugin.notes, load: plugin.load,
|
|
218
|
+
enabled: state.enabled.value, status: state.status.value, error: state.error.value,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return rows;
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
/** Load a demand plugin, or return a running plugin's services. Repeated calls return the same services. */
|
|
225
|
+
function load<Id extends PluginId>(this: void, id: Id): Result<PluginServices<Id>> {
|
|
226
|
+
return loadPlugin(id) as Result<PluginServices<Id>>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Turn a plugin on or off in the addon list. Check `reloadRequired` to offer a reload. */
|
|
230
|
+
function setEnabled(this: void, id: PluginId, enabled: boolean): Result<void> {
|
|
231
|
+
return setPluginEnabled(id, enabled, reloadRequired);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function status(this: void, id: PluginId): PluginStatus | undefined {
|
|
235
|
+
return host?.states.get(id)?.status.value;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Reload the interface so plugin changes take effect. */
|
|
239
|
+
function reload(this: void): void {
|
|
240
|
+
const ui = api.C_UI;
|
|
241
|
+
if (typeof ui?.Reload === "function") ui.Reload();
|
|
242
|
+
else (api as { ReloadUI?: (this: void) => void }).ReloadUI?.();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return { list, reloadRequired: readonly(reloadRequired), load, setEnabled, status, reload };
|
|
246
|
+
});
|
package/wow/protect.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ok, type Failure, type Result } from "../src/result";
|
|
2
|
+
import { rawField } from "./lua-table";
|
|
3
|
+
import { api, isSecret } from "./native";
|
|
2
4
|
import type { LuaMultiReturn } from "@kumi/wow-generated";
|
|
3
5
|
|
|
4
6
|
type ProtectedNative<Values extends unknown[]> = LuaMultiReturn<
|
|
@@ -15,10 +17,32 @@ declare function pcall<Receiver extends object, Args extends unknown[], Value>(
|
|
|
15
17
|
this: void, run: (this: Receiver, ...args: Args) => Value, receiver: Receiver, ...args: Args
|
|
16
18
|
): ProtectedNative<[Value]>;
|
|
17
19
|
|
|
20
|
+
declare function xpcall<Value>(
|
|
21
|
+
this: void, run: (this: void) => Value, onError: (this: void, error: unknown) => Failure
|
|
22
|
+
): LuaMultiReturn<[success: true, value: Value] | [success: false, error: Failure]>;
|
|
23
|
+
|
|
18
24
|
/** Preserve native multiple returns and leave error objects opaque. */
|
|
19
25
|
export const protectNative = pcall;
|
|
20
26
|
|
|
27
|
+
type DebugStack = (this: void, skip: number, top: number, bottom: number) => string;
|
|
28
|
+
type Traceback = (this: void, prefix: string, level: number) => string;
|
|
29
|
+
|
|
30
|
+
function readTrace(this: void): string | undefined {
|
|
31
|
+
const stack = rawField<DebugStack>(api, "debugstack");
|
|
32
|
+
const trace = stack === undefined
|
|
33
|
+
? rawField<Traceback>(rawField(api, "debug"), "traceback")?.("", 3)
|
|
34
|
+
: stack(3, 24, 8);
|
|
35
|
+
return isSecret(trace) || trace === "" ? undefined : trace;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// xpcall invokes the handler while the throwing callback's stack is still available.
|
|
39
|
+
function captureFailure(this: void, error: unknown): Failure {
|
|
40
|
+
const [described, reason] = protectNative(() => isSecret(error) ? "Protected WoW error" : String(error));
|
|
41
|
+
const [captured, trace] = protectNative(readTrace);
|
|
42
|
+
return { ok: false, reason: described ? reason : "WoW callback failed", trace: captured ? trace : undefined };
|
|
43
|
+
}
|
|
44
|
+
|
|
21
45
|
export function protect<T>(run: (this: void) => T): Result<T> {
|
|
22
|
-
const [success, value] =
|
|
23
|
-
return success ? ok(value) :
|
|
46
|
+
const [success, value] = xpcall(run, captureFailure);
|
|
47
|
+
return success ? ok(value) : value;
|
|
24
48
|
}
|