@shadowdara/webgameengine 1.0.0 → 1.1.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.
- package/README.md +7 -21
- package/dist/renderer.d.ts +1 -1
- package/dist/texture.js +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.js +9 -2
- package/dist/types/rectangle.d.ts +2 -2
- package/dist/types/vector2d.d.ts +1 -0
- package/dist/types/vector2d.js +8 -1
- package/dist/types/vector3d.d.ts +1 -0
- package/dist/types/vector3d.js +11 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
# WebGameEngine 🎮
|
|
2
2
|
|
|
3
|
-
**(Currently trying to make this into a lib)**
|
|
4
|
-
|
|
5
|
-
**Use `bun tools/build.ts`**
|
|
6
|
-
|
|
7
3
|
A lightweight, TypeScript-first web game engine framework for building 2D games.
|
|
8
4
|
|
|
9
5
|
## Features
|
|
@@ -19,14 +15,7 @@ A lightweight, TypeScript-first web game engine framework for building 2D games.
|
|
|
19
15
|
## Installation
|
|
20
16
|
|
|
21
17
|
```bash
|
|
22
|
-
npm install @
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Or use directly from source:
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
bun install
|
|
29
|
-
bun run dev
|
|
18
|
+
npm install @shadowdara/webgameengine
|
|
30
19
|
```
|
|
31
20
|
|
|
32
21
|
## Quick Start
|
|
@@ -34,7 +23,7 @@ bun run dev
|
|
|
34
23
|
### Basic Game Loop
|
|
35
24
|
|
|
36
25
|
```typescript
|
|
37
|
-
import { startEngine, setupInput, dlog, renderText } from '@
|
|
26
|
+
import { startEngine, setupInput, dlog, renderText } from '@shadowdara/webgameengine';
|
|
38
27
|
|
|
39
28
|
const canvas = document.getElementById('gameCanvas') as HTMLCanvasElement;
|
|
40
29
|
const ctx = canvas.getContext('2d')!;
|
|
@@ -62,19 +51,16 @@ startEngine(init, gameLoop);
|
|
|
62
51
|
### Using Bun (local development)
|
|
63
52
|
|
|
64
53
|
```bash
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
bun tools/build.ts --release # Production build
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
npx webgameengine # Build main game
|
|
55
|
+
npx webgameengine --release # Production build
|
|
70
56
|
```
|
|
71
57
|
|
|
72
58
|
### Configuration
|
|
73
59
|
|
|
74
|
-
Edit `
|
|
60
|
+
Edit `webgameengine.config.ts` to configure your game:
|
|
75
61
|
|
|
76
62
|
```typescript
|
|
77
|
-
import { defineConfig } from '
|
|
63
|
+
import { defineConfig } from '@shadowdara/webgameengine/build';
|
|
78
64
|
|
|
79
65
|
export function defineConfig() {
|
|
80
66
|
return {
|
|
@@ -90,7 +76,7 @@ or
|
|
|
90
76
|
```typescript
|
|
91
77
|
// Project File for the Game
|
|
92
78
|
|
|
93
|
-
import { type buildconfig, new_buildconfig } from "
|
|
79
|
+
import { type buildconfig, new_buildconfig } from "@shadowdara/webgameengine/build";
|
|
94
80
|
|
|
95
81
|
export function defineConfig(): buildconfig {
|
|
96
82
|
let config: buildconfig = new_buildconfig();
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Rect } from "./types/rectangle";
|
|
1
|
+
import { type Rect } from "./types/rectangle.js";
|
|
2
2
|
export declare function renderText(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, color?: string, font?: string): void;
|
|
3
3
|
type CharMap = Record<string, Rect>;
|
|
4
4
|
export declare function renderBitmapText(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, sprite: HTMLImageElement, charMap: CharMap, scale?: number): void;
|
package/dist/texture.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
export {
|
|
1
|
+
export { type Vector2d, normalize2d, clamp2d, lerp2d, map2d } from "./vector2d.js";
|
|
2
|
+
export { type Vector3d, normalize3d, clamp3d, lerp3d, map3d } from "./vector3d.js";
|
|
3
|
+
export { type Color, invertcolor, invertHexColor } from "./color.js";
|
|
4
|
+
export { type Rect, centerRectX, centerRectY, centerRect, isPointInRect, isMouseInRect, isRectClicked } from "./rectangle.js";
|
|
5
|
+
export { clamp, lerp, map } from "./math-utils.js";
|
package/dist/types/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
// Types Export
|
|
2
|
-
|
|
2
|
+
// Vector 2D
|
|
3
|
+
export { normalize2d, clamp2d, lerp2d, map2d } from "./vector2d.js";
|
|
4
|
+
// Vector 3D
|
|
5
|
+
export { normalize3d, clamp3d, lerp3d, map3d } from "./vector3d.js";
|
|
6
|
+
// Color Type
|
|
7
|
+
export { invertcolor, invertHexColor } from "./color.js";
|
|
8
|
+
// Retangle Type
|
|
9
|
+
export { centerRectX, centerRectY, centerRect, isPointInRect, isMouseInRect, isRectClicked } from "./rectangle.js";
|
|
3
10
|
// Math Utilities
|
|
4
|
-
|
|
11
|
+
export { clamp, lerp, map } from "./math-utils.js";
|
package/dist/types/vector2d.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export type Vector2d = {
|
|
|
5
5
|
export declare function normalize2d(vector: Vector2d): Vector2d;
|
|
6
6
|
export declare function clamp2d(vector: Vector2d, min: Vector2d, max: Vector2d): Vector2d;
|
|
7
7
|
export declare function lerp2d(start: Vector2d, end: Vector2d, t: Vector2d): Vector2d;
|
|
8
|
+
export declare function map2d(value: Vector2d, inMin: Vector2d, inMax: Vector2d, outMin: Vector2d, outMax: Vector2d): Vector2d;
|
package/dist/types/vector2d.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 2 Dimensional Vector Type
|
|
2
|
-
import { clamp, lerp } from "./math-utils";
|
|
2
|
+
import { clamp, lerp, map } from "./math-utils.js";
|
|
3
3
|
// Function to normalize a Vector 2d
|
|
4
4
|
export function normalize2d(vector) {
|
|
5
5
|
// Check if the Vector is zero because then you dont need to
|
|
@@ -27,3 +27,10 @@ export function lerp2d(start, end, t) {
|
|
|
27
27
|
y: lerp(start.y, end.y, t.y),
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
// Map Function for a 2d Vector
|
|
31
|
+
export function map2d(value, inMin, inMax, outMin, outMax) {
|
|
32
|
+
return {
|
|
33
|
+
x: map(value.x, inMin.x, inMax.x, outMin.x, outMax.x),
|
|
34
|
+
y: map(value.y, inMin.y, inMax.y, outMin.y, outMax.y),
|
|
35
|
+
};
|
|
36
|
+
}
|
package/dist/types/vector3d.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export type Vector3d = {
|
|
|
6
6
|
export declare function normalize3d(vector: Vector3d): Vector3d;
|
|
7
7
|
export declare function clamp3d(vector: Vector3d, min: Vector3d, max: Vector3d): Vector3d;
|
|
8
8
|
export declare function lerp3d(start: Vector3d, end: Vector3d, t: Vector3d): Vector3d;
|
|
9
|
+
export declare function map3d(value: Vector3d, inMin: Vector3d, inMax: Vector3d, outMin: Vector3d, outMax: Vector3d): Vector3d;
|
package/dist/types/vector3d.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 3d Vector
|
|
2
|
-
import { clamp, lerp } from "./math-utils";
|
|
2
|
+
import { clamp, lerp, map } from "./math-utils.js";
|
|
3
3
|
// Function to normalize a Vector 2d
|
|
4
4
|
export function normalize3d(vector) {
|
|
5
5
|
// Check if the Vector is zero because then you dont need to
|
|
@@ -14,7 +14,7 @@ export function normalize3d(vector) {
|
|
|
14
14
|
vector.z = vector.z / root;
|
|
15
15
|
return vector;
|
|
16
16
|
}
|
|
17
|
-
// Function to clamp a Vector
|
|
17
|
+
// Function to clamp a Vector 3d
|
|
18
18
|
export function clamp3d(vector, min, max) {
|
|
19
19
|
return {
|
|
20
20
|
x: clamp(vector.x, min.x, max.x),
|
|
@@ -22,7 +22,7 @@ export function clamp3d(vector, min, max) {
|
|
|
22
22
|
z: clamp(vector.y, min.y, max.y),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
// Lerp for a
|
|
25
|
+
// Lerp for a 3d Vector
|
|
26
26
|
export function lerp3d(start, end, t) {
|
|
27
27
|
return {
|
|
28
28
|
x: lerp(start.x, end.x, t.x),
|
|
@@ -30,3 +30,11 @@ export function lerp3d(start, end, t) {
|
|
|
30
30
|
z: lerp(start.y, end.y, t.y),
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
// Map Function for a 3d Vector
|
|
34
|
+
export function map3d(value, inMin, inMax, outMin, outMax) {
|
|
35
|
+
return {
|
|
36
|
+
x: map(value.x, inMin.x, inMax.x, outMin.x, outMax.x),
|
|
37
|
+
y: map(value.y, inMin.y, inMax.y, outMin.y, outMax.y),
|
|
38
|
+
z: map(value.z, inMin.z, inMax.z, outMin.z, outMax.z),
|
|
39
|
+
};
|
|
40
|
+
}
|