@vpmedia/phaser 1.0.1 → 1.0.3

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.
Files changed (112) hide show
  1. package/README.md +20 -3
  2. package/dist/phaser.cjs +1 -1
  3. package/dist/phaser.cjs.LICENSE.txt +1 -1
  4. package/dist/phaser.cjs.map +1 -1
  5. package/dist/phaser.js +1 -1
  6. package/dist/phaser.js.LICENSE.txt +1 -1
  7. package/dist/phaser.js.map +1 -1
  8. package/package.json +23 -17
  9. package/src/index.js +142 -0
  10. package/src/phaser/core/animation.js +355 -0
  11. package/src/phaser/core/animation_manager.js +238 -0
  12. package/src/phaser/core/animation_parser.js +133 -0
  13. package/src/phaser/core/array_set.js +107 -0
  14. package/src/phaser/core/cache.js +558 -0
  15. package/src/phaser/core/const.js +106 -0
  16. package/src/phaser/core/device.js +67 -0
  17. package/src/phaser/core/device_util.js +388 -0
  18. package/src/phaser/core/dom.js +207 -0
  19. package/src/phaser/core/event_manager.js +243 -0
  20. package/src/phaser/core/factory.js +74 -0
  21. package/src/phaser/core/frame.js +75 -0
  22. package/src/phaser/core/frame_data.js +84 -0
  23. package/src/phaser/core/frame_util.js +33 -0
  24. package/src/phaser/core/game.js +412 -0
  25. package/src/phaser/core/input.js +401 -0
  26. package/src/phaser/core/input_button.js +102 -0
  27. package/src/phaser/core/input_handler.js +687 -0
  28. package/src/phaser/core/input_mouse.js +289 -0
  29. package/src/phaser/core/input_mspointer.js +197 -0
  30. package/src/phaser/core/input_pointer.js +427 -0
  31. package/src/phaser/core/input_touch.js +157 -0
  32. package/src/phaser/core/loader.js +1057 -0
  33. package/src/phaser/core/loader_parser.js +109 -0
  34. package/src/phaser/core/raf.js +46 -0
  35. package/src/phaser/core/raf_fb.js +75 -0
  36. package/src/phaser/core/raf_to.js +34 -0
  37. package/src/phaser/core/scale_manager.js +806 -0
  38. package/src/phaser/core/scene.js +65 -0
  39. package/src/phaser/core/scene_manager.js +309 -0
  40. package/src/phaser/core/signal.js +175 -0
  41. package/src/phaser/core/signal_binding.js +69 -0
  42. package/src/phaser/core/sound.js +538 -0
  43. package/src/phaser/core/sound_manager.js +364 -0
  44. package/src/phaser/core/stage.js +108 -0
  45. package/src/phaser/core/time.js +203 -0
  46. package/src/phaser/core/timer.js +276 -0
  47. package/src/phaser/core/timer_event.js +21 -0
  48. package/src/phaser/core/tween.js +329 -0
  49. package/src/phaser/core/tween_data.js +258 -0
  50. package/src/phaser/core/tween_easing.js +341 -0
  51. package/src/phaser/core/tween_manager.js +185 -0
  52. package/src/phaser/core/world.js +18 -0
  53. package/src/phaser/display/bitmap_text.js +322 -0
  54. package/src/phaser/display/button.js +194 -0
  55. package/src/phaser/display/canvas/buffer.js +36 -0
  56. package/src/phaser/display/canvas/graphics.js +227 -0
  57. package/src/phaser/display/canvas/masker.js +39 -0
  58. package/src/phaser/display/canvas/pool.js +126 -0
  59. package/src/phaser/display/canvas/renderer.js +123 -0
  60. package/src/phaser/display/canvas/tinter.js +144 -0
  61. package/src/phaser/display/canvas/util.js +159 -0
  62. package/src/phaser/display/display_object.js +597 -0
  63. package/src/phaser/display/graphics.js +723 -0
  64. package/src/phaser/display/graphics_data.js +27 -0
  65. package/src/phaser/display/graphics_data_util.js +15 -0
  66. package/src/phaser/display/group.js +227 -0
  67. package/src/phaser/display/image.js +288 -0
  68. package/src/phaser/display/sprite_batch.js +15 -0
  69. package/src/phaser/display/sprite_util.js +250 -0
  70. package/src/phaser/display/text.js +1089 -0
  71. package/src/phaser/display/webgl/abstract_filter.js +25 -0
  72. package/src/phaser/display/webgl/base_texture.js +68 -0
  73. package/src/phaser/display/webgl/blend_manager.js +35 -0
  74. package/src/phaser/display/webgl/earcut.js +662 -0
  75. package/src/phaser/display/webgl/earcut_node.js +28 -0
  76. package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
  77. package/src/phaser/display/webgl/filter_manager.js +46 -0
  78. package/src/phaser/display/webgl/filter_texture.js +61 -0
  79. package/src/phaser/display/webgl/graphics.js +624 -0
  80. package/src/phaser/display/webgl/graphics_data.js +42 -0
  81. package/src/phaser/display/webgl/mask_manager.js +36 -0
  82. package/src/phaser/display/webgl/render_texture.js +81 -0
  83. package/src/phaser/display/webgl/renderer.js +234 -0
  84. package/src/phaser/display/webgl/shader/complex.js +74 -0
  85. package/src/phaser/display/webgl/shader/fast.js +97 -0
  86. package/src/phaser/display/webgl/shader/normal.js +225 -0
  87. package/src/phaser/display/webgl/shader/primitive.js +72 -0
  88. package/src/phaser/display/webgl/shader/strip.js +77 -0
  89. package/src/phaser/display/webgl/shader_manager.js +89 -0
  90. package/src/phaser/display/webgl/sprite_batch.js +320 -0
  91. package/src/phaser/display/webgl/stencil_manager.js +170 -0
  92. package/src/phaser/display/webgl/texture.js +117 -0
  93. package/src/phaser/display/webgl/texture_util.js +34 -0
  94. package/src/phaser/display/webgl/util.js +78 -0
  95. package/src/phaser/geom/circle.js +186 -0
  96. package/src/phaser/geom/ellipse.js +65 -0
  97. package/src/phaser/geom/line.js +190 -0
  98. package/src/phaser/geom/matrix.js +147 -0
  99. package/src/phaser/geom/point.js +164 -0
  100. package/src/phaser/geom/polygon.js +140 -0
  101. package/src/phaser/geom/rectangle.js +306 -0
  102. package/src/phaser/geom/rounded_rectangle.js +36 -0
  103. package/src/phaser/geom/util/circle.js +122 -0
  104. package/src/phaser/geom/util/ellipse.js +34 -0
  105. package/src/phaser/geom/util/line.js +135 -0
  106. package/src/phaser/geom/util/matrix.js +53 -0
  107. package/src/phaser/geom/util/point.js +296 -0
  108. package/src/phaser/geom/util/polygon.js +28 -0
  109. package/src/phaser/geom/util/rectangle.js +229 -0
  110. package/src/phaser/geom/util/rounded_rectangle.js +32 -0
  111. package/src/phaser/util/math.js +297 -0
  112. package/src/phaser/util/string.js +32 -0
@@ -0,0 +1,229 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import Rectangle from '../rectangle';
7
+ import Point from '../point';
8
+
9
+ /**
10
+ *
11
+ * @param {object} a TBD
12
+ * @param {number} dx TBD
13
+ * @param {number} dy TBD
14
+ * @returns {object} TBD
15
+ */
16
+ export function inflate(a, dx, dy) {
17
+ a.x -= dx;
18
+ a.width += 2 * dx;
19
+ a.y -= dy;
20
+ a.height += 2 * dy;
21
+ return a;
22
+ }
23
+
24
+ /**
25
+ *
26
+ * @param {object} a TBD
27
+ * @param {object} point TBD
28
+ * @returns {object} TBD
29
+ */
30
+ export function inflatePoint(a, point) {
31
+ return inflate(a, point.x, point.y);
32
+ }
33
+
34
+ /**
35
+ *
36
+ * @param {object} a TBD
37
+ * @param {object} output TBD
38
+ * @returns {object} TBD
39
+ */
40
+ export function size(a, output = null) {
41
+ const result = output || new Point();
42
+ result.setTo(a.width, a.height);
43
+ return result;
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @param {object} input TBD
49
+ * @param {object} output TBD
50
+ * @returns {object} TBD
51
+ */
52
+ export function clone(input, output = null) {
53
+ const result = output || new Rectangle();
54
+ result.setTo(input.x, input.y, input.width, input.height);
55
+ return result;
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @param {object} a TBD
61
+ * @param {number} x TBD
62
+ * @param {number} y TBD
63
+ * @returns {boolean} TBD
64
+ */
65
+ export function contains(a, x, y) {
66
+ if (a.width <= 0 || a.height <= 0) {
67
+ return false;
68
+ }
69
+ return (x >= a.x && x < a.right && y >= a.y && y < a.bottom);
70
+ }
71
+
72
+ /**
73
+ *
74
+ * @param {number} rx TBD
75
+ * @param {number} ry TBD
76
+ * @param {number} rw TBD
77
+ * @param {number} rh TBD
78
+ * @param {number} x TBD
79
+ * @param {number} y TBD
80
+ * @returns {boolean} TBD
81
+ */
82
+ export function containsRaw(rx, ry, rw, rh, x, y) {
83
+ return (x >= rx && x < (rx + rw) && y >= ry && y < (ry + rh));
84
+ }
85
+
86
+ /**
87
+ *
88
+ * @param {object} a TBD
89
+ * @param {object} point TBD
90
+ * @returns {boolean} TBD
91
+ */
92
+ export function containsPoint(a, point) {
93
+ return contains(a, point.x, point.y);
94
+ }
95
+
96
+ /**
97
+ *
98
+ * @param {object} a TBD
99
+ * @param {object} b TBD
100
+ * @returns {boolean} TBD
101
+ */
102
+ export function containsRect(a, b) {
103
+ if (a.volume > b.volume) {
104
+ return false;
105
+ }
106
+ return (a.x >= b.x && a.y >= b.y && a.right < b.right && a.bottom < b.bottom);
107
+ }
108
+
109
+ /**
110
+ *
111
+ * @param {object} a TBD
112
+ * @param {object} b TBD
113
+ * @returns {boolean} TBD
114
+ */
115
+ export function equals(a, b) {
116
+ return (a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height);
117
+ }
118
+
119
+ /**
120
+ *
121
+ * @param {object} a TBD
122
+ * @param {object} b TBD
123
+ * @returns {boolean} TBD
124
+ */
125
+ export function sameDimensions(a, b) {
126
+ return (a.width === b.width && a.height === b.height);
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @param {object} a TBD
132
+ * @param {object} b TBD
133
+ * @returns {boolean} TBD
134
+ */
135
+ export function intersects(a, b) {
136
+ if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0) {
137
+ return false;
138
+ }
139
+ return !(a.right < b.x || a.bottom < b.y || a.x > b.right || a.y > b.bottom);
140
+ }
141
+
142
+ /**
143
+ *
144
+ * @param {object} a TBD
145
+ * @param {object} b TBD
146
+ * @param {object} output TBD
147
+ * @returns {object} TBD
148
+ */
149
+ export function intersection(a, b, output = null) {
150
+ const result = output || new Rectangle();
151
+ if (intersects(a, b)) {
152
+ result.x = Math.max(a.x, b.x);
153
+ result.y = Math.max(a.y, b.y);
154
+ result.width = Math.min(a.right, b.right) - result.x;
155
+ result.height = Math.min(a.bottom, b.bottom) - result.y;
156
+ }
157
+ return result;
158
+ }
159
+
160
+ /**
161
+ *
162
+ * @param {object} a TBD
163
+ * @param {number} left TBD
164
+ * @param {number} right TBD
165
+ * @param {number} top TBD
166
+ * @param {number} bottom TBD
167
+ * @param {number} tolerance TBD
168
+ * @returns {boolean} TBD
169
+ */
170
+ export function intersectsRaw(a, left, right, top, bottom, tolerance = 0) {
171
+ return !(left > a.right + tolerance || right < a.left - tolerance || top > a.bottom + tolerance || bottom < a.top - tolerance);
172
+ }
173
+
174
+ /**
175
+ *
176
+ * @param {object} a TBD
177
+ * @param {object} b TBD
178
+ * @param {object} output TBD
179
+ * @returns {object} TBD
180
+ */
181
+ export function union(a, b, output = null) {
182
+ const result = output || new Rectangle();
183
+ return result.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right) - Math.min(a.left, b.left), Math.max(a.bottom, b.bottom) - Math.min(a.top, b.top));
184
+ }
185
+
186
+ /**
187
+ *
188
+ * @param {object[]} points TBD
189
+ * @param {object} output TBD
190
+ * @returns {object} TBD
191
+ */
192
+ export function aabb(points, output = null) {
193
+ const result = output || new Rectangle();
194
+ let xMax = Number.NEGATIVE_INFINITY;
195
+ let xMin = Number.POSITIVE_INFINITY;
196
+ let yMax = Number.NEGATIVE_INFINITY;
197
+ let yMin = Number.POSITIVE_INFINITY;
198
+ points.forEach((point) => {
199
+ if (point.x > xMax) {
200
+ xMax = point.x;
201
+ }
202
+ if (point.x < xMin) {
203
+ xMin = point.x;
204
+ }
205
+ if (point.y > yMax) {
206
+ yMax = point.y;
207
+ }
208
+ if (point.y < yMin) {
209
+ yMin = point.y;
210
+ }
211
+ });
212
+ result.setTo(xMin, yMin, xMax - xMin, yMax - yMin);
213
+ return result;
214
+ }
215
+
216
+ /**
217
+ * TBD
218
+ *
219
+ * @returns {object} TBD
220
+ */
221
+ export function getEmptyRectangle() {
222
+ if (!window.PhaserRegistry) {
223
+ window.PhaserRegistry = {};
224
+ }
225
+ if (!window.PhaserRegistry.EMPTY_RECTANGLE) {
226
+ window.PhaserRegistry.EMPTY_RECTANGLE = new Rectangle();
227
+ }
228
+ return window.PhaserRegistry.EMPTY_RECTANGLE;
229
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import RoundedRectangle from '../rounded_rectangle';
7
+
8
+ /**
9
+ * TBD
10
+ *
11
+ * @deprecated
12
+ * @returns {boolean} TBD
13
+ */
14
+ export default function () {
15
+ return true;
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param {object} input TBD
21
+ * @param {object} output TBD
22
+ * @returns {object} TBD
23
+ */
24
+ export function clone(input, output = null) {
25
+ const result = output || new RoundedRectangle();
26
+ result.x = input.x;
27
+ result.y = input.y;
28
+ result.width = input.width;
29
+ result.height = input.height;
30
+ result.radius = input.radius;
31
+ return result;
32
+ }
@@ -0,0 +1,297 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ export const DEG_TO_RAD = Math.PI / 180;
7
+ export const RAD_TO_DEG = 180 / Math.PI;
8
+ export const PI_2 = Math.PI * 2;
9
+
10
+ /**
11
+ *
12
+ * @param {number} hex TBD
13
+ * @returns {number[]} TBD
14
+ */
15
+ export function hex2rgb(hex) {
16
+ return [(hex >> 16 & 0xFF) / 255, (hex >> 8 & 0xFF) / 255, (hex & 0xFF) / 255];
17
+ }
18
+
19
+ /**
20
+ *
21
+ * @param {number} rgb TBD
22
+ * @returns {number} TBD
23
+ */
24
+ export function rgb2hex(rgb) {
25
+ return ((rgb[0] * 255 << 16) + (rgb[1] * 255 << 8) + rgb[2] * 255);
26
+ }
27
+
28
+ /**
29
+ *
30
+ * @param {number} value TBD
31
+ * @returns {number} TBD
32
+ */
33
+ export function getNextPowerOfTwo(value) {
34
+ // see: https://en.wikipedia.org/wiki/Power_of_two#Fast_algorithm_to_check_if_a_positive_number_is_a_power_of_two
35
+ if (value > 0 && (value & (value - 1)) === 0) {
36
+ return value;
37
+ }
38
+ let result = 1;
39
+ while (result < value) {
40
+ result <<= 1;
41
+ }
42
+ return result;
43
+ }
44
+
45
+ /**
46
+ *
47
+ * @param {number} width TBD
48
+ * @param {number} height TBD
49
+ * @returns {boolean} TBD
50
+ */
51
+ export function isPowerOfTwo(width, height) {
52
+ return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0);
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @param {number} degrees TBD
58
+ * @returns {number} TBD
59
+ */
60
+ export function degToRad(degrees) {
61
+ return degrees * DEG_TO_RAD;
62
+ }
63
+
64
+ /**
65
+ *
66
+ * @param {number} radians TBD
67
+ * @returns {number} TBD
68
+ */
69
+ export function radToDeg(radians) {
70
+ return radians * RAD_TO_DEG;
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @param {number} min TBD
76
+ * @param {number} max TBD
77
+ * @returns {number} TBD
78
+ */
79
+ export function between(min, max) {
80
+ return Math.floor(Math.random() * (max - min + 1) + min);
81
+ }
82
+
83
+ /**
84
+ *
85
+ * @param {number} input TBD
86
+ * @param {number} gap TBD
87
+ * @param {number} start TBD
88
+ * @returns {number} TBD
89
+ */
90
+ export function snapToCeil(input, gap = 0, start = 0) {
91
+ if (gap === 0) {
92
+ return input;
93
+ }
94
+ input -= start;
95
+ input = gap * Math.ceil(input / gap);
96
+ return start + input;
97
+ }
98
+
99
+ /**
100
+ *
101
+ * @param {number} value TBD
102
+ * @param {number} min TBD
103
+ * @param {number} max TBD
104
+ * @returns {number} TBD
105
+ */
106
+ export function wrap(value, min, max) {
107
+ const range = max - min;
108
+ if (range <= 0) {
109
+ return 0;
110
+ }
111
+ let result = (value - min) % range;
112
+ if (result < 0) {
113
+ result += range;
114
+ }
115
+ return result + min;
116
+ }
117
+
118
+ /**
119
+ *
120
+ * @param {number} p0 TBD
121
+ * @param {number} p1 TBD
122
+ * @param {number} t TBD
123
+ * @returns {number} TBD
124
+ */
125
+ export function linear(p0, p1, t) {
126
+ return (p1 - p0) * t + p0;
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @param {number} a TBD
132
+ * @param {number} b TBD
133
+ * @returns {number} TBD
134
+ */
135
+ export function difference(a, b) {
136
+ return Math.abs(a - b);
137
+ }
138
+
139
+ /**
140
+ *
141
+ * @param {number[]} v TBD
142
+ * @param {number} k TBD
143
+ * @returns {number} TBD
144
+ */
145
+ export function linearInterpolation(v, k) {
146
+ const m = v.length - 1;
147
+ const f = m * k;
148
+ const i = Math.floor(f);
149
+ if (k < 0) {
150
+ return linear(v[0], v[1], f);
151
+ }
152
+ if (k > 1) {
153
+ return linear(v[m], v[m - 1], m - f);
154
+ }
155
+ return linear(v[i], v[i + 1 > m ? m : i + 1], f - i);
156
+ }
157
+
158
+ /**
159
+ *
160
+ * @param {number} x1 TBD
161
+ * @param {number} y1 TBD
162
+ * @param {number} x2 TBD
163
+ * @param {number} y2 TBD
164
+ * @returns {number} TBD
165
+ */
166
+ export function distance(x1, y1, x2, y2) {
167
+ const dx = x1 - x2;
168
+ const dy = y1 - y2;
169
+ return Math.sqrt(dx * dx + dy * dy);
170
+ }
171
+
172
+ /**
173
+ *
174
+ * @param {number} a TBD
175
+ * @param {number} b TBD
176
+ * @param {number} tolerance TBD
177
+ * @returns {boolean} TBD
178
+ */
179
+ export function within(a, b, tolerance) {
180
+ return (Math.abs(a - b) <= tolerance);
181
+ }
182
+
183
+ /**
184
+ *
185
+ * @param {number} a TBD
186
+ * @param {number} r TBD
187
+ * @param {number} g TBD
188
+ * @param {number} b TBD
189
+ * @returns {number} TBD
190
+ */
191
+ export function getColor32(a, r, g, b) {
192
+ return a << 24 | r << 16 | g << 8 | b;
193
+ }
194
+
195
+ /**
196
+ *
197
+ * @param {number} r TBD
198
+ * @param {number} g TBD
199
+ * @param {number} b TBD
200
+ * @returns {number} TBD
201
+ */
202
+ export function getColor(r, g, b) {
203
+ return r << 16 | g << 8 | b;
204
+ }
205
+
206
+ /**
207
+ *
208
+ * @param {number} value TBD
209
+ * @param {object} out TBD
210
+ */
211
+ export function hexToColor(value, out) {
212
+ // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
213
+ value = value.replace(/^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => r + r + g + g + b + b);
214
+ const result = /^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(value);
215
+ if (result) {
216
+ out.r = parseInt(result[1], 16);
217
+ out.g = parseInt(result[2], 16);
218
+ out.b = parseInt(result[3], 16);
219
+ }
220
+ }
221
+
222
+ /**
223
+ *
224
+ * @param {number} value TBD
225
+ * @param {object} out TBD
226
+ */
227
+ export function webToColor(value, out) {
228
+ const result = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+(?:\.\d+)?))?\s*\)$/.exec(value);
229
+ if (result) {
230
+ out.r = parseInt(result[1], 10);
231
+ out.g = parseInt(result[2], 10);
232
+ out.b = parseInt(result[3], 10);
233
+ out.a = result[4] !== undefined ? parseFloat(result[4]) : 1;
234
+ }
235
+ }
236
+
237
+ /**
238
+ *
239
+ * @param {number} color TBD
240
+ * @returns {object} TBD
241
+ */
242
+ export function getRGB(color) {
243
+ if (color > 16777215) {
244
+ // The color value has an alpha component
245
+ return {
246
+ alpha: color >>> 24,
247
+ red: color >> 16 & 0xFF,
248
+ green: color >> 8 & 0xFF,
249
+ blue: color & 0xFF,
250
+ a: color >>> 24,
251
+ r: color >> 16 & 0xFF,
252
+ g: color >> 8 & 0xFF,
253
+ b: color & 0xFF,
254
+ };
255
+ }
256
+ return {
257
+ alpha: 255,
258
+ red: color >> 16 & 0xFF,
259
+ green: color >> 8 & 0xFF,
260
+ blue: color & 0xFF,
261
+ a: 255,
262
+ r: color >> 16 & 0xFF,
263
+ g: color >> 8 & 0xFF,
264
+ b: color & 0xFF,
265
+ };
266
+ }
267
+
268
+ /**
269
+ *
270
+ * @param {number} value TBD
271
+ * @param {object} out TBD
272
+ * @returns {object} TBD
273
+ */
274
+ export function valueToColor(value, out) {
275
+ if (typeof value === 'string') {
276
+ if (value.indexOf('rgb') === 0) {
277
+ webToColor(value, out);
278
+ } else {
279
+ // `hexToColor` does not support alpha; match `createColor`.
280
+ out.a = 1;
281
+ hexToColor(value, out);
282
+ }
283
+ } else if (typeof value === 'number') {
284
+ // `getRGB` does not take optional object to modify;
285
+ // alpha is also adjusted to match `createColor`.
286
+ const tempColor = getRGB(value);
287
+ out.r = tempColor.r;
288
+ out.g = tempColor.g;
289
+ out.b = tempColor.b;
290
+ out.a = tempColor.a / 255;
291
+ }
292
+ out.rgba = 'rgba(' + out.r.toString() + ',' + out.g.toString() + ',' + out.b.toString() + ',' + out.a.toString() + ')';
293
+ out.color = getColor(out.r, out.g, out.b);
294
+ out.color32 = getColor32(out.a * 255, out.r, out.g, out.b);
295
+ return out;
296
+
297
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+
7
+ /**
8
+ * TBD
9
+ *
10
+ * @returns {string} TBD
11
+ */
12
+ export function generateID() {
13
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
14
+ }
15
+
16
+ /**
17
+ * TBD
18
+ *
19
+ * @returns {string} TBD
20
+ */
21
+ export function generateUUID() {
22
+ return (`${generateID()}${generateID()}-${generateID()}-4${generateID().substr(0, 3)}-${generateID()}-${generateID()}${generateID()}${generateID()}`).toLowerCase();
23
+ }
24
+
25
+ /**
26
+ * TBD
27
+ *
28
+ * @returns {string} TBD
29
+ */
30
+ export function generateShaderID() {
31
+ return (`${generateID()}${generateID()}-${generateID()}`).toLowerCase();
32
+ }