@silkweaver/build 1.3.1 → 1.3.2

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/dist/build.js CHANGED
@@ -277,7 +277,9 @@ async function generate_entry_code(project_folder, proj, asset_mode, engine_path
277
277
  ${var_name}.room_width = ${rm_data.width ?? 640}
278
278
  ${var_name}.room_height = ${rm_data.height ?? 480}
279
279
  ${var_name}.room_speed = ${rm_data.room_speed ?? 60}
280
- ${var_name}.room_persistent = ${rm_data.persistent ?? false}
280
+ ${var_name}.room_persistent = ${rm_data.persistent ?? false}${room_physics[room_name]
281
+ ? `\n${var_name}.physics_world = true\n${var_name}.physics_gravity_x = ${room_physics[room_name].gx}\n${var_name}.physics_gravity_y = ${room_physics[room_name].gy}`
282
+ : ''}
281
283
  ${var_name}.background_show_color = ${rm_data.bg_show_color ?? true}
282
284
  ${var_name}.background_solid_color = ${hex_to_bgr(rm_data.bg_color ?? '#000000')}${rm_data.creation_code && rm_data.creation_code.trim()
283
285
  ? `\n${var_name}.creation_code = () => {\n${rm_data.creation_code}\n}`
@@ -534,6 +536,9 @@ export default async function init(canvas: HTMLCanvasElement): Promise<void> {
534
536
  // Set up rooms
535
537
  ${room_setups.join('\n')}
536
538
 
539
+ // Register rooms by name (room_goto('rm_x') / room_get('rm_x') / room_exists('rm_x'))
540
+ ${room_names.map(n => `room_register_name('${n}', _room_${n})`).join('\n ')}
541
+
537
542
  // Link room order
538
543
  ${room_var_names.map((v, i) => {
539
544
  const prev = room_var_names[i - 1];
@@ -546,7 +551,9 @@ export default async function init(canvas: HTMLCanvasElement): Promise<void> {
546
551
 
547
552
  const start = ${start_var}
548
553
  if (!start) { console.error('[Game] No rooms defined.'); return }
549
- ${room_physics[start_room] ? ` physics_world_create(${room_physics[start_room].gx}, ${room_physics[start_room].gy})\n` : ''} game_loop.start(start)
554
+ // The physics world is (re)created per-room in room.build_for_entry() from the room's
555
+ // physics_world/gravity fields — so it's fresh on every entry AND every restart.
556
+ game_loop.start(start)
550
557
  }
551
558
  `;
552
559
  return entry_code;
@@ -63,19 +63,6 @@ exports.META_ORDER = [
63
63
  'sprite', 'parent', 'solid', 'visible', 'persistent', 'depth',
64
64
  'physics', 'physics_shape', 'physics_density', 'physics_restitution', 'physics_friction', 'physics_sensor',
65
65
  ];
66
- /**
67
- * Explicit type annotations for static fields whose base-class type is narrower than what TypeScript
68
- * would infer from the literal initializer. Without this, `static physics_shape = 'box'` widens to
69
- * `string`, which doesn't satisfy the base's `'box' | 'circle'` and the subclass fails to compile.
70
- */
71
- const META_TYPES = {
72
- physics_shape: `'box' | 'circle'`,
73
- };
74
- /** Renders a `static <name>[: <type>] = <expr>;` declaration, adding an annotation where one is needed. */
75
- function _static_decl(name, expr) {
76
- const ann = META_TYPES[name];
77
- return `static ${name}${ann ? `: ${ann}` : ''} = ${expr};`;
78
- }
79
66
  /** Canonical GMS-style order of `on_*` event methods (used to keep events ordered in code). */
80
67
  exports.EVENT_ORDER = [
81
68
  'on_create', 'on_destroy',
@@ -239,19 +226,16 @@ function set_static(src, name, expr) {
239
226
  if (!cls)
240
227
  return src;
241
228
  const existing = _find_member(cls, m => ts.isPropertyDeclaration(m) && _is_static(m) && _name_of(m) === name);
229
+ if (existing?.initializer) {
230
+ return _apply(src, { start: existing.initializer.getStart(sf), end: existing.initializer.getEnd(), text: expr });
231
+ }
242
232
  if (existing) {
243
- // For annotated fields (e.g. physics_shape) replace the whole member so the type annotation is
244
- // always present/correct updating just the initializer could leave it un-annotated (→ widens
245
- // to string and fails to compile). For plain fields, the cheaper initializer-only edit is fine.
246
- if (META_TYPES[name])
247
- return _apply(src, { start: existing.getStart(sf), end: existing.getEnd(), text: _static_decl(name, expr) });
248
- if (existing.initializer)
249
- return _apply(src, { start: existing.initializer.getStart(sf), end: existing.initializer.getEnd(), text: expr });
250
- return _apply(src, { start: existing.getStart(sf), end: existing.getEnd(), text: _static_decl(name, expr) });
233
+ // declared without initializer replace the whole member
234
+ return _apply(src, { start: existing.getStart(sf), end: existing.getEnd(), text: `static ${name} = ${expr};` });
251
235
  }
252
236
  // New static: metadata lives at the TOP, ordered by META_ORDER. Insert before the first static
253
237
  // that sorts after it; else before the first non-static member (so statics stay grouped up top).
254
- const stub = ` ${_static_decl(name, expr)}\n`;
238
+ const stub = ` static ${name} = ${expr};\n`;
255
239
  const order = exports.META_ORDER.indexOf(name);
256
240
  if (order >= 0) {
257
241
  const after = cls.members.find(m => {
@@ -584,7 +568,7 @@ function scaffold_object(class_name, kind = 'normal') {
584
568
  if (kind === 'physics') {
585
569
  return `export class ${class_name} extends gm_object {
586
570
  static physics = true;
587
- static physics_shape: 'box' | 'circle' = 'box';
571
+ static physics_shape = 'box';
588
572
  static physics_density = 0.5;
589
573
  static physics_restitution = 0.1;
590
574
  static physics_friction = 0.2;
package/dist/templates.js CHANGED
@@ -51,6 +51,7 @@ const TEMPLATE_REGISTRY = [
51
51
  { id: 'empty', label: 'Empty', description: 'A blank project with a single empty room.' },
52
52
  { id: 'platformer', label: 'Platformer', description: 'A/D to move, Space to jump — gravity, solid platforms, parent-based collision.' },
53
53
  { id: 'topdown', label: 'Top-down', description: 'WASD movement with parent-based wall collision (place_meeting + a _col parent).' },
54
+ { id: 'physics_ball', label: 'Physics Ball', description: 'Bounce a ball on a mouse paddle for score — matter.js physics (circle/box bodies, restitution, instance_nearest).' },
54
55
  ];
55
56
  /** Absolute path to the bundled templates directory (sibling of dist/). */
56
57
  function templates_dir() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silkweaver/build",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Silkweaver toolchain — compiles a project folder into a runnable game (HTML5 / desktop executable). Usable from a CLI or the IDE.",
5
5
  "type": "commonjs",
6
6
  "license": "GPL-3.0",