samengine 1.7.4 → 1.7.6
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 +21 -1
- package/dist/build/index.js +1 -1
- package/dist/physics/index.d.ts +1 -1
- package/dist/physics/index.js +1 -1
- package/dist/physics/physicsEngine.d.ts +1 -0
- package/dist/physics/physicsEngine.js +6 -0
- package/dist/texture.js +4 -6
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +0 -1
- package/dist/utils/markdown.d.ts +1 -2
- package/dist/utils/markdown.js +27 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
A lightweight, TypeScript-first web game engine framework for building
|
|
4
4
|
2D games *and maybe 3D Games in the Future*.
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
## Features
|
|
7
8
|
|
|
8
9
|
- 🎯 Simple game loop management
|
|
@@ -13,6 +14,7 @@ A lightweight, TypeScript-first web game engine framework for building
|
|
|
13
14
|
- 📝 Logging utilities
|
|
14
15
|
- 💾 Save/Load system
|
|
15
16
|
|
|
17
|
+
|
|
16
18
|
## Quick Start
|
|
17
19
|
|
|
18
20
|
```sh
|
|
@@ -25,6 +27,7 @@ npx samengine-build --new
|
|
|
25
27
|
npx samengine-build
|
|
26
28
|
```
|
|
27
29
|
|
|
30
|
+
|
|
28
31
|
### Basic Game Loop
|
|
29
32
|
|
|
30
33
|
```typescript
|
|
@@ -53,8 +56,10 @@ function gameLoop(dt: number) {
|
|
|
53
56
|
startEngine(init, gameLoop);
|
|
54
57
|
```
|
|
55
58
|
|
|
59
|
+
|
|
56
60
|
## Development & Building
|
|
57
61
|
|
|
62
|
+
|
|
58
63
|
### Using Bun (local development)
|
|
59
64
|
|
|
60
65
|
```sh
|
|
@@ -65,6 +70,7 @@ npx samengine-build --new (newproject) # Create a new project with a
|
|
|
65
70
|
npx samengine-build --new-empty (new) # Create a new empty project
|
|
66
71
|
```
|
|
67
72
|
|
|
73
|
+
|
|
68
74
|
### Configuration
|
|
69
75
|
|
|
70
76
|
Edit `samengine.config.ts` to configure your game:
|
|
@@ -95,34 +101,42 @@ export function defineConfig(): buildconfig {
|
|
|
95
101
|
}
|
|
96
102
|
```
|
|
97
103
|
|
|
104
|
+
|
|
98
105
|
## API Reference
|
|
99
106
|
|
|
107
|
+
|
|
100
108
|
### Core Engine
|
|
101
109
|
- `startEngine(init, gameLoop)` - Initialize game loop
|
|
102
110
|
|
|
111
|
+
|
|
103
112
|
### Rendering
|
|
104
113
|
- `renderText(ctx, text, x, y, color?, font?)` - Render text
|
|
105
114
|
- `renderBitmapText()` - Render bitmap font text
|
|
106
115
|
|
|
116
|
+
|
|
107
117
|
### Input System
|
|
108
118
|
- `setupInput(canvas, width?, height?)` - Initialize input
|
|
109
119
|
- `getKeyState(key)` - Check key state
|
|
110
120
|
- Mouse state available via input module
|
|
111
121
|
|
|
122
|
+
|
|
112
123
|
### Types
|
|
113
124
|
- `Vector2D` / `Vector3D` - Vector mathematics
|
|
114
125
|
- `Color` - Color management
|
|
115
126
|
- `Rect` - Rectangle collision
|
|
116
127
|
- Math utilities for game logic
|
|
117
128
|
|
|
129
|
+
|
|
118
130
|
### Utilities
|
|
119
131
|
<!-- - `dlog()` - Development logging -->
|
|
120
132
|
- `startEngine()` - Manage game loop
|
|
121
133
|
|
|
134
|
+
|
|
122
135
|
## License
|
|
123
136
|
|
|
124
137
|
MIT
|
|
125
138
|
|
|
139
|
+
|
|
126
140
|
## More Addons in the Game Library
|
|
127
141
|
|
|
128
142
|
- a Full Markdown Parser *(maybe for notes or easy docs, feel free to use)*
|
|
@@ -130,6 +144,7 @@ MIT
|
|
|
130
144
|
|
|
131
145
|
*(I dont now why i added this)*
|
|
132
146
|
|
|
147
|
+
|
|
133
148
|
## More Tools for samengine and Game Making by me lol
|
|
134
149
|
|
|
135
150
|
- [samengine-build](https://www.npmjs.com/package/samengine-build)
|
|
@@ -137,11 +152,16 @@ MIT
|
|
|
137
152
|
- [old deprecated npm package](https://www.npmjs.com/package/@shadowdara/webgameengine)
|
|
138
153
|
- [linksaver](https://github.com/shadowdara/linksaver)
|
|
139
154
|
|
|
155
|
+
|
|
156
|
+
## Commit Tags
|
|
157
|
+
|
|
158
|
+
The tags which are ending with `-build` are for the `samengine-build` Tool and the
|
|
159
|
+
which end with `-cli` are for the `samengine-cli` package.
|
|
160
|
+
|
|
140
161
|
<!--
|
|
141
162
|
|
|
142
163
|
IDEAS
|
|
143
164
|
|
|
144
|
-
- SVG Integration
|
|
145
165
|
- SVG Generator
|
|
146
166
|
|
|
147
167
|
-->
|
package/dist/build/index.js
CHANGED
package/dist/physics/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { RigidBody, PhysicsObject, } from "./physicsObject.js";
|
|
2
|
-
export { PhysicsWorld } from "./physicsEngine.js";
|
|
2
|
+
export { PhysicsWorld, setGravityDirection } from "./physicsEngine.js";
|
package/dist/physics/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { RigidBody, PhysicsObject, } from "./physicsObject.js";
|
|
2
|
-
export { PhysicsWorld } from "./physicsEngine.js";
|
|
2
|
+
export { PhysicsWorld, setGravityDirection } from "./physicsEngine.js";
|
package/dist/texture.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dlog } from "./logger.js";
|
|
2
2
|
const textures = {};
|
|
3
3
|
function getresourcepath(path) {
|
|
4
|
-
return "resources/" + path;
|
|
4
|
+
return "/resources/" + path;
|
|
5
5
|
}
|
|
6
6
|
// Function to load a Texture Async
|
|
7
7
|
export function loadTextureAsync(src) {
|
|
@@ -13,20 +13,18 @@ export function loadTextureAsync(src) {
|
|
|
13
13
|
const img = new Image();
|
|
14
14
|
// 🔹 Hier Pfad modifizieren, z.B. Prefix hinzufügen
|
|
15
15
|
let finalSrc = getresourcepath(src);
|
|
16
|
-
const cacheKey = finalSrc;
|
|
17
|
-
// Check if resources are embedded (single file build)
|
|
18
16
|
const embeddedResources = window.__resources;
|
|
19
17
|
if (embeddedResources && embeddedResources[src]) {
|
|
20
|
-
// Use embedded resource (data URI)
|
|
21
18
|
finalSrc = embeddedResources[src];
|
|
22
19
|
}
|
|
20
|
+
const cacheKey = src; // 👈 WICHTIG: NICHT finalSrc
|
|
23
21
|
img.onload = () => {
|
|
24
22
|
// Cache speichern - always use the same cache key for consistency
|
|
25
23
|
textures[cacheKey] = img;
|
|
26
24
|
resolve(img);
|
|
27
25
|
};
|
|
28
26
|
img.onerror = () => {
|
|
29
|
-
const msg =
|
|
27
|
+
const msg = `Failed to load texture: ${finalSrc}`;
|
|
30
28
|
console.error(msg);
|
|
31
29
|
reject(new Error(msg));
|
|
32
30
|
};
|
|
@@ -36,7 +34,7 @@ export function loadTextureAsync(src) {
|
|
|
36
34
|
}
|
|
37
35
|
// Function to get the Texture
|
|
38
36
|
export function getTexture(src) {
|
|
39
|
-
return textures[
|
|
37
|
+
return textures[src];
|
|
40
38
|
}
|
|
41
39
|
// Function to draw a texture to the Screen
|
|
42
40
|
export function drawTexture(ctx, texture, x, y, options = {}) {
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { clamp, lerp, map, scale } from "./math.js";
|
|
2
|
+
export type { ParseOptions as MarkdownParseOptions } from "./markdown.js";
|
|
2
3
|
export { parse as parseMarkdown, parseToDocument as parseMarkdownToDocument, exportcss as exportMarkdownCSS } from "./markdown.js";
|
|
3
4
|
export type { JSONValue } from "./jsonc-parser.js";
|
|
4
5
|
export { parseJSONC } from "./jsonc-parser.js";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Utils Package
|
|
2
2
|
// Math Utilities
|
|
3
3
|
export { clamp, lerp, map, scale } from "./math.js";
|
|
4
|
-
// Markdown Parser
|
|
5
4
|
export { parse as parseMarkdown, parseToDocument as parseMarkdownToDocument, exportcss as exportMarkdownCSS } from "./markdown.js";
|
|
6
5
|
export { parseJSONC } from "./jsonc-parser.js";
|
package/dist/utils/markdown.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* geordnete & ungeordnete Listen (verschachtelt), Aufgabenlisten,
|
|
7
7
|
* horizontale Linien, Links, Bilder, Tabellen, Fußnoten, HTML-Entities.
|
|
8
8
|
*/
|
|
9
|
-
interface ParseOptions {
|
|
9
|
+
export interface ParseOptions {
|
|
10
10
|
/** Fügt target="_blank" rel="noopener noreferrer" zu externen Links hinzu */
|
|
11
11
|
externalLinks?: boolean;
|
|
12
12
|
/** Bricht einfache Zeilenumbrüche in <br> um */
|
|
@@ -38,4 +38,3 @@ export declare function parseToDocument(markdown: string, options?: ParseOptions
|
|
|
38
38
|
css?: string;
|
|
39
39
|
}): string;
|
|
40
40
|
export declare function exportcss(): string;
|
|
41
|
-
export {};
|
package/dist/utils/markdown.js
CHANGED
|
@@ -33,6 +33,26 @@ function isExternalUrl(url) {
|
|
|
33
33
|
// Inline-Renderer
|
|
34
34
|
// ---------------------------------------------------------------------------
|
|
35
35
|
function renderInline(text, opts) {
|
|
36
|
+
// ---------------------------------------------------------------------
|
|
37
|
+
// Escaped Zeichen sichern (wichtig für Markdown-Sonderzeichen)
|
|
38
|
+
// ---------------------------------------------------------------------
|
|
39
|
+
const ESCAPES = {
|
|
40
|
+
"\\\\": "\x00ESC_BACKSLASH\x00",
|
|
41
|
+
"\\[": "\x00ESC_LBRACKET\x00",
|
|
42
|
+
"\\]": "\x00ESC_RBRACKET\x00",
|
|
43
|
+
"\\(": "\x00ESC_LPAREN\x00",
|
|
44
|
+
"\\)": "\x00ESC_RPAREN\x00",
|
|
45
|
+
"\\|": "\x00ESC_PIPE\x00",
|
|
46
|
+
'\\"': "\x00ESC_QUOTE\x00",
|
|
47
|
+
"\\*": "\x00ESC_STAR\x00",
|
|
48
|
+
"\\_": "\x00ESC_UNDERSCORE\x00",
|
|
49
|
+
"\\`": "\x00ESC_BACKTICK\x00",
|
|
50
|
+
"\\~": "\x00ESC_TILDE\x00"
|
|
51
|
+
};
|
|
52
|
+
for (const [char, placeholder] of Object.entries(ESCAPES)) {
|
|
53
|
+
const regex = new RegExp(char.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "g");
|
|
54
|
+
text = text.replace(regex, placeholder);
|
|
55
|
+
}
|
|
36
56
|
// Roh-HTML bewahren (falls !sanitize)
|
|
37
57
|
const htmlPlaceholders = [];
|
|
38
58
|
if (!opts.sanitize) {
|
|
@@ -97,6 +117,10 @@ function renderInline(text, opts) {
|
|
|
97
117
|
if (!opts.sanitize) {
|
|
98
118
|
text = text.replace(/\x00HTML(\d+)\x00/g, (_, i) => htmlPlaceholders[+i]);
|
|
99
119
|
}
|
|
120
|
+
// <<< HIER rein
|
|
121
|
+
for (const [char, placeholder] of Object.entries(ESCAPES)) {
|
|
122
|
+
text = text.replace(new RegExp(placeholder, "g"), char.replace("\\", ""));
|
|
123
|
+
}
|
|
100
124
|
return text;
|
|
101
125
|
}
|
|
102
126
|
function parseListItems(lines, baseIndent) {
|
|
@@ -169,10 +193,10 @@ function parseTable(block, opts) {
|
|
|
169
193
|
if (rows.length < 2)
|
|
170
194
|
return `<p>${renderInline(block, opts)}</p>`;
|
|
171
195
|
const headerCells = rows[0]
|
|
172
|
-
.split(
|
|
196
|
+
.split(/(?<!\\)\|/)
|
|
173
197
|
.filter((_, i, a) => !(i === 0 && _ === "") && !(i === a.length - 1 && _ === ""))
|
|
174
198
|
.map((c) => c.trim());
|
|
175
|
-
const alignRow = rows[1].split(
|
|
199
|
+
const alignRow = rows[1].split(/(?<!\\)\|/).filter((c) => /[-:]/.test(c));
|
|
176
200
|
const aligns = alignRow.map((c) => {
|
|
177
201
|
c = c.trim();
|
|
178
202
|
if (c.startsWith(":") && c.endsWith(":"))
|
|
@@ -191,7 +215,7 @@ function parseTable(block, opts) {
|
|
|
191
215
|
.join("\n")}\n</tr>\n</thead>`;
|
|
192
216
|
const bodyRows = rows.slice(2).map((row) => {
|
|
193
217
|
const cells = row
|
|
194
|
-
.split(
|
|
218
|
+
.split(/(?<!\\)\|/)
|
|
195
219
|
.filter((_, i, a) => !(i === 0 && _ === "") && !(i === a.length - 1 && _ === ""))
|
|
196
220
|
.map((c) => c.trim());
|
|
197
221
|
return `<tr>\n${cells
|