samengine 1.7.3 → 1.7.5

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 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
  -->
@@ -1,4 +1,4 @@
1
1
  // Function to get the Version
2
2
  export function version() {
3
- return "1.7.3";
3
+ return "1.7.5";
4
4
  }
@@ -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";
@@ -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";
@@ -5,3 +5,4 @@ export declare class PhysicsWorld {
5
5
  gravity: Vector2d;
6
6
  step(dt: number): void;
7
7
  }
8
+ export declare function setGravityDirection(world: PhysicsWorld, x: number, y: number, strength: number): void;
@@ -74,3 +74,9 @@ export class PhysicsWorld {
74
74
  }
75
75
  }
76
76
  }
77
+ export function setGravityDirection(world, x, y, strength) {
78
+ const len = Math.sqrt(x * x + y * y);
79
+ if (len === 0)
80
+ return;
81
+ world.gravity = makeVector2d((x / len) * strength, (y / len) * strength);
82
+ }
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 = `❌ Failed to load texture: ${finalSrc}`;
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[getresourcepath(src)];
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 = {}) {
@@ -1,8 +1,9 @@
1
1
  import { Rect } from "./rectangle.js";
2
+ import { Mouse } from "../input.js";
2
3
  export type Button = {
3
4
  form: Rect;
4
5
  text: string;
5
6
  };
6
7
  export declare function makeButton(form: Rect, text: string): Button;
7
- export declare function clickedButton(btn: Button): boolean;
8
+ export declare function clickedButton(btn: Button, mouse: Mouse): boolean;
8
9
  export declare function drawButton(btn: Button, ctx: CanvasRenderingContext2D, color?: string, textColor?: string, font?: string): void;
@@ -1,5 +1,4 @@
1
1
  // Button
2
- import { getMouse } from "../input.js";
3
2
  import { isRectClicked } from "./rectangle.js";
4
3
  import { drawRect } from "../renderer.js";
5
4
  import { renderText } from "../renderer.js";
@@ -11,8 +10,7 @@ export function makeButton(form, text) {
11
10
  };
12
11
  }
13
12
  // Prüft, ob der Button geklickt wurde
14
- export function clickedButton(btn) {
15
- const mouse = getMouse();
13
+ export function clickedButton(btn, mouse) {
16
14
  return isRectClicked(mouse, btn.form);
17
15
  }
18
16
  // Zeichnet den Button (Rechteck + Text)
@@ -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";
@@ -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";
@@ -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 {};
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samengine",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "A TypeScript game library to make HTML Games",
5
5
  "sideEffects": false,
6
6
  "files": [