@canvasengine/presets 2.0.0-beta.2 → 2.0.0-beta.20
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/index.d.ts +112 -0
- package/dist/index.js +955 -0
- package/dist/index.js.map +1 -0
- package/package.json +11 -3
- package/src/Bar.ts +13 -10
- package/src/Joystick.ts +2 -2
- package/src/Tilemap/Tile.ts +83 -0
- package/src/Tilemap/TileGroup.ts +207 -0
- package/src/Tilemap/TileLayer.ts +146 -0
- package/src/Tilemap/TileSet.ts +41 -0
- package/src/Tilemap/index.ts +221 -0
- package/src/Weathers/index.ts +224 -0
- package/src/index.ts +3 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,955 @@
|
|
|
1
|
+
// src/Bar.ts
|
|
2
|
+
import { Graphics, h, useProps } from "canvasengine";
|
|
3
|
+
function componentToHex(c) {
|
|
4
|
+
var hex = c.toString(16);
|
|
5
|
+
return hex.length == 1 ? "0" + hex : hex;
|
|
6
|
+
}
|
|
7
|
+
function rgbToHex(r, g, b) {
|
|
8
|
+
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
9
|
+
}
|
|
10
|
+
function Bar(opts) {
|
|
11
|
+
const {
|
|
12
|
+
width,
|
|
13
|
+
height,
|
|
14
|
+
value,
|
|
15
|
+
maxValue,
|
|
16
|
+
backgroundColor,
|
|
17
|
+
foregroundColor,
|
|
18
|
+
border,
|
|
19
|
+
innerMargin,
|
|
20
|
+
borderRadius
|
|
21
|
+
} = useProps(opts, {
|
|
22
|
+
backgroundColor: "#000000",
|
|
23
|
+
foregroundColor: "#FFFFFF",
|
|
24
|
+
innerMargin: 0,
|
|
25
|
+
borderRadius: 0
|
|
26
|
+
});
|
|
27
|
+
return h(
|
|
28
|
+
Graphics,
|
|
29
|
+
{
|
|
30
|
+
...opts,
|
|
31
|
+
width,
|
|
32
|
+
height,
|
|
33
|
+
draw(graphics) {
|
|
34
|
+
if (borderRadius()) {
|
|
35
|
+
graphics.roundRect(0, 0, width(), height(), borderRadius());
|
|
36
|
+
} else {
|
|
37
|
+
graphics.rect(0, 0, width(), height());
|
|
38
|
+
}
|
|
39
|
+
if (border) {
|
|
40
|
+
graphics.stroke(border);
|
|
41
|
+
}
|
|
42
|
+
graphics.fill(backgroundColor());
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
h(Graphics, {
|
|
46
|
+
width,
|
|
47
|
+
height,
|
|
48
|
+
draw(graphics) {
|
|
49
|
+
const margin = innerMargin();
|
|
50
|
+
const _borderRadius = borderRadius();
|
|
51
|
+
const w = Math.max(
|
|
52
|
+
0,
|
|
53
|
+
Math.min(
|
|
54
|
+
width() - 2 * margin,
|
|
55
|
+
value() / maxValue() * (width() - 2 * margin)
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
const h7 = height() - 2 * margin;
|
|
59
|
+
if (borderRadius) {
|
|
60
|
+
graphics.roundRect(margin, margin, w, h7, _borderRadius);
|
|
61
|
+
} else {
|
|
62
|
+
graphics.rect(margin, margin, w, h7);
|
|
63
|
+
}
|
|
64
|
+
const color = foregroundColor();
|
|
65
|
+
if (color.startsWith("rgba")) {
|
|
66
|
+
const [r, g, b, a] = color.match(/\d+(\.\d+)?/g).map(Number);
|
|
67
|
+
graphics.fill({ color: rgbToHex(r, g, b), alpha: a });
|
|
68
|
+
} else {
|
|
69
|
+
graphics.fill(color);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/Particle.ts
|
|
77
|
+
import * as PIXI from "pixi.js";
|
|
78
|
+
import { FX } from "revolt-fx";
|
|
79
|
+
import { h as h2, mount, tick, Container, on, useProps as useProps2 } from "canvasengine";
|
|
80
|
+
function Particle(options) {
|
|
81
|
+
const { emit, settings: settings2 = {} } = options;
|
|
82
|
+
const { name } = useProps2(options);
|
|
83
|
+
const fx = new FX();
|
|
84
|
+
let element;
|
|
85
|
+
PIXI.Assets.add({ alias: "fx_settings", src: "/default-bundle.json" });
|
|
86
|
+
PIXI.Assets.add({
|
|
87
|
+
alias: "fx_spritesheet",
|
|
88
|
+
src: "/revoltfx-spritesheet.json"
|
|
89
|
+
});
|
|
90
|
+
tick(({ deltaRatio }) => {
|
|
91
|
+
fx.update(deltaRatio);
|
|
92
|
+
});
|
|
93
|
+
mount(async (_element) => {
|
|
94
|
+
element = _element;
|
|
95
|
+
const data = await PIXI.Assets.load(["fx_settings", "fx_spritesheet"]);
|
|
96
|
+
let fxSettings = { ...data.fx_settings };
|
|
97
|
+
if (settings2.emitters) {
|
|
98
|
+
const lastId = 1e4;
|
|
99
|
+
const emittersWithIds = settings2.emitters.map((emitter, index) => ({
|
|
100
|
+
...emitter,
|
|
101
|
+
id: lastId + index
|
|
102
|
+
}));
|
|
103
|
+
fxSettings.emitters = [
|
|
104
|
+
...fxSettings.emitters,
|
|
105
|
+
...emittersWithIds
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
fx.initBundle(fxSettings, true);
|
|
109
|
+
});
|
|
110
|
+
on(emit, () => {
|
|
111
|
+
const emitter = fx.getParticleEmitter(name());
|
|
112
|
+
emitter.init(element.componentInstance);
|
|
113
|
+
});
|
|
114
|
+
return h2(Container);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/NightAmbiant.ts
|
|
118
|
+
import { Container as Container2, Graphics as Graphics2, h as h3, mount as mount2, useProps as useProps3, animatedSignal, RadialGradient, effect, isSignal, signal, isObservable } from "canvasengine";
|
|
119
|
+
function LightSpot(opts) {
|
|
120
|
+
const { radius } = useProps3(opts);
|
|
121
|
+
const scale = animatedSignal(1);
|
|
122
|
+
const minScale = 1;
|
|
123
|
+
const maxScale = 2;
|
|
124
|
+
const scintillationSpeed = 1e-3;
|
|
125
|
+
const animate = () => {
|
|
126
|
+
const time = Date.now() * scintillationSpeed;
|
|
127
|
+
const scintillationFactor = (Math.sin(time) + Math.sin(time * 1.3) + Math.sin(time * 0.7)) / 3;
|
|
128
|
+
const newScale = minScale + (maxScale - minScale) * (scintillationFactor * 0.5 + 0.5);
|
|
129
|
+
scale.update(() => newScale);
|
|
130
|
+
requestAnimationFrame(animate);
|
|
131
|
+
};
|
|
132
|
+
animate();
|
|
133
|
+
const draw = (g) => {
|
|
134
|
+
const size = radius() * 2;
|
|
135
|
+
const gradient = new RadialGradient(size, size, 0, size, size, 0);
|
|
136
|
+
gradient.addColorStop(0, "rgba(255, 255, 0, 1)");
|
|
137
|
+
gradient.addColorStop(0.5, "rgba(255, 255, 0, 0.3)");
|
|
138
|
+
gradient.addColorStop(0.8, "rgba(255, 255, 0, 0)");
|
|
139
|
+
const translate = size / 2;
|
|
140
|
+
g.rect(-translate, -translate, size, size).fill(
|
|
141
|
+
gradient.render({ translate: { x: translate, y: translate } })
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
return h3(Graphics2, {
|
|
145
|
+
draw,
|
|
146
|
+
...opts,
|
|
147
|
+
scale
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function NightAmbiant(props) {
|
|
151
|
+
const { children } = props;
|
|
152
|
+
let el;
|
|
153
|
+
const width = signal(0);
|
|
154
|
+
const height = signal(0);
|
|
155
|
+
let subscription;
|
|
156
|
+
const draw = (rectAndHole) => {
|
|
157
|
+
const margin = 80;
|
|
158
|
+
rectAndHole.rect(-margin, -margin, width() + margin * 2, height() + margin * 2);
|
|
159
|
+
rectAndHole.fill(0);
|
|
160
|
+
const applyChildren = (child) => {
|
|
161
|
+
const x = isSignal(child.propObservables.x) ? child.propObservables.x() : child.props.x;
|
|
162
|
+
const y = isSignal(child.propObservables.y) ? child.propObservables.y() : child.props.y;
|
|
163
|
+
const radius = isSignal(child.propObservables.radius) ? child.propObservables.radius() : child.props.radius;
|
|
164
|
+
rectAndHole.circle(x, y, radius);
|
|
165
|
+
rectAndHole.cut();
|
|
166
|
+
};
|
|
167
|
+
for (let child of children) {
|
|
168
|
+
if (isObservable(child)) {
|
|
169
|
+
if (subscription) {
|
|
170
|
+
subscription.unsubscribe();
|
|
171
|
+
}
|
|
172
|
+
subscription = child.subscribe((event) => {
|
|
173
|
+
for (let child2 of event.fullElements) {
|
|
174
|
+
applyChildren(child2);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
applyChildren(child);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
mount2((el2) => {
|
|
183
|
+
effect(() => {
|
|
184
|
+
const { displayWidth, displayHeight } = el2.componentInstance;
|
|
185
|
+
const w = +displayWidth();
|
|
186
|
+
const h7 = +displayHeight();
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
width.update(() => w);
|
|
189
|
+
height.update(() => h7);
|
|
190
|
+
}, 0);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
return h3(
|
|
194
|
+
Container2,
|
|
195
|
+
{
|
|
196
|
+
width: "100%",
|
|
197
|
+
height: "100%",
|
|
198
|
+
...props
|
|
199
|
+
},
|
|
200
|
+
h3(Graphics2, {
|
|
201
|
+
draw,
|
|
202
|
+
alpha: 0.8,
|
|
203
|
+
blur: 80
|
|
204
|
+
}),
|
|
205
|
+
...children
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/Joystick.ts
|
|
210
|
+
import * as PIXI2 from "pixi.js";
|
|
211
|
+
import { Container as Container3, Graphics as Graphics3, Sprite, h as h4, signal as signal2 } from "canvasengine";
|
|
212
|
+
var Direction = /* @__PURE__ */ ((Direction2) => {
|
|
213
|
+
Direction2["LEFT"] = "left";
|
|
214
|
+
Direction2["TOP"] = "top";
|
|
215
|
+
Direction2["BOTTOM"] = "bottom";
|
|
216
|
+
Direction2["RIGHT"] = "right";
|
|
217
|
+
Direction2["TOP_LEFT"] = "top_left";
|
|
218
|
+
Direction2["TOP_RIGHT"] = "top_right";
|
|
219
|
+
Direction2["BOTTOM_LEFT"] = "bottom_left";
|
|
220
|
+
Direction2["BOTTOM_RIGHT"] = "bottom_right";
|
|
221
|
+
return Direction2;
|
|
222
|
+
})(Direction || {});
|
|
223
|
+
function Joystick(opts = {}) {
|
|
224
|
+
const settings2 = Object.assign(
|
|
225
|
+
{
|
|
226
|
+
outerScale: { x: 1, y: 1 },
|
|
227
|
+
innerScale: { x: 1, y: 1 }
|
|
228
|
+
},
|
|
229
|
+
opts
|
|
230
|
+
);
|
|
231
|
+
let outerRadius = 70;
|
|
232
|
+
let innerRadius = 10;
|
|
233
|
+
const innerAlphaStandby = 0.5;
|
|
234
|
+
let dragging = false;
|
|
235
|
+
let startPosition = null;
|
|
236
|
+
let power = 0;
|
|
237
|
+
const innerPositionX = signal2(0);
|
|
238
|
+
const innerPositionY = signal2(0);
|
|
239
|
+
const innerAlpha = signal2(innerAlphaStandby);
|
|
240
|
+
function getPower(centerPoint) {
|
|
241
|
+
const a = centerPoint.x - 0;
|
|
242
|
+
const b = centerPoint.y - 0;
|
|
243
|
+
return Math.min(1, Math.sqrt(a * a + b * b) / outerRadius);
|
|
244
|
+
}
|
|
245
|
+
function getDirection(center) {
|
|
246
|
+
let rad = Math.atan2(center.y, center.x);
|
|
247
|
+
if (rad >= -Math.PI / 8 && rad < 0 || rad >= 0 && rad < Math.PI / 8) {
|
|
248
|
+
return "right" /* RIGHT */;
|
|
249
|
+
} else if (rad >= Math.PI / 8 && rad < 3 * Math.PI / 8) {
|
|
250
|
+
return "bottom_right" /* BOTTOM_RIGHT */;
|
|
251
|
+
} else if (rad >= 3 * Math.PI / 8 && rad < 5 * Math.PI / 8) {
|
|
252
|
+
return "bottom" /* BOTTOM */;
|
|
253
|
+
} else if (rad >= 5 * Math.PI / 8 && rad < 7 * Math.PI / 8) {
|
|
254
|
+
return "bottom_left" /* BOTTOM_LEFT */;
|
|
255
|
+
} else if (rad >= 7 * Math.PI / 8 && rad < Math.PI || rad >= -Math.PI && rad < -7 * Math.PI / 8) {
|
|
256
|
+
return "left" /* LEFT */;
|
|
257
|
+
} else if (rad >= -7 * Math.PI / 8 && rad < -5 * Math.PI / 8) {
|
|
258
|
+
return "top_left" /* TOP_LEFT */;
|
|
259
|
+
} else if (rad >= -5 * Math.PI / 8 && rad < -3 * Math.PI / 8) {
|
|
260
|
+
return "top" /* TOP */;
|
|
261
|
+
} else {
|
|
262
|
+
return "top_right" /* TOP_RIGHT */;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function handleDragStart(event) {
|
|
266
|
+
startPosition = event.getLocalPosition(this);
|
|
267
|
+
dragging = true;
|
|
268
|
+
innerAlpha.set(1);
|
|
269
|
+
settings2.onStart?.();
|
|
270
|
+
}
|
|
271
|
+
function handleDragEnd() {
|
|
272
|
+
if (!dragging) return;
|
|
273
|
+
innerPositionX.set(0);
|
|
274
|
+
innerPositionY.set(0);
|
|
275
|
+
dragging = false;
|
|
276
|
+
innerAlpha.set(innerAlphaStandby);
|
|
277
|
+
settings2.onEnd?.();
|
|
278
|
+
}
|
|
279
|
+
function handleDragMove(event) {
|
|
280
|
+
if (dragging == false) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
let newPosition = event.getLocalPosition(this);
|
|
284
|
+
let sideX = newPosition.x - (startPosition?.x ?? 0);
|
|
285
|
+
let sideY = newPosition.y - (startPosition?.y ?? 0);
|
|
286
|
+
let centerPoint = new PIXI2.Point(0, 0);
|
|
287
|
+
let angle = 0;
|
|
288
|
+
if (sideX == 0 && sideY == 0) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
let calRadius = 0;
|
|
292
|
+
if (sideX * sideX + sideY * sideY >= outerRadius * outerRadius) {
|
|
293
|
+
calRadius = outerRadius;
|
|
294
|
+
} else {
|
|
295
|
+
calRadius = outerRadius - innerRadius;
|
|
296
|
+
}
|
|
297
|
+
let direction = "left" /* LEFT */;
|
|
298
|
+
if (sideX == 0) {
|
|
299
|
+
if (sideY > 0) {
|
|
300
|
+
centerPoint.set(0, sideY > outerRadius ? outerRadius : sideY);
|
|
301
|
+
angle = 270;
|
|
302
|
+
direction = "bottom" /* BOTTOM */;
|
|
303
|
+
} else {
|
|
304
|
+
centerPoint.set(
|
|
305
|
+
0,
|
|
306
|
+
-(Math.abs(sideY) > outerRadius ? outerRadius : Math.abs(sideY))
|
|
307
|
+
);
|
|
308
|
+
angle = 90;
|
|
309
|
+
direction = "top" /* TOP */;
|
|
310
|
+
}
|
|
311
|
+
innerPositionX.set(centerPoint.x);
|
|
312
|
+
innerPositionY.set(centerPoint.y);
|
|
313
|
+
power = getPower(centerPoint);
|
|
314
|
+
settings2.onChange?.({ angle, direction, power });
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (sideY == 0) {
|
|
318
|
+
if (sideX > 0) {
|
|
319
|
+
centerPoint.set(
|
|
320
|
+
Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX),
|
|
321
|
+
0
|
|
322
|
+
);
|
|
323
|
+
angle = 0;
|
|
324
|
+
direction = "left" /* LEFT */;
|
|
325
|
+
} else {
|
|
326
|
+
centerPoint.set(
|
|
327
|
+
-(Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX)),
|
|
328
|
+
0
|
|
329
|
+
);
|
|
330
|
+
angle = 180;
|
|
331
|
+
direction = "right" /* RIGHT */;
|
|
332
|
+
}
|
|
333
|
+
innerPositionX.set(centerPoint.x);
|
|
334
|
+
innerPositionY.set(centerPoint.y);
|
|
335
|
+
power = getPower(centerPoint);
|
|
336
|
+
settings2.onChange?.({ angle, direction, power });
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
let tanVal = Math.abs(sideY / sideX);
|
|
340
|
+
let radian = Math.atan(tanVal);
|
|
341
|
+
angle = radian * 180 / Math.PI;
|
|
342
|
+
let centerX = 0;
|
|
343
|
+
let centerY = 0;
|
|
344
|
+
if (sideX * sideX + sideY * sideY >= outerRadius * outerRadius) {
|
|
345
|
+
centerX = outerRadius * Math.cos(radian);
|
|
346
|
+
centerY = outerRadius * Math.sin(radian);
|
|
347
|
+
} else {
|
|
348
|
+
centerX = Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX);
|
|
349
|
+
centerY = Math.abs(sideY) > outerRadius ? outerRadius : Math.abs(sideY);
|
|
350
|
+
}
|
|
351
|
+
if (sideY < 0) {
|
|
352
|
+
centerY = -Math.abs(centerY);
|
|
353
|
+
}
|
|
354
|
+
if (sideX < 0) {
|
|
355
|
+
centerX = -Math.abs(centerX);
|
|
356
|
+
}
|
|
357
|
+
if (sideX > 0 && sideY < 0) {
|
|
358
|
+
} else if (sideX < 0 && sideY < 0) {
|
|
359
|
+
angle = 180 - angle;
|
|
360
|
+
} else if (sideX < 0 && sideY > 0) {
|
|
361
|
+
angle = angle + 180;
|
|
362
|
+
} else if (sideX > 0 && sideY > 0) {
|
|
363
|
+
angle = 360 - angle;
|
|
364
|
+
}
|
|
365
|
+
centerPoint.set(centerX, centerY);
|
|
366
|
+
power = getPower(centerPoint);
|
|
367
|
+
direction = getDirection(centerPoint);
|
|
368
|
+
innerPositionX.set(centerPoint.x);
|
|
369
|
+
innerPositionY.set(centerPoint.y);
|
|
370
|
+
settings2.onChange?.({ angle, direction, power });
|
|
371
|
+
}
|
|
372
|
+
let innerElement;
|
|
373
|
+
let outerElement;
|
|
374
|
+
if (!settings2.outer) {
|
|
375
|
+
outerElement = h4(Graphics3, {
|
|
376
|
+
draw: (g) => {
|
|
377
|
+
g.circle(0, 0, outerRadius).fill(0);
|
|
378
|
+
},
|
|
379
|
+
alpha: 0.5
|
|
380
|
+
});
|
|
381
|
+
} else {
|
|
382
|
+
outerElement = h4(Sprite, {
|
|
383
|
+
image: settings2.outer,
|
|
384
|
+
anchor: { x: 0.5, y: 0.5 },
|
|
385
|
+
scale: settings2.outerScale
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
const innerOptions = {
|
|
389
|
+
scale: settings2.innerScale,
|
|
390
|
+
x: innerPositionX,
|
|
391
|
+
y: innerPositionY,
|
|
392
|
+
alpha: innerAlpha
|
|
393
|
+
};
|
|
394
|
+
if (!settings2.inner) {
|
|
395
|
+
innerElement = h4(Graphics3, {
|
|
396
|
+
draw: (g) => {
|
|
397
|
+
g.circle(0, 0, innerRadius * 2.5).fill(0);
|
|
398
|
+
},
|
|
399
|
+
...innerOptions
|
|
400
|
+
});
|
|
401
|
+
} else {
|
|
402
|
+
innerElement = h4(Sprite, {
|
|
403
|
+
image: settings2.inner,
|
|
404
|
+
anchor: { x: 0.5, y: 0.5 },
|
|
405
|
+
...innerOptions
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
return h4(
|
|
409
|
+
Container3,
|
|
410
|
+
{
|
|
411
|
+
...opts,
|
|
412
|
+
pointerdown: handleDragStart,
|
|
413
|
+
pointerup: handleDragEnd,
|
|
414
|
+
pointerupoutside: handleDragEnd,
|
|
415
|
+
pointermove: handleDragMove
|
|
416
|
+
},
|
|
417
|
+
outerElement,
|
|
418
|
+
innerElement
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/Tilemap/index.ts
|
|
423
|
+
import { TiledLayerType, TiledParserFile } from "@rpgjs/tiled";
|
|
424
|
+
import { loop, h as h5, Container as Container4, TilingSprite, useProps as useProps4, effect as effect2, signal as signal3 } from "canvasengine";
|
|
425
|
+
|
|
426
|
+
// src/Tilemap/TileLayer.ts
|
|
427
|
+
import {
|
|
428
|
+
CompositeTilemap,
|
|
429
|
+
settings
|
|
430
|
+
} from "@canvasengine/tilemap";
|
|
431
|
+
import { Layer } from "@rpgjs/tiled";
|
|
432
|
+
import {
|
|
433
|
+
createComponent,
|
|
434
|
+
registerComponent,
|
|
435
|
+
DisplayObject
|
|
436
|
+
} from "canvasengine";
|
|
437
|
+
|
|
438
|
+
// src/Tilemap/Tile.ts
|
|
439
|
+
import { AnimatedSprite, groupD8 } from "pixi.js";
|
|
440
|
+
var Tile = class _Tile extends AnimatedSprite {
|
|
441
|
+
constructor(tile, tileSet) {
|
|
442
|
+
super(_Tile.getTextures(tile, tileSet));
|
|
443
|
+
this.tile = tile;
|
|
444
|
+
this.tileSet = tileSet;
|
|
445
|
+
this.animations = [];
|
|
446
|
+
this._x = 0;
|
|
447
|
+
this._y = 0;
|
|
448
|
+
this.properties = {};
|
|
449
|
+
this.animations = tile.animations || [];
|
|
450
|
+
this.properties = tile.properties;
|
|
451
|
+
this.textures = _Tile.getTextures(tile, tileSet);
|
|
452
|
+
this.texture = this.textures[0];
|
|
453
|
+
this.flip();
|
|
454
|
+
}
|
|
455
|
+
static getTextures(tile, tileSet) {
|
|
456
|
+
const textures = [];
|
|
457
|
+
if (tile.animations && tile.animations.length) {
|
|
458
|
+
tile.animations.forEach((frame) => {
|
|
459
|
+
textures.push(tileSet.textures[frame.tileid]);
|
|
460
|
+
});
|
|
461
|
+
} else {
|
|
462
|
+
textures.push(tileSet.textures[tile.gid - tileSet.firstgid]);
|
|
463
|
+
}
|
|
464
|
+
return textures;
|
|
465
|
+
}
|
|
466
|
+
get z() {
|
|
467
|
+
return this.properties.z ?? 0;
|
|
468
|
+
}
|
|
469
|
+
get gid() {
|
|
470
|
+
return this.tile.gid;
|
|
471
|
+
}
|
|
472
|
+
setAnimation(frame) {
|
|
473
|
+
const size = this.animations.length;
|
|
474
|
+
if (size > 1) {
|
|
475
|
+
const offset = (this.animations[1].tileid - this.animations[0].tileid) * this.width;
|
|
476
|
+
frame.tileAnimX(offset, size);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
flip() {
|
|
480
|
+
let symmetry;
|
|
481
|
+
let i = 0;
|
|
482
|
+
const add = (symmetrySecond) => {
|
|
483
|
+
i++;
|
|
484
|
+
if (symmetry) symmetry = groupD8.add(symmetry, symmetrySecond);
|
|
485
|
+
else symmetry = symmetrySecond;
|
|
486
|
+
};
|
|
487
|
+
if (this.tile.horizontalFlip) {
|
|
488
|
+
add(groupD8.MIRROR_HORIZONTAL);
|
|
489
|
+
}
|
|
490
|
+
if (this.tile.verticalFlip) {
|
|
491
|
+
add(groupD8.MIRROR_VERTICAL);
|
|
492
|
+
}
|
|
493
|
+
if (this.tile.diagonalFlip) {
|
|
494
|
+
if (i % 2 == 0) {
|
|
495
|
+
add(groupD8.MAIN_DIAGONAL);
|
|
496
|
+
} else {
|
|
497
|
+
add(groupD8.REVERSE_DIAGONAL);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// src/Tilemap/TileLayer.ts
|
|
504
|
+
settings.use32bitIndex = true;
|
|
505
|
+
var CanvasTileLayer = class _CanvasTileLayer extends DisplayObject(CompositeTilemap) {
|
|
506
|
+
constructor() {
|
|
507
|
+
super(...arguments);
|
|
508
|
+
this._tiles = {};
|
|
509
|
+
// TODO: fix this, remove any. replace with Layer
|
|
510
|
+
this.frameTile = 0;
|
|
511
|
+
this.frameRateAnimation = 10;
|
|
512
|
+
}
|
|
513
|
+
static findTileSet(gid, tileSets) {
|
|
514
|
+
let tileset;
|
|
515
|
+
for (let i = tileSets.length - 1; i >= 0; i--) {
|
|
516
|
+
tileset = tileSets[i];
|
|
517
|
+
if (tileset.firstgid && tileset.firstgid <= gid) {
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return tileset;
|
|
522
|
+
}
|
|
523
|
+
/** @internal */
|
|
524
|
+
createTile(x, y, options = {}) {
|
|
525
|
+
const { real, filter } = options;
|
|
526
|
+
const { tilewidth, tileheight, width } = this._layer;
|
|
527
|
+
if (real) {
|
|
528
|
+
x = Math.floor(x / tilewidth);
|
|
529
|
+
y = Math.floor(y / tileheight);
|
|
530
|
+
}
|
|
531
|
+
const i = x + y * width;
|
|
532
|
+
const tiledTile = this._layer.getTileByIndex(i);
|
|
533
|
+
if (!tiledTile || tiledTile && tiledTile.gid == 0) return;
|
|
534
|
+
const tileset = _CanvasTileLayer.findTileSet(tiledTile.gid, this.tileSets);
|
|
535
|
+
if (!tileset) return;
|
|
536
|
+
const tile = new Tile(tiledTile, tileset);
|
|
537
|
+
tile.x = x * tilewidth;
|
|
538
|
+
tile.y = y * tileheight + (tileheight - tile.texture.height);
|
|
539
|
+
tile._x = x;
|
|
540
|
+
tile._y = y;
|
|
541
|
+
if (tileset.tileoffset) {
|
|
542
|
+
tile.x += tileset.tileoffset.x ?? 0;
|
|
543
|
+
tile.y += tileset.tileoffset.y ?? 0;
|
|
544
|
+
}
|
|
545
|
+
if (filter) {
|
|
546
|
+
const ret = filter(tile);
|
|
547
|
+
if (!ret) return;
|
|
548
|
+
}
|
|
549
|
+
return tile;
|
|
550
|
+
}
|
|
551
|
+
_addFrame(tile, x, y) {
|
|
552
|
+
const frame = this.tile(tile.texture, tile.x, tile.y, {
|
|
553
|
+
rotate: tile.texture.rotate
|
|
554
|
+
});
|
|
555
|
+
tile.setAnimation(frame);
|
|
556
|
+
this._tiles[x + ";" + y] = tile;
|
|
557
|
+
}
|
|
558
|
+
async onMount(args) {
|
|
559
|
+
const { props } = args;
|
|
560
|
+
this.tileSets = props.tilesets;
|
|
561
|
+
this._layer = new Layer(
|
|
562
|
+
{
|
|
563
|
+
...props
|
|
564
|
+
},
|
|
565
|
+
this.tileSets
|
|
566
|
+
);
|
|
567
|
+
const tick3 = props.context.tick;
|
|
568
|
+
this.subscriptionTick = tick3.observable.subscribe(({ value }) => {
|
|
569
|
+
if (value.frame % this.frameRateAnimation == 0) {
|
|
570
|
+
this.tileAnim = [this.frameTile, this.frameTile];
|
|
571
|
+
this.frameTile++;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
super.onMount(args);
|
|
575
|
+
}
|
|
576
|
+
onUpdate(props) {
|
|
577
|
+
super.onUpdate(props);
|
|
578
|
+
if (!this.isMounted) return;
|
|
579
|
+
if (props.tileheight) this._layer.tileheight = props.tileheight;
|
|
580
|
+
if (props.tilewidth) this._layer.tilewidth = props.tilewidth;
|
|
581
|
+
if (props.width) this._layer.width = props.width;
|
|
582
|
+
if (props.height) this._layer.height = props.height;
|
|
583
|
+
if (props.parallaxX) this._layer.parallaxX = props.parallaxx;
|
|
584
|
+
if (props.parallaxY) this._layer.parallaxY = props.parallaxy;
|
|
585
|
+
this.removeChildren();
|
|
586
|
+
for (let y = 0; y < this._layer.height; y++) {
|
|
587
|
+
for (let x = 0; x < this._layer.width; x++) {
|
|
588
|
+
const tile = this.createTile(x, y);
|
|
589
|
+
if (tile) {
|
|
590
|
+
this._addFrame(tile, x, y);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
async onDestroy(parent) {
|
|
596
|
+
this.subscriptionTick.unsubscribe();
|
|
597
|
+
await super.onDestroy(parent);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
registerComponent("CompositeTileLayer", CanvasTileLayer);
|
|
601
|
+
function CompositeTileLayer(props) {
|
|
602
|
+
return createComponent("CompositeTileLayer", props);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// src/Tilemap/TileSet.ts
|
|
606
|
+
import { Tileset as TiledTilesetClass } from "@rpgjs/tiled";
|
|
607
|
+
import { Assets as Assets2, Rectangle, Texture as Texture2 } from "pixi.js";
|
|
608
|
+
var TileSet = class extends TiledTilesetClass {
|
|
609
|
+
constructor(tileSet) {
|
|
610
|
+
super(tileSet);
|
|
611
|
+
this.textures = [];
|
|
612
|
+
this.tileGroups = {};
|
|
613
|
+
}
|
|
614
|
+
loadGroup() {
|
|
615
|
+
}
|
|
616
|
+
/** @internal */
|
|
617
|
+
async load(image) {
|
|
618
|
+
const texture = await Assets2.load(image);
|
|
619
|
+
for (let y = this.margin; y < this.image.height; y += this.tileheight + this.spacing) {
|
|
620
|
+
for (let x = this.margin; x < this.image.width; x += this.tilewidth + this.spacing) {
|
|
621
|
+
this.textures.push(
|
|
622
|
+
new Texture2({
|
|
623
|
+
source: texture.source,
|
|
624
|
+
frame: new Rectangle(+x, +y, +this.tilewidth, +this.tileheight)
|
|
625
|
+
})
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
this.loadGroup();
|
|
630
|
+
return this;
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// src/Tilemap/index.ts
|
|
635
|
+
function reorganizeLayersByTileZ(originalLayers, tilesets, mapData) {
|
|
636
|
+
const reorganizedLayers = [];
|
|
637
|
+
for (const layer of originalLayers) {
|
|
638
|
+
if (layer.type !== TiledLayerType.Tile) {
|
|
639
|
+
reorganizedLayers.push(layer);
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
const layersByZ = /* @__PURE__ */ new Map();
|
|
643
|
+
let layerData;
|
|
644
|
+
if (Array.isArray(layer.data)) {
|
|
645
|
+
layerData = layer.data.map((gid) => {
|
|
646
|
+
if (typeof gid === "number") {
|
|
647
|
+
return gid;
|
|
648
|
+
} else {
|
|
649
|
+
return parseInt(String(gid), 10);
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
} else {
|
|
653
|
+
reorganizedLayers.push(layer);
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
let tilesProcessed = 0;
|
|
657
|
+
let tilesWithZ = 0;
|
|
658
|
+
for (let i = 0; i < layerData.length; i++) {
|
|
659
|
+
const gid = layerData[i];
|
|
660
|
+
if (gid === 0) continue;
|
|
661
|
+
tilesProcessed++;
|
|
662
|
+
let tileset;
|
|
663
|
+
for (let j = tilesets.length - 1; j >= 0; j--) {
|
|
664
|
+
if (tilesets[j].firstgid && tilesets[j].firstgid <= gid) {
|
|
665
|
+
tileset = tilesets[j];
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (!tileset) {
|
|
670
|
+
if (!layersByZ.has(0)) {
|
|
671
|
+
layersByZ.set(0, new Array(layerData.length).fill(0));
|
|
672
|
+
}
|
|
673
|
+
layersByZ.get(0)[i] = gid;
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
const localTileId = gid - tileset.firstgid;
|
|
677
|
+
const tileProperties = tileset.tileset.tiles?.[localTileId]?.properties;
|
|
678
|
+
const zValue = tileProperties?.z ?? 0;
|
|
679
|
+
if (tileProperties?.z !== void 0) {
|
|
680
|
+
tilesWithZ++;
|
|
681
|
+
}
|
|
682
|
+
if (!layersByZ.has(zValue)) {
|
|
683
|
+
layersByZ.set(zValue, new Array(layerData.length).fill(0));
|
|
684
|
+
}
|
|
685
|
+
layersByZ.get(zValue)[i] = gid;
|
|
686
|
+
}
|
|
687
|
+
const sortedZValues = Array.from(layersByZ.keys()).sort((a, b) => a - b);
|
|
688
|
+
for (const zValue of sortedZValues) {
|
|
689
|
+
const layerDataForZ = layersByZ.get(zValue);
|
|
690
|
+
if (layerDataForZ.some((gid) => gid !== 0)) {
|
|
691
|
+
const newLayer = {
|
|
692
|
+
...layer,
|
|
693
|
+
name: `${layer.name}_z${zValue}`,
|
|
694
|
+
// Always add _z suffix
|
|
695
|
+
data: layerDataForZ,
|
|
696
|
+
properties: {
|
|
697
|
+
...layer.properties,
|
|
698
|
+
z: zValue
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
reorganizedLayers.push(newLayer);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
reorganizedLayers.sort((a, b) => {
|
|
706
|
+
const zA = a.properties?.z ?? 0.5;
|
|
707
|
+
const zB = b.properties?.z ?? 0.5;
|
|
708
|
+
return zA - zB;
|
|
709
|
+
});
|
|
710
|
+
return reorganizedLayers;
|
|
711
|
+
}
|
|
712
|
+
function TiledMap(props) {
|
|
713
|
+
const { map, basePath, createLayersPerTilesZ } = useProps4(props, {
|
|
714
|
+
createLayersPerTilesZ: false,
|
|
715
|
+
basePath: ""
|
|
716
|
+
});
|
|
717
|
+
const layers = signal3([]);
|
|
718
|
+
const objectLayer = props.objectLayer;
|
|
719
|
+
let tilesets = [];
|
|
720
|
+
let mapData = {};
|
|
721
|
+
const parseTmx = async (file, relativePath = "") => {
|
|
722
|
+
if (typeof file !== "string") {
|
|
723
|
+
return file;
|
|
724
|
+
}
|
|
725
|
+
const parser = new TiledParserFile(
|
|
726
|
+
file,
|
|
727
|
+
{
|
|
728
|
+
basePath: "",
|
|
729
|
+
staticDir: "",
|
|
730
|
+
relativePath
|
|
731
|
+
}
|
|
732
|
+
);
|
|
733
|
+
const data = await parser.parseFilePromise({
|
|
734
|
+
getOnlyBasename: false
|
|
735
|
+
});
|
|
736
|
+
return data;
|
|
737
|
+
};
|
|
738
|
+
effect2(async () => {
|
|
739
|
+
const _map = map();
|
|
740
|
+
if (_map) {
|
|
741
|
+
mapData = await parseTmx(_map, basePath());
|
|
742
|
+
tilesets = [];
|
|
743
|
+
for (let tileSet of mapData.tilesets) {
|
|
744
|
+
if (tileSet.tile) tileSet.tiles = tileSet.tile;
|
|
745
|
+
tilesets.push(await new TileSet(tileSet).load(tileSet.image.source));
|
|
746
|
+
}
|
|
747
|
+
let finalLayers = mapData.layers;
|
|
748
|
+
if (createLayersPerTilesZ()) {
|
|
749
|
+
finalLayers = reorganizeLayersByTileZ(mapData.layers, tilesets, mapData);
|
|
750
|
+
}
|
|
751
|
+
layers.set(finalLayers);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
const createLayer = (layers2, props2 = {}) => {
|
|
755
|
+
return h5(Container4, props2, loop(layers2, (layer) => {
|
|
756
|
+
switch (layer.type) {
|
|
757
|
+
case TiledLayerType.Tile:
|
|
758
|
+
return h5(CompositeTileLayer, {
|
|
759
|
+
tilewidth: mapData.tilewidth,
|
|
760
|
+
tileheight: mapData.tileheight,
|
|
761
|
+
// @ts-ignore
|
|
762
|
+
width: mapData.width,
|
|
763
|
+
// @ts-ignore
|
|
764
|
+
height: mapData.height,
|
|
765
|
+
...layer,
|
|
766
|
+
tilesets
|
|
767
|
+
});
|
|
768
|
+
case TiledLayerType.Image:
|
|
769
|
+
const { width, height, source } = layer.image;
|
|
770
|
+
return h5(TilingSprite, {
|
|
771
|
+
image: source,
|
|
772
|
+
...layer,
|
|
773
|
+
width: layer.repeatx ? layer.width * layer.tilewidth : width,
|
|
774
|
+
height: layer.repeaty ? layer.height * layer.tileheight : height
|
|
775
|
+
});
|
|
776
|
+
case TiledLayerType.Group:
|
|
777
|
+
return createLayer(signal3(layer.layers), layer);
|
|
778
|
+
case TiledLayerType.ObjectGroup:
|
|
779
|
+
const child = objectLayer?.(layer);
|
|
780
|
+
return h5(Container4, layer, child);
|
|
781
|
+
default:
|
|
782
|
+
return h5(Container4);
|
|
783
|
+
}
|
|
784
|
+
}));
|
|
785
|
+
};
|
|
786
|
+
return h5(Container4, props, createLayer(layers));
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// src/Weathers/index.ts
|
|
790
|
+
import {
|
|
791
|
+
tick as tick2,
|
|
792
|
+
useProps as useProps5,
|
|
793
|
+
h as h6,
|
|
794
|
+
Mesh,
|
|
795
|
+
signal as signal4
|
|
796
|
+
} from "canvasengine";
|
|
797
|
+
import { Geometry, Shader, GlProgram, UniformGroup } from "pixi.js";
|
|
798
|
+
var WeatherEffect = (options) => {
|
|
799
|
+
const {
|
|
800
|
+
speed = signal4(0.5),
|
|
801
|
+
windDirection = signal4(0),
|
|
802
|
+
windStrength = signal4(0.2),
|
|
803
|
+
density = signal4(180),
|
|
804
|
+
resolution = signal4([1e3, 1e3])
|
|
805
|
+
} = useProps5(options);
|
|
806
|
+
const speedSignal = typeof speed === "function" ? speed : signal4(speed);
|
|
807
|
+
const windDirectionSignal = typeof windDirection === "function" ? windDirection : signal4(windDirection);
|
|
808
|
+
const windStrengthSignal = typeof windStrength === "function" ? windStrength : signal4(windStrength);
|
|
809
|
+
const densitySignal = typeof density === "function" ? density : signal4(density);
|
|
810
|
+
const resolutionSignal = typeof resolution === "function" ? resolution : signal4(resolution);
|
|
811
|
+
const vertexSrc = (
|
|
812
|
+
/* glsl */
|
|
813
|
+
`
|
|
814
|
+
precision mediump float;
|
|
815
|
+
attribute vec2 aPosition;
|
|
816
|
+
attribute vec2 aUV;
|
|
817
|
+
varying vec2 vUV;
|
|
818
|
+
void main() {
|
|
819
|
+
vUV = aUV;
|
|
820
|
+
gl_Position = vec4(aPosition, 0.0, 1.0);
|
|
821
|
+
}
|
|
822
|
+
`
|
|
823
|
+
);
|
|
824
|
+
const fragmentSrc = (
|
|
825
|
+
/* glsl */
|
|
826
|
+
`
|
|
827
|
+
precision mediump float;
|
|
828
|
+
varying vec2 vUV;
|
|
829
|
+
uniform float uTime;
|
|
830
|
+
uniform vec2 uResolution;
|
|
831
|
+
uniform float uRainSpeed;
|
|
832
|
+
uniform float uWindDirection;
|
|
833
|
+
uniform float uWindStrength;
|
|
834
|
+
uniform float uRainDensity;
|
|
835
|
+
|
|
836
|
+
// Hash function for pseudo-random number generation
|
|
837
|
+
float hash(float n){ return fract(sin(n)*43758.5453); }
|
|
838
|
+
|
|
839
|
+
// Generate a single raindrop at given UV coordinates
|
|
840
|
+
float rainDrop(vec2 uv, float t, float seed) {
|
|
841
|
+
// Random X position with wider coverage for screen edges
|
|
842
|
+
float x = hash(seed) * 2.4 - 1.2;
|
|
843
|
+
|
|
844
|
+
// Falling speed with variation per drop
|
|
845
|
+
float baseSpeed = 1.0 + hash(seed + 1.0) * 1.5;
|
|
846
|
+
float speed = baseSpeed * uRainSpeed;
|
|
847
|
+
|
|
848
|
+
// Y position falling from top (1.0) to bottom (-1.0)
|
|
849
|
+
float y = 1.2 - fract(t * speed + hash(seed + 2.0)) * 2.4;
|
|
850
|
+
|
|
851
|
+
// Wind effect: more drift as drop falls further
|
|
852
|
+
float fallProgress = (1.2 - y) / 2.4; // 0 = top, 1 = bottom
|
|
853
|
+
float windOffset = uWindDirection * uWindStrength * fallProgress * 0.5;
|
|
854
|
+
x += windOffset;
|
|
855
|
+
|
|
856
|
+
vec2 dropPos = vec2(x, y);
|
|
857
|
+
vec2 diff = uv - dropPos;
|
|
858
|
+
|
|
859
|
+
// Raindrop shape (thin streaks)
|
|
860
|
+
float dropWidth = 0.0015 + hash(seed + 3.0) * 0.0005;
|
|
861
|
+
float dropLength = 0.025 + hash(seed + 4.0) * 0.015;
|
|
862
|
+
|
|
863
|
+
// Slight tilt based on wind
|
|
864
|
+
float windAngle = uWindDirection * uWindStrength * 0.2;
|
|
865
|
+
float cosA = cos(windAngle);
|
|
866
|
+
float sinA = sin(windAngle);
|
|
867
|
+
vec2 rotatedDiff = vec2(
|
|
868
|
+
diff.x * cosA - diff.y * sinA,
|
|
869
|
+
diff.x * sinA + diff.y * cosA
|
|
870
|
+
);
|
|
871
|
+
|
|
872
|
+
// Distance calculation for thin streaks
|
|
873
|
+
float distX = abs(rotatedDiff.x) / dropWidth;
|
|
874
|
+
float distY = abs(rotatedDiff.y) / dropLength;
|
|
875
|
+
float dist = max(distX, distY * 0.4);
|
|
876
|
+
|
|
877
|
+
// Intensity with fade and variation (Zelda-style)
|
|
878
|
+
float intensity = 1.0 - smoothstep(0.0, 1.2, dist);
|
|
879
|
+
intensity *= 0.7 + 0.3 * hash(seed + 5.0);
|
|
880
|
+
|
|
881
|
+
// Natural fade at top and bottom edges
|
|
882
|
+
intensity *= smoothstep(-1.2, -0.8, y) * smoothstep(1.2, 0.8, y);
|
|
883
|
+
|
|
884
|
+
return intensity;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
void main(){
|
|
888
|
+
// Normalized UV coordinates centered on screen
|
|
889
|
+
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / min(uResolution.x, uResolution.y);
|
|
890
|
+
|
|
891
|
+
float rain = 0.0;
|
|
892
|
+
|
|
893
|
+
// Generate multiple raindrops
|
|
894
|
+
for(float i = 0.0; i < 200.0; i++) {
|
|
895
|
+
rain += rainDrop(uv, uTime, i * 12.34);
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// Adjust intensity based on density setting
|
|
899
|
+
rain *= (uRainDensity / 200.0);
|
|
900
|
+
|
|
901
|
+
// Zelda-style rain color (bright and visible)
|
|
902
|
+
vec3 rainColor = vec3(0.85, 0.9, 1.0);
|
|
903
|
+
|
|
904
|
+
gl_FragColor = vec4(rainColor * rain, rain * 0.8);
|
|
905
|
+
}
|
|
906
|
+
`
|
|
907
|
+
);
|
|
908
|
+
const glProgram = new GlProgram({ vertex: vertexSrc, fragment: fragmentSrc });
|
|
909
|
+
const uniformGroup = new UniformGroup({
|
|
910
|
+
uTime: { value: 0, type: "f32" },
|
|
911
|
+
uResolution: { value: resolutionSignal(), type: "vec2<f32>" },
|
|
912
|
+
uRainSpeed: { value: speedSignal(), type: "f32" },
|
|
913
|
+
uWindDirection: { value: windDirectionSignal(), type: "f32" },
|
|
914
|
+
uWindStrength: { value: windStrengthSignal(), type: "f32" },
|
|
915
|
+
uRainDensity: { value: densitySignal(), type: "f32" }
|
|
916
|
+
});
|
|
917
|
+
const shader = new Shader({
|
|
918
|
+
glProgram,
|
|
919
|
+
resources: {
|
|
920
|
+
uniforms: uniformGroup
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
const geometry = new Geometry({
|
|
924
|
+
attributes: {
|
|
925
|
+
aPosition: [-1, -1, 1, -1, 1, 1, -1, 1],
|
|
926
|
+
aUV: [0, 0, 1, 0, 1, 1, 0, 1]
|
|
927
|
+
},
|
|
928
|
+
indexBuffer: [0, 1, 2, 0, 2, 3]
|
|
929
|
+
});
|
|
930
|
+
tick2(({ deltaTime }) => {
|
|
931
|
+
uniformGroup.uniforms.uTime += deltaTime;
|
|
932
|
+
uniformGroup.uniforms.uRainSpeed = speedSignal();
|
|
933
|
+
uniformGroup.uniforms.uWindDirection = windDirectionSignal();
|
|
934
|
+
uniformGroup.uniforms.uWindStrength = windStrengthSignal();
|
|
935
|
+
uniformGroup.uniforms.uRainDensity = densitySignal();
|
|
936
|
+
uniformGroup.uniforms.uResolution = resolutionSignal();
|
|
937
|
+
});
|
|
938
|
+
return h6(Mesh, {
|
|
939
|
+
geometry,
|
|
940
|
+
shader
|
|
941
|
+
});
|
|
942
|
+
};
|
|
943
|
+
var Weather = WeatherEffect;
|
|
944
|
+
export {
|
|
945
|
+
Bar,
|
|
946
|
+
Direction,
|
|
947
|
+
Joystick,
|
|
948
|
+
LightSpot,
|
|
949
|
+
NightAmbiant,
|
|
950
|
+
Particle,
|
|
951
|
+
TiledMap,
|
|
952
|
+
Weather,
|
|
953
|
+
WeatherEffect
|
|
954
|
+
};
|
|
955
|
+
//# sourceMappingURL=index.js.map
|