@rpgjs/common 5.0.0-alpha.25 → 5.0.0-alpha.27

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.
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Perlin Noise 2D Generator
3
+ *
4
+ * A simple, efficient, and performant implementation of 2D Perlin noise.
5
+ * Perlin noise generates smooth, natural-looking random values that are coherent
6
+ * across space, making it ideal for procedural generation and smooth random movements.
7
+ *
8
+ * ## Features
9
+ * - **Deterministic**: Same seed and coordinates always produce the same value
10
+ * - **Smooth**: Values change gradually, creating natural-looking patterns
11
+ * - **Performant**: Optimized for real-time use in movement systems
12
+ * - **Seeded**: Optional seed for reproducible results
13
+ *
14
+ * ## Usage
15
+ * ```ts
16
+ * const noise = new PerlinNoise2D();
17
+ * const value = noise.get(x, y); // Returns value between -1 and 1
18
+ *
19
+ * // With seed for deterministic results
20
+ * const seededNoise = new PerlinNoise2D(12345);
21
+ * ```
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // Use in movement system for smooth random directions
26
+ * const noise = new PerlinNoise2D();
27
+ * const time = Date.now() * 0.001;
28
+ * const direction = Math.floor(noise.get(player.x(), player.y(), time) * 4) % 4;
29
+ * ```
30
+ */
31
+ export declare class PerlinNoise2D {
32
+ private readonly permutation;
33
+ private readonly p;
34
+ /**
35
+ * Creates a new Perlin noise generator
36
+ *
37
+ * @param seed - Optional seed for deterministic noise generation. If not provided, uses a default seed.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const noise = new PerlinNoise2D(12345);
42
+ * const value = noise.get(10, 20);
43
+ * ```
44
+ */
45
+ constructor(seed?: number);
46
+ /**
47
+ * Generates a permutation table based on seed
48
+ *
49
+ * @param seed - Seed value for permutation generation
50
+ * @returns Array of 256 shuffled values
51
+ */
52
+ private generatePermutation;
53
+ /**
54
+ * Fade function for smooth interpolation (ease curve)
55
+ *
56
+ * @param t - Value between 0 and 1
57
+ * @returns Smoothed value between 0 and 1
58
+ */
59
+ private fade;
60
+ /**
61
+ * Linear interpolation
62
+ *
63
+ * @param a - Start value
64
+ * @param b - End value
65
+ * @param t - Interpolation factor (0 to 1)
66
+ * @returns Interpolated value
67
+ */
68
+ private lerp;
69
+ /**
70
+ * Gradient function - generates a pseudo-random gradient vector
71
+ *
72
+ * @param hash - Hash value from permutation table
73
+ * @param x - X component
74
+ * @param y - Y component
75
+ * @returns Dot product of gradient and position
76
+ */
77
+ private grad;
78
+ /**
79
+ * Gets the noise value at the specified 2D coordinates
80
+ *
81
+ * Returns a value between approximately -1 and 1, though values near the edges
82
+ * are less common. For practical use, you may want to clamp or normalize the result.
83
+ *
84
+ * @param x - X coordinate
85
+ * @param y - Y coordinate
86
+ * @param scale - Optional scale factor (default: 0.1). Lower values create smoother, larger patterns.
87
+ * @returns Noise value between approximately -1 and 1
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const noise = new PerlinNoise2D();
92
+ * const value = noise.get(10, 20); // Basic usage
93
+ * const scaled = noise.get(10, 20, 0.05); // Smoother pattern
94
+ * ```
95
+ */
96
+ get(x: number, y: number, scale?: number): number;
97
+ /**
98
+ * Gets a normalized noise value between 0 and 1
99
+ *
100
+ * Convenience method that normalizes the noise output to a 0-1 range.
101
+ *
102
+ * @param x - X coordinate
103
+ * @param y - Y coordinate
104
+ * @param scale - Optional scale factor (default: 0.1)
105
+ * @returns Noise value between 0 and 1
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const noise = new PerlinNoise2D();
110
+ * const normalized = noise.getNormalized(10, 20);
111
+ * // Returns value between 0 and 1
112
+ * ```
113
+ */
114
+ getNormalized(x: number, y: number, scale?: number): number;
115
+ /**
116
+ * Gets a noise value mapped to a specific range
117
+ *
118
+ * Maps the noise output to a custom min-max range.
119
+ *
120
+ * @param x - X coordinate
121
+ * @param y - Y coordinate
122
+ * @param min - Minimum output value
123
+ * @param max - Maximum output value
124
+ * @param scale - Optional scale factor (default: 0.1)
125
+ * @returns Noise value between min and max
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const noise = new PerlinNoise2D();
130
+ * const direction = noise.getRange(10, 20, 0, 3); // Returns 0, 1, 2, or 3
131
+ * ```
132
+ */
133
+ getRange(x: number, y: number, min: number, max: number, scale?: number): number;
134
+ /**
135
+ * Gets an integer noise value in a specific range (inclusive)
136
+ *
137
+ * Useful for selecting discrete values like array indices or enum values.
138
+ *
139
+ * @param x - X coordinate
140
+ * @param y - Y coordinate
141
+ * @param min - Minimum integer value (inclusive)
142
+ * @param max - Maximum integer value (inclusive)
143
+ * @param scale - Optional scale factor (default: 0.1)
144
+ * @returns Integer noise value between min and max (inclusive)
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * const noise = new PerlinNoise2D();
149
+ * const directionIndex = noise.getInt(10, 20, 0, 3); // Returns 0, 1, 2, or 3
150
+ * ```
151
+ */
152
+ getInt(x: number, y: number, min: number, max: number, scale?: number): number;
153
+ }
154
+ export declare function getSharedPerlinNoise(seed?: number): PerlinNoise2D;
155
+ /**
156
+ * Resets the shared Perlin noise instance
157
+ *
158
+ * Useful for testing or when you need to change the seed.
159
+ *
160
+ * @param seed - Optional new seed for the instance
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * resetSharedPerlinNoise(12345);
165
+ * ```
166
+ */
167
+ export declare function resetSharedPerlinNoise(seed?: number): void;
package/dist/Player.d.ts CHANGED
@@ -126,5 +126,6 @@ export declare abstract class RpgCommonPlayer {
126
126
  * ```
127
127
  */
128
128
  getDirection(): Direction;
129
+ abstract isEvent(): boolean;
129
130
  }
130
131
  export type PlayerCtor<T extends RpgCommonPlayer = RpgCommonPlayer> = Constructor<T>;
@@ -1,4 +1,11 @@
1
1
  import { RpgCommonPlayer } from '../Player';
2
+ interface ItemData {
3
+ name: string;
4
+ description: string;
5
+ price: number;
6
+ quantity: number;
7
+ onAdd: (player: RpgCommonPlayer) => void;
8
+ }
2
9
  export declare class Item {
3
10
  id: import('@signe/reactive').WritableSignal<string>;
4
11
  name: import('@signe/reactive').WritableSignal<string>;
@@ -6,5 +13,6 @@ export declare class Item {
6
13
  price: import('@signe/reactive').WritableSignal<number>;
7
14
  quantity: import('@signe/reactive').WritableSignal<number>;
8
15
  onAdd: (player: RpgCommonPlayer) => void;
9
- constructor(data: any);
16
+ constructor(data?: ItemData);
10
17
  }
18
+ export {};
package/dist/index.d.ts CHANGED
@@ -7,4 +7,5 @@ export * from './services/updateMap';
7
7
  export * from './Utils';
8
8
  export * from './PrebuiltGui';
9
9
  export * from './database';
10
+ export * from './PerlinNoise';
10
11
  export * from '@rpgjs/physic';