@canvasengine/presets 2.0.0-beta.24 → 2.0.0-beta.25
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/Bar.d.ts +14 -0
- package/dist/Bar.d.ts.map +1 -0
- package/dist/Button.d.ts +1 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Joystick.d.ts +32 -0
- package/dist/Joystick.d.ts.map +1 -0
- package/dist/NightAmbiant.d.ts +3 -0
- package/dist/NightAmbiant.d.ts.map +1 -0
- package/dist/Particle.d.ts +2 -0
- package/dist/Particle.d.ts.map +1 -0
- package/dist/Tilemap/Tile.d.ts +23 -0
- package/dist/Tilemap/Tile.d.ts.map +1 -0
- package/dist/Tilemap/TileGroup.d.ts +62 -0
- package/dist/Tilemap/TileGroup.d.ts.map +1 -0
- package/dist/Tilemap/TileLayer.d.ts +87 -0
- package/dist/Tilemap/TileLayer.d.ts.map +1 -0
- package/dist/Tilemap/TileSet.d.ts +11 -0
- package/dist/Tilemap/TileSet.d.ts.map +1 -0
- package/dist/Tilemap/index.d.ts +2 -0
- package/dist/Tilemap/index.d.ts.map +1 -0
- package/dist/Weathers/index.d.ts +57 -0
- package/dist/Weathers/index.d.ts.map +1 -0
- package/dist/index.d.ts +7 -112
- package/dist/index.d.ts.map +1 -0
- package/dist/index.global.js +25 -951
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +5891 -4
- package/dist/index.js.map +1 -1
- package/package.json +31 -9
- package/src/Bar.ts +0 -90
- package/src/Button.ts +0 -0
- package/src/Joystick.ts +0 -284
- package/src/NightAmbiant.ts +0 -116
- package/src/Particle.ts +0 -50
- package/src/Tilemap/Tile.ts +0 -83
- package/src/Tilemap/TileGroup.ts +0 -207
- package/src/Tilemap/TileLayer.ts +0 -146
- package/src/Tilemap/TileSet.ts +0 -41
- package/src/Tilemap/index.ts +0 -222
- package/src/Weathers/index.ts +0 -224
- package/src/index.ts +0 -6
- package/tsup.config.ts +0 -18
package/package.json
CHANGED
|
@@ -1,21 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canvasengine/presets",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"canvasengine": "^2.0.0-beta.24",
|
|
12
|
+
"pixi.js": "^8.9.2"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.6.2",
|
|
16
|
+
"vite": "^5.4.4",
|
|
17
|
+
"vite-plugin-dts": "^4.5.4"
|
|
18
|
+
},
|
|
8
19
|
"author": "Samuel Ronce",
|
|
9
20
|
"license": "MIT",
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
21
|
+
"homepage": "https://canvasengine.net",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/RSamaium/CanvasEngine.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/RSamaium/CanvasEngine/issues"
|
|
13
28
|
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"canvas",
|
|
31
|
+
"pixijs",
|
|
32
|
+
"reactive",
|
|
33
|
+
"html5",
|
|
34
|
+
"presets"
|
|
35
|
+
],
|
|
14
36
|
"dependencies": {
|
|
15
37
|
"@canvasengine/tilemap": "^5.0.1",
|
|
16
|
-
"@rpgjs/tiled": "5.0.0-alpha.5",
|
|
17
38
|
"revolt-fx": "^1.3.5",
|
|
18
|
-
"rxjs": "^7.8.1"
|
|
39
|
+
"rxjs": "^7.8.1",
|
|
40
|
+
"@canvasengine/tiled": "2.0.0-beta.25"
|
|
19
41
|
},
|
|
20
42
|
"publishConfig": {
|
|
21
43
|
"access": "public"
|
|
@@ -26,7 +48,7 @@
|
|
|
26
48
|
}
|
|
27
49
|
},
|
|
28
50
|
"scripts": {
|
|
29
|
-
"build": "
|
|
30
|
-
"dev": "
|
|
51
|
+
"build": "vite build",
|
|
52
|
+
"dev": "vite build --watch"
|
|
31
53
|
}
|
|
32
54
|
}
|
package/src/Bar.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { Graphics, h, useProps } from "canvasengine";
|
|
2
|
-
import * as PIXI from "pixi.js";
|
|
3
|
-
|
|
4
|
-
interface BarProps {
|
|
5
|
-
backgroundColor?: string;
|
|
6
|
-
foregroundColor?: string;
|
|
7
|
-
value: number;
|
|
8
|
-
maxValue: number;
|
|
9
|
-
width: number;
|
|
10
|
-
height: number;
|
|
11
|
-
border?: any;
|
|
12
|
-
innerMargin?: number;
|
|
13
|
-
borderRadius?: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function componentToHex(c) {
|
|
17
|
-
var hex = c.toString(16);
|
|
18
|
-
return hex.length == 1 ? "0" + hex : hex;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function rgbToHex(r, g, b) {
|
|
22
|
-
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function Bar(opts: BarProps) {
|
|
26
|
-
const {
|
|
27
|
-
width,
|
|
28
|
-
height,
|
|
29
|
-
value,
|
|
30
|
-
maxValue,
|
|
31
|
-
backgroundColor,
|
|
32
|
-
foregroundColor,
|
|
33
|
-
border,
|
|
34
|
-
innerMargin,
|
|
35
|
-
borderRadius,
|
|
36
|
-
} = useProps(opts, {
|
|
37
|
-
backgroundColor: "#000000",
|
|
38
|
-
foregroundColor: "#FFFFFF",
|
|
39
|
-
innerMargin: 0,
|
|
40
|
-
borderRadius: 0,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return h(
|
|
44
|
-
Graphics,
|
|
45
|
-
{
|
|
46
|
-
...opts,
|
|
47
|
-
width,
|
|
48
|
-
height,
|
|
49
|
-
draw(graphics: any) {
|
|
50
|
-
if (borderRadius()) {
|
|
51
|
-
graphics.roundRect(0, 0, width(), height(), borderRadius());
|
|
52
|
-
} else {
|
|
53
|
-
graphics.rect(0, 0, width(), height());
|
|
54
|
-
}
|
|
55
|
-
if (border) {
|
|
56
|
-
graphics.stroke(border);
|
|
57
|
-
}
|
|
58
|
-
graphics.fill(backgroundColor());
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
h(Graphics, {
|
|
62
|
-
width,
|
|
63
|
-
height,
|
|
64
|
-
draw(graphics: any) {
|
|
65
|
-
const margin = innerMargin();
|
|
66
|
-
const _borderRadius = borderRadius();
|
|
67
|
-
const w = Math.max(
|
|
68
|
-
0,
|
|
69
|
-
Math.min(
|
|
70
|
-
width() - 2 * margin,
|
|
71
|
-
(value() / maxValue()) * (width() - 2 * margin)
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
const h = height() - 2 * margin;
|
|
75
|
-
if (borderRadius) {
|
|
76
|
-
graphics.roundRect(margin, margin, w, h, _borderRadius);
|
|
77
|
-
} else {
|
|
78
|
-
graphics.rect(margin, margin, w, h);
|
|
79
|
-
}
|
|
80
|
-
const color = foregroundColor();
|
|
81
|
-
if (color.startsWith("rgba")) {
|
|
82
|
-
const [r, g, b, a] = color.match(/\d+(\.\d+)?/g).map(Number);
|
|
83
|
-
graphics.fill({ color: rgbToHex(r, g, b), alpha: a });
|
|
84
|
-
} else {
|
|
85
|
-
graphics.fill(color);
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
})
|
|
89
|
-
);
|
|
90
|
-
}
|
package/src/Button.ts
DELETED
|
File without changes
|
package/src/Joystick.ts
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Joystick
|
|
3
|
-
*
|
|
4
|
-
* Inspired by https://github.com/endel/pixi-virtual-joystick
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as PIXI from "pixi.js";
|
|
8
|
-
import { Container, Graphics, Sprite, h, signal } from "canvasengine";
|
|
9
|
-
|
|
10
|
-
export interface JoystickChangeEvent {
|
|
11
|
-
angle: number;
|
|
12
|
-
direction: Direction;
|
|
13
|
-
power: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export enum Direction {
|
|
17
|
-
LEFT = "left",
|
|
18
|
-
TOP = "top",
|
|
19
|
-
BOTTOM = "bottom",
|
|
20
|
-
RIGHT = "right",
|
|
21
|
-
TOP_LEFT = "top_left",
|
|
22
|
-
TOP_RIGHT = "top_right",
|
|
23
|
-
BOTTOM_LEFT = "bottom_left",
|
|
24
|
-
BOTTOM_RIGHT = "bottom_right",
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface JoystickSettings {
|
|
28
|
-
outer?: string;
|
|
29
|
-
inner?: string;
|
|
30
|
-
outerScale?: { x: number; y: number };
|
|
31
|
-
innerScale?: { x: number; y: number };
|
|
32
|
-
onChange?: (data: JoystickChangeEvent) => void;
|
|
33
|
-
onStart?: () => void;
|
|
34
|
-
onEnd?: () => void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function Joystick(opts: JoystickSettings = {}) {
|
|
38
|
-
const settings = Object.assign(
|
|
39
|
-
{
|
|
40
|
-
outerScale: { x: 1, y: 1 },
|
|
41
|
-
innerScale: { x: 1, y: 1 },
|
|
42
|
-
},
|
|
43
|
-
opts
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
let outerRadius = 70;
|
|
47
|
-
let innerRadius = 10;
|
|
48
|
-
const innerAlphaStandby = 0.5;
|
|
49
|
-
|
|
50
|
-
let dragging = false;
|
|
51
|
-
let startPosition: PIXI.PointData | null = null;
|
|
52
|
-
let power = 0;
|
|
53
|
-
|
|
54
|
-
const innerPositionX = signal(0);
|
|
55
|
-
const innerPositionY = signal(0);
|
|
56
|
-
const innerAlpha = signal(innerAlphaStandby);
|
|
57
|
-
|
|
58
|
-
function getPower(centerPoint: PIXI.Point) {
|
|
59
|
-
const a = centerPoint.x - 0;
|
|
60
|
-
const b = centerPoint.y - 0;
|
|
61
|
-
return Math.min(1, Math.sqrt(a * a + b * b) / outerRadius);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getDirection(center: PIXI.Point) {
|
|
65
|
-
let rad = Math.atan2(center.y, center.x); // [-PI, PI]
|
|
66
|
-
if ((rad >= -Math.PI / 8 && rad < 0) || (rad >= 0 && rad < Math.PI / 8)) {
|
|
67
|
-
return Direction.RIGHT;
|
|
68
|
-
} else if (rad >= Math.PI / 8 && rad < (3 * Math.PI) / 8) {
|
|
69
|
-
return Direction.BOTTOM_RIGHT;
|
|
70
|
-
} else if (rad >= (3 * Math.PI) / 8 && rad < (5 * Math.PI) / 8) {
|
|
71
|
-
return Direction.BOTTOM;
|
|
72
|
-
} else if (rad >= (5 * Math.PI) / 8 && rad < (7 * Math.PI) / 8) {
|
|
73
|
-
return Direction.BOTTOM_LEFT;
|
|
74
|
-
} else if (
|
|
75
|
-
(rad >= (7 * Math.PI) / 8 && rad < Math.PI) ||
|
|
76
|
-
(rad >= -Math.PI && rad < (-7 * Math.PI) / 8)
|
|
77
|
-
) {
|
|
78
|
-
return Direction.LEFT;
|
|
79
|
-
} else if (rad >= (-7 * Math.PI) / 8 && rad < (-5 * Math.PI) / 8) {
|
|
80
|
-
return Direction.TOP_LEFT;
|
|
81
|
-
} else if (rad >= (-5 * Math.PI) / 8 && rad < (-3 * Math.PI) / 8) {
|
|
82
|
-
return Direction.TOP;
|
|
83
|
-
} else {
|
|
84
|
-
return Direction.TOP_RIGHT;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function handleDragStart(event: any) {
|
|
89
|
-
startPosition = event.getLocalPosition(this);
|
|
90
|
-
dragging = true;
|
|
91
|
-
innerAlpha.set(1);
|
|
92
|
-
settings.onStart?.();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function handleDragEnd() {
|
|
96
|
-
if (!dragging) return;
|
|
97
|
-
innerPositionX.set(0);
|
|
98
|
-
innerPositionY.set(0);
|
|
99
|
-
dragging = false;
|
|
100
|
-
innerAlpha.set(innerAlphaStandby);
|
|
101
|
-
settings.onEnd?.();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function handleDragMove(event: any) {
|
|
105
|
-
if (dragging == false) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
let newPosition = event.getLocalPosition(this);
|
|
110
|
-
|
|
111
|
-
let sideX = newPosition.x - (startPosition?.x ?? 0);
|
|
112
|
-
let sideY = newPosition.y - (startPosition?.y ?? 0);
|
|
113
|
-
|
|
114
|
-
let centerPoint = new PIXI.Point(0, 0);
|
|
115
|
-
let angle = 0;
|
|
116
|
-
|
|
117
|
-
if (sideX == 0 && sideY == 0) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
let calRadius = 0;
|
|
122
|
-
|
|
123
|
-
if (sideX * sideX + sideY * sideY >= outerRadius * outerRadius) {
|
|
124
|
-
calRadius = outerRadius;
|
|
125
|
-
} else {
|
|
126
|
-
calRadius = outerRadius - innerRadius;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* x: -1 <-> 1
|
|
131
|
-
* y: -1 <-> 1
|
|
132
|
-
* Y
|
|
133
|
-
* ^
|
|
134
|
-
* |
|
|
135
|
-
* 180 | 90
|
|
136
|
-
* ------------> X
|
|
137
|
-
* 270 | 360
|
|
138
|
-
* |
|
|
139
|
-
* |
|
|
140
|
-
*/
|
|
141
|
-
|
|
142
|
-
let direction = Direction.LEFT;
|
|
143
|
-
|
|
144
|
-
if (sideX == 0) {
|
|
145
|
-
if (sideY > 0) {
|
|
146
|
-
centerPoint.set(0, sideY > outerRadius ? outerRadius : sideY);
|
|
147
|
-
angle = 270;
|
|
148
|
-
direction = Direction.BOTTOM;
|
|
149
|
-
} else {
|
|
150
|
-
centerPoint.set(
|
|
151
|
-
0,
|
|
152
|
-
-(Math.abs(sideY) > outerRadius ? outerRadius : Math.abs(sideY))
|
|
153
|
-
);
|
|
154
|
-
angle = 90;
|
|
155
|
-
direction = Direction.TOP;
|
|
156
|
-
}
|
|
157
|
-
innerPositionX.set(centerPoint.x);
|
|
158
|
-
innerPositionY.set(centerPoint.y);
|
|
159
|
-
power = getPower(centerPoint);
|
|
160
|
-
settings.onChange?.({ angle, direction, power });
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (sideY == 0) {
|
|
165
|
-
if (sideX > 0) {
|
|
166
|
-
centerPoint.set(
|
|
167
|
-
Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX),
|
|
168
|
-
0
|
|
169
|
-
);
|
|
170
|
-
angle = 0;
|
|
171
|
-
direction = Direction.LEFT;
|
|
172
|
-
} else {
|
|
173
|
-
centerPoint.set(
|
|
174
|
-
-(Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX)),
|
|
175
|
-
0
|
|
176
|
-
);
|
|
177
|
-
angle = 180;
|
|
178
|
-
direction = Direction.RIGHT;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
innerPositionX.set(centerPoint.x);
|
|
182
|
-
innerPositionY.set(centerPoint.y);
|
|
183
|
-
power = getPower(centerPoint);
|
|
184
|
-
settings.onChange?.({ angle, direction, power });
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let tanVal = Math.abs(sideY / sideX);
|
|
189
|
-
let radian = Math.atan(tanVal);
|
|
190
|
-
angle = (radian * 180) / Math.PI;
|
|
191
|
-
|
|
192
|
-
let centerX = 0;
|
|
193
|
-
let centerY = 0;
|
|
194
|
-
|
|
195
|
-
if (sideX * sideX + sideY * sideY >= outerRadius * outerRadius) {
|
|
196
|
-
centerX = outerRadius * Math.cos(radian);
|
|
197
|
-
centerY = outerRadius * Math.sin(radian);
|
|
198
|
-
} else {
|
|
199
|
-
centerX = Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX);
|
|
200
|
-
centerY = Math.abs(sideY) > outerRadius ? outerRadius : Math.abs(sideY);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (sideY < 0) {
|
|
204
|
-
centerY = -Math.abs(centerY);
|
|
205
|
-
}
|
|
206
|
-
if (sideX < 0) {
|
|
207
|
-
centerX = -Math.abs(centerX);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (sideX > 0 && sideY < 0) {
|
|
211
|
-
// < 90
|
|
212
|
-
} else if (sideX < 0 && sideY < 0) {
|
|
213
|
-
// 90 ~ 180
|
|
214
|
-
angle = 180 - angle;
|
|
215
|
-
} else if (sideX < 0 && sideY > 0) {
|
|
216
|
-
// 180 ~ 270
|
|
217
|
-
angle = angle + 180;
|
|
218
|
-
} else if (sideX > 0 && sideY > 0) {
|
|
219
|
-
// 270 ~ 369
|
|
220
|
-
angle = 360 - angle;
|
|
221
|
-
}
|
|
222
|
-
centerPoint.set(centerX, centerY);
|
|
223
|
-
power = getPower(centerPoint);
|
|
224
|
-
|
|
225
|
-
direction = getDirection(centerPoint);
|
|
226
|
-
innerPositionX.set(centerPoint.x);
|
|
227
|
-
innerPositionY.set(centerPoint.y);
|
|
228
|
-
|
|
229
|
-
settings.onChange?.({ angle, direction, power });
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
let innerElement;
|
|
233
|
-
let outerElement;
|
|
234
|
-
|
|
235
|
-
if (!settings.outer) {
|
|
236
|
-
outerElement = h(Graphics, {
|
|
237
|
-
draw: (g) => {
|
|
238
|
-
g.circle(0, 0, outerRadius).fill(0x000000);
|
|
239
|
-
},
|
|
240
|
-
alpha: 0.5,
|
|
241
|
-
});
|
|
242
|
-
} else {
|
|
243
|
-
outerElement = h(Sprite, {
|
|
244
|
-
image: settings.outer,
|
|
245
|
-
anchor: { x: 0.5, y: 0.5 },
|
|
246
|
-
scale: settings.outerScale,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const innerOptions: any = {
|
|
251
|
-
scale: settings.innerScale,
|
|
252
|
-
x: innerPositionX,
|
|
253
|
-
y: innerPositionY,
|
|
254
|
-
alpha: innerAlpha,
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
if (!settings.inner) {
|
|
258
|
-
innerElement = h(Graphics, {
|
|
259
|
-
draw: (g) => {
|
|
260
|
-
g.circle(0, 0, innerRadius * 2.5).fill(0x000000);
|
|
261
|
-
},
|
|
262
|
-
...innerOptions,
|
|
263
|
-
});
|
|
264
|
-
} else {
|
|
265
|
-
innerElement = h(Sprite, {
|
|
266
|
-
image: settings.inner,
|
|
267
|
-
anchor: { x: 0.5, y: 0.5 },
|
|
268
|
-
...innerOptions,
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return h(
|
|
273
|
-
Container,
|
|
274
|
-
{
|
|
275
|
-
...opts,
|
|
276
|
-
pointerdown: handleDragStart,
|
|
277
|
-
pointerup: handleDragEnd,
|
|
278
|
-
pointerupoutside: handleDragEnd,
|
|
279
|
-
pointermove: handleDragMove,
|
|
280
|
-
},
|
|
281
|
-
outerElement,
|
|
282
|
-
innerElement
|
|
283
|
-
);
|
|
284
|
-
}
|
package/src/NightAmbiant.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Container, Graphics, h, mount, useProps, animatedSignal, RadialGradient, effect, isSignal, signal, isObservable } from "canvasengine";
|
|
2
|
-
|
|
3
|
-
export function LightSpot(opts) {
|
|
4
|
-
const { radius } = useProps(opts);
|
|
5
|
-
const scale = animatedSignal(1);
|
|
6
|
-
|
|
7
|
-
const minScale = 1;
|
|
8
|
-
const maxScale = 2; // Reduced max scale for subtler effect
|
|
9
|
-
const scintillationSpeed = 0.001; // Significantly reduced for slower scintillation
|
|
10
|
-
|
|
11
|
-
const animate = () => {
|
|
12
|
-
// Use time-based animation for smoother, slower scintillation
|
|
13
|
-
const time = Date.now() * scintillationSpeed;
|
|
14
|
-
|
|
15
|
-
// Combine multiple sine waves for a more natural, less predictable effect
|
|
16
|
-
const scintillationFactor =
|
|
17
|
-
(Math.sin(time) + Math.sin(time * 1.3) + Math.sin(time * 0.7)) / 3;
|
|
18
|
-
|
|
19
|
-
// Map the scintillation factor to the scale range
|
|
20
|
-
const newScale =
|
|
21
|
-
minScale + (maxScale - minScale) * (scintillationFactor * 0.5 + 0.5);
|
|
22
|
-
|
|
23
|
-
scale.update(() => newScale);
|
|
24
|
-
|
|
25
|
-
requestAnimationFrame(animate);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
animate();
|
|
29
|
-
|
|
30
|
-
const draw = (g) => {
|
|
31
|
-
const size = radius() * 2;
|
|
32
|
-
const gradient = new RadialGradient(size, size, 0, size, size, 0);
|
|
33
|
-
gradient.addColorStop(0, "rgba(255, 255, 0, 1)");
|
|
34
|
-
gradient.addColorStop(0.5, "rgba(255, 255, 0, 0.3)");
|
|
35
|
-
gradient.addColorStop(0.8, "rgba(255, 255, 0, 0)");
|
|
36
|
-
|
|
37
|
-
const translate = size / 2;
|
|
38
|
-
|
|
39
|
-
g.rect(-translate, -translate, size, size).fill(
|
|
40
|
-
gradient.render({ translate: { x: translate, y: translate } })
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return h(Graphics, {
|
|
45
|
-
draw,
|
|
46
|
-
...opts,
|
|
47
|
-
scale,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function NightAmbiant(props) {
|
|
52
|
-
const { children } = props;
|
|
53
|
-
let el
|
|
54
|
-
const width = signal(0);
|
|
55
|
-
const height = signal(0);
|
|
56
|
-
let subscription
|
|
57
|
-
const draw = (rectAndHole) => {
|
|
58
|
-
const margin = 80
|
|
59
|
-
rectAndHole.rect(-margin, -margin, width() + margin*2, height() + margin*2);
|
|
60
|
-
rectAndHole.fill(0x000000);
|
|
61
|
-
const applyChildren = (child) => {
|
|
62
|
-
const x = isSignal(child.propObservables.x)
|
|
63
|
-
? child.propObservables.x()
|
|
64
|
-
: child.props.x;
|
|
65
|
-
const y = isSignal(child.propObservables.y)
|
|
66
|
-
? child.propObservables.y()
|
|
67
|
-
: child.props.y;
|
|
68
|
-
const radius = isSignal(child.propObservables.radius)
|
|
69
|
-
? child.propObservables.radius()
|
|
70
|
-
: child.props.radius;
|
|
71
|
-
rectAndHole.circle(x, y, radius);
|
|
72
|
-
rectAndHole.cut();
|
|
73
|
-
}
|
|
74
|
-
for (let child of children) {
|
|
75
|
-
if (isObservable(child)) {
|
|
76
|
-
if (subscription) {
|
|
77
|
-
subscription.unsubscribe()
|
|
78
|
-
}
|
|
79
|
-
subscription = child.subscribe((event: any) => {
|
|
80
|
-
for (let child of event.fullElements) {
|
|
81
|
-
applyChildren(child)
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
applyChildren(child)
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
mount((el) => {
|
|
91
|
-
effect(() => {
|
|
92
|
-
const { displayWidth, displayHeight } = el.componentInstance as any
|
|
93
|
-
const w = +displayWidth()
|
|
94
|
-
const h = +displayHeight()
|
|
95
|
-
setTimeout(() => {
|
|
96
|
-
width.update(() => w)
|
|
97
|
-
height.update(() => h)
|
|
98
|
-
}, 0) // hack
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return h(
|
|
103
|
-
Container,
|
|
104
|
-
{
|
|
105
|
-
width: "100%",
|
|
106
|
-
height: "100%",
|
|
107
|
-
...props,
|
|
108
|
-
},
|
|
109
|
-
h(Graphics, {
|
|
110
|
-
draw,
|
|
111
|
-
alpha: 0.8,
|
|
112
|
-
blur: 80,
|
|
113
|
-
}),
|
|
114
|
-
...children
|
|
115
|
-
);
|
|
116
|
-
}
|
package/src/Particle.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as PIXI from "pixi.js";
|
|
2
|
-
import { FX } from "revolt-fx";
|
|
3
|
-
import { h, mount, tick, Container, on, useProps } from "canvasengine";
|
|
4
|
-
|
|
5
|
-
export function Particle(options) {
|
|
6
|
-
const { emit, settings = {} } = options;
|
|
7
|
-
const { name } = useProps(options);
|
|
8
|
-
const fx = new FX();
|
|
9
|
-
let element;
|
|
10
|
-
|
|
11
|
-
PIXI.Assets.add({ alias: "fx_settings", src: "/default-bundle.json" });
|
|
12
|
-
PIXI.Assets.add({
|
|
13
|
-
alias: "fx_spritesheet",
|
|
14
|
-
src: "/revoltfx-spritesheet.json",
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
tick(({deltaRatio}) => {
|
|
18
|
-
fx.update(deltaRatio);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
mount(async (_element) => {
|
|
22
|
-
element = _element;
|
|
23
|
-
|
|
24
|
-
const data = await PIXI.Assets.load(["fx_settings", "fx_spritesheet"]);
|
|
25
|
-
let fxSettings = {...data.fx_settings};
|
|
26
|
-
|
|
27
|
-
if (settings.emitters) {
|
|
28
|
-
const lastId = 10000;
|
|
29
|
-
const emittersWithIds = settings.emitters.map((emitter, index) => ({
|
|
30
|
-
...emitter,
|
|
31
|
-
id: lastId + index
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
fxSettings.emitters = [
|
|
35
|
-
...fxSettings.emitters,
|
|
36
|
-
...emittersWithIds,
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fx.initBundle(fxSettings, true);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
on(emit, () => {
|
|
45
|
-
const emitter = fx.getParticleEmitter(name());
|
|
46
|
-
emitter.init(element.componentInstance);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return h(Container);
|
|
50
|
-
}
|
package/src/Tilemap/Tile.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { CompositeTilemap } from "@pixi/tilemap";
|
|
2
|
-
import { Tile as TiledTileClass } from '@rpgjs/tiled';
|
|
3
|
-
import { AnimatedSprite, Texture, groupD8 } from "pixi.js";
|
|
4
|
-
import { TileSet } from "./TileSet";
|
|
5
|
-
|
|
6
|
-
export class Tile extends AnimatedSprite {
|
|
7
|
-
static getTextures(tile: TiledTileClass, tileSet: TileSet) {
|
|
8
|
-
const textures: Texture[] = [];
|
|
9
|
-
|
|
10
|
-
if (tile.animations && tile.animations.length) {
|
|
11
|
-
tile.animations.forEach(frame => {
|
|
12
|
-
textures.push(tileSet.textures[frame.tileid])
|
|
13
|
-
});
|
|
14
|
-
} else {
|
|
15
|
-
textures.push(tileSet.textures[tile.gid - tileSet.firstgid])
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return textures;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
animations: { tileid: number, duration: number }[] = []
|
|
22
|
-
_x: number = 0
|
|
23
|
-
_y: number = 0
|
|
24
|
-
pointsBufIndex: number
|
|
25
|
-
properties: any = {}
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
private tile: TiledTileClass,
|
|
29
|
-
private tileSet: TileSet
|
|
30
|
-
) {
|
|
31
|
-
super(Tile.getTextures(tile, tileSet));
|
|
32
|
-
this.animations = tile.animations || []
|
|
33
|
-
this.properties = tile.properties
|
|
34
|
-
this.textures = Tile.getTextures(tile, tileSet)
|
|
35
|
-
this.texture = this.textures[0] as Texture
|
|
36
|
-
this.flip()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get z() {
|
|
40
|
-
return this.properties.z ?? 0
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get gid() {
|
|
44
|
-
return this.tile.gid
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
setAnimation(frame: CompositeTilemap) {
|
|
48
|
-
const size = this.animations.length
|
|
49
|
-
if (size > 1) {
|
|
50
|
-
const offset = (this.animations[1].tileid - this.animations[0].tileid) * this.width
|
|
51
|
-
frame.tileAnimX(offset, size)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
flip() {
|
|
56
|
-
let symmetry
|
|
57
|
-
let i = 0
|
|
58
|
-
const add = (symmetrySecond) => {
|
|
59
|
-
i++
|
|
60
|
-
if (symmetry) symmetry = groupD8.add(symmetry, symmetrySecond)
|
|
61
|
-
else symmetry = symmetrySecond
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (this.tile.horizontalFlip) {
|
|
65
|
-
add(groupD8.MIRROR_HORIZONTAL)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (this.tile.verticalFlip) {
|
|
69
|
-
add(groupD8.MIRROR_VERTICAL)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (this.tile.diagonalFlip) {
|
|
73
|
-
if (i % 2 == 0) {
|
|
74
|
-
add(groupD8.MAIN_DIAGONAL)
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
add(groupD8.REVERSE_DIAGONAL)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//if (symmetry) this.texture.rotate = symmetry
|
|
82
|
-
}
|
|
83
|
-
}
|