@dithrkit/sdk 0.1.6 → 0.2.0-rc.4
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/configs/tsconfig.base.json +2 -4
- package/lib/binary.js +1 -0
- package/lib/commands/create.js +3 -2
- package/lib/packager.js +12 -3
- package/package.json +11 -6
- package/templates/blank.js +1 -1
- package/templates/blank.ts +2 -2
- package/types/dithr.d.ts +80 -0
package/lib/binary.js
CHANGED
package/lib/commands/create.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
+
const { version: SDK_VERSION } = require("../../package.json");
|
|
6
7
|
|
|
7
8
|
const TEMPLATES_DIR = path.join(__dirname, "..", "..", "templates");
|
|
8
9
|
|
|
@@ -102,7 +103,7 @@ if (useTypescript) {
|
|
|
102
103
|
// tsconfig.json — extends the shared SDK config
|
|
103
104
|
const tsconfig = {
|
|
104
105
|
extends: "@dithrkit/sdk/configs/tsconfig.base.json",
|
|
105
|
-
include: ["src/**/*.ts"],
|
|
106
|
+
include: ["src/**/*.ts", "node_modules/@dithrkit/sdk/types/**/*.d.ts"],
|
|
106
107
|
};
|
|
107
108
|
fs.writeFileSync(path.join(dir, "tsconfig.json"), JSON.stringify(tsconfig, null, 4) + "\n");
|
|
108
109
|
}
|
|
@@ -149,7 +150,7 @@ const pkg = {
|
|
|
149
150
|
typecheck: useTypescript ? "tsc --noEmit" : undefined,
|
|
150
151
|
},
|
|
151
152
|
devDependencies: {
|
|
152
|
-
"@dithrkit/sdk":
|
|
153
|
+
"@dithrkit/sdk": `^${SDK_VERSION}`,
|
|
153
154
|
eslint: "^9.0.0",
|
|
154
155
|
prettier: "^3.0.0",
|
|
155
156
|
...(useTypescript
|
package/lib/packager.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const fs = require("node:fs");
|
|
4
4
|
const path = require("node:path");
|
|
5
5
|
|
|
6
|
+
const EXCLUDED_DIRECTORIES = new Set([".git", "build", "node_modules"]);
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* Pack a directory tree into the Emscripten preload data format.
|
|
8
10
|
*
|
|
@@ -39,6 +41,10 @@ function packDirectory(dir, mount) {
|
|
|
39
41
|
continue;
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
if (entry.isDirectory() && EXCLUDED_DIRECTORIES.has(entry.name)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
if (entry.isDirectory()) {
|
|
43
49
|
walk(fullPath, relPath);
|
|
44
50
|
} else if (entry.isFile()) {
|
|
@@ -80,7 +86,10 @@ function generatePackageLoader(dataFilename, files) {
|
|
|
80
86
|
for (const f of files) {
|
|
81
87
|
const parts = f.filename.split("/");
|
|
82
88
|
for (let i = 1; i < parts.length; i++) {
|
|
83
|
-
|
|
89
|
+
const dir = parts.slice(0, i).join("/");
|
|
90
|
+
if (dir) {
|
|
91
|
+
dirs.add(dir);
|
|
92
|
+
}
|
|
84
93
|
}
|
|
85
94
|
}
|
|
86
95
|
|
|
@@ -114,14 +123,14 @@ function generatePackageLoader(dataFilename, files) {
|
|
|
114
123
|
" // Create directories",
|
|
115
124
|
...dirList.map(
|
|
116
125
|
(d) =>
|
|
117
|
-
` Module
|
|
126
|
+
` Module.FS.createPath('${path.posix.dirname(d)}', '${path.posix.basename(d)}', true, true);`,
|
|
118
127
|
),
|
|
119
128
|
"",
|
|
120
129
|
" // Create files",
|
|
121
130
|
" PACKAGE_INFO.files.forEach(function(fileInfo) {",
|
|
122
131
|
" var data = byteArray.subarray(fileInfo.start, fileInfo.end);",
|
|
123
132
|
" var dir = fileInfo.filename.substring(0, fileInfo.filename.lastIndexOf('/'));",
|
|
124
|
-
" Module
|
|
133
|
+
" Module.FS.createDataFile(dir, fileInfo.filename.split('/').pop(), data, true, true, true);",
|
|
125
134
|
" });",
|
|
126
135
|
" }",
|
|
127
136
|
"",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dithrkit/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-rc.4",
|
|
4
4
|
"description": "SDK and CLI for the dithr fantasy console",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dithrkit",
|
|
@@ -25,9 +25,13 @@
|
|
|
25
25
|
"bin": {
|
|
26
26
|
"dithrkit": "bin/dithrkit.js"
|
|
27
27
|
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "node --test test/*.test.js"
|
|
30
|
+
},
|
|
28
31
|
"exports": {
|
|
29
32
|
"./configs/tsconfig.base.json": "./configs/tsconfig.base.json",
|
|
30
33
|
"./configs/eslint": "./configs/eslint.config.js",
|
|
34
|
+
"./lib/commands/create.js": "./lib/commands/create.js",
|
|
31
35
|
"./types/*": "./types/*"
|
|
32
36
|
},
|
|
33
37
|
"files": [
|
|
@@ -38,15 +42,16 @@
|
|
|
38
42
|
"configs/"
|
|
39
43
|
],
|
|
40
44
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
45
|
+
"node": ">=22.14.0"
|
|
42
46
|
},
|
|
43
47
|
"dependencies": {
|
|
44
48
|
"esbuild": "^0.24.0"
|
|
45
49
|
},
|
|
46
50
|
"optionalDependencies": {
|
|
47
|
-
"@dithrkit/win32-x64": "0.
|
|
48
|
-
"@dithrkit/linux-x64": "0.
|
|
49
|
-
"@dithrkit/
|
|
50
|
-
"@dithrkit/
|
|
51
|
+
"@dithrkit/win32-x64": "0.2.0-rc.4",
|
|
52
|
+
"@dithrkit/linux-x64": "0.2.0-rc.4",
|
|
53
|
+
"@dithrkit/linux-arm64": "0.2.0-rc.4",
|
|
54
|
+
"@dithrkit/darwin-arm64": "0.2.0-rc.4",
|
|
55
|
+
"@dithrkit/wasm": "0.2.0-rc.4"
|
|
51
56
|
}
|
|
52
57
|
}
|
package/templates/blank.js
CHANGED
package/templates/blank.ts
CHANGED
|
@@ -4,11 +4,11 @@ export function _init(): void {
|
|
|
4
4
|
gfx.cls(0);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export function _update(
|
|
7
|
+
export function _update(_dt: number): void {
|
|
8
8
|
// Update logic here
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function _draw(): void {
|
|
12
12
|
gfx.cls(0);
|
|
13
|
-
gfx.print(
|
|
13
|
+
gfx.print("hello, dithr!", 4, 4, 7);
|
|
14
14
|
}
|
package/types/dithr.d.ts
CHANGED
|
@@ -102,12 +102,18 @@ interface DithrGfx {
|
|
|
102
102
|
print(text: string | number, x?: number, y?: number, col?: number): void;
|
|
103
103
|
textWidth(text: string): number;
|
|
104
104
|
textHeight(text: string): number;
|
|
105
|
+
/** Draw text with word-wrap within maxW pixels. Returns total pixel height consumed. */
|
|
106
|
+
printWrapped(text: string, x: number, y: number, maxW: number, col?: number): number;
|
|
107
|
+
/** Measure the pixel height printWrapped would consume without drawing. */
|
|
108
|
+
textWrapHeight(text: string, maxW: number): number;
|
|
105
109
|
font(sx?: number, sy?: number, char_w?: number, char_h?: number, first?: number, count?: number): void;
|
|
106
110
|
|
|
107
111
|
// Sprites
|
|
108
112
|
spr(idx?: number, x?: number, y?: number, w?: number, h?: number, flip_x?: boolean, flip_y?: boolean): void;
|
|
109
113
|
sprBatch(data: Int32Array, count?: number): void;
|
|
110
114
|
sspr(sx?: number, sy?: number, sw?: number, sh?: number, dx?: number, dy?: number, dw?: number, dh?: number): void;
|
|
115
|
+
/** Draw a 9-slice / 9-patch from the sprite sheet into the destination rect. */
|
|
116
|
+
nineSlice(sx?: number, sy?: number, sw?: number, sh?: number, dx?: number, dy?: number, dw?: number, dh?: number, border?: number): void;
|
|
111
117
|
sprRot(idx?: number, x?: number, y?: number, angle?: number, cx?: number, cy?: number): void;
|
|
112
118
|
sprAffine(idx?: number, x?: number, y?: number, origin_x?: number, origin_y?: number, rot_x?: number, rot_y?: number): void;
|
|
113
119
|
|
|
@@ -159,6 +165,8 @@ interface DithrGfx {
|
|
|
159
165
|
dlEnd(): void;
|
|
160
166
|
dlSpr(layer: number, idx: number, x: number, y: number, w?: number, h?: number, flip_x?: boolean, flip_y?: boolean): void;
|
|
161
167
|
dlSspr(layer: number, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
|
|
168
|
+
/** Enqueue a 9-slice draw command on the draw list at the given layer. */
|
|
169
|
+
dlNineSlice(layer: number, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number, border: number): void;
|
|
162
170
|
dlSprRot(layer: number, idx: number, x: number, y: number, angle?: number, cx?: number, cy?: number): void;
|
|
163
171
|
dlSprAffine(layer: number, idx: number, x: number, y: number, origin_x?: number, origin_y?: number, rot_x?: number, rot_y?: number): void;
|
|
164
172
|
}
|
|
@@ -493,6 +501,10 @@ interface DithrMath {
|
|
|
493
501
|
dist(x1: number, y1: number, x2: number, y2: number): number;
|
|
494
502
|
angle(x1: number, y1: number, x2: number, y2: number): number;
|
|
495
503
|
|
|
504
|
+
// Perlin noise (Ken Perlin's improved noise, deterministic, returns ~-1..1)
|
|
505
|
+
noise2d(x: number, y: number): number;
|
|
506
|
+
noise3d(x: number, y: number, z: number): number;
|
|
507
|
+
|
|
496
508
|
// Constants
|
|
497
509
|
readonly PI: number;
|
|
498
510
|
readonly TAU: number;
|
|
@@ -572,6 +584,7 @@ interface DithrSys {
|
|
|
572
584
|
// File I/O (sandboxed to cart directory)
|
|
573
585
|
readFile(path: string): string | undefined;
|
|
574
586
|
writeFile(path: string, content: string): boolean;
|
|
587
|
+
deleteFile(path: string): boolean;
|
|
575
588
|
listFiles(dir?: string): string[];
|
|
576
589
|
listDirs(dir?: string): string[];
|
|
577
590
|
|
|
@@ -605,6 +618,14 @@ interface DithrCol {
|
|
|
605
618
|
// ui — UI Layout Helpers
|
|
606
619
|
// ---------------------------------------------------------------------------
|
|
607
620
|
|
|
621
|
+
/** Handle returned by ui.group() — call .end() when drawing is complete. */
|
|
622
|
+
interface DithrUiGroup {
|
|
623
|
+
/** The rect this group was pushed with. */
|
|
624
|
+
readonly rect: DithrRect;
|
|
625
|
+
/** Pop the group (and restore clip if clip was requested). */
|
|
626
|
+
end(): void;
|
|
627
|
+
}
|
|
628
|
+
|
|
608
629
|
interface DithrUi {
|
|
609
630
|
rect(x: number, y: number, w: number, h: number): DithrRect;
|
|
610
631
|
inset(rect: DithrRect, n: number): DithrRect;
|
|
@@ -614,6 +635,18 @@ interface DithrUi {
|
|
|
614
635
|
hstack(rect: DithrRect, n: number, gap?: number): DithrRect[];
|
|
615
636
|
vstack(rect: DithrRect, n: number, gap?: number): DithrRect[];
|
|
616
637
|
place(parent: DithrRect, ax: number, ay: number, w: number, h: number): DithrRect;
|
|
638
|
+
/** Push a group rect onto the stack. Returns true on success. */
|
|
639
|
+
groupPush(rect: DithrRect, clip?: boolean): boolean;
|
|
640
|
+
/** Pop the innermost group (safe to call on empty stack). */
|
|
641
|
+
groupPop(): void;
|
|
642
|
+
/** Return the current group rect, or {x:0,y:0,w:0,h:0} if no group is active. */
|
|
643
|
+
groupRect(): DithrRect;
|
|
644
|
+
/** Clamp child to the intersection with the current group rect. */
|
|
645
|
+
fit(child: DithrRect): DithrRect;
|
|
646
|
+
/** Draw a 9-slice panel from the sprite sheet, clamped to the active group bounds. */
|
|
647
|
+
panel(rect: DithrRect, sx: number, sy: number, sw: number, sh: number, border: number): void;
|
|
648
|
+
/** Push a group, call fn, then pop. opts.clip applies gfx.clip automatically. */
|
|
649
|
+
withGroup(rect: DithrRect, fn: () => void, opts?: { clip?: boolean }): void;
|
|
617
650
|
}
|
|
618
651
|
|
|
619
652
|
// ---------------------------------------------------------------------------
|
|
@@ -681,6 +714,52 @@ interface DithrSynth {
|
|
|
681
714
|
fxNames(): string[];
|
|
682
715
|
}
|
|
683
716
|
|
|
717
|
+
// ---------------------------------------------------------------------------
|
|
718
|
+
// particles — Fixed-pool particle system
|
|
719
|
+
// ---------------------------------------------------------------------------
|
|
720
|
+
|
|
721
|
+
interface DithrParticleSpawn {
|
|
722
|
+
x?: number;
|
|
723
|
+
y?: number;
|
|
724
|
+
vx?: number;
|
|
725
|
+
vy?: number;
|
|
726
|
+
ax?: number;
|
|
727
|
+
ay?: number;
|
|
728
|
+
/** Per-second velocity decay, 0 (none) .. 1 (instant). */
|
|
729
|
+
drag?: number;
|
|
730
|
+
/** Lifetime in seconds (default 1). */
|
|
731
|
+
life?: number;
|
|
732
|
+
/** Palette index at birth (default 7). */
|
|
733
|
+
color?: number;
|
|
734
|
+
/** Optional palette index at death (interpolates from `color`). */
|
|
735
|
+
color1?: number;
|
|
736
|
+
/** Render size in pixels (default 1). */
|
|
737
|
+
size?: number;
|
|
738
|
+
/** Render kind: particles.PIXEL | RECT | CIRCLE. */
|
|
739
|
+
kind?: number;
|
|
740
|
+
/** Burst size; > 1 enables `spread`/`speedMin`/`speedMax`. */
|
|
741
|
+
count?: number;
|
|
742
|
+
/** Cone half-angle (radians) around the (vx,vy) direction. */
|
|
743
|
+
spread?: number;
|
|
744
|
+
speedMin?: number;
|
|
745
|
+
speedMax?: number;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
interface DithrParticles {
|
|
749
|
+
readonly PIXEL: number;
|
|
750
|
+
readonly RECT: number;
|
|
751
|
+
readonly CIRCLE: number;
|
|
752
|
+
|
|
753
|
+
/** Spawn one or more particles; returns the count actually emitted. */
|
|
754
|
+
emit(cfg: DithrParticleSpawn): number;
|
|
755
|
+
/** Advance simulation; defaults to `sys.delta()` when omitted. */
|
|
756
|
+
update(dt?: number): void;
|
|
757
|
+
/** Render every active particle via gfx primitives. */
|
|
758
|
+
draw(): void;
|
|
759
|
+
clear(): void;
|
|
760
|
+
count(): number;
|
|
761
|
+
}
|
|
762
|
+
|
|
684
763
|
// ---------------------------------------------------------------------------
|
|
685
764
|
// Global declarations
|
|
686
765
|
// ---------------------------------------------------------------------------
|
|
@@ -704,6 +783,7 @@ declare const ui: DithrUi;
|
|
|
704
783
|
declare const tween: DithrTween;
|
|
705
784
|
declare const cam: DithrCam;
|
|
706
785
|
declare const synth: DithrSynth;
|
|
786
|
+
declare const particles: DithrParticles;
|
|
707
787
|
|
|
708
788
|
// ---------------------------------------------------------------------------
|
|
709
789
|
// Global callbacks (implement these in your cart)
|