core2d 2.11.1 → 2.11.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/README.md +0 -1
- package/package.json +53 -53
- package/src/ACL.mjs +54 -54
- package/src/Animation.mjs +73 -73
- package/src/ButtonLayout.mjs +36 -36
- package/src/ButtonLayoutMap.mjs +1 -1
- package/src/Color.mjs +148 -148
- package/src/Command.mjs +10 -10
- package/src/CompositeOperations.mjs +11 -11
- package/src/Controller.mjs +82 -82
- package/src/Core2D.mjs +269 -269
- package/src/Direction.mjs +22 -22
- package/src/Engine.mjs +448 -448
- package/src/FontFamily.mjs +5 -5
- package/src/Frame.mjs +37 -37
- package/src/GamePad.mjs +43 -43
- package/src/Input.mjs +114 -114
- package/src/Key.mjs +18 -18
- package/src/KeyMap.mjs +18 -18
- package/src/Keyboard.mjs +28 -28
- package/src/Mouse.mjs +35 -35
- package/src/Point.mjs +61 -61
- package/src/Pointer.mjs +48 -48
- package/src/Rect.mjs +239 -239
- package/src/RenderableList.mjs +12 -12
- package/src/Scene.mjs +137 -137
- package/src/Sound.mjs +134 -134
- package/src/Sprite.mjs +686 -680
- package/src/Static.mjs +54 -54
- package/src/TextSprite.mjs +228 -228
- package/src/Touch.mjs +41 -41
- package/src/Transition.mjs +12 -12
- package/src/plugin/BaseTile.mjs +4 -4
- package/src/plugin/ClickableSprite.mjs +14 -14
- package/src/plugin/ControllableSprite.mjs +36 -36
- package/src/plugin/CursorSprite.mjs +32 -32
- package/src/plugin/Fog.mjs +23 -23
- package/src/plugin/FontSprite.mjs +59 -59
- package/src/plugin/JumperSprite.mjs +132 -132
- package/src/plugin/RandomRectTransition.mjs +22 -22
- package/src/plugin/Starfield.mjs +47 -47
package/README.md
CHANGED
|
@@ -118,7 +118,6 @@ To contribute to Core2D, you'll need to set up your development environment.
|
|
|
118
118
|
5. **Git Hooks:**
|
|
119
119
|
This project uses [husky](https://typicode.github.io/husky/) to manage Git hooks. A `pre-commit` hook is configured to run `npm test` before each commit. This ensures that all tests pass and the code is linted before it's committed. After running `npm install`, the hooks will be automatically configured.
|
|
120
120
|
|
|
121
|
-
|
|
122
121
|
# Hall of Fame
|
|
123
122
|
|
|
124
123
|
Apps created with Core2D:
|
package/package.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
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
|
-
|
|
2
|
+
"name": "core2d",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.11.4",
|
|
5
|
+
"description": "Multiplatform 2D interaction engine",
|
|
6
|
+
"files": [
|
|
7
|
+
"src"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"format": "prettier --write .",
|
|
11
|
+
"lint": "eslint",
|
|
12
|
+
"prepublishOnly": "git checkout main && git pull --rebase && npm test && git push && git push --tags",
|
|
13
|
+
"test": "npm run lint && for test in ./test/*.mjs; do node $test; done",
|
|
14
|
+
"prepare": "husky"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/dgchrt/core2d.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"2d",
|
|
22
|
+
"core",
|
|
23
|
+
"core2d",
|
|
24
|
+
"engine",
|
|
25
|
+
"game",
|
|
26
|
+
"game-engine",
|
|
27
|
+
"gamepad",
|
|
28
|
+
"interaction",
|
|
29
|
+
"keyboard",
|
|
30
|
+
"mouse",
|
|
31
|
+
"multi-platform",
|
|
32
|
+
"multimedia",
|
|
33
|
+
"object-oriented",
|
|
34
|
+
"sprites",
|
|
35
|
+
"scenes",
|
|
36
|
+
"touch"
|
|
37
|
+
],
|
|
38
|
+
"author": "Diogo Eichert",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/dgchrt/core2d/issues"
|
|
42
|
+
},
|
|
43
|
+
"funding": {
|
|
44
|
+
"url": "https://github.com/sponsors/dgchrt"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://dgchrt.github.io/core2d/",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@eslint/js": "^9.30.1",
|
|
49
|
+
"eslint": "^9.30.1",
|
|
50
|
+
"eslint-config-prettier": "^10.1.5",
|
|
51
|
+
"globals": "^16.3.0",
|
|
52
|
+
"husky": "^9.1.7",
|
|
53
|
+
"prettier": "^3.6.2"
|
|
54
|
+
}
|
|
55
55
|
}
|
package/src/ACL.mjs
CHANGED
|
@@ -4,69 +4,69 @@
|
|
|
4
4
|
* Sets up the environment based on its runtime (browser or not).
|
|
5
5
|
*/
|
|
6
6
|
if (typeof global != "undefined") {
|
|
7
|
-
|
|
7
|
+
global.addEventListener = () => {};
|
|
8
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
|
-
|
|
9
|
+
global.document = {
|
|
10
|
+
createElement: (name) => {
|
|
11
|
+
if (name == "canvas") {
|
|
12
|
+
return {
|
|
13
|
+
getContext: () => {
|
|
14
|
+
return {
|
|
15
|
+
measureText: (text) => {
|
|
16
|
+
return {
|
|
17
|
+
width: text.length,
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
getElementById: (id) => {
|
|
26
|
+
if (id == "app") {
|
|
27
|
+
return {
|
|
28
|
+
focus: () => {},
|
|
29
|
+
getContext: () => {
|
|
30
|
+
return {
|
|
31
|
+
fillRect: () => {},
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
height: 400,
|
|
35
|
+
offsetLeft: 0,
|
|
36
|
+
offsetTop: 0,
|
|
37
|
+
style: {},
|
|
38
|
+
width: 640,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
return {};
|
|
43
|
+
},
|
|
44
|
+
getElementsByTagName: () => {
|
|
45
|
+
return [];
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
global.localStorage = {};
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
/**
|
|
52
|
+
* For older Node.js versions.
|
|
53
|
+
*/
|
|
54
|
+
if (!global.navigator) {
|
|
55
|
+
global.navigator = {};
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
global.window = {
|
|
59
|
+
focus: () => {},
|
|
60
|
+
innerHeight: 600,
|
|
61
|
+
innerWidth: 800,
|
|
62
|
+
requestAnimationFrame: () => true,
|
|
63
|
+
};
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Anti-Corruption Layer, to be used instead of direct API calls.
|
|
68
68
|
*/
|
|
69
69
|
export const ACL = {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
document,
|
|
71
|
+
window,
|
|
72
72
|
};
|
package/src/Animation.mjs
CHANGED
|
@@ -6,88 +6,88 @@ import { Frame } from "./Frame.mjs";
|
|
|
6
6
|
* Represents an animation, which is a sequence of frames.
|
|
7
7
|
*/
|
|
8
8
|
export class Animation {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new Animation.
|
|
11
|
+
* @param {Frame[]} frames The frames of the animation.
|
|
12
|
+
*/
|
|
13
|
+
constructor(frames) {
|
|
14
|
+
this._frames = frames;
|
|
15
|
+
this._index = 0;
|
|
16
|
+
this._tick = 0;
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new Animation from a list of images.
|
|
21
|
+
* @param {HTMLImageElement[]|HTMLCanvasElement[]} images The images of the animation.
|
|
22
|
+
* @param {number} duration The duration of each frame in ticks.
|
|
23
|
+
* @returns {Animation} The new animation.
|
|
24
|
+
*/
|
|
25
|
+
static fromImages(images, duration) {
|
|
26
|
+
return new this(images.map((image) => new Frame(image, duration)));
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The image of the current frame.
|
|
31
|
+
* @type {HTMLImageElement|HTMLCanvasElement}
|
|
32
|
+
*/
|
|
33
|
+
get image() {
|
|
34
|
+
return this._frames[this._index].image;
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The width of the current frame.
|
|
39
|
+
* @type {number}
|
|
40
|
+
*/
|
|
41
|
+
get width() {
|
|
42
|
+
return this._frames[this._index].width;
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The height of the current frame.
|
|
47
|
+
* @type {number}
|
|
48
|
+
*/
|
|
49
|
+
get height() {
|
|
50
|
+
return this._frames[this._index].height;
|
|
51
|
+
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Sets the index of the current frame.
|
|
55
|
+
* @param {number} index The index of the frame.
|
|
56
|
+
*/
|
|
57
|
+
setFrameIndex(index) {
|
|
58
|
+
if (index < this._frames.length) {
|
|
59
|
+
this._index = index;
|
|
60
|
+
this._tick = 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The index of the current frame.
|
|
66
|
+
* @type {number}
|
|
67
|
+
*/
|
|
68
|
+
set frameIndex(index) {
|
|
69
|
+
this.setFrameIndex(index);
|
|
70
|
+
}
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Synchronizes the animation.
|
|
74
|
+
* @returns {boolean} Whether the animation has looped.
|
|
75
|
+
*/
|
|
76
|
+
sync() {
|
|
77
|
+
const DURATION = this._frames[this._index].duration;
|
|
78
|
+
let hasLooped = false;
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if (DURATION && ++this._tick >= DURATION) {
|
|
81
|
+
let index = this._index + 1;
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
if (index == this._frames.length) {
|
|
84
|
+
hasLooped = true;
|
|
85
|
+
index = 0;
|
|
86
|
+
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
this.setFrameIndex(index);
|
|
89
|
+
}
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
return hasLooped;
|
|
92
|
+
}
|
|
93
93
|
}
|
package/src/ButtonLayout.mjs
CHANGED
|
@@ -3,41 +3,41 @@
|
|
|
3
3
|
import { Static } from "./Static.mjs";
|
|
4
4
|
|
|
5
5
|
export const ButtonLayout = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
reversed: Static.makeEnum([
|
|
7
|
+
"B",
|
|
8
|
+
"A",
|
|
9
|
+
"Y",
|
|
10
|
+
"X",
|
|
11
|
+
"L1",
|
|
12
|
+
"R1",
|
|
13
|
+
"L2",
|
|
14
|
+
"R2",
|
|
15
|
+
"SELECT",
|
|
16
|
+
"START",
|
|
17
|
+
"L3",
|
|
18
|
+
"R3",
|
|
19
|
+
"UP",
|
|
20
|
+
"DOWN",
|
|
21
|
+
"LEFT",
|
|
22
|
+
"RIGHT",
|
|
23
|
+
]),
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
standard: Static.makeEnum([
|
|
26
|
+
"A",
|
|
27
|
+
"B",
|
|
28
|
+
"X",
|
|
29
|
+
"Y",
|
|
30
|
+
"L1",
|
|
31
|
+
"R1",
|
|
32
|
+
"L2",
|
|
33
|
+
"R2",
|
|
34
|
+
"SELECT",
|
|
35
|
+
"START",
|
|
36
|
+
"L3",
|
|
37
|
+
"R3",
|
|
38
|
+
"UP",
|
|
39
|
+
"DOWN",
|
|
40
|
+
"LEFT",
|
|
41
|
+
"RIGHT",
|
|
42
|
+
]),
|
|
43
43
|
};
|
package/src/ButtonLayoutMap.mjs
CHANGED