@silkweaver/build 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.
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ /**
3
+ * Starter templates for the New Project flow.
4
+ *
5
+ * Each template is a real, ready-to-build project folder bundled under `../templates/<id>/`
6
+ * (sprites and all). Creating a project from a template is just a recursive copy of that folder
7
+ * into the destination — no codegen — so the templates stay editable/diffable in the repo and a
8
+ * dogfooded example game *is* the template. Pure Node (fs/path), reusable from the IDE or CLI.
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.list_templates = list_templates;
45
+ exports.create_from_template = create_from_template;
46
+ const fs = __importStar(require("node:fs"));
47
+ const path = __importStar(require("node:path"));
48
+ /** Ordered registry of the bundled starter templates (folders live under ../templates/<id>). */
49
+ const TEMPLATE_REGISTRY = [
50
+ { id: 'empty', label: 'Empty', description: 'A blank project with a single empty room.' },
51
+ { id: 'platformer', label: 'Platformer', description: 'A/D to move, Space to jump — gravity, solid platforms, parent-based collision.' },
52
+ { id: 'topdown', label: 'Top-down', description: 'WASD movement with parent-based wall collision (place_meeting + a _col parent).' },
53
+ ];
54
+ /** Absolute path to the bundled templates directory (sibling of dist/). */
55
+ function templates_dir() {
56
+ return path.join(__dirname, '..', 'templates');
57
+ }
58
+ /** Names never copied into a new project (build artifacts / VCS / deps), as a defensive guard. */
59
+ const COPY_DENYLIST = new Set(['_entry.ts', '_engine_globals.ts', 'node_modules', '.git', 'exports', 'game.js']);
60
+ /** Returns the available starter templates — only those whose folder is actually installed. */
61
+ function list_templates() {
62
+ const out = [];
63
+ for (const t of TEMPLATE_REGISTRY) {
64
+ let display_color = '#1a1a2e';
65
+ try {
66
+ const j = JSON.parse(fs.readFileSync(path.join(templates_dir(), t.id, 'project.json'), 'utf8'));
67
+ if (typeof j?.settings?.displayColor === 'string')
68
+ display_color = j.settings.displayColor;
69
+ }
70
+ catch {
71
+ continue;
72
+ } // folder missing/unreadable → omit it
73
+ out.push({ id: t.id, label: t.label, description: t.description, display_color });
74
+ }
75
+ return out;
76
+ }
77
+ /**
78
+ * Materializes a starter template into `dest_folder` by recursively copying its bundled project
79
+ * folder, then (optionally) setting the display name in project.json.
80
+ * @param template_id - 'empty' | 'platformer' | 'topdown'
81
+ * @param dest_folder - Absolute path of the new project folder (created if missing)
82
+ * @param name - Optional display name to write into project.json
83
+ */
84
+ async function create_from_template(template_id, dest_folder, name) {
85
+ if (!TEMPLATE_REGISTRY.some(t => t.id === template_id))
86
+ throw new Error(`Unknown template: ${template_id}`);
87
+ const src = path.join(templates_dir(), template_id);
88
+ if (!fs.existsSync(path.join(src, 'project.json')))
89
+ throw new Error(`Template '${template_id}' is not installed`);
90
+ if (fs.existsSync(path.join(dest_folder, 'project.json')))
91
+ throw new Error('A project already exists in that folder');
92
+ await fs.promises.mkdir(dest_folder, { recursive: true });
93
+ await fs.promises.cp(src, dest_folder, {
94
+ recursive: true,
95
+ filter: (s) => !COPY_DENYLIST.has(path.basename(s)),
96
+ });
97
+ if (name && name.trim()) {
98
+ const proj_path = path.join(dest_folder, 'project.json');
99
+ try {
100
+ const j = JSON.parse(await fs.promises.readFile(proj_path, 'utf8'));
101
+ j.name = name.trim();
102
+ await fs.promises.writeFile(proj_path, JSON.stringify(j, null, 2) + '\n', 'utf8');
103
+ }
104
+ catch { /* keep the template's bundled name */ }
105
+ }
106
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silkweaver/build",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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",
@@ -23,14 +23,15 @@
23
23
  },
24
24
  "files": [
25
25
  "dist",
26
- "assets"
26
+ "assets",
27
+ "templates"
27
28
  ],
28
29
  "scripts": {
29
30
  "build": "tsc -p ."
30
31
  },
31
32
  "dependencies": {
32
- "@silkweaver/engine": "1.0.0",
33
- "@silkweaver/project": "1.0.0",
33
+ "@silkweaver/engine": "^1.0.0",
34
+ "@silkweaver/project": "^1.0.0",
34
35
  "@electron/packager": "^19.0.5",
35
36
  "esbuild": "^0.27.2",
36
37
  "typescript": "^5.9.3"
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "Empty",
3
+ "version": "1.0.0",
4
+ "engineVersion": "1.0.0",
5
+ "settings": {
6
+ "roomSpeed": 60,
7
+ "windowWidth": 640,
8
+ "windowHeight": 480,
9
+ "startRoom": "room_main",
10
+ "displayColor": "#1a1a2e"
11
+ },
12
+ "resources": {
13
+ "sprites": {},
14
+ "sounds": {},
15
+ "backgrounds": {},
16
+ "paths": {},
17
+ "scripts": {},
18
+ "fonts": {},
19
+ "timelines": {},
20
+ "objects": {},
21
+ "rooms": {
22
+ "room_main": {
23
+ "name": "room_main"
24
+ }
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "width": 640,
3
+ "height": 480,
4
+ "room_speed": 60,
5
+ "persistent": false,
6
+ "creation_code": "",
7
+ "instances": [],
8
+ "backgrounds": [],
9
+ "views": [],
10
+ "tiles": [],
11
+ "bg_color": "#1a1a2e",
12
+ "bg_show_color": true,
13
+ "physics_world": false,
14
+ "physics_gravity_x": 0,
15
+ "physics_gravity_y": 10
16
+ }
@@ -0,0 +1,3 @@
1
+ export class _col extends gm_object {
2
+ static visible = false
3
+ }
@@ -0,0 +1,10 @@
1
+ export class obj_platform extends gm_object {
2
+ on_create(): void {
3
+ }
4
+
5
+ // block width
6
+ // block height
7
+
8
+ static parent = _col
9
+ static sprite = 'spr_platform'
10
+ }
@@ -0,0 +1,73 @@
1
+ export class obj_player extends gm_object {
2
+ spd = 5;
3
+ jump_force = 15;
4
+ weight = 1;
5
+
6
+ on_create(): void {
7
+ this.grounded = false;
8
+ this.vertical_acc = 0.0;
9
+ this.vertical_vel = 0.0;
10
+ this.horizontal_vel = 0.0;
11
+ }
12
+
13
+ on_step(): void {
14
+ // controlls
15
+ let key_left = keyboard_check(ord("A"));
16
+ let key_right = keyboard_check(ord("D"));
17
+ let key_jump = keyboard_check(vk_space);
18
+
19
+ // ------------------------------
20
+ // left to right
21
+ // ------------------------------
22
+
23
+ // motion
24
+ let dir = 0;
25
+ if (key_left) {
26
+ dir = -1;
27
+ }
28
+
29
+ if (key_right) {
30
+ dir = 1;
31
+ }
32
+
33
+ // movenemt
34
+ this.horizontal_vel = dir * this.spd;
35
+ if (!this.place_meeting(this.x + this.horizontal_vel, this.y, _col)) {
36
+ this.x += this.horizontal_vel;
37
+ }
38
+
39
+ // ------------------------------
40
+ // jump and gravity
41
+ // ------------------------------
42
+
43
+ // grounding
44
+ if (this.place_meeting(this.x, this.y + 1, _col)) {
45
+ this.grounded = true;
46
+ this.vertical_vel = 0;
47
+ this.vertical_acc = 0;
48
+ } else {
49
+ this.grounded = false;
50
+ }
51
+
52
+ // vertical acceleration (gravity pulls down while airborne)
53
+ if (!this.grounded) {
54
+ this.vertical_acc = -this.weight;
55
+ }
56
+
57
+ // jump
58
+ if (key_jump && this.grounded) {
59
+ this.vertical_acc = this.jump_force;
60
+ }
61
+
62
+ // apply acceleration, then move — snapping flush against anything in the way
63
+ this.vertical_vel += this.vertical_acc;
64
+ if (this.place_meeting(this.x, this.y - this.vertical_vel, _col)) {
65
+ while (!this.place_meeting(this.x, this.y - sign(this.vertical_vel), _col)) {
66
+ this.y -= sign(this.vertical_vel);
67
+ }
68
+ this.vertical_vel = 0;
69
+ }
70
+ this.y -= this.vertical_vel;
71
+ }
72
+ static sprite = 'spr_player'
73
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "Platformer",
3
+ "version": "1.0.0",
4
+ "engineVersion": "1.0.0",
5
+ "settings": {
6
+ "roomSpeed": 60,
7
+ "windowWidth": 640,
8
+ "windowHeight": 480,
9
+ "startRoom": "room_main",
10
+ "displayColor": "#10131c"
11
+ },
12
+ "resources": {
13
+ "sprites": {
14
+ "spr_player": {
15
+ "name": "spr_player"
16
+ },
17
+ "spr_platform": {
18
+ "name": "spr_platform"
19
+ }
20
+ },
21
+ "sounds": {},
22
+ "backgrounds": {},
23
+ "paths": {},
24
+ "scripts": {},
25
+ "fonts": {},
26
+ "timelines": {},
27
+ "objects": {
28
+ "obj_player": {
29
+ "name": "obj_player"
30
+ },
31
+ "_col": {
32
+ "name": "_col"
33
+ },
34
+ "obj_platform": {
35
+ "name": "obj_platform"
36
+ }
37
+ },
38
+ "rooms": {
39
+ "room_main": {
40
+ "name": "room_main"
41
+ }
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,327 @@
1
+ {
2
+ "width": 640,
3
+ "height": 480,
4
+ "room_speed": 60,
5
+ "persistent": false,
6
+ "creation_code": "",
7
+ "instances": [
8
+ {
9
+ "id": 28,
10
+ "object_name": "obj_player",
11
+ "x": 96,
12
+ "y": 400,
13
+ "scale_x": 1,
14
+ "scale_y": 1,
15
+ "rotation": 0,
16
+ "creation_code": ""
17
+ },
18
+ {
19
+ "id": 37,
20
+ "object_name": "obj_platform",
21
+ "x": 0,
22
+ "y": 448,
23
+ "scale_x": 1,
24
+ "scale_y": 1,
25
+ "rotation": 0,
26
+ "creation_code": ""
27
+ },
28
+ {
29
+ "id": 38,
30
+ "object_name": "obj_platform",
31
+ "x": 32,
32
+ "y": 448,
33
+ "scale_x": 1,
34
+ "scale_y": 1,
35
+ "rotation": 0,
36
+ "creation_code": ""
37
+ },
38
+ {
39
+ "id": 39,
40
+ "object_name": "obj_platform",
41
+ "x": 64,
42
+ "y": 448,
43
+ "scale_x": 1,
44
+ "scale_y": 1,
45
+ "rotation": 0,
46
+ "creation_code": ""
47
+ },
48
+ {
49
+ "id": 40,
50
+ "object_name": "obj_platform",
51
+ "x": 96,
52
+ "y": 448,
53
+ "scale_x": 1,
54
+ "scale_y": 1,
55
+ "rotation": 0,
56
+ "creation_code": ""
57
+ },
58
+ {
59
+ "id": 41,
60
+ "object_name": "obj_platform",
61
+ "x": 128,
62
+ "y": 448,
63
+ "scale_x": 1,
64
+ "scale_y": 1,
65
+ "rotation": 0,
66
+ "creation_code": ""
67
+ },
68
+ {
69
+ "id": 42,
70
+ "object_name": "obj_platform",
71
+ "x": 160,
72
+ "y": 448,
73
+ "scale_x": 1,
74
+ "scale_y": 1,
75
+ "rotation": 0,
76
+ "creation_code": ""
77
+ },
78
+ {
79
+ "id": 43,
80
+ "object_name": "obj_platform",
81
+ "x": 192,
82
+ "y": 448,
83
+ "scale_x": 1,
84
+ "scale_y": 1,
85
+ "rotation": 0,
86
+ "creation_code": ""
87
+ },
88
+ {
89
+ "id": 44,
90
+ "object_name": "obj_platform",
91
+ "x": 224,
92
+ "y": 448,
93
+ "scale_x": 1,
94
+ "scale_y": 1,
95
+ "rotation": 0,
96
+ "creation_code": ""
97
+ },
98
+ {
99
+ "id": 45,
100
+ "object_name": "obj_platform",
101
+ "x": 256,
102
+ "y": 448,
103
+ "scale_x": 1,
104
+ "scale_y": 1,
105
+ "rotation": 0,
106
+ "creation_code": ""
107
+ },
108
+ {
109
+ "id": 46,
110
+ "object_name": "obj_platform",
111
+ "x": 288,
112
+ "y": 448,
113
+ "scale_x": 1,
114
+ "scale_y": 1,
115
+ "rotation": 0,
116
+ "creation_code": ""
117
+ },
118
+ {
119
+ "id": 47,
120
+ "object_name": "obj_platform",
121
+ "x": 320,
122
+ "y": 448,
123
+ "scale_x": 1,
124
+ "scale_y": 1,
125
+ "rotation": 0,
126
+ "creation_code": ""
127
+ },
128
+ {
129
+ "id": 48,
130
+ "object_name": "obj_platform",
131
+ "x": 352,
132
+ "y": 448,
133
+ "scale_x": 1,
134
+ "scale_y": 1,
135
+ "rotation": 0,
136
+ "creation_code": ""
137
+ },
138
+ {
139
+ "id": 49,
140
+ "object_name": "obj_platform",
141
+ "x": 384,
142
+ "y": 448,
143
+ "scale_x": 1,
144
+ "scale_y": 1,
145
+ "rotation": 0,
146
+ "creation_code": ""
147
+ },
148
+ {
149
+ "id": 50,
150
+ "object_name": "obj_platform",
151
+ "x": 416,
152
+ "y": 448,
153
+ "scale_x": 1,
154
+ "scale_y": 1,
155
+ "rotation": 0,
156
+ "creation_code": ""
157
+ },
158
+ {
159
+ "id": 51,
160
+ "object_name": "obj_platform",
161
+ "x": 448,
162
+ "y": 448,
163
+ "scale_x": 1,
164
+ "scale_y": 1,
165
+ "rotation": 0,
166
+ "creation_code": ""
167
+ },
168
+ {
169
+ "id": 52,
170
+ "object_name": "obj_platform",
171
+ "x": 480,
172
+ "y": 448,
173
+ "scale_x": 1,
174
+ "scale_y": 1,
175
+ "rotation": 0,
176
+ "creation_code": ""
177
+ },
178
+ {
179
+ "id": 53,
180
+ "object_name": "obj_platform",
181
+ "x": 512,
182
+ "y": 448,
183
+ "scale_x": 1,
184
+ "scale_y": 1,
185
+ "rotation": 0,
186
+ "creation_code": ""
187
+ },
188
+ {
189
+ "id": 54,
190
+ "object_name": "obj_platform",
191
+ "x": 544,
192
+ "y": 448,
193
+ "scale_x": 1,
194
+ "scale_y": 1,
195
+ "rotation": 0,
196
+ "creation_code": ""
197
+ },
198
+ {
199
+ "id": 55,
200
+ "object_name": "obj_platform",
201
+ "x": 576,
202
+ "y": 448,
203
+ "scale_x": 1,
204
+ "scale_y": 1,
205
+ "rotation": 0,
206
+ "creation_code": ""
207
+ },
208
+ {
209
+ "id": 56,
210
+ "object_name": "obj_platform",
211
+ "x": 608,
212
+ "y": 448,
213
+ "scale_x": 1,
214
+ "scale_y": 1,
215
+ "rotation": 0,
216
+ "creation_code": ""
217
+ },
218
+ {
219
+ "id": 59,
220
+ "object_name": "obj_platform",
221
+ "x": 224,
222
+ "y": 352,
223
+ "scale_x": 1,
224
+ "scale_y": 1,
225
+ "rotation": 0,
226
+ "creation_code": ""
227
+ },
228
+ {
229
+ "id": 60,
230
+ "object_name": "obj_platform",
231
+ "x": 256,
232
+ "y": 352,
233
+ "scale_x": 1,
234
+ "scale_y": 1,
235
+ "rotation": 0,
236
+ "creation_code": ""
237
+ },
238
+ {
239
+ "id": 62,
240
+ "object_name": "obj_platform",
241
+ "x": 192,
242
+ "y": 352,
243
+ "scale_x": 1,
244
+ "scale_y": 1,
245
+ "rotation": 0,
246
+ "creation_code": ""
247
+ },
248
+ {
249
+ "id": 63,
250
+ "object_name": "obj_platform",
251
+ "x": 352,
252
+ "y": 288,
253
+ "scale_x": 1,
254
+ "scale_y": 1,
255
+ "rotation": 0,
256
+ "creation_code": ""
257
+ },
258
+ {
259
+ "id": 64,
260
+ "object_name": "obj_platform",
261
+ "x": 384,
262
+ "y": 288,
263
+ "scale_x": 1,
264
+ "scale_y": 1,
265
+ "rotation": 0,
266
+ "creation_code": ""
267
+ },
268
+ {
269
+ "id": 65,
270
+ "object_name": "obj_platform",
271
+ "x": 416,
272
+ "y": 288,
273
+ "scale_x": 1,
274
+ "scale_y": 1,
275
+ "rotation": 0,
276
+ "creation_code": ""
277
+ },
278
+ {
279
+ "id": 66,
280
+ "object_name": "obj_platform",
281
+ "x": 448,
282
+ "y": 288,
283
+ "scale_x": 1,
284
+ "scale_y": 1,
285
+ "rotation": 0,
286
+ "creation_code": ""
287
+ },
288
+ {
289
+ "id": 67,
290
+ "object_name": "obj_platform",
291
+ "x": 544,
292
+ "y": 256,
293
+ "scale_x": 1,
294
+ "scale_y": 1,
295
+ "rotation": 0,
296
+ "creation_code": ""
297
+ },
298
+ {
299
+ "id": 68,
300
+ "object_name": "obj_platform",
301
+ "x": 576,
302
+ "y": 256,
303
+ "scale_x": 1,
304
+ "scale_y": 1,
305
+ "rotation": 0,
306
+ "creation_code": ""
307
+ },
308
+ {
309
+ "id": 69,
310
+ "object_name": "obj_platform",
311
+ "x": 608,
312
+ "y": 256,
313
+ "scale_x": 1,
314
+ "scale_y": 1,
315
+ "rotation": 0,
316
+ "creation_code": ""
317
+ }
318
+ ],
319
+ "backgrounds": [],
320
+ "views": [],
321
+ "tiles": [],
322
+ "bg_color": "#10131c",
323
+ "bg_show_color": true,
324
+ "physics_world": false,
325
+ "physics_gravity_x": 0,
326
+ "physics_gravity_y": 10
327
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "origin_x": 0,
3
+ "origin_y": 0,
4
+ "width": 32,
5
+ "height": 32,
6
+ "anim_speed": 15,
7
+ "mask_type": "rectangle",
8
+ "mask_x": 0,
9
+ "mask_y": 0,
10
+ "mask_w": 32,
11
+ "mask_h": 32,
12
+ "frames": [
13
+ {
14
+ "name": "0.png"
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "origin_x": 16,
3
+ "origin_y": 16,
4
+ "width": 32,
5
+ "height": 32,
6
+ "anim_speed": 15,
7
+ "mask_type": "rectangle",
8
+ "mask_x": 0,
9
+ "mask_y": 0,
10
+ "mask_w": 32,
11
+ "mask_h": 32,
12
+ "frames": [
13
+ {
14
+ "name": "0.png"
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1,2 @@
1
+ export class _col extends gm_object {
2
+ }