@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.
Files changed (42) hide show
  1. package/dist/Bar.d.ts +14 -0
  2. package/dist/Bar.d.ts.map +1 -0
  3. package/dist/Button.d.ts +1 -0
  4. package/dist/Button.d.ts.map +1 -0
  5. package/dist/Joystick.d.ts +32 -0
  6. package/dist/Joystick.d.ts.map +1 -0
  7. package/dist/NightAmbiant.d.ts +3 -0
  8. package/dist/NightAmbiant.d.ts.map +1 -0
  9. package/dist/Particle.d.ts +2 -0
  10. package/dist/Particle.d.ts.map +1 -0
  11. package/dist/Tilemap/Tile.d.ts +23 -0
  12. package/dist/Tilemap/Tile.d.ts.map +1 -0
  13. package/dist/Tilemap/TileGroup.d.ts +62 -0
  14. package/dist/Tilemap/TileGroup.d.ts.map +1 -0
  15. package/dist/Tilemap/TileLayer.d.ts +87 -0
  16. package/dist/Tilemap/TileLayer.d.ts.map +1 -0
  17. package/dist/Tilemap/TileSet.d.ts +11 -0
  18. package/dist/Tilemap/TileSet.d.ts.map +1 -0
  19. package/dist/Tilemap/index.d.ts +2 -0
  20. package/dist/Tilemap/index.d.ts.map +1 -0
  21. package/dist/Weathers/index.d.ts +57 -0
  22. package/dist/Weathers/index.d.ts.map +1 -0
  23. package/dist/index.d.ts +7 -112
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.global.js +25 -951
  26. package/dist/index.global.js.map +1 -1
  27. package/dist/index.js +5891 -4
  28. package/dist/index.js.map +1 -1
  29. package/package.json +31 -9
  30. package/src/Bar.ts +0 -90
  31. package/src/Button.ts +0 -0
  32. package/src/Joystick.ts +0 -284
  33. package/src/NightAmbiant.ts +0 -116
  34. package/src/Particle.ts +0 -50
  35. package/src/Tilemap/Tile.ts +0 -83
  36. package/src/Tilemap/TileGroup.ts +0 -207
  37. package/src/Tilemap/TileLayer.ts +0 -146
  38. package/src/Tilemap/TileSet.ts +0 -41
  39. package/src/Tilemap/index.ts +0 -222
  40. package/src/Weathers/index.ts +0 -224
  41. package/src/index.ts +0 -6
  42. package/tsup.config.ts +0 -18
@@ -1,224 +0,0 @@
1
- import {
2
- tick,
3
- useProps,
4
- h,
5
- Mesh,
6
- signal,
7
- } from "canvasengine";
8
- import { Geometry, Shader, GlProgram, UniformGroup } from "pixi.js";
9
-
10
- /**
11
- * Weather Effect Component
12
- *
13
- * Creates a realistic rain effect using WebGL shaders with customizable parameters.
14
- * The effect simulates raindrops falling with wind influence, density control, and speed adjustment.
15
- *
16
- * ## Design
17
- *
18
- * The component uses a fragment shader to generate procedural rain drops with:
19
- * - **Procedural generation**: Each raindrop is generated using hash functions for randomness
20
- * - **Wind simulation**: Raindrops are affected by wind direction and strength as they fall
21
- * - **Density control**: Number of visible raindrops can be adjusted
22
- * - **Speed variation**: Each drop has slightly different falling speed for realism
23
- * - **Visual styling**: Zelda-inspired rain appearance with proper fade effects
24
- *
25
- * @param {Object} options - Configuration options for the weather effect
26
- * @param {number} [options.speed=0.5] - Rain falling speed (0.1 = slow, 2.0 = fast)
27
- * @param {number} [options.windDirection=0.0] - Wind direction (-1.0 = left, 1.0 = right)
28
- * @param {number} [options.windStrength=0.2] - Wind strength (0.0 = no wind, 1.0 = strong)
29
- * @param {number} [options.density=180.0] - Rain density (number of raindrops, 50-400)
30
- * @param {Array<number>} [options.resolution=[1000, 1000]] - Screen resolution for proper scaling
31
- *
32
- * @example
33
- * ```jsx
34
- * // Basic usage with default settings
35
- * <Weather />
36
- *
37
- * // Customized heavy rain with strong wind
38
- * <Weather
39
- * speed={1.5}
40
- * windDirection={0.8}
41
- * windStrength={0.6}
42
- * density={300}
43
- * />
44
- *
45
- * // Light drizzle
46
- * <Weather
47
- * speed={0.2}
48
- * density={80}
49
- * windStrength={0.1}
50
- * />
51
- *
52
- * // Using signals for dynamic control
53
- * const rainSpeed = signal(0.5);
54
- * const windDir = signal(0.0);
55
- *
56
- * <Weather
57
- * speed={rainSpeed}
58
- * windDirection={windDir}
59
- * />
60
- * ```
61
- *
62
- * @returns {JSX.Element} A mesh component with the weather shader effect
63
- */
64
- export const WeatherEffect = (options) => {
65
- const {
66
- speed = signal(0.5),
67
- windDirection = signal(0.0),
68
- windStrength = signal(0.2),
69
- density = signal(180.0),
70
- resolution = signal([1000, 1000])
71
- } = useProps(options);
72
-
73
- // Convert to signals if not already
74
- const speedSignal = typeof speed === 'function' ? speed : signal(speed);
75
- const windDirectionSignal = typeof windDirection === 'function' ? windDirection : signal(windDirection);
76
- const windStrengthSignal = typeof windStrength === 'function' ? windStrength : signal(windStrength);
77
- const densitySignal = typeof density === 'function' ? density : signal(density);
78
- const resolutionSignal = typeof resolution === 'function' ? resolution : signal(resolution);
79
-
80
- // Vertex shader - handles vertex positioning and UV mapping
81
- const vertexSrc = /* glsl */ `
82
- precision mediump float;
83
- attribute vec2 aPosition;
84
- attribute vec2 aUV;
85
- varying vec2 vUV;
86
- void main() {
87
- vUV = aUV;
88
- gl_Position = vec4(aPosition, 0.0, 1.0);
89
- }
90
- `;
91
-
92
- // Fragment shader - generates the rain effect
93
- const fragmentSrc = /* glsl */ `
94
- precision mediump float;
95
- varying vec2 vUV;
96
- uniform float uTime;
97
- uniform vec2 uResolution;
98
- uniform float uRainSpeed;
99
- uniform float uWindDirection;
100
- uniform float uWindStrength;
101
- uniform float uRainDensity;
102
-
103
- // Hash function for pseudo-random number generation
104
- float hash(float n){ return fract(sin(n)*43758.5453); }
105
-
106
- // Generate a single raindrop at given UV coordinates
107
- float rainDrop(vec2 uv, float t, float seed) {
108
- // Random X position with wider coverage for screen edges
109
- float x = hash(seed) * 2.4 - 1.2;
110
-
111
- // Falling speed with variation per drop
112
- float baseSpeed = 1.0 + hash(seed + 1.0) * 1.5;
113
- float speed = baseSpeed * uRainSpeed;
114
-
115
- // Y position falling from top (1.0) to bottom (-1.0)
116
- float y = 1.2 - fract(t * speed + hash(seed + 2.0)) * 2.4;
117
-
118
- // Wind effect: more drift as drop falls further
119
- float fallProgress = (1.2 - y) / 2.4; // 0 = top, 1 = bottom
120
- float windOffset = uWindDirection * uWindStrength * fallProgress * 0.5;
121
- x += windOffset;
122
-
123
- vec2 dropPos = vec2(x, y);
124
- vec2 diff = uv - dropPos;
125
-
126
- // Raindrop shape (thin streaks)
127
- float dropWidth = 0.0015 + hash(seed + 3.0) * 0.0005;
128
- float dropLength = 0.025 + hash(seed + 4.0) * 0.015;
129
-
130
- // Slight tilt based on wind
131
- float windAngle = uWindDirection * uWindStrength * 0.2;
132
- float cosA = cos(windAngle);
133
- float sinA = sin(windAngle);
134
- vec2 rotatedDiff = vec2(
135
- diff.x * cosA - diff.y * sinA,
136
- diff.x * sinA + diff.y * cosA
137
- );
138
-
139
- // Distance calculation for thin streaks
140
- float distX = abs(rotatedDiff.x) / dropWidth;
141
- float distY = abs(rotatedDiff.y) / dropLength;
142
- float dist = max(distX, distY * 0.4);
143
-
144
- // Intensity with fade and variation (Zelda-style)
145
- float intensity = 1.0 - smoothstep(0.0, 1.2, dist);
146
- intensity *= 0.7 + 0.3 * hash(seed + 5.0);
147
-
148
- // Natural fade at top and bottom edges
149
- intensity *= smoothstep(-1.2, -0.8, y) * smoothstep(1.2, 0.8, y);
150
-
151
- return intensity;
152
- }
153
-
154
- void main(){
155
- // Normalized UV coordinates centered on screen
156
- vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / min(uResolution.x, uResolution.y);
157
-
158
- float rain = 0.0;
159
-
160
- // Generate multiple raindrops
161
- for(float i = 0.0; i < 200.0; i++) {
162
- rain += rainDrop(uv, uTime, i * 12.34);
163
- }
164
-
165
- // Adjust intensity based on density setting
166
- rain *= (uRainDensity / 200.0);
167
-
168
- // Zelda-style rain color (bright and visible)
169
- vec3 rainColor = vec3(0.85, 0.9, 1.0);
170
-
171
- gl_FragColor = vec4(rainColor * rain, rain * 0.8);
172
- }
173
- `;
174
-
175
- // Create WebGL program
176
- const glProgram = new GlProgram({ vertex: vertexSrc, fragment: fragmentSrc });
177
-
178
- // Uniform group for shader parameters
179
- const uniformGroup = new UniformGroup({
180
- uTime: { value: 0, type: "f32" },
181
- uResolution: { value: resolutionSignal(), type: "vec2<f32>" },
182
- uRainSpeed: { value: speedSignal(), type: "f32" },
183
- uWindDirection: { value: windDirectionSignal(), type: "f32" },
184
- uWindStrength: { value: windStrengthSignal(), type: "f32" },
185
- uRainDensity: { value: densitySignal(), type: "f32" },
186
- });
187
-
188
- // Create shader with program and resources
189
- const shader = new Shader({
190
- glProgram,
191
- resources: {
192
- uniforms: uniformGroup,
193
- },
194
- });
195
-
196
- // Full-screen quad geometry
197
- const geometry = new Geometry({
198
- attributes: {
199
- aPosition: [-1, -1, 1, -1, 1, 1, -1, 1],
200
- aUV: [0, 0, 1, 0, 1, 1, 0, 1],
201
- },
202
- indexBuffer: [0, 1, 2, 0, 2, 3],
203
- });
204
-
205
- // Animation loop - update time and reactive uniforms
206
- tick(({ deltaTime }) => {
207
- uniformGroup.uniforms.uTime += deltaTime;
208
-
209
- // Update uniforms from signals
210
- uniformGroup.uniforms.uRainSpeed = speedSignal();
211
- uniformGroup.uniforms.uWindDirection = windDirectionSignal();
212
- uniformGroup.uniforms.uWindStrength = windStrengthSignal();
213
- uniformGroup.uniforms.uRainDensity = densitySignal();
214
- uniformGroup.uniforms.uResolution = resolutionSignal();
215
- });
216
-
217
- return h(Mesh, {
218
- geometry,
219
- shader,
220
- });
221
- };
222
-
223
- // Export as Weather for easier usage
224
- export const Weather = WeatherEffect;
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from './Bar'
2
- export * from './Particle'
3
- export * from './NightAmbiant'
4
- export * from './Joystick'
5
- export * from './Tilemap'
6
- export * from './Weathers'
package/tsup.config.ts DELETED
@@ -1,18 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig({
4
- format: ['esm', 'iife'],
5
- target: 'es2020',
6
- splitting: true,
7
- clean: true,
8
- shims: false,
9
- minify: true,
10
- dts: true,
11
- sourcemap: true,
12
- entry: ['src/index.ts'],
13
- outDir: 'dist',
14
- define: {
15
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
16
- },
17
- globalName: 'CanvasEnginePresets'
18
- })