@bloopjs/bloop 0.0.6 → 0.0.8
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/jsr.json +1 -1
- package/package.json +6 -1
- package/src/context.ts +7 -0
- package/src/mod.ts +85 -2
- package/src/schema.ts +1 -0
- package/src/system.ts +54 -0
- package/test/inputs.test.ts +89 -0
- package/tsconfig.json +1 -1
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloopjs/bloop",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -14,12 +14,17 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "bun build src/mod.ts --outdir=dist --sourcemap=linked && bun run build:tsc",
|
|
16
16
|
"build:tsc": "tsc -p publish/tsconfig.publish.json",
|
|
17
|
+
"ci": "bun run ci:tsc && bun run ci:jsr && bun run build",
|
|
17
18
|
"ci:tsc": "tsc --noEmit",
|
|
19
|
+
"ci:jsr": "bunx jsr publish --dry-run --allow-dirty",
|
|
18
20
|
"dev": "bun --watch src/mod.ts"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|
|
21
23
|
"@types/bun": "latest"
|
|
22
24
|
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@bloopjs/engine": "0.0.8"
|
|
27
|
+
},
|
|
23
28
|
"peerDependencies": {
|
|
24
29
|
"typescript": "^5"
|
|
25
30
|
}
|
package/src/context.ts
ADDED
package/src/mod.ts
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { System } from "./system";
|
|
2
|
+
import { EngineInputs, type PlatformEvent } from "@bloopjs/engine";
|
|
3
|
+
|
|
4
|
+
type BloopLoop = {
|
|
5
|
+
system: (label: string, system: System) => void;
|
|
6
|
+
systemsCallback: (events: PlatformEvent[]) => void;
|
|
3
7
|
}
|
|
8
|
+
|
|
9
|
+
export function Bloop(): BloopLoop {
|
|
10
|
+
const systems = [] as System[];
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
system(label: string, system: System) {
|
|
14
|
+
systems.push(system);
|
|
15
|
+
},
|
|
16
|
+
systemsCallback: (events: PlatformEvent[]) => {
|
|
17
|
+
for (const system of systems) {
|
|
18
|
+
system.update?.();
|
|
19
|
+
|
|
20
|
+
for (const event of events) {
|
|
21
|
+
switch(event.type) {
|
|
22
|
+
case "keydown":
|
|
23
|
+
system.keydown?.({
|
|
24
|
+
event: {
|
|
25
|
+
key: event.key,
|
|
26
|
+
pressure: 1,
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
break;
|
|
30
|
+
case "keyheld":
|
|
31
|
+
system.keyheld?.({
|
|
32
|
+
event: {
|
|
33
|
+
key: event.key,
|
|
34
|
+
pressure: 1,
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
break;
|
|
38
|
+
case "keyup":
|
|
39
|
+
system.keyup?.({
|
|
40
|
+
event: {
|
|
41
|
+
key: event.key,
|
|
42
|
+
pressure: 0,
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
break;
|
|
46
|
+
case "mousemove":
|
|
47
|
+
system.mousemove?.({
|
|
48
|
+
event: {
|
|
49
|
+
x: event.x,
|
|
50
|
+
y: event.y,
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
break;
|
|
54
|
+
case "mousedown":
|
|
55
|
+
system.mousedown?.({
|
|
56
|
+
event: {
|
|
57
|
+
button: event.button,
|
|
58
|
+
pressure: event.pressure,
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
break;
|
|
62
|
+
case "mouseup":
|
|
63
|
+
system.mouseup?.({
|
|
64
|
+
event: {
|
|
65
|
+
button: event.button,
|
|
66
|
+
pressure: event.pressure,
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
break;
|
|
70
|
+
case "mousewheel":
|
|
71
|
+
system.mousewheel?.({
|
|
72
|
+
event: {
|
|
73
|
+
x: event.x,
|
|
74
|
+
y: event.y,
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
break;
|
|
78
|
+
default:
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type GameSchema = unknown;
|
package/src/system.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
KeyEvent,
|
|
3
|
+
MouseButtonEvent,
|
|
4
|
+
MousePositionEvent,
|
|
5
|
+
MouseWheelEvent,
|
|
6
|
+
} from "@bloopjs/engine";
|
|
7
|
+
import type { Context } from "./context";
|
|
8
|
+
import type { GameSchema } from "./schema";
|
|
9
|
+
|
|
10
|
+
export type System<GS extends GameSchema = GameSchema> = {
|
|
11
|
+
update?: () => void;
|
|
12
|
+
|
|
13
|
+
keydown?: (
|
|
14
|
+
context: Context<GS> & {
|
|
15
|
+
event: KeyEvent;
|
|
16
|
+
},
|
|
17
|
+
) => void;
|
|
18
|
+
|
|
19
|
+
keyup?: (
|
|
20
|
+
context: Context<GS> & {
|
|
21
|
+
event: KeyEvent;
|
|
22
|
+
},
|
|
23
|
+
) => void;
|
|
24
|
+
|
|
25
|
+
keyheld?: (
|
|
26
|
+
context: Context<GS> & {
|
|
27
|
+
event: KeyEvent;
|
|
28
|
+
},
|
|
29
|
+
) => void;
|
|
30
|
+
|
|
31
|
+
mousedown?: (
|
|
32
|
+
context: Context<GS> & {
|
|
33
|
+
event: MouseButtonEvent;
|
|
34
|
+
},
|
|
35
|
+
) => void;
|
|
36
|
+
|
|
37
|
+
mouseup?: (
|
|
38
|
+
context: Context<GS> & {
|
|
39
|
+
event: MouseButtonEvent;
|
|
40
|
+
},
|
|
41
|
+
) => void;
|
|
42
|
+
|
|
43
|
+
mousemove?: (
|
|
44
|
+
context: Context<GS> & {
|
|
45
|
+
event: MousePositionEvent;
|
|
46
|
+
},
|
|
47
|
+
) => void;
|
|
48
|
+
|
|
49
|
+
mousewheel?: (
|
|
50
|
+
context: Context<GS> & {
|
|
51
|
+
event: MouseWheelEvent;
|
|
52
|
+
},
|
|
53
|
+
) => void;
|
|
54
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { it, expect, describe } from "bun:test";
|
|
2
|
+
import { mount, type Key, type MouseButton } from "@bloopjs/engine";
|
|
3
|
+
import { Bloop } from "../src/mod";
|
|
4
|
+
|
|
5
|
+
describe("loop", () => {
|
|
6
|
+
it("runs a single system", async () => {
|
|
7
|
+
const bloop = Bloop();
|
|
8
|
+
let count = 0;
|
|
9
|
+
|
|
10
|
+
bloop.system("test", {
|
|
11
|
+
update() {
|
|
12
|
+
count++;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const { runtime } = await mount(bloop);
|
|
17
|
+
runtime.step();
|
|
18
|
+
|
|
19
|
+
expect(count).toEqual(1);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("passes through input events", async () => {
|
|
23
|
+
const bloop = Bloop();
|
|
24
|
+
|
|
25
|
+
const events = {
|
|
26
|
+
keydown: null as Key | null,
|
|
27
|
+
keyup: null as Key | null,
|
|
28
|
+
keyheld: null as Key | null,
|
|
29
|
+
|
|
30
|
+
mousemove: null as { x: number; y: number } | null,
|
|
31
|
+
mousedown: null as MouseButton | null,
|
|
32
|
+
mouseheld: null as MouseButton | null,
|
|
33
|
+
mouseup: null as MouseButton | null,
|
|
34
|
+
mousewheel: null as { x: number; y: number } | null,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
bloop.system("input", {
|
|
38
|
+
keydown({ event }) {
|
|
39
|
+
events.keydown = event.key;
|
|
40
|
+
},
|
|
41
|
+
keyup({ event }) {
|
|
42
|
+
events.keyup = event.key;
|
|
43
|
+
},
|
|
44
|
+
keyheld({ event }) {
|
|
45
|
+
events.keyheld = event.key;
|
|
46
|
+
},
|
|
47
|
+
mousemove({ event }) {
|
|
48
|
+
events.mousemove = { x: event.x, y: event.y };
|
|
49
|
+
},
|
|
50
|
+
mousedown({ event }) {
|
|
51
|
+
events.mousedown = event.button;
|
|
52
|
+
},
|
|
53
|
+
mouseup({ event }) {
|
|
54
|
+
events.mouseup = event.button;
|
|
55
|
+
},
|
|
56
|
+
mousewheel({ event }) {
|
|
57
|
+
events.mousewheel = event;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const { runtime, emitter } = await mount(bloop);
|
|
62
|
+
|
|
63
|
+
emitter.keydown("Space");
|
|
64
|
+
emitter.mousemove(100, 150);
|
|
65
|
+
emitter.mousedown("Left");
|
|
66
|
+
emitter.mousewheel(1, 2);
|
|
67
|
+
|
|
68
|
+
runtime.step();
|
|
69
|
+
|
|
70
|
+
expect(events.keydown).toEqual("Space");
|
|
71
|
+
expect(events.mousemove).toEqual({ x: 100, y: 150 });
|
|
72
|
+
expect(events.mousedown).toEqual("Left");
|
|
73
|
+
expect(events.mousewheel).toEqual({ x: 1, y: 2 });
|
|
74
|
+
|
|
75
|
+
emitter.keyup("Space");
|
|
76
|
+
emitter.mouseup("Left");
|
|
77
|
+
emitter.mousemove(3, 4);
|
|
78
|
+
|
|
79
|
+
runtime.step();
|
|
80
|
+
|
|
81
|
+
expect(events.keyup).toEqual("Space");
|
|
82
|
+
expect(events.mouseup).toEqual("Left");
|
|
83
|
+
expect(events.mousemove).toEqual({ x: 3, y: 4 });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it.skip("keeps track of keyboard and mouse snapshots", async () => {});
|
|
87
|
+
|
|
88
|
+
it.skip('synthesizes "keyheld" and "mouseheld" events', async () => {});
|
|
89
|
+
});
|
package/tsconfig.json
CHANGED