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 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
- "name": "core2d",
3
- "type": "module",
4
- "version": "2.11.1",
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
- }
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
- global.addEventListener = () => {};
7
+ global.addEventListener = () => {};
8
8
 
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
- }
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
- return {};
43
- },
44
- getElementsByTagName: () => {
45
- return [];
46
- },
47
- };
42
+ return {};
43
+ },
44
+ getElementsByTagName: () => {
45
+ return [];
46
+ },
47
+ };
48
48
 
49
- global.localStorage = {};
49
+ global.localStorage = {};
50
50
 
51
- /**
52
- * For older Node.js versions.
53
- */
54
- if (!global.navigator) {
55
- global.navigator = {};
56
- }
51
+ /**
52
+ * For older Node.js versions.
53
+ */
54
+ if (!global.navigator) {
55
+ global.navigator = {};
56
+ }
57
57
 
58
- global.window = {
59
- focus: () => {},
60
- innerHeight: 600,
61
- innerWidth: 800,
62
- requestAnimationFrame: () => true,
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
- document,
71
- window,
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
- * 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
- }
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
- * 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
- }
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
- * The image of the current frame.
31
- * @type {HTMLImageElement|HTMLCanvasElement}
32
- */
33
- get image() {
34
- return this._frames[this._index].image;
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
- * The width of the current frame.
39
- * @type {number}
40
- */
41
- get width() {
42
- return this._frames[this._index].width;
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
- * The height of the current frame.
47
- * @type {number}
48
- */
49
- get height() {
50
- return this._frames[this._index].height;
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
- * 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
- }
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
- * The index of the current frame.
66
- * @type {number}
67
- */
68
- set frameIndex(index) {
69
- this.setFrameIndex(index);
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
- * 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;
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
- if (DURATION && ++this._tick >= DURATION) {
81
- let index = this._index + 1;
80
+ if (DURATION && ++this._tick >= DURATION) {
81
+ let index = this._index + 1;
82
82
 
83
- if (index == this._frames.length) {
84
- hasLooped = true;
85
- index = 0;
86
- }
83
+ if (index == this._frames.length) {
84
+ hasLooped = true;
85
+ index = 0;
86
+ }
87
87
 
88
- this.setFrameIndex(index);
89
- }
88
+ this.setFrameIndex(index);
89
+ }
90
90
 
91
- return hasLooped;
92
- }
91
+ return hasLooped;
92
+ }
93
93
  }
@@ -3,41 +3,41 @@
3
3
  import { Static } from "./Static.mjs";
4
4
 
5
5
  export const ButtonLayout = {
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
- ]),
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
- 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
- ]),
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
  };
@@ -1,5 +1,5 @@
1
1
  "use static";
2
2
 
3
3
  export const ButtonLayoutMap = {
4
- "8bitdo s": "reversed",
4
+ "8bitdo s": "reversed",
5
5
  };