kaplay-ui 0.8.2 → 0.9.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/README.md CHANGED
@@ -4,12 +4,16 @@ _Expect breaking changes and incomplete features._
4
4
 
5
5
  # KAPLAY UI - A UI Component Library for KAPLAY
6
6
 
7
- _A simple and customizable UI library for [KAPLAY](https://kaplayjs.com/)._
7
+ _A simple and customizable component UI library for [KAPLAY](https://kaplayjs.com/)._
8
8
 
9
9
  ## 🚀 Introduction
10
10
 
11
11
  Kaplay UI is a component library designed specifically for KAPLAY. It will provide ready-made UI components to help you build better user interfaces for your KAPLAY games with minimal effort.
12
12
 
13
+ - [Installation](#installation)
14
+ - [Usage](#usage)
15
+ - [License](#license)
16
+
13
17
  ## 📦 Installation
14
18
 
15
19
  You can install Kaplay UI via npm:
@@ -0,0 +1,73 @@
1
+ import "kaplay/global";
2
+
3
+ /**
4
+ * Adds a clickable button with custom text
5
+ * @param {string} txt - Button text to display
6
+ * @param {Function} [onClick] - Click event handler (default is () => {}))
7
+ * @param {number} x - The x postion to set (default is center().x).
8
+ * @param {number} y - The x postion to set (default is center().y)
9
+ * @param {number} w - Width of button (default is 120)
10
+ * @param {number} h - Height of button (default is 50)
11
+ * @param {number} txtSize - Text size of button (default is 15)
12
+ * @param {boolean} [hoverFx] - Add hover effect (default is true)
13
+ * @returns {GameObj}
14
+ */
15
+ export const addTextButton = (
16
+ txt,
17
+ onClick = () => {},
18
+ x = center().x,
19
+ y = center().y,
20
+ w = 120,
21
+ h = 50,
22
+ txtSize = 15,
23
+ hoverFx = true
24
+ ) => {
25
+ // Shadow effect
26
+ const shadow = add([
27
+ rect(w, h, { radius: 8 }),
28
+ pos(x + 2, y + 2),
29
+ area(),
30
+ scale(1),
31
+ anchor("center"),
32
+ outline(1),
33
+ color(128, 128, 128),
34
+ ]);
35
+
36
+ // Button
37
+ const btn = add([
38
+ rect(w, h, { radius: 8 }),
39
+ pos(x, y),
40
+ area(),
41
+ scale(1),
42
+ anchor("center"),
43
+ outline(1),
44
+ color(255, 255, 255),
45
+ ]);
46
+
47
+ // Button text
48
+ btn.add([text(txt, { size: txtSize }), anchor("center"), color(0, 0, 0)]);
49
+
50
+ // On click handler
51
+ btn.onClick(() => {
52
+ setCursor("default");
53
+ onClick();
54
+ });
55
+
56
+ btn.onHover(() => {
57
+ setCursor("pointer");
58
+ if (hoverFx) {
59
+ btn.scale = vec2(1.03);
60
+ shadow.scale = vec2(1.03);
61
+ }
62
+ });
63
+
64
+ btn.onHoverEnd(() => {
65
+ setCursor("default");
66
+ if (hoverFx) {
67
+ btn.scale = vec2(1);
68
+ shadow.scale = vec2(1);
69
+ }
70
+ });
71
+
72
+ return btn;
73
+ };
package/index.js CHANGED
@@ -1,73 +0,0 @@
1
- import "kaplay/global";
2
-
3
- /**
4
- * Adds a clickable button with custom text
5
- * @param {string} txt - Button text to display
6
- * @param {Function} [onClick] - Click event handler (default is () => {}))
7
- * @param {number} x - The x postion to set (default is center().x).
8
- * @param {number} y - The x postion to set (default is center().y)
9
- * @param {number} w - Width of button (default is 120)
10
- * @param {number} h - Height of button (default is 50)
11
- * @param {number} txtSize - Text size of button (default is 15)
12
- * @param {boolean} [hoverFx] - Add hover effect (default is true)
13
- * @returns {GameObj}
14
- */
15
- export const addTextButton = (
16
- txt,
17
- onClick = () => {},
18
- x = center().x,
19
- y = center().y,
20
- w = 120,
21
- h = 50,
22
- txtSize = 15,
23
- hoverFx = true
24
- ) => {
25
- // Shadow effect
26
- const shadow = add([
27
- rect(w, h, { radius: 8 }),
28
- pos(x + 2, y + 2),
29
- area(),
30
- scale(1),
31
- anchor("center"),
32
- outline(1),
33
- color(128, 128, 128),
34
- ]);
35
-
36
- // Button
37
- const btn = add([
38
- rect(w, h, { radius: 8 }),
39
- pos(x, y),
40
- area(),
41
- scale(1),
42
- anchor("center"),
43
- outline(1),
44
- color(255, 255, 255),
45
- ]);
46
-
47
- // Button text
48
- btn.add([text(txt, { size: txtSize }), anchor("center"), color(0, 0, 0)]);
49
-
50
- // On click handler
51
- btn.onClick(() => {
52
- setCursor("default");
53
- onClick();
54
- });
55
-
56
- btn.onHover(() => {
57
- setCursor("pointer");
58
- if (hoverFx) {
59
- btn.scale = vec2(1.03);
60
- shadow.scale = vec2(1.03);
61
- }
62
- });
63
-
64
- btn.onHoverEnd(() => {
65
- setCursor("default");
66
- if (hoverFx) {
67
- btn.scale = vec2(1);
68
- shadow.scale = vec2(1);
69
- }
70
- });
71
-
72
- return btn;
73
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaplay-ui",
3
- "version": "0.8.2",
3
+ "version": "0.9.1",
4
4
  "description": "UI components for KAPLAY",
5
5
  "main": "index.js",
6
6
  "repository": {