kaplay-plugin-ui 1.0.0 → 1.0.1

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/dist/plugin.d.cts CHANGED
@@ -1,20 +1,177 @@
1
- import { Color as Color$1, Comp, GameObj, KAPLAYCtx, Rect, Vec2 } from "kaplay";
2
- /** Color value accepted by the UI theme and components. */
3
- type Color = Color$1 | string;
1
+ import { Color, KAPLAYCtx, Vec2 } from "kaplay";
2
+ declare function createButton(k: KAPLAYCtx, theme: Theme, text: string, opt: ButtonOpt & {
3
+ pos?: Vec2;
4
+ onClick?: () => void;
5
+ color?: string | Color;
6
+ hoverColor?: string | Color;
7
+ pressedColor?: string | Color;
8
+ textColor?: string | Color;
9
+ }): {
10
+ label: import("kaplay").GameObj<import("kaplay").ColorComp | import("kaplay").AnchorComp | import("kaplay").TextComp>;
11
+ add<T>(comps?: import("kaplay").CompList<T> | import("kaplay").GameObj<T>): import("kaplay").GameObj<T>;
12
+ readd<T>(obj: import("kaplay").GameObj<T>): import("kaplay").GameObj<T>;
13
+ remove(obj: import("kaplay").GameObj): void;
14
+ removeAll(tag: import("kaplay").Tag): void;
15
+ removeAll(): void;
16
+ get(tag: import("kaplay").Tag | import("kaplay").Tag[], opts?: import("kaplay").GetOpt): import("kaplay").GameObj[];
17
+ query(opt: import("kaplay").QueryOpt): import("kaplay").GameObj[];
18
+ parent: import("kaplay").GameObj | null;
19
+ children: import("kaplay").GameObj[];
20
+ tags: string[];
21
+ fixedUpdate(): void;
22
+ update(): void;
23
+ draw(): void;
24
+ drawInspect: () => void;
25
+ clearEvents: () => void;
26
+ use(comp: import("kaplay").Comp | import("kaplay").Tag): void;
27
+ unuse(comp: import("kaplay").Tag): void;
28
+ has(compId: string | string[], op?: "and" | "or"): boolean;
29
+ tag(tag: import("kaplay").Tag | import("kaplay").Tag[]): void;
30
+ untag(tag: import("kaplay").Tag | import("kaplay").Tag[]): void;
31
+ is(tag: import("kaplay").Tag | import("kaplay").Tag[], op?: "and" | "or"): boolean;
32
+ on(event: import("kaplay").GameObjEventNames | (string & {}), action: (...args: any) => void): import("kaplay").KEventController;
33
+ trigger(event: string, ...args: any): void;
34
+ destroy(): void;
35
+ c(id: string): import("kaplay").Comp | null;
36
+ inspect(): import("kaplay").GameObjInspect;
37
+ onAdd(action: () => void): import("kaplay").KEventController;
38
+ onUpdate(action: () => void): import("kaplay").KEventController;
39
+ onFixedUpdate(action: () => void): import("kaplay").KEventController;
40
+ onDraw(action: () => void): import("kaplay").KEventController;
41
+ onDestroy(action: () => void): import("kaplay").KEventController;
42
+ onUse(action: (id: string) => void): import("kaplay").KEventController;
43
+ onUnuse(action: (id: string) => void): import("kaplay").KEventController;
44
+ onTag(action: (tag: string) => void): import("kaplay").KEventController;
45
+ onUntag(action: (tag: string) => void): import("kaplay").KEventController;
46
+ exists(): boolean;
47
+ isAncestorOf(obj: import("kaplay").GameObj): boolean;
48
+ transform: import("kaplay").Mat4;
49
+ hidden: boolean;
50
+ paused: boolean;
51
+ id: import("kaplay").GameObjID | null;
52
+ canvas: import("kaplay").FrameBuffer | null;
53
+ onKeyDown: KAPLAYCtx["onKeyDown"];
54
+ onKeyPress: KAPLAYCtx["onKeyPress"];
55
+ onKeyPressRepeat: KAPLAYCtx["onKeyPressRepeat"];
56
+ onKeyRelease: KAPLAYCtx["onKeyRelease"];
57
+ onCharInput: KAPLAYCtx["onCharInput"];
58
+ onMouseDown: KAPLAYCtx["onMouseDown"];
59
+ onMousePress: KAPLAYCtx["onMousePress"];
60
+ onMouseRelease: KAPLAYCtx["onMouseRelease"];
61
+ onMouseMove: KAPLAYCtx["onMouseMove"];
62
+ onTouchStart: KAPLAYCtx["onTouchStart"];
63
+ onTouchMove: KAPLAYCtx["onTouchMove"];
64
+ onTouchEnd: KAPLAYCtx["onTouchEnd"];
65
+ onScroll: KAPLAYCtx["onScroll"];
66
+ onGamepadButtonDown: KAPLAYCtx["onGamepadButtonDown"];
67
+ onGamepadButtonPress: KAPLAYCtx["onGamepadButtonPress"];
68
+ onGamepadButtonRelease: KAPLAYCtx["onGamepadButtonRelease"];
69
+ onGamepadStick: KAPLAYCtx["onGamepadStick"];
70
+ onButtonDown: KAPLAYCtx["onButtonDown"];
71
+ onButtonPress: KAPLAYCtx["onButtonPress"];
72
+ onButtonRelease: KAPLAYCtx["onButtonRelease"];
73
+ radius?: number | [number, number, number, number] | undefined;
74
+ width: number;
75
+ height: number;
76
+ renderArea: () => import("kaplay").Rect;
77
+ pos: Vec2;
78
+ move: {
79
+ (xVel: number, yVel: number): void;
80
+ (vel: Vec2): void;
81
+ };
82
+ moveBy: {
83
+ (dx: number, dy: number): void;
84
+ (d: Vec2): void;
85
+ };
86
+ moveTo: {
87
+ (dest: Vec2, speed?: number): void;
88
+ (x: number, y: number, speed?: number): void;
89
+ };
90
+ screenPos: (newPos?: Vec2) => Vec2 | null;
91
+ worldPos: (newPos?: Vec2) => Vec2 | null;
92
+ toScreen: (this: import("kaplay").GameObj<import("kaplay").PosComp | import("kaplay").FixedComp>, p: Vec2) => Vec2;
93
+ toWorld: (this: import("kaplay").GameObj<import("kaplay").PosComp>, p: Vec2) => Vec2;
94
+ fromScreen: (this: import("kaplay").GameObj<import("kaplay").PosComp | import("kaplay").FixedComp>, p: Vec2) => Vec2;
95
+ fromWorld: (this: import("kaplay").GameObj<import("kaplay").PosComp>, p: Vec2) => Vec2;
96
+ toOther: (this: import("kaplay").GameObj<import("kaplay").PosComp>, other: import("kaplay").GameObj<import("kaplay").PosComp>, p: Vec2) => Vec2;
97
+ fromOther: (this: import("kaplay").GameObj<import("kaplay").PosComp>, other: import("kaplay").GameObj<import("kaplay").PosComp>, p: Vec2) => Vec2;
98
+ area: {
99
+ shape: import("kaplay").Shape | null;
100
+ scale: Vec2;
101
+ offset: Vec2;
102
+ cursor: import("kaplay").Cursor | null;
103
+ };
104
+ collisionIgnore: import("kaplay").Tag[];
105
+ isClicked: () => boolean;
106
+ isHovering: () => boolean;
107
+ checkCollision: (other: import("kaplay").GameObj<import("kaplay").AreaComp>) => import("kaplay").Collision | null;
108
+ getCollisions: () => import("kaplay").Collision[];
109
+ isColliding: (o: import("kaplay").GameObj<import("kaplay").AreaComp>) => boolean;
110
+ isOverlapping: (o: import("kaplay").GameObj<import("kaplay").AreaComp>) => boolean;
111
+ onClick: (f: () => void, btn?: import("kaplay").MouseButton) => import("kaplay").KEventController;
112
+ onHover: (action: () => void) => import("kaplay").KEventController;
113
+ onHoverUpdate: (action: () => void) => import("kaplay").KEventController;
114
+ onHoverEnd: (action: () => void) => import("kaplay").KEventController;
115
+ onCollide: {
116
+ (tag: import("kaplay").Tag, f: (obj: import("kaplay").GameObj, col?: import("kaplay").Collision) => void): import("kaplay").KEventController;
117
+ (f: (obj: import("kaplay").GameObj, col?: import("kaplay").Collision) => void): import("kaplay").KEventController;
118
+ };
119
+ onCollideUpdate: {
120
+ (tag: import("kaplay").Tag, f: (obj: import("kaplay").GameObj, col?: import("kaplay").Collision) => import("kaplay").KEventController): import("kaplay").KEventController;
121
+ (f: (obj: import("kaplay").GameObj, col?: import("kaplay").Collision) => void): import("kaplay").KEventController;
122
+ };
123
+ onCollideEnd: {
124
+ (tag: import("kaplay").Tag, f: (obj: import("kaplay").GameObj) => void): import("kaplay").KEventController;
125
+ (f: (obj: import("kaplay").GameObj) => void): void;
126
+ };
127
+ hasPoint: (p: Vec2) => boolean;
128
+ resolveCollision: (obj: import("kaplay").GameObj) => void;
129
+ localArea: () => import("kaplay").Shape;
130
+ worldArea: () => import("kaplay").Polygon;
131
+ screenArea: () => import("kaplay").Polygon;
132
+ scale: Vec2;
133
+ scaleTo: {
134
+ (s: number): void;
135
+ (s: Vec2): void;
136
+ (sx: number, sy: number): void;
137
+ };
138
+ scaleBy: {
139
+ (s: number): void;
140
+ (s: Vec2): void;
141
+ (sx: number, sy: number): void;
142
+ };
143
+ color: Color;
144
+ anchor: import("kaplay").Anchor | Vec2;
145
+ };
146
+ interface UIPlugin {
147
+ addButton: (text?: string, opt?: ButtonOpt & {
148
+ pos?: Vec2;
149
+ onClick?: () => void;
150
+ color?: string | Color;
151
+ hoverColor?: string | Color;
152
+ pressedColor?: string | Color;
153
+ textColor?: string | Color;
154
+ }) => ReturnType<typeof createButton>;
155
+ getTheme: () => Theme;
156
+ setTheme: (theme: DeepPartial<Theme>) => void;
157
+ }
158
+ declare module 'kaplay' {
159
+ interface KAPLAYCtx extends UIPlugin {}
160
+ }
4
161
  /** Recursively partial version of a type. */
5
162
  type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]; };
6
163
  interface Theme {
7
164
  palette: {
8
- primary: Color;
9
- secondary: Color;
10
- background: Color;
11
- surface: Color;
12
- text: Color;
13
- textSecondary: Color;
14
- hover: Color;
15
- pressed: Color;
16
- disabled: Color;
17
- error: Color;
165
+ primary: string | Color;
166
+ secondary: string | Color;
167
+ background: string | Color;
168
+ surface: string | Color;
169
+ text: string | Color;
170
+ textSecondary: string | Color;
171
+ hover: string | Color;
172
+ pressed: string | Color;
173
+ disabled: string | Color;
174
+ error: string | Color;
18
175
  };
19
176
  typography: {
20
177
  fontFamily: string;
@@ -40,70 +197,25 @@ interface Theme {
40
197
  borderRadius: number;
41
198
  };
42
199
  tooltip: {
43
- background: Color;
44
- textColor: Color;
200
+ background: string | Color;
201
+ textColor: string | Color;
45
202
  delay: number;
46
203
  };
47
204
  };
48
205
  }
49
- /** Options for a single button. */
50
- interface ButtonCompOpt {
206
+ /** Button options. */
207
+ interface ButtonOpt {
51
208
  width?: number;
52
209
  height?: number;
53
210
  size?: number;
54
211
  font?: string;
55
- fill?: Color;
56
- textColor?: Color;
212
+ fill?: string | Color;
213
+ textColor?: string | Color;
57
214
  radius?: number;
58
- hoverFill?: Color;
59
- pressedFill?: Color;
60
- }
61
- /** The `button` component. */
62
- interface ButtonComp extends Comp {
63
- id: 'button';
64
- text: string;
65
- width: number;
66
- height: number;
67
- renderArea(): Rect;
68
- setStyle(opt: Partial<ButtonCompOpt>): void;
69
- }
70
- export declare function createButtonComponent(k: KAPLAYCtx, theme: Theme, text: string, opt: ButtonCompOpt): ButtonComp;
71
- export declare function createButtonObject(k: KAPLAYCtx, theme: Theme, text: string, opt: ButtonCompOpt & {
72
- pos?: Vec2;
73
- onClick?: () => void;
74
- color?: Color;
75
- hoverColor?: Color;
76
- pressedColor?: Color;
77
- textColor?: Color;
78
- }): GameObj;
79
- declare module 'kaplay' {
80
- interface KAPLAYCtx {
81
- button: (text?: string, opt?: ButtonCompOpt) => ButtonComp;
82
- addButton: (text?: string, opt?: ButtonCompOpt & {
83
- pos?: Vec2;
84
- onClick?: () => void;
85
- color?: Color;
86
- hoverColor?: Color;
87
- pressedColor?: Color;
88
- textColor?: Color;
89
- }) => GameObj;
90
- setTheme: (theme: DeepPartial<Theme>) => void;
91
- getTheme: () => Theme;
92
- }
215
+ hoverFill?: string | Color;
216
+ pressedFill?: string | Color;
93
217
  }
94
218
  /** KAPLAY UI plugin. */
95
- export declare function uiPlugin(k: KAPLAYCtx, theme?: DeepPartial<Theme>): {
96
- button: (text?: string, opt?: ButtonCompOpt) => ButtonComp;
97
- addButton: (text?: string, opt?: ButtonCompOpt & {
98
- pos?: Vec2;
99
- onClick?: () => void;
100
- color?: Color;
101
- hoverColor?: Color;
102
- pressedColor?: Color;
103
- textColor?: Color;
104
- }) => GameObj;
105
- setTheme: (next: DeepPartial<Theme>) => void;
106
- getTheme: () => Theme;
107
- };
108
- export type { ButtonComp, ButtonCompOpt, Color, Theme };
219
+ export declare function uiPlugin(k: KAPLAYCtx, theme?: DeepPartial<Theme>): UIPlugin;
220
+ export type { ButtonOpt, Theme, UIPlugin };
109
221
  //# sourceMappingURL=plugin.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.cts","names":["KaplayColor"],"sources":["../src/types.ts","../src/button.ts","../src/plugin.ts"],"mappings":";;KAGY,QAAQA;;KAGR,YAAY,QACrB,WAAW,KAAK,EAAE,oBAAoB,YAAY,EAAE,MAAM,EAAE;UAG9C;EACf;IACE,SAAS;IACT,WAAW;IACX,YAAY;IACZ,SAAS;IACT,MAAM;IACN,eAAe;IACf,OAAO;IACP,SAAS;IACT,UAAU;IACV,OAAO;;EAET;IACE;IACA;IACA;IACA;;EAEF;IACE;;EAEF;EACA;IACE;MACE;MACA;MACA;MACA;MACA;MACA;;IAEF;MACE;MACA;;IAEF;MACE,YAAY;MACZ,WAAW;MACX;;;;;UAMW;EACf;EACA;EACA;EACA;EACA,OAAO;EACP,YAAY;EACZ;EACA,YAAY;EACZ,cAAc;;;UAIC,mBAAmB;EAClC;EACA;EACA;EACA;EACA,cAAc;EACd,SAAS,KAAK,QAAQ;;wBCtER,sBACd,GAAG,WACH,OAAO,OACP,cACA,KAAK,gBACJ;wBA+Ea,mBACd,GAAG,WACH,OAAO,OACP,cACA,KAAK;EACH,MAAM;EACN;EACA,QAAQ;EACR,aAAa;EACb,eAAe;EACf,YAAY;IAEb;;YCpFS;IACR,SAAS,eAAe,MAAM,kBAAkB;IAChD,YACE,eACA,MAAM;MACJ,MAAM;MACN;MACA,QAAQ;MACR,aAAa;MACb,eAAe;MACf,YAAY;UAEX;IACL,WAAW,OAAO,YAAY;IAC9B,gBAAgB;;;;wBAKJ,SAAS,GAAG,WAAW,QAAO,YAAY;EAWxB,SAAA,eAAA,MAAA,kBAAqB;EAM9C,YAAA,eAAA,MAAA;IACH,MAAM;IACN;IACA,QAAQ;IACR,aAAa;IACb,eAAe;IACf,YAAY;QAEb;EAnBqB,WAAA,MAAA,YAAY;EAFf,gBAAA"}
1
+ {"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/button.ts","../src/types.ts","../src/plugin.ts"],"mappings":";iBAKgB,aACd,GAAG,WACH,OAAO,OACP,cACA,KAAK;EACH,MAAM;EACN;EACA,iBAAiB;EACjB,sBAAsB;EACtB,wBAAwB;EACxB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;EAmDuj0M,GAAA,wBAAA,mCAAA,YAAG,sCAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAA34hJ,sBAAA,KAAA,IAAA,sBAAA,SAAA,uBAAC,sCAAA;KAA8K,IAAA,sBAAA,SAAA,uBAAC,sCAAA;;;KAAsN,sBAAA,KAAA,IAAA,sBAAA,SAAA,uBAAC,+BAAA,oCAAA;KAAuM,IAAA,sBAAA,SAAA,uBAAC,sCAAA;;;;;;;;;;;;;;;;;;;;;;;;;UC9DtwzD;EACf,YACE,eACA,MAAM;IACJ,MAAM;IACN;IACA,iBAAiB;IACjB,sBAAsB;IACtB,wBAAwB;IACxB,qBAAqB;QAEpB,kBAAkB;EAEvB,gBAAgB;EAEhB,WAAW,OAAO,YAAY;;;YAKpB,kBAAkB;;;KAIlB,YAAY,QACrB,WAAW,KAAK,EAAE,oBAAoB,YAAY,EAAE,MAAM,EAAE;UAG9C;EACf;IACE,kBAAkB;IAClB,oBAAoB;IACpB,qBAAqB;IACrB,kBAAkB;IAClB,eAAe;IACf,wBAAwB;IACxB,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;IACnB,gBAAgB;;EAElB;IACE;IACA;IACA;IACA;;EAEF;IACE;;EAEF;EACA;IACE;MACE;MACA;MACA;MACA;MACA;MACA;;IAEF;MACE;MACA;;IAEF;MACE,qBAAqB;MACrB,oBAAoB;MACpB;;;;;UAMW;EACf;EACA;EACA;EACA;EACA,gBAAgB;EAChB,qBAAqB;EACrB;EACA,qBAAqB;EACrB,uBAAuB;;;wBC7ET,SACd,GAAG,WACH,QAAO,YAAY,SAClB"}
package/dist/plugin.d.mts CHANGED
@@ -1,20 +1,177 @@
1
- import { Color as Color$1, Comp, GameObj, KAPLAYCtx, Rect, Vec2 } from "kaplay";
2
- /** Color value accepted by the UI theme and components. */
3
- type Color = Color$1 | string;
1
+ import { Color, KAPLAYCtx, Vec2 } from "kaplay";
2
+ declare function createButton(k: KAPLAYCtx, theme: Theme, text: string, opt: ButtonOpt & {
3
+ pos?: Vec2;
4
+ onClick?: () => void;
5
+ color?: string | Color;
6
+ hoverColor?: string | Color;
7
+ pressedColor?: string | Color;
8
+ textColor?: string | Color;
9
+ }): {
10
+ label: import("kaplay").GameObj<import("kaplay").ColorComp | import("kaplay").AnchorComp | import("kaplay").TextComp>;
11
+ add<T>(comps?: import("kaplay").CompList<T> | import("kaplay").GameObj<T>): import("kaplay").GameObj<T>;
12
+ readd<T>(obj: import("kaplay").GameObj<T>): import("kaplay").GameObj<T>;
13
+ remove(obj: import("kaplay").GameObj): void;
14
+ removeAll(tag: import("kaplay").Tag): void;
15
+ removeAll(): void;
16
+ get(tag: import("kaplay").Tag | import("kaplay").Tag[], opts?: import("kaplay").GetOpt): import("kaplay").GameObj[];
17
+ query(opt: import("kaplay").QueryOpt): import("kaplay").GameObj[];
18
+ parent: import("kaplay").GameObj | null;
19
+ children: import("kaplay").GameObj[];
20
+ tags: string[];
21
+ fixedUpdate(): void;
22
+ update(): void;
23
+ draw(): void;
24
+ drawInspect: () => void;
25
+ clearEvents: () => void;
26
+ use(comp: import("kaplay").Comp | import("kaplay").Tag): void;
27
+ unuse(comp: import("kaplay").Tag): void;
28
+ has(compId: string | string[], op?: "and" | "or"): boolean;
29
+ tag(tag: import("kaplay").Tag | import("kaplay").Tag[]): void;
30
+ untag(tag: import("kaplay").Tag | import("kaplay").Tag[]): void;
31
+ is(tag: import("kaplay").Tag | import("kaplay").Tag[], op?: "and" | "or"): boolean;
32
+ on(event: import("kaplay").GameObjEventNames | (string & {}), action: (...args: any) => void): import("kaplay").KEventController;
33
+ trigger(event: string, ...args: any): void;
34
+ destroy(): void;
35
+ c(id: string): import("kaplay").Comp | null;
36
+ inspect(): import("kaplay").GameObjInspect;
37
+ onAdd(action: () => void): import("kaplay").KEventController;
38
+ onUpdate(action: () => void): import("kaplay").KEventController;
39
+ onFixedUpdate(action: () => void): import("kaplay").KEventController;
40
+ onDraw(action: () => void): import("kaplay").KEventController;
41
+ onDestroy(action: () => void): import("kaplay").KEventController;
42
+ onUse(action: (id: string) => void): import("kaplay").KEventController;
43
+ onUnuse(action: (id: string) => void): import("kaplay").KEventController;
44
+ onTag(action: (tag: string) => void): import("kaplay").KEventController;
45
+ onUntag(action: (tag: string) => void): import("kaplay").KEventController;
46
+ exists(): boolean;
47
+ isAncestorOf(obj: import("kaplay").GameObj): boolean;
48
+ transform: import("kaplay").Mat4;
49
+ hidden: boolean;
50
+ paused: boolean;
51
+ id: import("kaplay").GameObjID | null;
52
+ canvas: import("kaplay").FrameBuffer | null;
53
+ onKeyDown: KAPLAYCtx["onKeyDown"];
54
+ onKeyPress: KAPLAYCtx["onKeyPress"];
55
+ onKeyPressRepeat: KAPLAYCtx["onKeyPressRepeat"];
56
+ onKeyRelease: KAPLAYCtx["onKeyRelease"];
57
+ onCharInput: KAPLAYCtx["onCharInput"];
58
+ onMouseDown: KAPLAYCtx["onMouseDown"];
59
+ onMousePress: KAPLAYCtx["onMousePress"];
60
+ onMouseRelease: KAPLAYCtx["onMouseRelease"];
61
+ onMouseMove: KAPLAYCtx["onMouseMove"];
62
+ onTouchStart: KAPLAYCtx["onTouchStart"];
63
+ onTouchMove: KAPLAYCtx["onTouchMove"];
64
+ onTouchEnd: KAPLAYCtx["onTouchEnd"];
65
+ onScroll: KAPLAYCtx["onScroll"];
66
+ onGamepadButtonDown: KAPLAYCtx["onGamepadButtonDown"];
67
+ onGamepadButtonPress: KAPLAYCtx["onGamepadButtonPress"];
68
+ onGamepadButtonRelease: KAPLAYCtx["onGamepadButtonRelease"];
69
+ onGamepadStick: KAPLAYCtx["onGamepadStick"];
70
+ onButtonDown: KAPLAYCtx["onButtonDown"];
71
+ onButtonPress: KAPLAYCtx["onButtonPress"];
72
+ onButtonRelease: KAPLAYCtx["onButtonRelease"];
73
+ radius?: number | [number, number, number, number] | undefined;
74
+ width: number;
75
+ height: number;
76
+ renderArea: () => import("kaplay").Rect;
77
+ pos: Vec2;
78
+ move: {
79
+ (xVel: number, yVel: number): void;
80
+ (vel: Vec2): void;
81
+ };
82
+ moveBy: {
83
+ (dx: number, dy: number): void;
84
+ (d: Vec2): void;
85
+ };
86
+ moveTo: {
87
+ (dest: Vec2, speed?: number): void;
88
+ (x: number, y: number, speed?: number): void;
89
+ };
90
+ screenPos: (newPos?: Vec2) => Vec2 | null;
91
+ worldPos: (newPos?: Vec2) => Vec2 | null;
92
+ toScreen: (this: import("kaplay").GameObj<import("kaplay").PosComp | import("kaplay").FixedComp>, p: Vec2) => Vec2;
93
+ toWorld: (this: import("kaplay").GameObj<import("kaplay").PosComp>, p: Vec2) => Vec2;
94
+ fromScreen: (this: import("kaplay").GameObj<import("kaplay").PosComp | import("kaplay").FixedComp>, p: Vec2) => Vec2;
95
+ fromWorld: (this: import("kaplay").GameObj<import("kaplay").PosComp>, p: Vec2) => Vec2;
96
+ toOther: (this: import("kaplay").GameObj<import("kaplay").PosComp>, other: import("kaplay").GameObj<import("kaplay").PosComp>, p: Vec2) => Vec2;
97
+ fromOther: (this: import("kaplay").GameObj<import("kaplay").PosComp>, other: import("kaplay").GameObj<import("kaplay").PosComp>, p: Vec2) => Vec2;
98
+ area: {
99
+ shape: import("kaplay").Shape | null;
100
+ scale: Vec2;
101
+ offset: Vec2;
102
+ cursor: import("kaplay").Cursor | null;
103
+ };
104
+ collisionIgnore: import("kaplay").Tag[];
105
+ isClicked: () => boolean;
106
+ isHovering: () => boolean;
107
+ checkCollision: (other: import("kaplay").GameObj<import("kaplay").AreaComp>) => import("kaplay").Collision | null;
108
+ getCollisions: () => import("kaplay").Collision[];
109
+ isColliding: (o: import("kaplay").GameObj<import("kaplay").AreaComp>) => boolean;
110
+ isOverlapping: (o: import("kaplay").GameObj<import("kaplay").AreaComp>) => boolean;
111
+ onClick: (f: () => void, btn?: import("kaplay").MouseButton) => import("kaplay").KEventController;
112
+ onHover: (action: () => void) => import("kaplay").KEventController;
113
+ onHoverUpdate: (action: () => void) => import("kaplay").KEventController;
114
+ onHoverEnd: (action: () => void) => import("kaplay").KEventController;
115
+ onCollide: {
116
+ (tag: import("kaplay").Tag, f: (obj: import("kaplay").GameObj, col?: import("kaplay").Collision) => void): import("kaplay").KEventController;
117
+ (f: (obj: import("kaplay").GameObj, col?: import("kaplay").Collision) => void): import("kaplay").KEventController;
118
+ };
119
+ onCollideUpdate: {
120
+ (tag: import("kaplay").Tag, f: (obj: import("kaplay").GameObj, col?: import("kaplay").Collision) => import("kaplay").KEventController): import("kaplay").KEventController;
121
+ (f: (obj: import("kaplay").GameObj, col?: import("kaplay").Collision) => void): import("kaplay").KEventController;
122
+ };
123
+ onCollideEnd: {
124
+ (tag: import("kaplay").Tag, f: (obj: import("kaplay").GameObj) => void): import("kaplay").KEventController;
125
+ (f: (obj: import("kaplay").GameObj) => void): void;
126
+ };
127
+ hasPoint: (p: Vec2) => boolean;
128
+ resolveCollision: (obj: import("kaplay").GameObj) => void;
129
+ localArea: () => import("kaplay").Shape;
130
+ worldArea: () => import("kaplay").Polygon;
131
+ screenArea: () => import("kaplay").Polygon;
132
+ scale: Vec2;
133
+ scaleTo: {
134
+ (s: number): void;
135
+ (s: Vec2): void;
136
+ (sx: number, sy: number): void;
137
+ };
138
+ scaleBy: {
139
+ (s: number): void;
140
+ (s: Vec2): void;
141
+ (sx: number, sy: number): void;
142
+ };
143
+ color: Color;
144
+ anchor: import("kaplay").Anchor | Vec2;
145
+ };
146
+ interface UIPlugin {
147
+ addButton: (text?: string, opt?: ButtonOpt & {
148
+ pos?: Vec2;
149
+ onClick?: () => void;
150
+ color?: string | Color;
151
+ hoverColor?: string | Color;
152
+ pressedColor?: string | Color;
153
+ textColor?: string | Color;
154
+ }) => ReturnType<typeof createButton>;
155
+ getTheme: () => Theme;
156
+ setTheme: (theme: DeepPartial<Theme>) => void;
157
+ }
158
+ declare module 'kaplay' {
159
+ interface KAPLAYCtx extends UIPlugin {}
160
+ }
4
161
  /** Recursively partial version of a type. */
5
162
  type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]; };
6
163
  interface Theme {
7
164
  palette: {
8
- primary: Color;
9
- secondary: Color;
10
- background: Color;
11
- surface: Color;
12
- text: Color;
13
- textSecondary: Color;
14
- hover: Color;
15
- pressed: Color;
16
- disabled: Color;
17
- error: Color;
165
+ primary: string | Color;
166
+ secondary: string | Color;
167
+ background: string | Color;
168
+ surface: string | Color;
169
+ text: string | Color;
170
+ textSecondary: string | Color;
171
+ hover: string | Color;
172
+ pressed: string | Color;
173
+ disabled: string | Color;
174
+ error: string | Color;
18
175
  };
19
176
  typography: {
20
177
  fontFamily: string;
@@ -40,70 +197,25 @@ interface Theme {
40
197
  borderRadius: number;
41
198
  };
42
199
  tooltip: {
43
- background: Color;
44
- textColor: Color;
200
+ background: string | Color;
201
+ textColor: string | Color;
45
202
  delay: number;
46
203
  };
47
204
  };
48
205
  }
49
- /** Options for a single button. */
50
- interface ButtonCompOpt {
206
+ /** Button options. */
207
+ interface ButtonOpt {
51
208
  width?: number;
52
209
  height?: number;
53
210
  size?: number;
54
211
  font?: string;
55
- fill?: Color;
56
- textColor?: Color;
212
+ fill?: string | Color;
213
+ textColor?: string | Color;
57
214
  radius?: number;
58
- hoverFill?: Color;
59
- pressedFill?: Color;
60
- }
61
- /** The `button` component. */
62
- interface ButtonComp extends Comp {
63
- id: 'button';
64
- text: string;
65
- width: number;
66
- height: number;
67
- renderArea(): Rect;
68
- setStyle(opt: Partial<ButtonCompOpt>): void;
69
- }
70
- export declare function createButtonComponent(k: KAPLAYCtx, theme: Theme, text: string, opt: ButtonCompOpt): ButtonComp;
71
- export declare function createButtonObject(k: KAPLAYCtx, theme: Theme, text: string, opt: ButtonCompOpt & {
72
- pos?: Vec2;
73
- onClick?: () => void;
74
- color?: Color;
75
- hoverColor?: Color;
76
- pressedColor?: Color;
77
- textColor?: Color;
78
- }): GameObj;
79
- declare module 'kaplay' {
80
- interface KAPLAYCtx {
81
- button: (text?: string, opt?: ButtonCompOpt) => ButtonComp;
82
- addButton: (text?: string, opt?: ButtonCompOpt & {
83
- pos?: Vec2;
84
- onClick?: () => void;
85
- color?: Color;
86
- hoverColor?: Color;
87
- pressedColor?: Color;
88
- textColor?: Color;
89
- }) => GameObj;
90
- setTheme: (theme: DeepPartial<Theme>) => void;
91
- getTheme: () => Theme;
92
- }
215
+ hoverFill?: string | Color;
216
+ pressedFill?: string | Color;
93
217
  }
94
218
  /** KAPLAY UI plugin. */
95
- export declare function uiPlugin(k: KAPLAYCtx, theme?: DeepPartial<Theme>): {
96
- button: (text?: string, opt?: ButtonCompOpt) => ButtonComp;
97
- addButton: (text?: string, opt?: ButtonCompOpt & {
98
- pos?: Vec2;
99
- onClick?: () => void;
100
- color?: Color;
101
- hoverColor?: Color;
102
- pressedColor?: Color;
103
- textColor?: Color;
104
- }) => GameObj;
105
- setTheme: (next: DeepPartial<Theme>) => void;
106
- getTheme: () => Theme;
107
- };
108
- export type { ButtonComp, ButtonCompOpt, Color, Theme };
219
+ export declare function uiPlugin(k: KAPLAYCtx, theme?: DeepPartial<Theme>): UIPlugin;
220
+ export type { ButtonOpt, Theme, UIPlugin };
109
221
  //# sourceMappingURL=plugin.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.mts","names":["KaplayColor"],"sources":["../src/types.ts","../src/button.ts","../src/plugin.ts"],"mappings":";;KAGY,QAAQA;;KAGR,YAAY,QACrB,WAAW,KAAK,EAAE,oBAAoB,YAAY,EAAE,MAAM,EAAE;UAG9C;EACf;IACE,SAAS;IACT,WAAW;IACX,YAAY;IACZ,SAAS;IACT,MAAM;IACN,eAAe;IACf,OAAO;IACP,SAAS;IACT,UAAU;IACV,OAAO;;EAET;IACE;IACA;IACA;IACA;;EAEF;IACE;;EAEF;EACA;IACE;MACE;MACA;MACA;MACA;MACA;MACA;;IAEF;MACE;MACA;;IAEF;MACE,YAAY;MACZ,WAAW;MACX;;;;;UAMW;EACf;EACA;EACA;EACA;EACA,OAAO;EACP,YAAY;EACZ;EACA,YAAY;EACZ,cAAc;;;UAIC,mBAAmB;EAClC;EACA;EACA;EACA;EACA,cAAc;EACd,SAAS,KAAK,QAAQ;;wBCtER,sBACd,GAAG,WACH,OAAO,OACP,cACA,KAAK,gBACJ;wBA+Ea,mBACd,GAAG,WACH,OAAO,OACP,cACA,KAAK;EACH,MAAM;EACN;EACA,QAAQ;EACR,aAAa;EACb,eAAe;EACf,YAAY;IAEb;;YCpFS;IACR,SAAS,eAAe,MAAM,kBAAkB;IAChD,YACE,eACA,MAAM;MACJ,MAAM;MACN;MACA,QAAQ;MACR,aAAa;MACb,eAAe;MACf,YAAY;UAEX;IACL,WAAW,OAAO,YAAY;IAC9B,gBAAgB;;;;wBAKJ,SAAS,GAAG,WAAW,QAAO,YAAY;EAWxB,SAAA,eAAA,MAAA,kBAAqB;EAM9C,YAAA,eAAA,MAAA;IACH,MAAM;IACN;IACA,QAAQ;IACR,aAAa;IACb,eAAe;IACf,YAAY;QAEb;EAnBqB,WAAA,MAAA,YAAY;EAFf,gBAAA"}
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/button.ts","../src/types.ts","../src/plugin.ts"],"mappings":";iBAKgB,aACd,GAAG,WACH,OAAO,OACP,cACA,KAAK;EACH,MAAM;EACN;EACA,iBAAiB;EACjB,sBAAsB;EACtB,wBAAwB;EACxB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;EAmDuj0M,GAAA,wBAAA,mCAAA,YAAG,sCAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAA34hJ,sBAAA,KAAA,IAAA,sBAAA,SAAA,uBAAC,sCAAA;KAA8K,IAAA,sBAAA,SAAA,uBAAC,sCAAA;;;KAAsN,sBAAA,KAAA,IAAA,sBAAA,SAAA,uBAAC,+BAAA,oCAAA;KAAuM,IAAA,sBAAA,SAAA,uBAAC,sCAAA;;;;;;;;;;;;;;;;;;;;;;;;;UC9DtwzD;EACf,YACE,eACA,MAAM;IACJ,MAAM;IACN;IACA,iBAAiB;IACjB,sBAAsB;IACtB,wBAAwB;IACxB,qBAAqB;QAEpB,kBAAkB;EAEvB,gBAAgB;EAEhB,WAAW,OAAO,YAAY;;;YAKpB,kBAAkB;;;KAIlB,YAAY,QACrB,WAAW,KAAK,EAAE,oBAAoB,YAAY,EAAE,MAAM,EAAE;UAG9C;EACf;IACE,kBAAkB;IAClB,oBAAoB;IACpB,qBAAqB;IACrB,kBAAkB;IAClB,eAAe;IACf,wBAAwB;IACxB,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;IACnB,gBAAgB;;EAElB;IACE;IACA;IACA;IACA;;EAEF;IACE;;EAEF;EACA;IACE;MACE;MACA;MACA;MACA;MACA;MACA;;IAEF;MACE;MACA;;IAEF;MACE,qBAAqB;MACrB,oBAAoB;MACpB;;;;;UAMW;EACf;EACA;EACA;EACA;EACA,gBAAgB;EAChB,qBAAqB;EACrB;EACA,qBAAqB;EACrB,uBAAuB;;;wBC7ET,SACd,GAAG,WACH,QAAO,YAAY,SAClB"}