samengine 1.9.0 → 1.10.0

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 (87) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +203 -0
  3. package/dist/config/buildconfig.d.ts +146 -0
  4. package/dist/config/buildconfig.js +115 -0
  5. package/dist/config/index.d.ts +9 -0
  6. package/dist/config/index.js +1 -0
  7. package/dist/core.d.ts +17 -0
  8. package/dist/core.js +24 -0
  9. package/dist/html.d.ts +29 -0
  10. package/dist/html.js +20 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.js +1 -2
  13. package/dist/input.d.ts +51 -0
  14. package/dist/input.js +44 -3
  15. package/dist/keys.d.ts +6 -0
  16. package/dist/keys.js +6 -2
  17. package/dist/logger.d.ts +8 -0
  18. package/dist/logger.js +8 -1
  19. package/dist/nonbrowser/getversion.d.ts +13 -0
  20. package/dist/nonbrowser/getversion.js +35 -0
  21. package/dist/nonbrowser/ghresolver.d.ts +1 -0
  22. package/dist/nonbrowser/ghresolver.js +7 -0
  23. package/dist/nonbrowser/index.d.ts +9 -0
  24. package/dist/nonbrowser/index.js +9 -0
  25. package/dist/nonbrowser/internal/buildhelper.d.ts +42 -0
  26. package/dist/nonbrowser/internal/buildhelper.js +144 -0
  27. package/dist/nonbrowser/internal/cli/argparser.d.ts +20 -0
  28. package/dist/nonbrowser/internal/cli/argparser.js +36 -0
  29. package/dist/nonbrowser/internal/cli/main.d.ts +13 -0
  30. package/dist/nonbrowser/internal/cli/main.js +262 -0
  31. package/dist/nonbrowser/internal/config.d.ts +9 -0
  32. package/dist/nonbrowser/internal/config.js +40 -0
  33. package/dist/nonbrowser/internal/exporthtml.d.ts +37 -0
  34. package/dist/nonbrowser/internal/exporthtml.js +622 -0
  35. package/dist/nonbrowser/internal/projcreator/downloadZip.d.ts +4 -0
  36. package/dist/nonbrowser/internal/projcreator/downloadZip.js +83 -0
  37. package/dist/nonbrowser/internal/projcreator/main.d.ts +1 -0
  38. package/dist/nonbrowser/internal/projcreator/main.js +81 -0
  39. package/dist/nonbrowser/utils.d.ts +8 -0
  40. package/dist/nonbrowser/utils.js +18 -0
  41. package/dist/physics/collision.d.ts +33 -0
  42. package/dist/physics/collision.js +27 -0
  43. package/dist/physics/physicsEngine.d.ts +18 -0
  44. package/dist/physics/physicsEngine.js +18 -0
  45. package/dist/physics/physicsObject.d.ts +20 -0
  46. package/dist/physics/physicsObject.js +20 -0
  47. package/dist/renderer.d.ts +85 -2
  48. package/dist/renderer.js +86 -7
  49. package/dist/samegui/index.d.ts +49 -0
  50. package/dist/samegui/index.js +137 -0
  51. package/dist/save.d.ts +30 -0
  52. package/dist/save.js +25 -0
  53. package/dist/sound/audioplayer.d.ts +39 -0
  54. package/dist/sound/audioplayer.js +39 -5
  55. package/dist/storage/index.d.ts +57 -0
  56. package/dist/storage/index.js +89 -0
  57. package/dist/text/index.d.ts +14 -0
  58. package/dist/text/index.js +58 -0
  59. package/dist/texture.d.ts +100 -0
  60. package/dist/texture.js +75 -41
  61. package/dist/types/button.d.ts +25 -0
  62. package/dist/types/button.js +22 -0
  63. package/dist/types/circle.d.ts +26 -0
  64. package/dist/types/circle.js +21 -7
  65. package/dist/types/color.d.ts +17 -0
  66. package/dist/types/color.js +11 -1
  67. package/dist/types/index.d.ts +1 -1
  68. package/dist/types/index.js +1 -1
  69. package/dist/types/rectangle.d.ts +29 -0
  70. package/dist/types/rectangle.js +23 -6
  71. package/dist/types/triangle.d.ts +23 -0
  72. package/dist/types/triangle.js +20 -6
  73. package/dist/types/vector2d.d.ts +42 -0
  74. package/dist/types/vector2d.js +39 -11
  75. package/dist/types/vector3d.d.ts +38 -0
  76. package/dist/types/vector3d.js +35 -11
  77. package/dist/utils/index.d.ts +13 -4
  78. package/dist/utils/index.js +26 -2
  79. package/dist/utils/logger/index.d.ts +24 -0
  80. package/dist/utils/logger/index.js +44 -0
  81. package/dist/utils/math.d.ts +18 -0
  82. package/dist/utils/math.js +18 -4
  83. package/package.json +40 -10
  84. package/dist/utils/jsonc-parser.d.ts +0 -4
  85. package/dist/utils/jsonc-parser.js +0 -166
  86. package/dist/utils/markdown.d.ts +0 -41
  87. package/dist/utils/markdown.js +0 -699
@@ -1,5 +1,8 @@
1
1
  import { Mouse } from "../input.js";
2
2
  import { type Vector2d } from "./vector2d.js";
3
+ /**
4
+ * Triangle shape represented by three points.
5
+ */
3
6
  export type Triangle = {
4
7
  x1: number;
5
8
  y1: number;
@@ -8,9 +11,29 @@ export type Triangle = {
8
11
  x3: number;
9
12
  y3: number;
10
13
  };
14
+ /**
15
+ * Creates a triangle from three points.
16
+ */
11
17
  export declare function makeTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): Triangle;
18
+ /**
19
+ * Returns the centroid of the triangle.
20
+ */
12
21
  export declare function centerTriangle(triangle: Triangle): Vector2d;
22
+ /**
23
+ * Checks whether a point lies inside the triangle.
24
+ *
25
+ * Uses an area comparison with a small tolerance to avoid floating point noise.
26
+ */
13
27
  export declare function isPointInTriangle(x: number, y: number, triangle: Triangle): boolean;
28
+ /**
29
+ * Checks whether the current mouse position is inside the triangle.
30
+ */
14
31
  export declare function isMouseInTriangle(mouse: Mouse, triangle: Triangle): boolean;
32
+ /**
33
+ * Checks whether the triangle was clicked during the current frame.
34
+ */
15
35
  export declare function isTriangleClicked(mouse: Mouse, triangle: Triangle): boolean;
36
+ /**
37
+ * Returns the perimeter length of the triangle.
38
+ */
16
39
  export declare function getTrianglePerimeter(triangle: Triangle): number;
@@ -1,5 +1,7 @@
1
1
  // Triangle Type for Hitboxes
2
- // Function to create an Object of Type triangle
2
+ /**
3
+ * Creates a triangle from three points.
4
+ */
3
5
  export function makeTriangle(x1, y1, x2, y2, x3, y3) {
4
6
  return {
5
7
  x1: x1,
@@ -14,14 +16,20 @@ export function makeTriangle(x1, y1, x2, y2, x3, y3) {
14
16
  function getTriangleArea(x1, y1, x2, y2, x3, y3) {
15
17
  return Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
16
18
  }
17
- // Function to get the Center of the Triangle
19
+ /**
20
+ * Returns the centroid of the triangle.
21
+ */
18
22
  export function centerTriangle(triangle) {
19
23
  return {
20
24
  x: (triangle.x1 + triangle.x2 + triangle.x3) / 3,
21
25
  y: (triangle.y1 + triangle.y2 + triangle.y3) / 3
22
26
  };
23
27
  }
24
- // Check if a Point is in the Triangle using barycentric coordinates
28
+ /**
29
+ * Checks whether a point lies inside the triangle.
30
+ *
31
+ * Uses an area comparison with a small tolerance to avoid floating point noise.
32
+ */
25
33
  export function isPointInTriangle(x, y, triangle) {
26
34
  const areaTriangle = getTriangleArea(triangle.x1, triangle.y1, triangle.x2, triangle.y2, triangle.x3, triangle.y3);
27
35
  const area1 = getTriangleArea(x, y, triangle.x2, triangle.y2, triangle.x3, triangle.y3);
@@ -29,15 +37,21 @@ export function isPointInTriangle(x, y, triangle) {
29
37
  const area3 = getTriangleArea(triangle.x1, triangle.y1, triangle.x2, triangle.y2, x, y);
30
38
  return Math.abs(areaTriangle - (area1 + area2 + area3)) < 0.01;
31
39
  }
32
- // Check if Mouse is in the Triangle
40
+ /**
41
+ * Checks whether the current mouse position is inside the triangle.
42
+ */
33
43
  export function isMouseInTriangle(mouse, triangle) {
34
44
  return isPointInTriangle(mouse.x, mouse.y, triangle);
35
45
  }
36
- // Function to check if a Triangle is clicked
46
+ /**
47
+ * Checks whether the triangle was clicked during the current frame.
48
+ */
37
49
  export function isTriangleClicked(mouse, triangle) {
38
50
  return isMouseInTriangle(mouse, triangle) && mouse.justPressed;
39
51
  }
40
- // Get the Perimeter of the Triangle
52
+ /**
53
+ * Returns the perimeter length of the triangle.
54
+ */
41
55
  export function getTrianglePerimeter(triangle) {
42
56
  const side1 = Math.sqrt((triangle.x2 - triangle.x1) * (triangle.x2 - triangle.x1) +
43
57
  (triangle.y2 - triangle.y1) * (triangle.y2 - triangle.y1));
@@ -1,15 +1,57 @@
1
+ /**
2
+ * Two-dimensional vector for positions, directions, velocities, and sizes.
3
+ */
1
4
  export type Vector2d = {
2
5
  x: number;
3
6
  y: number;
4
7
  };
8
+ /**
9
+ * Creates a new 2D vector.
10
+ */
5
11
  export declare function makeVector2d(x: number, y: number): Vector2d;
12
+ /**
13
+ * Adds two vectors and returns a new vector.
14
+ */
6
15
  export declare function add2d(vector1: Vector2d, vector2: Vector2d): Vector2d;
16
+ /**
17
+ * Subtracts `vector2` from `vector1` and returns a new vector.
18
+ */
7
19
  export declare function subtract2d(vector1: Vector2d, vector2: Vector2d): Vector2d;
20
+ /**
21
+ * Returns the Euclidean length/magnitude of a vector.
22
+ */
8
23
  export declare function length2d(vector: Vector2d): number;
24
+ /**
25
+ * Normalizes a vector to length `1`.
26
+ *
27
+ * Important: this function mutates and returns the original vector object. Zero
28
+ * vectors are returned unchanged.
29
+ */
9
30
  export declare function normalize2d(vector: Vector2d): Vector2d;
31
+ /**
32
+ * Returns the dot product of two vectors.
33
+ */
10
34
  export declare function dot2d(v1: Vector2d, v2: Vector2d): number;
35
+ /**
36
+ * Returns the distance between two vector positions.
37
+ */
11
38
  export declare function distance2d(v1: Vector2d, v2: Vector2d): number;
39
+ /**
40
+ * Clamps each component of `vector` between the matching `min` and `max`
41
+ * component.
42
+ */
12
43
  export declare function clamp2d(vector: Vector2d, min: Vector2d, max: Vector2d): Vector2d;
44
+ /**
45
+ * Linearly interpolates each component from `start` to `end`.
46
+ *
47
+ * `t.x` controls x interpolation and `t.y` controls y interpolation.
48
+ */
13
49
  export declare function lerp2d(start: Vector2d, end: Vector2d, t: Vector2d): Vector2d;
50
+ /**
51
+ * Maps each vector component from one numeric range into another range.
52
+ */
14
53
  export declare function map2d(value: Vector2d, inMin: Vector2d, inMax: Vector2d, outMin: Vector2d, outMax: Vector2d): Vector2d;
54
+ /**
55
+ * Multiplies both vector components by a scalar.
56
+ */
15
57
  export declare function scale2d(value: Vector2d, vscale: number): Vector2d;
@@ -1,33 +1,46 @@
1
1
  // 2 Dimensional Vector Type
2
2
  import { clamp, lerp, map, scale } from "../utils/math.js";
3
- // Function to create an Object of Type Vector2D
3
+ /**
4
+ * Creates a new 2D vector.
5
+ */
4
6
  export function makeVector2d(x, y) {
5
7
  return {
6
8
  x: x,
7
9
  y: y
8
10
  };
9
11
  }
10
- // Function to add 2 Vectors together
12
+ /**
13
+ * Adds two vectors and returns a new vector.
14
+ */
11
15
  export function add2d(vector1, vector2) {
12
16
  return {
13
17
  x: vector1.x + vector2.x,
14
18
  y: vector1.y + vector2.y,
15
19
  };
16
20
  }
17
- // Function to subtract 2 Vectors from each other
21
+ /**
22
+ * Subtracts `vector2` from `vector1` and returns a new vector.
23
+ */
18
24
  export function subtract2d(vector1, vector2) {
19
25
  return {
20
26
  x: vector1.x - vector2.x,
21
27
  y: vector1.y - vector2.y,
22
28
  };
23
29
  }
24
- // Function to get the length from an Vector
30
+ /**
31
+ * Returns the Euclidean length/magnitude of a vector.
32
+ */
25
33
  export function length2d(vector) {
26
34
  let produkt = vector.x * vector.x + vector.y * vector.y;
27
35
  let root = Math.sqrt(produkt);
28
36
  return root;
29
37
  }
30
- // Function to normalize a Vector 2d
38
+ /**
39
+ * Normalizes a vector to length `1`.
40
+ *
41
+ * Important: this function mutates and returns the original vector object. Zero
42
+ * vectors are returned unchanged.
43
+ */
31
44
  export function normalize2d(vector) {
32
45
  // Check if the Vector is zero because then you dont need to
33
46
  // calculate sth
@@ -39,38 +52,53 @@ export function normalize2d(vector) {
39
52
  vector.y = vector.y / root;
40
53
  return vector;
41
54
  }
42
- // Function to make scalar produkt from an Vector
55
+ /**
56
+ * Returns the dot product of two vectors.
57
+ */
43
58
  export function dot2d(v1, v2) {
44
59
  return (v1.x * v2.x + v1.y * v2.y);
45
60
  }
46
61
  // crossprodukt (only for 3 Dimensinal Vectors)
47
- // Calculate the Distance between 2 Vectors
62
+ /**
63
+ * Returns the distance between two vector positions.
64
+ */
48
65
  export function distance2d(v1, v2) {
49
66
  let tmp = subtract2d(v1, v2);
50
67
  return length2d(tmp);
51
68
  }
52
- // Function to clamp a Vector 2d
69
+ /**
70
+ * Clamps each component of `vector` between the matching `min` and `max`
71
+ * component.
72
+ */
53
73
  export function clamp2d(vector, min, max) {
54
74
  return {
55
75
  x: clamp(vector.x, min.x, max.x),
56
76
  y: clamp(vector.y, min.y, max.y),
57
77
  };
58
78
  }
59
- // Lerp for a 2d Vector
79
+ /**
80
+ * Linearly interpolates each component from `start` to `end`.
81
+ *
82
+ * `t.x` controls x interpolation and `t.y` controls y interpolation.
83
+ */
60
84
  export function lerp2d(start, end, t) {
61
85
  return {
62
86
  x: lerp(start.x, end.x, t.x),
63
87
  y: lerp(start.y, end.y, t.y),
64
88
  };
65
89
  }
66
- // Map Function for a 2d Vector
90
+ /**
91
+ * Maps each vector component from one numeric range into another range.
92
+ */
67
93
  export function map2d(value, inMin, inMax, outMin, outMax) {
68
94
  return {
69
95
  x: map(value.x, inMin.x, inMax.x, outMin.x, outMax.x),
70
96
  y: map(value.y, inMin.y, inMax.y, outMin.y, outMax.y),
71
97
  };
72
98
  }
73
- // Function to scale a Vector
99
+ /**
100
+ * Multiplies both vector components by a scalar.
101
+ */
74
102
  export function scale2d(value, vscale) {
75
103
  return {
76
104
  x: scale(value.x, vscale),
@@ -1,16 +1,54 @@
1
+ /**
2
+ * Three-dimensional vector for positions, directions, and velocities.
3
+ */
1
4
  export type Vector3d = {
2
5
  x: number;
3
6
  y: number;
4
7
  z: number;
5
8
  };
9
+ /**
10
+ * Creates a new 3D vector.
11
+ */
6
12
  export declare function makeVector3d(x: number, y: number, z: number): Vector3d;
13
+ /**
14
+ * Adds two vectors and returns a new vector.
15
+ */
7
16
  export declare function add3d(vector1: Vector3d, vector2: Vector3d): Vector3d;
17
+ /**
18
+ * Subtracts `vector2` from `vector1` and returns a new vector.
19
+ */
8
20
  export declare function subtract3d(vector1: Vector3d, vector2: Vector3d): Vector3d;
21
+ /**
22
+ * Returns the Euclidean length/magnitude of a 3D vector.
23
+ */
9
24
  export declare function length3d(vector: Vector3d): number;
25
+ /**
26
+ * Normalizes a vector to length `1`.
27
+ *
28
+ * Important: this function mutates and returns the original vector object.
29
+ */
10
30
  export declare function normalize3d(vector: Vector3d): Vector3d;
31
+ /**
32
+ * Returns the dot product of two vectors.
33
+ */
11
34
  export declare function dot3d(v1: Vector3d, v2: Vector3d): number;
35
+ /**
36
+ * Returns the cross product of two 3D vectors.
37
+ */
12
38
  export declare function crossprodukt3d(v1: Vector3d, v2: Vector3d): Vector3d;
39
+ /**
40
+ * Returns the distance between two 3D vector positions.
41
+ */
13
42
  export declare function distance3d(v1: Vector3d, v2: Vector3d): number;
43
+ /**
44
+ * Clamps vector components between the matching `min` and `max` components.
45
+ */
14
46
  export declare function clamp3d(vector: Vector3d, min: Vector3d, max: Vector3d): Vector3d;
47
+ /**
48
+ * Linearly interpolates each component from `start` to `end`.
49
+ */
15
50
  export declare function lerp3d(start: Vector3d, end: Vector3d, t: Vector3d): Vector3d;
51
+ /**
52
+ * Maps each vector component from one numeric range into another range.
53
+ */
16
54
  export declare function map3d(value: Vector3d, inMin: Vector3d, inMax: Vector3d, outMin: Vector3d, outMax: Vector3d): Vector3d;
@@ -1,6 +1,8 @@
1
1
  // 3d Vector
2
2
  import { clamp, lerp, map } from "../utils/math.js";
3
- // Function to create an Object of Type Vector3D
3
+ /**
4
+ * Creates a new 3D vector.
5
+ */
4
6
  export function makeVector3d(x, y, z) {
5
7
  return {
6
8
  x: x,
@@ -8,7 +10,9 @@ export function makeVector3d(x, y, z) {
8
10
  z: z
9
11
  };
10
12
  }
11
- // Function to add 2 Vectors together
13
+ /**
14
+ * Adds two vectors and returns a new vector.
15
+ */
12
16
  export function add3d(vector1, vector2) {
13
17
  return {
14
18
  x: vector1.x + vector2.x,
@@ -16,7 +20,9 @@ export function add3d(vector1, vector2) {
16
20
  z: vector1.z + vector2.z,
17
21
  };
18
22
  }
19
- // Function to subtract 2 Vectors from each other
23
+ /**
24
+ * Subtracts `vector2` from `vector1` and returns a new vector.
25
+ */
20
26
  export function subtract3d(vector1, vector2) {
21
27
  return {
22
28
  x: vector1.x - vector2.x,
@@ -24,13 +30,19 @@ export function subtract3d(vector1, vector2) {
24
30
  z: vector1.z - vector2.z,
25
31
  };
26
32
  }
27
- // Function to get the length from an Vector
33
+ /**
34
+ * Returns the Euclidean length/magnitude of a 3D vector.
35
+ */
28
36
  export function length3d(vector) {
29
37
  let produkt = vector.x * vector.x + vector.y * vector.y + vector.z * vector.z;
30
38
  let root = Math.sqrt(produkt);
31
39
  return root;
32
40
  }
33
- // Function to normalize a Vector 2d
41
+ /**
42
+ * Normalizes a vector to length `1`.
43
+ *
44
+ * Important: this function mutates and returns the original vector object.
45
+ */
34
46
  export function normalize3d(vector) {
35
47
  // Check if the Vector is zero because then you dont need to
36
48
  // calculate sth
@@ -43,11 +55,15 @@ export function normalize3d(vector) {
43
55
  vector.z = vector.z / root;
44
56
  return vector;
45
57
  }
46
- // Function to make scalar produkt from an Vector
58
+ /**
59
+ * Returns the dot product of two vectors.
60
+ */
47
61
  export function dot3d(v1, v2) {
48
62
  return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
49
63
  }
50
- // Function to calculate the cross produkt
64
+ /**
65
+ * Returns the cross product of two 3D vectors.
66
+ */
51
67
  export function crossprodukt3d(v1, v2) {
52
68
  return {
53
69
  x: (v1.y * v2.z - v1.z * v2.y),
@@ -55,12 +71,16 @@ export function crossprodukt3d(v1, v2) {
55
71
  z: (v1.x * v2.y - v1.y * v2.x),
56
72
  };
57
73
  }
58
- // Calculate the Distance between 2 Vectors
74
+ /**
75
+ * Returns the distance between two 3D vector positions.
76
+ */
59
77
  export function distance3d(v1, v2) {
60
78
  let tmp = subtract3d(v1, v2);
61
79
  return length3d(tmp);
62
80
  }
63
- // Function to clamp a Vector 3d
81
+ /**
82
+ * Clamps vector components between the matching `min` and `max` components.
83
+ */
64
84
  export function clamp3d(vector, min, max) {
65
85
  return {
66
86
  x: clamp(vector.x, min.x, max.x),
@@ -68,7 +88,9 @@ export function clamp3d(vector, min, max) {
68
88
  z: clamp(vector.y, min.y, max.y),
69
89
  };
70
90
  }
71
- // Lerp for a 3d Vector
91
+ /**
92
+ * Linearly interpolates each component from `start` to `end`.
93
+ */
72
94
  export function lerp3d(start, end, t) {
73
95
  return {
74
96
  x: lerp(start.x, end.x, t.x),
@@ -76,7 +98,9 @@ export function lerp3d(start, end, t) {
76
98
  z: lerp(start.y, end.y, t.y),
77
99
  };
78
100
  }
79
- // Map Function for a 3d Vector
101
+ /**
102
+ * Maps each vector component from one numeric range into another range.
103
+ */
80
104
  export function map3d(value, inMin, inMax, outMin, outMax) {
81
105
  return {
82
106
  x: map(value.x, inMin.x, inMax.x, outMin.x, outMax.x),
@@ -1,5 +1,14 @@
1
1
  export { clamp, lerp, map, scale } from "./math.js";
2
- export type { ParseOptions as MarkdownParseOptions } from "./markdown.js";
3
- export { parse as parseMarkdown, parseToDocument as parseMarkdownToDocument, exportcss as exportMarkdownCSS } from "./markdown.js";
4
- export type { JSONValue } from "./jsonc-parser.js";
5
- export { parseJSONC } from "./jsonc-parser.js";
2
+ /**
3
+ * Creates a small deterministic 32-bit hash from a string.
4
+ *
5
+ * Used internally by the immediate-mode HTML UI to turn labels into stable
6
+ * numeric ids. This is not a cryptographic hash.
7
+ */
8
+ export declare function hash(str: string): number;
9
+ /**
10
+ * Shuffles an array in place using the Fisher-Yates algorithm.
11
+ *
12
+ * The same array instance is returned for convenient chaining.
13
+ */
14
+ export declare function shuffle<T>(array: T[]): T[];
@@ -1,5 +1,29 @@
1
1
  // Utils Package
2
2
  // Math Utilities
3
3
  export { clamp, lerp, map, scale } from "./math.js";
4
- export { parse as parseMarkdown, parseToDocument as parseMarkdownToDocument, exportcss as exportMarkdownCSS } from "./markdown.js";
5
- export { parseJSONC } from "./jsonc-parser.js";
4
+ /**
5
+ * Creates a small deterministic 32-bit hash from a string.
6
+ *
7
+ * Used internally by the immediate-mode HTML UI to turn labels into stable
8
+ * numeric ids. This is not a cryptographic hash.
9
+ */
10
+ export function hash(str) {
11
+ let h = 0;
12
+ for (let i = 0; i < str.length; i++) {
13
+ h = (h << 5) - h + str.charCodeAt(i);
14
+ h |= 0; // 32bit int
15
+ }
16
+ return h;
17
+ }
18
+ /**
19
+ * Shuffles an array in place using the Fisher-Yates algorithm.
20
+ *
21
+ * The same array instance is returned for convenient chaining.
22
+ */
23
+ export function shuffle(array) {
24
+ for (let i = array.length - 1; i > 0; i--) {
25
+ const j = Math.floor(Math.random() * (i + 1));
26
+ [array[i], array[j]] = [array[j], array[i]];
27
+ }
28
+ return array;
29
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Function to get the Date for the Logger
3
+ * @returns String for the current Date
4
+ */
5
+ export declare function getDate(): string;
6
+ /**
7
+ * Logger Class for samengine
8
+ */
9
+ export declare class Logger {
10
+ constructor();
11
+ log(input: string): void;
12
+ warn(input: string): void;
13
+ error(input: string): void;
14
+ }
15
+ /**
16
+ * Logger Class with the same functions but they are doing nothing
17
+ * to remove the console logs in the export
18
+ */
19
+ export declare class ExportLogger {
20
+ constructor();
21
+ log(input: string): void;
22
+ warn(input: string): void;
23
+ error(input: string): void;
24
+ }
@@ -0,0 +1,44 @@
1
+ // Logger
2
+ /**
3
+ * Function to get the Date for the Logger
4
+ * @returns String for the current Date
5
+ */
6
+ export function getDate() {
7
+ const now = new Date();
8
+ const time = `[${now.getHours().toString().padStart(2, "0")}:` +
9
+ `${now.getMinutes().toString().padStart(2, "0")}:` +
10
+ `${now.getSeconds().toString().padStart(2, "0")}.` +
11
+ `${now.getMilliseconds().toString().padStart(3, "0")}]`;
12
+ return time;
13
+ }
14
+ /**
15
+ * Logger Class for samengine
16
+ */
17
+ export class Logger {
18
+ constructor() { }
19
+ log(input) {
20
+ console.log(`${getDate()} ${input}`);
21
+ }
22
+ warn(input) {
23
+ console.warn(`${getDate()} ${input}`);
24
+ }
25
+ error(input) {
26
+ console.error(`${getDate()} ${input}`);
27
+ }
28
+ }
29
+ /**
30
+ * Logger Class with the same functions but they are doing nothing
31
+ * to remove the console logs in the export
32
+ */
33
+ export class ExportLogger {
34
+ constructor() { }
35
+ log(input) {
36
+ // Empty
37
+ }
38
+ warn(input) {
39
+ // Empty
40
+ }
41
+ error(input) {
42
+ // Empty
43
+ }
44
+ }
@@ -1,4 +1,22 @@
1
+ /**
2
+ * Restricts a number to the inclusive range between `min` and `max`.
3
+ */
1
4
  export declare function clamp(input: number, min: number, max: number): number;
5
+ /**
6
+ * Linear interpolation between `start` and `end`.
7
+ *
8
+ * `t = 0` returns `start`, `t = 1` returns `end`, and values between them blend.
9
+ */
2
10
  export declare function lerp(start: number, end: number, t: number): number;
11
+ /**
12
+ * Maps a number from one range into another range.
13
+ *
14
+ * Example: `map(5, 0, 10, 0, 100)` returns `50`.
15
+ */
3
16
  export declare function map(value: number, inMin: number, inMax: number, outMin: number, outMax: number): number;
17
+ /**
18
+ * Multiplies two numbers.
19
+ *
20
+ * Kept as a tiny utility so vector helpers can use the same naming style.
21
+ */
4
22
  export declare function scale(n1: number, n2: number): number;
@@ -1,16 +1,30 @@
1
- // Clamp
1
+ /**
2
+ * Restricts a number to the inclusive range between `min` and `max`.
3
+ */
2
4
  export function clamp(input, min, max) {
3
5
  return Math.min(Math.max(input, min), max);
4
6
  }
5
- // Lerp
7
+ /**
8
+ * Linear interpolation between `start` and `end`.
9
+ *
10
+ * `t = 0` returns `start`, `t = 1` returns `end`, and values between them blend.
11
+ */
6
12
  export function lerp(start, end, t) {
7
13
  return (start + (end - start) * t);
8
14
  }
9
- // Map
15
+ /**
16
+ * Maps a number from one range into another range.
17
+ *
18
+ * Example: `map(5, 0, 10, 0, 100)` returns `50`.
19
+ */
10
20
  export function map(value, inMin, inMax, outMin, outMax) {
11
21
  return (outMax - outMin) * ((value - inMin) / (inMax - inMin)) + outMin;
12
22
  }
13
- // Scale
23
+ /**
24
+ * Multiplies two numbers.
25
+ *
26
+ * Kept as a tiny utility so vector helpers can use the same naming style.
27
+ */
14
28
  export function scale(n1, n2) {
15
29
  return n1 * n2;
16
30
  }