core2d 2.10.4 → 2.11.2

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/src/Color.mjs CHANGED
@@ -3,152 +3,152 @@
3
3
  import { Static } from "./Static.mjs";
4
4
 
5
5
  export const Color = Static.makeHash([
6
- "AliceBlue",
7
- "AntiqueWhite",
8
- "Aqua",
9
- "Aquamarine",
10
- "Azure",
11
- "Beige",
12
- "Bisque",
13
- "Black",
14
- "BlanchedAlmond",
15
- "Blue",
16
- "BlueViolet",
17
- "Brown",
18
- "BurlyWood",
19
- "CadetBlue",
20
- "Chartreuse",
21
- "Chocolate",
22
- "Coral",
23
- "CornflowerBlue",
24
- "Cornsilk",
25
- "Crimson",
26
- "Cyan",
27
- "DarkBlue",
28
- "DarkCyan",
29
- "DarkGoldenRod",
30
- "DarkGray",
31
- "DarkGreen",
32
- "DarkGrey",
33
- "DarkKhaki",
34
- "DarkMagenta",
35
- "DarkOliveGreen",
36
- "Darkorange",
37
- "DarkOrchid",
38
- "DarkRed",
39
- "DarkSalmon",
40
- "DarkSeaGreen",
41
- "DarkSlateBlue",
42
- "DarkSlateGray",
43
- "DarkSlateGrey",
44
- "DarkTurquoise",
45
- "DarkViolet",
46
- "DeepPink",
47
- "DeepSkyBlue",
48
- "DimGray",
49
- "DimGrey",
50
- "DodgerBlue",
51
- "FireBrick",
52
- "FloralWhite",
53
- "ForestGreen",
54
- "Fuchsia",
55
- "Gainsboro",
56
- "GhostWhite",
57
- "Gold",
58
- "GoldenRod",
59
- "Gray",
60
- "Green",
61
- "GreenYellow",
62
- "Grey",
63
- "HoneyDew",
64
- "HotPink",
65
- "IndianRed",
66
- "Indigo",
67
- "Ivory",
68
- "Khaki",
69
- "Lavender",
70
- "LavenderBlush",
71
- "LawnGreen",
72
- "LemonChiffon",
73
- "LightBlue",
74
- "LightCoral",
75
- "LightCyan",
76
- "LightGoldenRodYellow",
77
- "LightGray",
78
- "LightGreen",
79
- "LightGrey",
80
- "LightPink",
81
- "LightSalmon",
82
- "LightSeaGreen",
83
- "LightSkyBlue",
84
- "LightSlateGray",
85
- "LightSlateGrey",
86
- "LightSteelBlue",
87
- "LightYellow",
88
- "Lime",
89
- "LimeGreen",
90
- "Linen",
91
- "Magenta",
92
- "Maroon",
93
- "MediumAquaMarine",
94
- "MediumBlue",
95
- "MediumOrchid",
96
- "MediumPurple",
97
- "MediumSeaGreen",
98
- "MediumSlateBlue",
99
- "MediumSpringGreen",
100
- "MediumTurquoise",
101
- "MediumVioletRed",
102
- "MidnightBlue",
103
- "MintCream",
104
- "MistyRose",
105
- "Moccasin",
106
- "NavajoWhite",
107
- "Navy",
108
- "OldLace",
109
- "Olive",
110
- "OliveDrab",
111
- "Orange",
112
- "OrangeRed",
113
- "Orchid",
114
- "PaleGoldenRod",
115
- "PaleGreen",
116
- "PaleTurquoise",
117
- "PaleVioletRed",
118
- "PapayaWhip",
119
- "PeachPuff",
120
- "Peru",
121
- "Pink",
122
- "Plum",
123
- "PowderBlue",
124
- "Purple",
125
- "RebeccaPurple",
126
- "Red",
127
- "RosyBrown",
128
- "RoyalBlue",
129
- "SaddleBrown",
130
- "Salmon",
131
- "SandyBrown",
132
- "SeaGreen",
133
- "SeaShell",
134
- "Sienna",
135
- "Silver",
136
- "SkyBlue",
137
- "SlateBlue",
138
- "SlateGray",
139
- "SlateGrey",
140
- "Snow",
141
- "SpringGreen",
142
- "SteelBlue",
143
- "Tan",
144
- "Teal",
145
- "Thistle",
146
- "Tomato",
147
- "Turquoise",
148
- "Violet",
149
- "Wheat",
150
- "White",
151
- "WhiteSmoke",
152
- "Yellow",
153
- "YellowGreen",
6
+ "AliceBlue",
7
+ "AntiqueWhite",
8
+ "Aqua",
9
+ "Aquamarine",
10
+ "Azure",
11
+ "Beige",
12
+ "Bisque",
13
+ "Black",
14
+ "BlanchedAlmond",
15
+ "Blue",
16
+ "BlueViolet",
17
+ "Brown",
18
+ "BurlyWood",
19
+ "CadetBlue",
20
+ "Chartreuse",
21
+ "Chocolate",
22
+ "Coral",
23
+ "CornflowerBlue",
24
+ "Cornsilk",
25
+ "Crimson",
26
+ "Cyan",
27
+ "DarkBlue",
28
+ "DarkCyan",
29
+ "DarkGoldenRod",
30
+ "DarkGray",
31
+ "DarkGreen",
32
+ "DarkGrey",
33
+ "DarkKhaki",
34
+ "DarkMagenta",
35
+ "DarkOliveGreen",
36
+ "Darkorange",
37
+ "DarkOrchid",
38
+ "DarkRed",
39
+ "DarkSalmon",
40
+ "DarkSeaGreen",
41
+ "DarkSlateBlue",
42
+ "DarkSlateGray",
43
+ "DarkSlateGrey",
44
+ "DarkTurquoise",
45
+ "DarkViolet",
46
+ "DeepPink",
47
+ "DeepSkyBlue",
48
+ "DimGray",
49
+ "DimGrey",
50
+ "DodgerBlue",
51
+ "FireBrick",
52
+ "FloralWhite",
53
+ "ForestGreen",
54
+ "Fuchsia",
55
+ "Gainsboro",
56
+ "GhostWhite",
57
+ "Gold",
58
+ "GoldenRod",
59
+ "Gray",
60
+ "Green",
61
+ "GreenYellow",
62
+ "Grey",
63
+ "HoneyDew",
64
+ "HotPink",
65
+ "IndianRed",
66
+ "Indigo",
67
+ "Ivory",
68
+ "Khaki",
69
+ "Lavender",
70
+ "LavenderBlush",
71
+ "LawnGreen",
72
+ "LemonChiffon",
73
+ "LightBlue",
74
+ "LightCoral",
75
+ "LightCyan",
76
+ "LightGoldenRodYellow",
77
+ "LightGray",
78
+ "LightGreen",
79
+ "LightGrey",
80
+ "LightPink",
81
+ "LightSalmon",
82
+ "LightSeaGreen",
83
+ "LightSkyBlue",
84
+ "LightSlateGray",
85
+ "LightSlateGrey",
86
+ "LightSteelBlue",
87
+ "LightYellow",
88
+ "Lime",
89
+ "LimeGreen",
90
+ "Linen",
91
+ "Magenta",
92
+ "Maroon",
93
+ "MediumAquaMarine",
94
+ "MediumBlue",
95
+ "MediumOrchid",
96
+ "MediumPurple",
97
+ "MediumSeaGreen",
98
+ "MediumSlateBlue",
99
+ "MediumSpringGreen",
100
+ "MediumTurquoise",
101
+ "MediumVioletRed",
102
+ "MidnightBlue",
103
+ "MintCream",
104
+ "MistyRose",
105
+ "Moccasin",
106
+ "NavajoWhite",
107
+ "Navy",
108
+ "OldLace",
109
+ "Olive",
110
+ "OliveDrab",
111
+ "Orange",
112
+ "OrangeRed",
113
+ "Orchid",
114
+ "PaleGoldenRod",
115
+ "PaleGreen",
116
+ "PaleTurquoise",
117
+ "PaleVioletRed",
118
+ "PapayaWhip",
119
+ "PeachPuff",
120
+ "Peru",
121
+ "Pink",
122
+ "Plum",
123
+ "PowderBlue",
124
+ "Purple",
125
+ "RebeccaPurple",
126
+ "Red",
127
+ "RosyBrown",
128
+ "RoyalBlue",
129
+ "SaddleBrown",
130
+ "Salmon",
131
+ "SandyBrown",
132
+ "SeaGreen",
133
+ "SeaShell",
134
+ "Sienna",
135
+ "Silver",
136
+ "SkyBlue",
137
+ "SlateBlue",
138
+ "SlateGray",
139
+ "SlateGrey",
140
+ "Snow",
141
+ "SpringGreen",
142
+ "SteelBlue",
143
+ "Tan",
144
+ "Teal",
145
+ "Thistle",
146
+ "Tomato",
147
+ "Turquoise",
148
+ "Violet",
149
+ "Wheat",
150
+ "White",
151
+ "WhiteSmoke",
152
+ "Yellow",
153
+ "YellowGreen",
154
154
  ]);
package/src/Command.mjs CHANGED
@@ -3,14 +3,14 @@
3
3
  import { Static } from "./Static.mjs";
4
4
 
5
5
  export const Command = Static.makeEnum([
6
- "UP",
7
- "DOWN",
8
- "LEFT",
9
- "RIGHT",
10
- "A",
11
- "B",
12
- "X",
13
- "Y",
14
- "SELECT",
15
- "START",
6
+ "UP",
7
+ "DOWN",
8
+ "LEFT",
9
+ "RIGHT",
10
+ "A",
11
+ "B",
12
+ "X",
13
+ "Y",
14
+ "SELECT",
15
+ "START",
16
16
  ]);
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  export const CompositeOperations = {
4
- COPY: "copy",
5
- DESTINATION_ATOP: "destination-atop",
6
- DESTINATION_IN: "destination-in",
7
- DESTINATION_OUT: "destination-out",
8
- DESTINATION_OVER: "destination-over",
9
- LIGHTER: "lighter",
10
- SOURCE_ATOP: "source-atop",
11
- SOURCE_IN: "source-in",
12
- SOURCE_OUT: "source-out",
13
- SOURCE_OVER: "source-over",
14
- XOR: "xor",
4
+ COPY: "copy",
5
+ DESTINATION_ATOP: "destination-atop",
6
+ DESTINATION_IN: "destination-in",
7
+ DESTINATION_OUT: "destination-out",
8
+ DESTINATION_OVER: "destination-over",
9
+ LIGHTER: "lighter",
10
+ SOURCE_ATOP: "source-atop",
11
+ SOURCE_IN: "source-in",
12
+ SOURCE_OUT: "source-out",
13
+ SOURCE_OVER: "source-over",
14
+ XOR: "xor",
15
15
  };
@@ -2,66 +2,101 @@
2
2
 
3
3
  import { Command } from "./Command.mjs";
4
4
 
5
+ /**
6
+ * Represents a controller, which can be a gamepad or a keyboard.
7
+ */
5
8
  export class Controller {
6
- constructor() {
7
- this.tolerance = 0;
8
- this._active = {};
9
- this._device = null;
10
- this._hold = {};
11
- this._sequence = [];
12
- this._tick = 0;
13
- }
9
+ /**
10
+ * Creates a new Controller.
11
+ */
12
+ constructor() {
13
+ /**
14
+ * The tolerance for the command sequence.
15
+ * @type {number}
16
+ */
17
+ this.tolerance = 0;
18
+ this._active = {};
19
+ this._device = null;
20
+ this._hold = {};
21
+ this._sequence = [];
22
+ this._tick = 0;
23
+ }
14
24
 
15
- didPerform(commands) {
16
- for (let i = 1; i <= commands.length; ++i) {
17
- if (this._sequence[this._sequence.length - i] != commands[commands.length - i]) {
18
- return false;
19
- }
20
- }
25
+ /**
26
+ * Checks if a sequence of commands was performed.
27
+ * @param {Command[]} commands The sequence of commands.
28
+ * @returns {boolean} Whether the sequence of commands was performed.
29
+ */
30
+ didPerform(commands) {
31
+ for (let i = 1; i <= commands.length; ++i) {
32
+ if (
33
+ this._sequence[this._sequence.length - i] !=
34
+ commands[commands.length - i]
35
+ ) {
36
+ return false;
37
+ }
38
+ }
21
39
 
22
- this._sequence = [];
23
- return true;
24
- }
40
+ this._sequence = [];
41
+ return true;
42
+ }
25
43
 
26
- keyDown(command) {
27
- return this._active[command];
28
- }
44
+ /**
45
+ * Checks if a command is being held down.
46
+ * @param {Command} command The command to check.
47
+ * @returns {boolean} Whether the command is being held down.
48
+ */
49
+ keyDown(command) {
50
+ return this._active[command];
51
+ }
29
52
 
30
- keyPush(command) {
31
- return this._active[command] && !this._hold[command];
32
- }
53
+ /**
54
+ * Checks if a command was just pushed.
55
+ * @param {Command} command The command to check.
56
+ * @returns {boolean} Whether the command was just pushed.
57
+ */
58
+ keyPush(command) {
59
+ return this._active[command] && !this._hold[command];
60
+ }
33
61
 
34
- setDevice(device) {
35
- this._device = device;
36
- }
62
+ /**
63
+ * Sets the device of the controller.
64
+ * @param {object} device The device.
65
+ */
66
+ setDevice(device) {
67
+ this._device = device;
68
+ }
37
69
 
38
- update() {
39
- if (!this._device) {
40
- return;
41
- }
70
+ /**
71
+ * Updates the controller.
72
+ */
73
+ update() {
74
+ if (!this._device) {
75
+ return;
76
+ }
42
77
 
43
- this._hold = {};
44
- const LAST = this._active;
45
- this._active = this._device.commands;
78
+ this._hold = {};
79
+ const LAST = this._active;
80
+ this._active = this._device.commands;
46
81
 
47
- for (let i in this._active) {
48
- if (LAST[i]) {
49
- this._hold[i] = true;
50
- }
51
- }
82
+ for (let i in this._active) {
83
+ if (LAST[i]) {
84
+ this._hold[i] = true;
85
+ }
86
+ }
52
87
 
53
- if (this.tolerance && ++this._tick > this.tolerance) {
54
- this._sequence = [];
55
- this._tick = 0;
56
- }
88
+ if (this.tolerance && ++this._tick > this.tolerance) {
89
+ this._sequence = [];
90
+ this._tick = 0;
91
+ }
57
92
 
58
- for (let i in Command) {
59
- const COMMAND = Command[i];
93
+ for (let i in Command) {
94
+ const COMMAND = Command[i];
60
95
 
61
- if (this.keyPush(COMMAND)) {
62
- this._sequence.push(COMMAND);
63
- this._tick = 0;
64
- }
65
- }
66
- }
96
+ if (this.keyPush(COMMAND)) {
97
+ this._sequence.push(COMMAND);
98
+ this._tick = 0;
99
+ }
100
+ }
101
+ }
67
102
  }