@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
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { direct, fail, formatFailure, ok, type Result } from "../src/result";
|
|
2
|
+
import { withReactiveScope } from "../src/reactive-scope";
|
|
3
|
+
import { setupRefKind, type ComputedRef, type ReadonlyRef, type Ref, type SignalRef } from "../src/reactivity";
|
|
4
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
5
|
+
import type { ServiceToken } from "../src/providers";
|
|
6
|
+
import { ownedArray, ownedMap, ownedWeakMap, type OwnedMap, type OwnedReadonlyArray, type OwnedWeakMap } from "../src/owned-collections";
|
|
7
|
+
import { batch, deferStoreWatches, hydrateSetupStore, type StorePersistence } from "./setup-store-persistence";
|
|
8
|
+
import { createSetupStoreView, type StoreAccessor } from "./setup-store-view";
|
|
9
|
+
import type { StoreStorage } from "./store";
|
|
10
|
+
|
|
11
|
+
declare const setupStoreShape: unique symbol;
|
|
12
|
+
declare const readonlySource: unique symbol;
|
|
13
|
+
|
|
14
|
+
/** A read-only view of a store ref. Actions still write the original ref. */
|
|
15
|
+
export interface StoreReadonly<T> extends ReadonlyRef<T> {
|
|
16
|
+
readonly [readonlySource]: true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type StoreField<Value> = Value extends SignalRef<infer State> ? State
|
|
20
|
+
: Value extends ComputedRef<infer State> ? State
|
|
21
|
+
: Value extends StoreReadonly<infer State> ? State : Value;
|
|
22
|
+
type WritableStoreKeys<Source> = {
|
|
23
|
+
[Key in keyof Source]-?: Source[Key] extends SignalRef<unknown> ? Key : never
|
|
24
|
+
}[keyof Source];
|
|
25
|
+
type ReadonlyStoreKeys<Source> = {
|
|
26
|
+
[Key in keyof Source]-?: Source[Key] extends StoreReadonly<unknown> ? Key : never
|
|
27
|
+
}[keyof Source];
|
|
28
|
+
type StorePatch<Source> = { [Key in WritableStoreKeys<Source>]?: StoreField<Source[Key]> };
|
|
29
|
+
|
|
30
|
+
/** Members Kumi adds to every store. */
|
|
31
|
+
export interface StoreApi<Source extends object> {
|
|
32
|
+
/** The ID passed to defineStore. */
|
|
33
|
+
readonly $id: string;
|
|
34
|
+
/** Write several writable fields as one change. Persisted fields are saved once. */
|
|
35
|
+
$patch(this: void, values: StorePatch<Source>): Result<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type SetupStore<Source extends object> = {
|
|
39
|
+
-readonly [Key in WritableStoreKeys<Source>]: StoreField<Source[Key]>
|
|
40
|
+
} & {
|
|
41
|
+
readonly [Key in Exclude<keyof Source, WritableStoreKeys<Source>>]: StoreField<Source[Key]>
|
|
42
|
+
} & StoreApi<Source> & { readonly [setupStoreShape]: Source };
|
|
43
|
+
|
|
44
|
+
export type SetupStoreRefs<Source extends object> = {
|
|
45
|
+
[Key in keyof Source as Source[Key] extends SignalRef<unknown> | ComputedRef<unknown> | StoreReadonly<unknown> ? Key : never]:
|
|
46
|
+
Source[Key] extends ComputedRef<infer State> ? ReadonlyRef<State>
|
|
47
|
+
: Source[Key] extends StoreReadonly<infer State> ? ReadonlyRef<State> : Source[Key]
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type PersistedStoreKey<Source> = (WritableStoreKeys<Source> | ReadonlyStoreKeys<Source>) & string;
|
|
51
|
+
|
|
52
|
+
export interface SetupStoreOptions<Source extends object, Key extends PersistedStoreKey<Source>> {
|
|
53
|
+
readonly persist?: {
|
|
54
|
+
/** Refs to save. A field exposed through readonly() can be saved too. */
|
|
55
|
+
readonly pick: readonly Key[];
|
|
56
|
+
/** Save in the addon's per-character SavedVariables instead of the account-wide one. */
|
|
57
|
+
readonly perCharacter?: boolean;
|
|
58
|
+
/** Defaults to the addon's SavedVariables, under this store's ID. */
|
|
59
|
+
readonly storage?: StoreStorage<{ [Field in NoInfer<Key>]: StoreField<Source[Field]> }>;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The function defineStore returns. Call it to get the store. */
|
|
64
|
+
export type StoreFactory<Source extends object> = (this: void, owner?: RuntimeScope) => SetupStore<Source>;
|
|
65
|
+
/** Any function returned by defineStore, as listed in a module's `stores`. */
|
|
66
|
+
export type AnyStoreFactory = (this: void, owner?: RuntimeScope) => object;
|
|
67
|
+
|
|
68
|
+
type Inject = (this: void, token: ServiceToken<object>) => Result<object>;
|
|
69
|
+
type DefaultStorage = (this: void, id: string, defaults: Readonly<Record<string, unknown>>, perCharacter: boolean) =>
|
|
70
|
+
StoreStorage<Record<string, unknown>> | undefined;
|
|
71
|
+
|
|
72
|
+
interface StoreDefinition {
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly setup: (this: void) => object;
|
|
75
|
+
readonly persistence?: StorePersistence;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface StoreSlot {
|
|
79
|
+
readonly definition: StoreDefinition;
|
|
80
|
+
store?: object;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface Registration {
|
|
84
|
+
readonly owner: RuntimeScope;
|
|
85
|
+
readonly resolve?: Inject;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @internal The stores of one addon: one instance per store ID, shared by every module and load-on-demand part. */
|
|
89
|
+
export interface StoreHost {
|
|
90
|
+
readonly registrations: OwnedMap<StoreDefinition, Registration>;
|
|
91
|
+
readonly instances: OwnedMap<string, StoreSlot>;
|
|
92
|
+
readonly root: (this: void) => RuntimeScope | undefined;
|
|
93
|
+
storage?: DefaultStorage;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class ReadonlyView<T> implements ReadonlyRef<T> {
|
|
97
|
+
constructor(readonly source: Ref<T>) {}
|
|
98
|
+
|
|
99
|
+
get value(): T {
|
|
100
|
+
return this.source.value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class StoreComputed<T> implements ReadonlyRef<T> {
|
|
105
|
+
constructor(private readonly source: ComputedRef<T>, private readonly name: string) {}
|
|
106
|
+
|
|
107
|
+
get value(): T {
|
|
108
|
+
const value = this.source.value;
|
|
109
|
+
if (!value.ok) throw new Error(this.name + ": " + formatFailure(value));
|
|
110
|
+
return value.value;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const definitions = ownedWeakMap<AnyStoreFactory, StoreDefinition>();
|
|
115
|
+
let owners: OwnedWeakMap<RuntimeScope, OwnedMap<string, StoreSlot>> | undefined;
|
|
116
|
+
let bindings: OwnedWeakMap<object, object> | undefined;
|
|
117
|
+
const opening: string[] = [];
|
|
118
|
+
let activeHost: StoreHost | undefined;
|
|
119
|
+
let activeInject: Inject | undefined;
|
|
120
|
+
|
|
121
|
+
/** Expose a ref read-only. Store actions keep writing the ref you pass in. */
|
|
122
|
+
export function readonly<T>(this: void, source: Ref<T>): StoreReadonly<T> {
|
|
123
|
+
return new ReadonlyView(source) as unknown as StoreReadonly<T>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get a service inside a store's setup. The store must be listed in a module's `stores`,
|
|
128
|
+
* and the token must be one of that module's providers or an export of a module it imports.
|
|
129
|
+
*/
|
|
130
|
+
export function inject<Value extends object>(this: void, token: abstract new (...dependencies: never[]) => Value): Value;
|
|
131
|
+
export function inject<Value extends object>(this: void, token: ServiceToken<Value>): Value;
|
|
132
|
+
export function inject<Value extends object>(this: void, token: ServiceToken<Value>): Value {
|
|
133
|
+
const resolve = activeInject;
|
|
134
|
+
if (resolve === undefined) {
|
|
135
|
+
throw new Error("inject(" + token.name + ") works only inside the setup of a store listed in a module's stores");
|
|
136
|
+
}
|
|
137
|
+
const result = resolve(token);
|
|
138
|
+
if (!result.ok) throw new Error(formatFailure(result));
|
|
139
|
+
return result.value as Value;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function createStoreFields(id: string, source: Record<string, unknown>) {
|
|
143
|
+
const fields: Record<string, unknown> = {};
|
|
144
|
+
const accessors: Record<string, StoreAccessor> = {};
|
|
145
|
+
const refs: Record<string, ReadonlyRef<unknown>> = {};
|
|
146
|
+
const cells: Record<string, Ref<unknown>> = {};
|
|
147
|
+
for (const key of Object.keys(source)) {
|
|
148
|
+
if (key === "$id" || key === "$patch") throw new Error("Store " + id + " cannot declare " + key);
|
|
149
|
+
const value = source[key];
|
|
150
|
+
const kind = setupRefKind(value);
|
|
151
|
+
if (kind === "signal") {
|
|
152
|
+
const cell = value as Ref<unknown>;
|
|
153
|
+
refs[key] = cell;
|
|
154
|
+
cells[key] = cell;
|
|
155
|
+
accessors[key] = { get: () => cell.value, set: next => { cell.value = next; }, enumerable: true };
|
|
156
|
+
} else if (kind === "computed") {
|
|
157
|
+
const cell = new StoreComputed(value as ComputedRef<unknown>, id + "." + key);
|
|
158
|
+
refs[key] = cell;
|
|
159
|
+
accessors[key] = { get: () => cell.value, enumerable: true };
|
|
160
|
+
} else if (value instanceof ReadonlyView) {
|
|
161
|
+
const view = value as ReadonlyView<unknown>;
|
|
162
|
+
refs[key] = view;
|
|
163
|
+
cells[key] = view.source;
|
|
164
|
+
accessors[key] = { get: () => view.value, enumerable: true };
|
|
165
|
+
} else {
|
|
166
|
+
fields[key] = value;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
fields.$id = id;
|
|
170
|
+
fields.$patch = (values: Record<string, unknown>) => batch(() => {
|
|
171
|
+
for (const key of Object.keys(values)) {
|
|
172
|
+
const accessor = accessors[key];
|
|
173
|
+
const write = accessor?.set;
|
|
174
|
+
if (write === undefined) throw new Error("Store " + id + " cannot patch " + key + ": it is not a writable ref");
|
|
175
|
+
write(values[key]);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return { store: createSetupStoreView(fields, accessors), refs, cells };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function protectLocalSetup<T>(this: void, run: (this: void) => T): Result<T> {
|
|
182
|
+
try {
|
|
183
|
+
return ok(run());
|
|
184
|
+
} catch (problem) {
|
|
185
|
+
return fail(String(problem));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function defaultsOf(pick: OwnedReadonlyArray<string>, cells: Readonly<Record<string, Ref<unknown>>>) {
|
|
190
|
+
const defaults: Record<string, unknown> = {};
|
|
191
|
+
for (const key of pick) {
|
|
192
|
+
const cell = cells[key];
|
|
193
|
+
if (cell !== undefined) defaults[key] = cell.value;
|
|
194
|
+
}
|
|
195
|
+
return defaults;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Open one instance in a registry, or return the instance it already holds. */
|
|
199
|
+
function openStore(definition: StoreDefinition, owner: RuntimeScope, registry: OwnedMap<string, StoreSlot>,
|
|
200
|
+
resolve: Inject | undefined, storage: DefaultStorage | undefined): object {
|
|
201
|
+
const { id, setup, persistence } = definition;
|
|
202
|
+
if (!owner.isActive()) throw new Error("Store " + id + " needs an active owner");
|
|
203
|
+
const existing = registry.get(id);
|
|
204
|
+
if (existing !== undefined) {
|
|
205
|
+
if (existing.definition !== definition) throw new Error("Duplicate store ID: " + id);
|
|
206
|
+
if (existing.store === undefined) throw new Error("Circular store dependency: " + [...opening, id].join(" -> "));
|
|
207
|
+
return existing.store;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const scope = owner.fork();
|
|
211
|
+
if (scope.protect === direct) scope.protect = protectLocalSetup;
|
|
212
|
+
const slot: StoreSlot = { definition };
|
|
213
|
+
registry.set(id, slot);
|
|
214
|
+
opening.push(id);
|
|
215
|
+
const previousInject = activeInject;
|
|
216
|
+
activeInject = resolve;
|
|
217
|
+
let opened = false;
|
|
218
|
+
try {
|
|
219
|
+
const ready = withReactiveScope(scope, () => {
|
|
220
|
+
if (persistence === undefined || persistence.pick.length === 0) {
|
|
221
|
+
return createStoreFields(id, setup() as Record<string, unknown>);
|
|
222
|
+
}
|
|
223
|
+
const startWatches = deferStoreWatches(scope);
|
|
224
|
+
const fields = createStoreFields(id, setup() as Record<string, unknown>);
|
|
225
|
+
const perCharacter = persistence.perCharacter === true;
|
|
226
|
+
const chosen = persistence.storage ?? storage?.(id, defaultsOf(persistence.pick, fields.cells), perCharacter);
|
|
227
|
+
if (chosen === undefined) {
|
|
228
|
+
throw new Error("Store " + id + " persists fields but has no storage. Set addon."
|
|
229
|
+
+ (perCharacter ? "savedVariablesPerCharacter" : "savedVariables") + " in kumi.config.ts or pass persist.storage.");
|
|
230
|
+
}
|
|
231
|
+
hydrateSetupStore(id, scope, persistence.pick, chosen, fields.cells);
|
|
232
|
+
startWatches();
|
|
233
|
+
return fields;
|
|
234
|
+
});
|
|
235
|
+
if (!ready.ok) throw new Error("Store " + id + ": " + formatFailure(ready));
|
|
236
|
+
const { store, refs } = ready.value;
|
|
237
|
+
const registered = scope.onDispose(() => {
|
|
238
|
+
bindings?.delete(store);
|
|
239
|
+
if (registry.get(id) === slot) registry.delete(id);
|
|
240
|
+
});
|
|
241
|
+
if (!registered.ok) throw new Error("Store " + id + ": " + formatFailure(registered));
|
|
242
|
+
const referenceMap = bindings ??= ownedWeakMap<object, object>();
|
|
243
|
+
referenceMap.set(store, refs);
|
|
244
|
+
slot.store = store;
|
|
245
|
+
opened = true;
|
|
246
|
+
return store;
|
|
247
|
+
} finally {
|
|
248
|
+
activeInject = previousInject;
|
|
249
|
+
opening.pop();
|
|
250
|
+
if (!opened) {
|
|
251
|
+
if (registry.get(id) === slot) registry.delete(id);
|
|
252
|
+
scope.dispose();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function openOwned(definition: StoreDefinition, owner: RuntimeScope) {
|
|
258
|
+
const registry = owners ??= ownedWeakMap<RuntimeScope, OwnedMap<string, StoreSlot>>();
|
|
259
|
+
let group = registry.get(owner);
|
|
260
|
+
if (group === undefined) {
|
|
261
|
+
group = ownedMap<string, StoreSlot>();
|
|
262
|
+
registry.set(owner, group);
|
|
263
|
+
}
|
|
264
|
+
return openStore(definition, owner, group, undefined, activeHost?.storage);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function openHosted(host: StoreHost, definition: StoreDefinition) {
|
|
268
|
+
const registration = host.registrations.get(definition);
|
|
269
|
+
const owner = registration?.owner ?? host.root();
|
|
270
|
+
if (owner === undefined) throw new Error("Store " + definition.id + " needs a running addon");
|
|
271
|
+
return openStore(definition, owner, host.instances, registration?.resolve, host.storage);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Define a store. Call the returned function anywhere in the addon to get its single instance.
|
|
276
|
+
* List it in a module's `stores` when its setup uses inject().
|
|
277
|
+
*/
|
|
278
|
+
export function defineStore<Source extends object, Key extends PersistedStoreKey<Source> = PersistedStoreKey<Source>>(
|
|
279
|
+
id: string, setup: (this: void) => Source, options?: SetupStoreOptions<NoInfer<Source>, Key>,
|
|
280
|
+
): StoreFactory<Source> {
|
|
281
|
+
const persist = options?.persist;
|
|
282
|
+
const definition: StoreDefinition = {
|
|
283
|
+
id,
|
|
284
|
+
setup: setup as (this: void) => object,
|
|
285
|
+
persistence: persist === undefined ? undefined : {
|
|
286
|
+
pick: persist.pick as unknown as OwnedReadonlyArray<string>,
|
|
287
|
+
perCharacter: persist.perCharacter,
|
|
288
|
+
storage: persist.storage as unknown as StoreStorage<Record<string, unknown>> | undefined,
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
const useStore = (owner?: RuntimeScope) => {
|
|
292
|
+
if (owner !== undefined) return openOwned(definition, owner) as SetupStore<Source>;
|
|
293
|
+
const host = activeHost;
|
|
294
|
+
if (host === undefined) throw new Error("Store " + id + " needs a running addon. Call it after startAddon, or pass an owner scope.");
|
|
295
|
+
return openHosted(host, definition) as SetupStore<Source>;
|
|
296
|
+
};
|
|
297
|
+
definitions.set(useStore, definition);
|
|
298
|
+
return useStore;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Return the store's refs for JSX bindings: writable refs stay writable, computed and readonly fields are read-only. */
|
|
302
|
+
export function storeToRefs<Source extends object>(store: SetupStore<Source>): SetupStoreRefs<Source> {
|
|
303
|
+
const refs = bindings?.get(store);
|
|
304
|
+
if (refs === undefined) throw new Error("Expected an active Kumi setup store");
|
|
305
|
+
return refs as SetupStoreRefs<Source>;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** @internal Create the store host of a module container. */
|
|
309
|
+
export function createStoreHost(this: void, root: (this: void) => RuntimeScope | undefined): StoreHost {
|
|
310
|
+
const host: StoreHost = { registrations: ownedMap(), instances: ownedMap(), root };
|
|
311
|
+
activeHost = host;
|
|
312
|
+
return host;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** @internal Make the host current, for example when an addon starts. */
|
|
316
|
+
export function activateStoreHost(this: void, host: StoreHost): void {
|
|
317
|
+
activeHost = host;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** @internal Register and open a module's stores in the module scope. */
|
|
321
|
+
export function openModuleStores(this: void, host: StoreHost, moduleId: string, stores: OwnedReadonlyArray<AnyStoreFactory>,
|
|
322
|
+
owner: RuntimeScope, resolve: Inject): Result<void> {
|
|
323
|
+
const chosen = ownedArray<StoreDefinition>();
|
|
324
|
+
for (const factory of stores) {
|
|
325
|
+
const definition = definitions.get(factory);
|
|
326
|
+
if (definition === undefined) return fail("Module " + moduleId + ": stores accepts functions returned by defineStore");
|
|
327
|
+
const other = host.registrations.get(definition);
|
|
328
|
+
if (other !== undefined) return fail("Module " + moduleId + ": store " + definition.id + " is already provided by another module");
|
|
329
|
+
chosen.push(definition);
|
|
330
|
+
}
|
|
331
|
+
for (const definition of chosen) host.registrations.set(definition, { owner, resolve });
|
|
332
|
+
const released = owner.onDispose(() => {
|
|
333
|
+
for (const definition of chosen) host.registrations.delete(definition);
|
|
334
|
+
});
|
|
335
|
+
if (!released.ok) return released;
|
|
336
|
+
activeHost = host;
|
|
337
|
+
for (const definition of chosen) {
|
|
338
|
+
const opened = protectLocalSetup(() => openStore(definition, owner, host.instances, resolve, host.storage));
|
|
339
|
+
if (!opened.ok) return fail("Module " + moduleId + ": " + opened.reason);
|
|
340
|
+
}
|
|
341
|
+
return ok(undefined);
|
|
342
|
+
}
|
package/state/store.ts
CHANGED
|
@@ -9,6 +9,8 @@ export { createStore };
|
|
|
9
9
|
export interface StoreStorage<State extends object> {
|
|
10
10
|
read(this: void): Result<Partial<State> | undefined>;
|
|
11
11
|
write(this: void, snapshot: Readonly<State>): Result<void>;
|
|
12
|
+
/** Reserve the storage for one open store. Return the release callback, or fail when another store holds it. */
|
|
13
|
+
claim?(this: void, owner: string): Result<(this: void) => void>;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
type StateKey<State> = keyof State & string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kumi-build-debug
|
|
3
|
+
description: Run, build and debug a Kumi addon - check, build, link to the game, and fix TypeScript, ESLint, style and native compiler errors. Use when npm run check or npm run build fails, or to test a change in the game.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Build and fix
|
|
7
|
+
|
|
8
|
+
```powershell
|
|
9
|
+
npm run check
|
|
10
|
+
npm run build -- --target forever
|
|
11
|
+
npm run link -- "<game>/_forever_/Interface/AddOns" # once
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Then `/reload` in the game. Lua errors appear in BugSack or the default error frame.
|
|
15
|
+
|
|
16
|
+
## Reading errors
|
|
17
|
+
|
|
18
|
+
Errors name `file:line:column`. Fix the first one and rerun.
|
|
19
|
+
|
|
20
|
+
| Message | Fix |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `... import is restricted ...` | The code is in the wrong layer. Move the call down a layer (component → store action → service → api). |
|
|
23
|
+
| `Unsupported property X` | That CSS property is not supported. Use a supported one (see the kumi-ui skill). |
|
|
24
|
+
| `Iteration currently requires a native collection` | Loop over an array you created, or a store/ref value. For data from Lua tables, copy it into an array first. |
|
|
25
|
+
| `Array length requires a proven dense representation` | The array comes from outside; build your own array, or use a typed list from the SDK. |
|
|
26
|
+
| `Destructure native multiple results from calls` | Write `const [a, b] = api.F()` in one statement. |
|
|
27
|
+
| `Circular runtime import` | Two files import each other. Move the shared part into a third file. |
|
|
28
|
+
| `Method signatures require an explicit this type` | Often a RegExp or a library method. Use string methods instead of regular expressions. |
|
|
29
|
+
| `inject(X) works only inside the setup of a store listed in a module's stores` | List the store in its module's `stores`, and call `inject` at the top of setup. |
|
|
30
|
+
| `Store X persists fields but has no storage` | Set `addon.savedVariables` in `kumi.config.ts`. |
|
|
31
|
+
| `X belongs to plugin Y, but Z imports it` | Core code imports a plugin file. Use `import type` or move the code into a core module. |
|
|
32
|
+
|
|
33
|
+
## In the game
|
|
34
|
+
|
|
35
|
+
- Nothing appears: check that the addon and its plugins are enabled in the addon list, and that the build was linked.
|
|
36
|
+
- A plugin shows "Failed" in the Plugins page: its error text says why; fix it, rebuild, `/reload`.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kumi-feature
|
|
3
|
+
description: Add a new feature module to a Kumi addon with its api, services, model, ui and widgets layers, and wire it into the app module. Use when the user asks for a new feature, panel, tracker or system in a Kumi project.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Add a feature
|
|
7
|
+
|
|
8
|
+
1. Pick a short lowercase name, for example `loot`. Create `src/modules/loot/` with the folders you need: `api/`, `services/`, `model/`, `ui/`, `widgets/`.
|
|
9
|
+
2. **api/**: one function per WoW call, returning plain values.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// src/modules/loot/api/money.api.ts
|
|
13
|
+
import { api } from "@kumi/wow";
|
|
14
|
+
export function readMoney(): number { return api.GetMoney(); }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
3. **services/**: the logic, as an `@Injectable` class that calls `api/`.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class LootService {
|
|
22
|
+
money() { return readMoney(); }
|
|
23
|
+
gained(start: number, now: number) { return Math.max(0, now - start); }
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
4. **model/**: a store that injects the service. See the kumi-store skill.
|
|
28
|
+
5. **ui/** and **widgets/**: components that read the store. See the kumi-ui skill.
|
|
29
|
+
6. **loot.module.ts**: the manifest and public API.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
export { useLootStore } from "./model/loot.store";
|
|
33
|
+
|
|
34
|
+
const metadata = {
|
|
35
|
+
id: "loot",
|
|
36
|
+
imports: [], // other features this one reads, by their module class
|
|
37
|
+
providers: [LootService],
|
|
38
|
+
stores: [useLootStore],
|
|
39
|
+
views: [], // HUD widgets to show while the feature runs
|
|
40
|
+
exports: {},
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
@Module(metadata)
|
|
44
|
+
export class LootModule extends ModuleType<typeof metadata> {}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
7. Add `LootModule` to `imports` in `src/app/app.module.ts`. If the feature should be optional, make it a plugin instead (kumi-plugin skill) and do not import it.
|
|
48
|
+
8. Run `npm run check` and `npm run build -- --target forever`.
|
|
49
|
+
|
|
50
|
+
Rules: other features import only `loot.module.ts`. Components never import `api/` or `services/`.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kumi-plugin
|
|
3
|
+
description: Add a plugin to a Kumi addon - an optional part that players turn on or off, built as its own addon - or load a part on demand. Use when a feature should be optional, separately toggleable, or loaded only when opened.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Add a plugin
|
|
7
|
+
|
|
8
|
+
1. Write the plugin as a normal feature module under `src/modules/<id>/` (kumi-feature skill). It may import core modules, but core code must not import its files.
|
|
9
|
+
2. Add it to `kumi.config.ts`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
plugins: {
|
|
13
|
+
loot: {
|
|
14
|
+
module: "src/modules/loot/loot.module.ts",
|
|
15
|
+
title: "Loot",
|
|
16
|
+
notes: "Counts gold and items",
|
|
17
|
+
load: "startup", // or "demand" to load on first use
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
pluginState: "character", // or "account"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. Do not add the module to `app.module.ts` imports. Kumi starts startup plugins itself.
|
|
24
|
+
4. Contribute UI from the plugin's module: `views` for HUD panels, `pages` for window pages, `extensions` for slots such as `"hud.footer"`.
|
|
25
|
+
5. For a demand plugin, load it from a store action or a button:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
const loaded = usePlugins().load("loot");
|
|
29
|
+
if (loaded.ok) { /* loaded.value has the module's exports */ }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
6. Run `npm run check` (generates the typed plugin list) and `npm run build -- --target forever`. The build creates `build/addons/<Addon>_<id>/`. Run `npm run link -- <AddOns>` again once so the new folder is linked.
|
|
33
|
+
|
|
34
|
+
The Plugins page (`src/app/routes/(window)/plugins/page.tsx`) lists plugins with `usePlugins()`. Turning one off asks for a reload.
|
|
35
|
+
|
|
36
|
+
If the build says a file "belongs to plugin X, but <Addon> imports it": core code imports a file from the plugin's folder. Use `import type`, or move the shared code into a core module.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kumi-store
|
|
3
|
+
description: Create or change a Kumi store (defineStore) - state, computed values, actions that call services, saving to SavedVariables, batch updates, events and timers. Use when adding state, settings or saved data to a Kumi addon.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Write a store
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
// src/modules/loot/model/loot.store.ts
|
|
10
|
+
import { batch, computed, defineStore, inject, readonly, ref } from "@kumi/state";
|
|
11
|
+
import { useEvent } from "@kumi/wow";
|
|
12
|
+
import { LootService } from "../services/loot.service";
|
|
13
|
+
|
|
14
|
+
export const useLootStore = defineStore("loot", () => {
|
|
15
|
+
const loot = inject(LootService); // only in a store listed in a module's `stores`
|
|
16
|
+
const start = ref(loot.money());
|
|
17
|
+
const copper = ref(loot.money());
|
|
18
|
+
const best = ref(0);
|
|
19
|
+
|
|
20
|
+
useEvent("PLAYER_MONEY", () => { copper.value = loot.money(); });
|
|
21
|
+
|
|
22
|
+
const gained = computed(() => loot.gained(start.value, copper.value));
|
|
23
|
+
|
|
24
|
+
function reset(this: void) {
|
|
25
|
+
return batch(() => { // one save, rolled back together on failure
|
|
26
|
+
start.value = copper.value;
|
|
27
|
+
best.value = 0;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { gained, best: readonly(best), start: readonly(start), reset };
|
|
32
|
+
}, { persist: { pick: ["best", "start"] } });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Steps:
|
|
36
|
+
|
|
37
|
+
1. Put the store in the owning feature's `model/` and list it in that module's `stores`.
|
|
38
|
+
2. Return refs for state, `readonly(ref)` for state with rules, `computed` for derived state, functions for actions.
|
|
39
|
+
3. Save fields with `persist: { pick: [...] }`; add `perCharacter: true` for per-character data. The addon's `savedVariables` in `kumi.config.ts` holds them.
|
|
40
|
+
4. Actions call services. Never call WoW from a store; add an `api/` function and a service method.
|
|
41
|
+
5. Read it anywhere with `useLootStore()`. In JSX use `const { gained } = storeToRefs(useLootStore())`.
|
|
42
|
+
|
|
43
|
+
Notes:
|
|
44
|
+
|
|
45
|
+
- Inside setup, `computed(...).value` is a `Result`. Share a plain function between computed values instead of reading one from another.
|
|
46
|
+
- A store used by several features stays in the feature that owns the data; others import that feature's module.
|
|
47
|
+
- `store.$patch({ ... })` writes several writable fields from outside.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kumi-ui
|
|
3
|
+
description: Build Kumi UI - TSX components, widgets, HUD views, window pages, SCSS styles, forms and animations. Use when adding or changing anything the player sees in a Kumi addon.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Build UI
|
|
7
|
+
|
|
8
|
+
## A component (`ui/`)
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import type { Binding, NodeRef } from "@kumi/core";
|
|
12
|
+
import styles from "@kumi/styles/modules/loot/ui/Loot";
|
|
13
|
+
|
|
14
|
+
interface LootRowProps {
|
|
15
|
+
readonly label: string;
|
|
16
|
+
readonly value: Binding<string>;
|
|
17
|
+
readonly ref?: NodeRef<"frame">;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function LootRow(props: LootRowProps) {
|
|
21
|
+
return (
|
|
22
|
+
<div className={styles.row} nodeRef={props.ref}>
|
|
23
|
+
<span className={styles.label} value={props.label} />
|
|
24
|
+
<span className={styles.value} value={props.value} />
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
One read-only props object, an optional `ref`, changing data as bindings.
|
|
31
|
+
|
|
32
|
+
## A widget (`widgets/`)
|
|
33
|
+
|
|
34
|
+
Widgets read stores and compose components:
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
export function LootPanel() {
|
|
38
|
+
const loot = useLootStore();
|
|
39
|
+
const { gained } = storeToRefs(loot);
|
|
40
|
+
return <LootRow label="Gold" value={computed(() => formatMoney(gained.value))} />;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- On screen all the time: list it in the module's `views`.
|
|
45
|
+
- As a window page: create `src/app/routes/(window)/<name>/page.tsx` with `export const title = "..."` and `export default function Page() { return <LootPanel />; }`.
|
|
46
|
+
- As a plugin page: list `{ path, title, component }` in the module's `pages`.
|
|
47
|
+
|
|
48
|
+
## Styles
|
|
49
|
+
|
|
50
|
+
`ui/Loot.module.scss` next to the components; import from `@kumi/styles/modules/loot/ui/Loot`. Use tokens from `src/shared/styles/_tokens.scss`. Run `npm run check` once after adding a stylesheet. Supported properties: flex layout, sizes, margin, padding, position, colors, borders (`border`, `border-width`, `border-color`, `border-radius` 0-9/11/12px), font size and weight, states `:hover :active :focus :disabled :checked`.
|
|
51
|
+
|
|
52
|
+
## Lists
|
|
53
|
+
|
|
54
|
+
`{rows.value.map(row => <LootRow key={row.id} ... />)}` over a ref. For a store field: `const { rows } = storeToRefs(store)`.
|
|
55
|
+
|
|
56
|
+
## Forms
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
const form = useForm<Settings>({ defaultValues: DEFAULTS, values: store, commit: store.updateSettings, validate });
|
|
60
|
+
<Form form={form}>{() => <Toggle {...form.register("enabled")} label="Enabled" />}</Form>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Animation
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
const refresh = useAnimation(presets.fadeIn({ from: 0.25 }));
|
|
67
|
+
watch(() => count.value, () => { refresh.play(); });
|
|
68
|
+
<span ref={refresh.ref} value={label} />
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Text: alpha presets (`fadeIn`, `flash`, `pulse`). Scale presets (`popIn`, `hop`) on icons and frames only: scaling text stretches it.
|
|
72
|
+
|
|
73
|
+
Reusable controls go in `src/shared/ui` and take everything through props.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kumi-wow-api
|
|
3
|
+
description: Call the World of Warcraft API from a Kumi addon - wrap a game function in the api layer, handle secret values, subscribe to events, and bind secure buttons for items, spells and toys. Use when a feature needs data or actions from the game.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Use the WoW API
|
|
7
|
+
|
|
8
|
+
1. Find the function in `build/types/wow-api.d.ts` (generated by `npm run check`). It has the exact parameters and results.
|
|
9
|
+
2. Wrap it in the feature's `api/` folder, returning plain values:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { api, readableApi } from "@kumi/wow";
|
|
13
|
+
|
|
14
|
+
export function readTargetName(): string | undefined {
|
|
15
|
+
const [name] = readableApi.UnitName("target"); // undefined while the client hides it
|
|
16
|
+
return name;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function readBagSlots(bag: number): number {
|
|
20
|
+
return api.C_Container.GetContainerNumSlots(bag);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Use `readableApi` when it has the function: it turns secret values into `undefined`. Destructure multiple results in one statement.
|
|
25
|
+
3. Call the `api/` function from a service. Stores call the service.
|
|
26
|
+
4. Events: `useEvent("BAG_UPDATE_DELAYED", () => { ... })` in a store setup, or `@OnEvent("BAG_UPDATE_DELAYED")` on a service method. Payloads are typed.
|
|
27
|
+
5. Actions that need a click (use an item, cast a spell): a button with `secureAction={{ kind: "item", id: 6948 }}` inside a module view. Cooldown: `readCooldownTiming(kind, id)` from `@kumi/wow` with `<cooldown value={timing} />`.
|
|
28
|
+
6. Disable protected actions during combat with `useCombat()`.
|
|
29
|
+
|
|
30
|
+
Never call WoW from `services/`, `model/`, `ui/` or `widgets/` directly; ESLint reports it.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kumi-build-debug
|
|
3
|
+
description: Run, build and debug a Kumi addon - check, build, link to the game, and fix TypeScript, ESLint, style and native compiler errors. Use when npm run check or npm run build fails, or to test a change in the game.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Build and fix
|
|
7
|
+
|
|
8
|
+
```powershell
|
|
9
|
+
npm run check
|
|
10
|
+
npm run build -- --target forever
|
|
11
|
+
npm run link -- "<game>/_forever_/Interface/AddOns" # once
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Then `/reload` in the game. Lua errors appear in BugSack or the default error frame.
|
|
15
|
+
|
|
16
|
+
## Reading errors
|
|
17
|
+
|
|
18
|
+
Errors name `file:line:column`. Fix the first one and rerun.
|
|
19
|
+
|
|
20
|
+
| Message | Fix |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `... import is restricted ...` | The code is in the wrong layer. Move the call down a layer (component → store action → service → api). |
|
|
23
|
+
| `Unsupported property X` | That CSS property is not supported. Use a supported one (see the kumi-ui skill). |
|
|
24
|
+
| `Iteration currently requires a native collection` | Loop over an array you created, or a store/ref value. For data from Lua tables, copy it into an array first. |
|
|
25
|
+
| `Array length requires a proven dense representation` | The array comes from outside; build your own array, or use a typed list from the SDK. |
|
|
26
|
+
| `Destructure native multiple results from calls` | Write `const [a, b] = api.F()` in one statement. |
|
|
27
|
+
| `Circular runtime import` | Two files import each other. Move the shared part into a third file. |
|
|
28
|
+
| `Method signatures require an explicit this type` | Often a RegExp or a library method. Use string methods instead of regular expressions. |
|
|
29
|
+
| `inject(X) works only inside the setup of a store listed in a module's stores` | List the store in its module's `stores`, and call `inject` at the top of setup. |
|
|
30
|
+
| `Store X persists fields but has no storage` | Set `addon.savedVariables` in `kumi.config.ts`. |
|
|
31
|
+
| `X belongs to plugin Y, but Z imports it` | Core code imports a plugin file. Use `import type` or move the code into a core module. |
|
|
32
|
+
|
|
33
|
+
## In the game
|
|
34
|
+
|
|
35
|
+
- Nothing appears: check that the addon and its plugins are enabled in the addon list, and that the build was linked.
|
|
36
|
+
- A plugin shows "Failed" in the Plugins page: its error text says why; fix it, rebuild, `/reload`.
|