woofjs-engine 0.2.0 → 0.4.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.
- package/CHANGELOG.md +13 -0
- package/README.md +16 -106
- package/THIRD_PARTY_NOTICES.md +7 -0
- package/dist/canvas.js +4 -31
- package/dist/collision.js +8 -5
- package/dist/game.js +4 -84
- package/dist/index-1jykaz1m.js +142 -0
- package/dist/index-9mz0qg9d.js +39 -0
- package/dist/index-b9a70qgn.js +34 -0
- package/dist/index-dp75gf4w.js +57 -0
- package/dist/index-f63yb8zf.js +85 -0
- package/dist/index-gypg8d50.js +31 -0
- package/dist/index-w4yvg8ax.js +2568 -0
- package/dist/index.js +134 -239
- package/dist/input.js +4 -33
- package/dist/play.js +304 -0
- package/dist/sound.js +4 -56
- package/dist/store.js +4 -30
- package/dist/types/canvas.d.ts +20 -2
- package/dist/types/collision.d.ts +62 -0
- package/dist/types/game.d.ts +21 -1
- package/dist/types/global.d.ts +4 -0
- package/dist/types/helpers.d.ts +92 -0
- package/dist/types/index.d.ts +23 -12
- package/dist/types/input.d.ts +4 -0
- package/dist/types/play.d.ts +167 -0
- package/dist/types/sound.d.ts +10 -3
- package/dist/types/sprites/custom.d.ts +9 -0
- package/dist/types/sprites/easing.d.ts +9 -0
- package/dist/types/sprites/geometry.d.ts +22 -0
- package/dist/types/sprites/options.d.ts +98 -0
- package/dist/types/sprites/render.d.ts +2 -0
- package/dist/types/sprites/sprite.d.ts +283 -0
- package/dist/types/store.d.ts +4 -0
- package/dist/types/ui.d.ts +65 -0
- package/dist/types/woof.d.ts +395 -0
- package/dist/types/world/audio.d.ts +118 -0
- package/dist/types/world/globals.d.ts +3 -0
- package/dist/types/world/keys.d.ts +2 -0
- package/dist/types/world/options.d.ts +44 -0
- package/dist/types/world/render.d.ts +13 -0
- package/dist/types/world/scheduler.d.ts +65 -0
- package/dist/ui.js +235 -0
- package/dist/woof.global.js +3620 -0
- package/docs/api.json +5439 -0
- package/docs/woof-parity.md +231 -0
- package/package.json +25 -8
- package/docs/architecture.md +0 -37
- package/docs/planning.md +0 -33
package/dist/index.js
CHANGED
|
@@ -1,241 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
previousTime = null;
|
|
76
|
-
return this;
|
|
77
|
-
},
|
|
78
|
-
get running() {
|
|
79
|
-
return running;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
return loop;
|
|
83
|
-
}
|
|
84
|
-
// src/sound.ts
|
|
85
|
-
function createSound(buffer, audioContext, { volume = 1, maxGain = 4 } = {}) {
|
|
86
|
-
if (!buffer)
|
|
87
|
-
throw new TypeError("buffer is required");
|
|
88
|
-
if (!audioContext || typeof audioContext.createBufferSource !== "function" || typeof audioContext.createGain !== "function") {
|
|
89
|
-
throw new TypeError("audioContext must provide createBufferSource() and createGain()");
|
|
90
|
-
}
|
|
91
|
-
if (!Number.isFinite(maxGain) || maxGain < 0)
|
|
92
|
-
throw new RangeError("maxGain must be a finite, non-negative number");
|
|
93
|
-
if (!Number.isFinite(volume) || volume < 0)
|
|
94
|
-
throw new RangeError("volume must be a finite, non-negative number");
|
|
95
|
-
return {
|
|
96
|
-
startPlaying({ loop = false, playbackRate = 1 } = {}) {
|
|
97
|
-
const source = audioContext.createBufferSource();
|
|
98
|
-
const gainNode = audioContext.createGain();
|
|
99
|
-
source.buffer = buffer;
|
|
100
|
-
source.loop = Boolean(loop);
|
|
101
|
-
if (source.playbackRate)
|
|
102
|
-
source.playbackRate.value = playbackRate;
|
|
103
|
-
const baseGain = clamp(volume, maxGain);
|
|
104
|
-
gainNode.gain.value = baseGain;
|
|
105
|
-
source.connect(gainNode);
|
|
106
|
-
gainNode.connect(audioContext.destination);
|
|
107
|
-
source.start();
|
|
108
|
-
let stopped = false;
|
|
109
|
-
return {
|
|
110
|
-
source,
|
|
111
|
-
amplify(multiplier) {
|
|
112
|
-
if (stopped)
|
|
113
|
-
return this;
|
|
114
|
-
if (multiplier === "max")
|
|
115
|
-
gainNode.gain.value = maxGain;
|
|
116
|
-
else if (typeof multiplier === "number" && Number.isFinite(multiplier)) {
|
|
117
|
-
gainNode.gain.value = clamp(baseGain * multiplier, maxGain);
|
|
118
|
-
} else
|
|
119
|
-
throw new TypeError("amplify expects a finite multiplier or 'max'");
|
|
120
|
-
return this;
|
|
121
|
-
},
|
|
122
|
-
stop() {
|
|
123
|
-
if (!stopped) {
|
|
124
|
-
stopped = true;
|
|
125
|
-
source.stop();
|
|
126
|
-
}
|
|
127
|
-
return this;
|
|
128
|
-
},
|
|
129
|
-
get stopped() {
|
|
130
|
-
return stopped;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function clamp(value, maximum) {
|
|
137
|
-
return Math.min(maximum, Math.max(0, value));
|
|
138
|
-
}
|
|
139
|
-
// src/store.ts
|
|
140
|
-
function createStore(initialState = {}) {
|
|
141
|
-
let state = initialState;
|
|
142
|
-
const listeners = new Set;
|
|
143
|
-
function setState(nextState) {
|
|
144
|
-
const next = typeof nextState === "function" ? nextState(state) : nextState;
|
|
145
|
-
if (Object.is(next, state))
|
|
146
|
-
return state;
|
|
147
|
-
state = next;
|
|
148
|
-
for (const listener of [...listeners])
|
|
149
|
-
listener(state);
|
|
150
|
-
return state;
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
getState: () => state,
|
|
154
|
-
setState,
|
|
155
|
-
update(mutator) {
|
|
156
|
-
if (typeof mutator !== "function")
|
|
157
|
-
throw new TypeError("mutator must be a function");
|
|
158
|
-
return setState(mutator(state));
|
|
159
|
-
},
|
|
160
|
-
subscribe(listener) {
|
|
161
|
-
if (typeof listener !== "function")
|
|
162
|
-
throw new TypeError("listener must be a function");
|
|
163
|
-
listeners.add(listener);
|
|
164
|
-
return () => listeners.delete(listener);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
// src/canvas.ts
|
|
169
|
-
function createCanvas({ document: doc = globalThis.document, parent, width = 300, height = 150, context = "2d", contextOptions } = {}) {
|
|
170
|
-
if (!doc || typeof doc.createElement !== "function")
|
|
171
|
-
throw new Error("A browser document is required; pass document explicitly");
|
|
172
|
-
const element = doc.createElement("canvas");
|
|
173
|
-
element.width = width;
|
|
174
|
-
element.height = height;
|
|
175
|
-
const drawingContext = element.getContext(context, contextOptions);
|
|
176
|
-
if (!drawingContext)
|
|
177
|
-
throw new Error(`Unable to create ${context} canvas context`);
|
|
178
|
-
parent?.appendChild(element);
|
|
179
|
-
let removed = false;
|
|
180
|
-
return {
|
|
181
|
-
element,
|
|
182
|
-
context: drawingContext,
|
|
183
|
-
resize(nextWidth, nextHeight) {
|
|
184
|
-
if (removed)
|
|
185
|
-
throw new Error("Cannot resize a removed canvas");
|
|
186
|
-
element.width = nextWidth;
|
|
187
|
-
element.height = nextHeight;
|
|
188
|
-
return this;
|
|
189
|
-
},
|
|
190
|
-
destroy() {
|
|
191
|
-
if (!removed) {
|
|
192
|
-
removed = true;
|
|
193
|
-
element.remove();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
// src/input.ts
|
|
199
|
-
function createKeyboard(target = globalThis.window) {
|
|
200
|
-
if (!target || typeof target.addEventListener !== "function")
|
|
201
|
-
throw new Error("A keyboard event target is required");
|
|
202
|
-
const pressed = new Set;
|
|
203
|
-
const down = (event) => {
|
|
204
|
-
const code = event.code;
|
|
205
|
-
if (code)
|
|
206
|
-
pressed.add(code);
|
|
207
|
-
};
|
|
208
|
-
const up = (event) => {
|
|
209
|
-
pressed.delete(event.code);
|
|
210
|
-
};
|
|
211
|
-
const clear = () => pressed.clear();
|
|
212
|
-
target.addEventListener("keydown", down);
|
|
213
|
-
target.addEventListener("keyup", up);
|
|
214
|
-
target.addEventListener("blur", clear);
|
|
215
|
-
let destroyed = false;
|
|
216
|
-
return {
|
|
217
|
-
isDown: (code) => pressed.has(code),
|
|
218
|
-
clear,
|
|
219
|
-
destroy() {
|
|
220
|
-
if (destroyed)
|
|
221
|
-
return;
|
|
222
|
-
destroyed = true;
|
|
223
|
-
target.removeEventListener("keydown", down);
|
|
224
|
-
target.removeEventListener("keyup", up);
|
|
225
|
-
target.removeEventListener("blur", clear);
|
|
226
|
-
clear();
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
// src/collision.ts
|
|
231
|
-
function overlaps(a, b) {
|
|
232
|
-
return a.width > 0 && a.height > 0 && b.width > 0 && b.height > 0 && a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
|
|
233
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createGame2
|
|
3
|
+
} from "./index-f63yb8zf.js";
|
|
4
|
+
import {
|
|
5
|
+
createSound2
|
|
6
|
+
} from "./index-dp75gf4w.js";
|
|
7
|
+
import {
|
|
8
|
+
createStore2
|
|
9
|
+
} from "./index-gypg8d50.js";
|
|
10
|
+
import {
|
|
11
|
+
createCanvas2
|
|
12
|
+
} from "./index-9mz0qg9d.js";
|
|
13
|
+
import {
|
|
14
|
+
createKeyboard2
|
|
15
|
+
} from "./index-b9a70qgn.js";
|
|
16
|
+
import {
|
|
17
|
+
overlaps2,
|
|
18
|
+
detectCollision2
|
|
19
|
+
} from "./index-1jykaz1m.js";
|
|
20
|
+
import {
|
|
21
|
+
clamp2,
|
|
22
|
+
lerp2,
|
|
23
|
+
distance2,
|
|
24
|
+
between2,
|
|
25
|
+
remove2,
|
|
26
|
+
randomFloat2,
|
|
27
|
+
random2,
|
|
28
|
+
pick2,
|
|
29
|
+
shuffle2,
|
|
30
|
+
range2,
|
|
31
|
+
rgb2,
|
|
32
|
+
randomColor2,
|
|
33
|
+
RIGHT2,
|
|
34
|
+
LEFT2,
|
|
35
|
+
UP2,
|
|
36
|
+
DOWN2,
|
|
37
|
+
sin2,
|
|
38
|
+
cos2,
|
|
39
|
+
tan2,
|
|
40
|
+
asin2,
|
|
41
|
+
acos2,
|
|
42
|
+
atan2,
|
|
43
|
+
sqrt2,
|
|
44
|
+
abs2,
|
|
45
|
+
floor2,
|
|
46
|
+
ceiling2,
|
|
47
|
+
ln2,
|
|
48
|
+
log2,
|
|
49
|
+
pow2,
|
|
50
|
+
hourMilitary2,
|
|
51
|
+
hour2,
|
|
52
|
+
minute2,
|
|
53
|
+
second2,
|
|
54
|
+
dayOfMonth2,
|
|
55
|
+
dayOfWeek2,
|
|
56
|
+
month2,
|
|
57
|
+
year2,
|
|
58
|
+
mobile2,
|
|
59
|
+
importCodeURL2,
|
|
60
|
+
extend2,
|
|
61
|
+
months2,
|
|
62
|
+
keyCodeToString2,
|
|
63
|
+
unitsToMiliseconds2,
|
|
64
|
+
throttle2,
|
|
65
|
+
getData2,
|
|
66
|
+
arrayToString2,
|
|
67
|
+
easings2,
|
|
68
|
+
Sprite2,
|
|
69
|
+
ProjectSound2,
|
|
70
|
+
Repeat2,
|
|
71
|
+
RepeatUntil2,
|
|
72
|
+
Project2,
|
|
73
|
+
woof2
|
|
74
|
+
} from "./index-w4yvg8ax.js";
|
|
234
75
|
export {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
76
|
+
DOWN2 as DOWN,
|
|
77
|
+
LEFT2 as LEFT,
|
|
78
|
+
Project2 as Project,
|
|
79
|
+
ProjectSound2 as ProjectSound,
|
|
80
|
+
RIGHT2 as RIGHT,
|
|
81
|
+
Repeat2 as Repeat,
|
|
82
|
+
RepeatUntil2 as RepeatUntil,
|
|
83
|
+
Sprite2 as Sprite,
|
|
84
|
+
UP2 as UP,
|
|
85
|
+
abs2 as abs,
|
|
86
|
+
acos2 as acos,
|
|
87
|
+
arrayToString2 as arrayToString,
|
|
88
|
+
asin2 as asin,
|
|
89
|
+
atan2 as atan,
|
|
90
|
+
between2 as between,
|
|
91
|
+
ceiling2 as ceiling,
|
|
92
|
+
clamp2 as clamp,
|
|
93
|
+
cos2 as cos,
|
|
94
|
+
createCanvas2 as createCanvas,
|
|
95
|
+
createGame2 as createGame,
|
|
96
|
+
createKeyboard2 as createKeyboard,
|
|
97
|
+
createSound2 as createSound,
|
|
98
|
+
createStore2 as createStore,
|
|
99
|
+
dayOfMonth2 as dayOfMonth,
|
|
100
|
+
dayOfWeek2 as dayOfWeek,
|
|
101
|
+
detectCollision2 as detectCollision,
|
|
102
|
+
distance2 as distance,
|
|
103
|
+
easings2 as easings,
|
|
104
|
+
extend2 as extend,
|
|
105
|
+
floor2 as floor,
|
|
106
|
+
getData2 as getData,
|
|
107
|
+
hour2 as hour,
|
|
108
|
+
hourMilitary2 as hourMilitary,
|
|
109
|
+
importCodeURL2 as importCodeURL,
|
|
110
|
+
keyCodeToString2 as keyCodeToString,
|
|
111
|
+
lerp2 as lerp,
|
|
112
|
+
ln2 as ln,
|
|
113
|
+
log2 as log,
|
|
114
|
+
minute2 as minute,
|
|
115
|
+
mobile2 as mobile,
|
|
116
|
+
month2 as month,
|
|
117
|
+
months2 as months,
|
|
118
|
+
overlaps2 as overlaps,
|
|
119
|
+
pick2 as pick,
|
|
120
|
+
pow2 as pow,
|
|
121
|
+
random2 as random,
|
|
122
|
+
randomColor2 as randomColor,
|
|
123
|
+
randomFloat2 as randomFloat,
|
|
124
|
+
range2 as range,
|
|
125
|
+
remove2 as remove,
|
|
126
|
+
rgb2 as rgb,
|
|
127
|
+
second2 as second,
|
|
128
|
+
shuffle2 as shuffle,
|
|
129
|
+
sin2 as sin,
|
|
130
|
+
sqrt2 as sqrt,
|
|
131
|
+
tan2 as tan,
|
|
132
|
+
throttle2 as throttle,
|
|
133
|
+
unitsToMiliseconds2 as unitsToMiliseconds,
|
|
134
|
+
woof2 as woof,
|
|
135
|
+
year2 as year
|
|
241
136
|
};
|
package/dist/input.js
CHANGED
|
@@ -1,35 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
throw new Error("A keyboard event target is required");
|
|
5
|
-
const pressed = new Set;
|
|
6
|
-
const down = (event) => {
|
|
7
|
-
const code = event.code;
|
|
8
|
-
if (code)
|
|
9
|
-
pressed.add(code);
|
|
10
|
-
};
|
|
11
|
-
const up = (event) => {
|
|
12
|
-
pressed.delete(event.code);
|
|
13
|
-
};
|
|
14
|
-
const clear = () => pressed.clear();
|
|
15
|
-
target.addEventListener("keydown", down);
|
|
16
|
-
target.addEventListener("keyup", up);
|
|
17
|
-
target.addEventListener("blur", clear);
|
|
18
|
-
let destroyed = false;
|
|
19
|
-
return {
|
|
20
|
-
isDown: (code) => pressed.has(code),
|
|
21
|
-
clear,
|
|
22
|
-
destroy() {
|
|
23
|
-
if (destroyed)
|
|
24
|
-
return;
|
|
25
|
-
destroyed = true;
|
|
26
|
-
target.removeEventListener("keydown", down);
|
|
27
|
-
target.removeEventListener("keyup", up);
|
|
28
|
-
target.removeEventListener("blur", clear);
|
|
29
|
-
clear();
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createKeyboard2
|
|
3
|
+
} from "./index-b9a70qgn.js";
|
|
33
4
|
export {
|
|
34
|
-
createKeyboard
|
|
5
|
+
createKeyboard2 as createKeyboard
|
|
35
6
|
};
|