frigame3 0.0.0-stage → 3.0.1

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 (76) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +80 -2
  3. package/dist/Animation.d.ts +42 -0
  4. package/dist/Animation.js +189 -0
  5. package/dist/BaseSprite.d.ts +116 -0
  6. package/dist/BaseSprite.js +518 -0
  7. package/dist/Gradient.d.ts +31 -0
  8. package/dist/Gradient.js +89 -0
  9. package/dist/Playground.d.ts +48 -0
  10. package/dist/Playground.js +167 -0
  11. package/dist/Rect.d.ts +63 -0
  12. package/dist/Rect.js +155 -0
  13. package/dist/Rectangle.d.ts +31 -0
  14. package/dist/Rectangle.js +69 -0
  15. package/dist/Renderer.d.ts +23 -0
  16. package/dist/Renderer.js +1 -0
  17. package/dist/ResourceManager.d.ts +21 -0
  18. package/dist/ResourceManager.js +100 -0
  19. package/dist/Sprite.d.ts +56 -0
  20. package/dist/Sprite.js +437 -0
  21. package/dist/SpriteGroup.d.ts +39 -0
  22. package/dist/SpriteGroup.js +176 -0
  23. package/dist/canvasRenderer/renderGroup.d.ts +15 -0
  24. package/dist/canvasRenderer/renderGroup.js +134 -0
  25. package/dist/canvasRenderer/renderPlayground.d.ts +9 -0
  26. package/dist/canvasRenderer/renderPlayground.js +67 -0
  27. package/dist/canvasRenderer/renderRectangle.d.ts +15 -0
  28. package/dist/canvasRenderer/renderRectangle.js +287 -0
  29. package/dist/canvasRenderer/renderSprite.d.ts +4 -0
  30. package/dist/canvasRenderer/renderSprite.js +93 -0
  31. package/dist/canvasRenderer.d.ts +2 -0
  32. package/dist/canvasRenderer.js +19 -0
  33. package/dist/dummyRenderer.d.ts +2 -0
  34. package/dist/dummyRenderer.js +41 -0
  35. package/dist/plugins/GamepadTracker.d.ts +15 -0
  36. package/dist/plugins/GamepadTracker.js +74 -0
  37. package/dist/plugins/Tilemap.d.ts +26 -0
  38. package/dist/plugins/Tilemap.js +85 -0
  39. package/dist/plugins/Vec2.d.ts +69 -0
  40. package/dist/plugins/Vec2.js +296 -0
  41. package/dist/plugins/fx/Shaker.d.ts +46 -0
  42. package/dist/plugins/fx/Shaker.js +190 -0
  43. package/dist/plugins/fx/Tweener.d.ts +42 -0
  44. package/dist/plugins/fx/Tweener.js +166 -0
  45. package/dist/plugins/fx/easing.d.ts +32 -0
  46. package/dist/plugins/fx/easing.js +192 -0
  47. package/dist/plugins/isometric/ISOMixin.d.ts +138 -0
  48. package/dist/plugins/isometric/ISOMixin.js +322 -0
  49. package/dist/plugins/isometric/ISORectangle.d.ts +151 -0
  50. package/dist/plugins/isometric/ISORectangle.js +127 -0
  51. package/dist/plugins/isometric/ISOSprite.d.ts +157 -0
  52. package/dist/plugins/isometric/ISOSprite.js +176 -0
  53. package/dist/plugins/isometric/ISOSpriteGroup.d.ts +151 -0
  54. package/dist/plugins/isometric/ISOSpriteGroup.js +116 -0
  55. package/dist/plugins/isometric/ISOTilemap.d.ts +24 -0
  56. package/dist/plugins/isometric/ISOTilemap.js +85 -0
  57. package/dist/plugins/isometric/utils.d.ts +2 -0
  58. package/dist/plugins/isometric/utils.js +10 -0
  59. package/dist/plugins/keyTracker.d.ts +3 -0
  60. package/dist/plugins/keyTracker.js +23 -0
  61. package/dist/plugins/mixer.d.ts +72 -0
  62. package/dist/plugins/mixer.js +396 -0
  63. package/dist/plugins/sorted/SortedAnimation.d.ts +13 -0
  64. package/dist/plugins/sorted/SortedAnimation.js +27 -0
  65. package/dist/plugins/sorted/SortedGroup.d.ts +137 -0
  66. package/dist/plugins/sorted/SortedGroup.js +61 -0
  67. package/dist/plugins/sorted/SortedMixin.d.ts +122 -0
  68. package/dist/plugins/sorted/SortedMixin.js +153 -0
  69. package/dist/plugins/sorted/SortedRectangle.d.ts +127 -0
  70. package/dist/plugins/sorted/SortedRectangle.js +17 -0
  71. package/dist/plugins/sorted/SortedSprite.d.ts +130 -0
  72. package/dist/plugins/sorted/SortedSprite.js +35 -0
  73. package/dist/utils.d.ts +11 -0
  74. package/dist/utils.js +33 -0
  75. package/frigame.css +12 -0
  76. package/package.json +54 -4
@@ -0,0 +1,89 @@
1
+ import { clamp, pick } from "./utils.js";
2
+ class Color {
3
+ _r = 0;
4
+ _g = 0;
5
+ _b = 0;
6
+ _a = 1;
7
+ _str = "rgba(0,0,0,1)";
8
+ get r() {
9
+ return this._r;
10
+ }
11
+ set r(value) {
12
+ this._r = clamp(Math.round(value), 0, 255) || 0;
13
+ this._str = `rgba(${this._r},${this._g},${this._b},${this._a})`;
14
+ }
15
+ get g() {
16
+ return this._g;
17
+ }
18
+ set g(value) {
19
+ this._g = clamp(Math.round(value), 0, 255) || 0;
20
+ this._str = `rgba(${this._r},${this._g},${this._b},${this._a})`;
21
+ }
22
+ get b() {
23
+ return this._b;
24
+ }
25
+ set b(value) {
26
+ this._b = clamp(Math.round(value), 0, 255) || 0;
27
+ this._str = `rgba(${this._r},${this._g},${this._b},${this._a})`;
28
+ }
29
+ get a() {
30
+ return this._a;
31
+ }
32
+ set a(value) {
33
+ this._a = clamp(typeof value === "number" && !Number.isNaN(value) ? value : 1, 0, 1);
34
+ this._str = `rgba(${this._r},${this._g},${this._b},${this._a})`;
35
+ }
36
+ constructor(options) {
37
+ if (options !== undefined) {
38
+ Object.assign(this, pick(options, ["r", "g", "b", "a"]));
39
+ }
40
+ }
41
+ }
42
+ export class Gradient {
43
+ startColor;
44
+ endColor;
45
+ type;
46
+ constructor(startColor, endColor, type = "vertical") {
47
+ const [r, g, b, a] = (() => {
48
+ if (startColor !== undefined) {
49
+ if (Array.isArray(startColor)) {
50
+ return [
51
+ startColor[0] || 0,
52
+ startColor[1] || 0,
53
+ startColor[2] || 0,
54
+ startColor[3] || 1,
55
+ ];
56
+ }
57
+ else {
58
+ const { r, g, b, a } = startColor;
59
+ return [r || 0, g || 0, b || 0, a || 1];
60
+ }
61
+ }
62
+ else {
63
+ return [0, 0, 0, 1];
64
+ }
65
+ })();
66
+ this.startColor = new Color({ r, g, b, a });
67
+ if (endColor !== undefined) {
68
+ const [r, g, b, a] = (() => {
69
+ if (Array.isArray(endColor)) {
70
+ return [
71
+ endColor[0] || 0,
72
+ endColor[1] || 0,
73
+ endColor[2] || 0,
74
+ endColor[3] || 1,
75
+ ];
76
+ }
77
+ else {
78
+ const { r, g, b, a } = endColor;
79
+ return [r || 0, g || 0, b || 0, a || 1];
80
+ }
81
+ })();
82
+ this.endColor = new Color({ r, g, b, a });
83
+ }
84
+ else {
85
+ this.endColor = this.startColor;
86
+ }
87
+ this.type = type;
88
+ }
89
+ }
@@ -0,0 +1,48 @@
1
+ import type { Renderer, RendererElement } from "./Renderer.js";
2
+ import { SpriteGroup } from "./SpriteGroup.js";
3
+ interface CallbackObj {
4
+ callback: () => void;
5
+ rate: number;
6
+ idleCounter: number;
7
+ }
8
+ export interface PlaygroundOptions {
9
+ refreshRate: number;
10
+ dom: string | RendererElement;
11
+ cssClass: string;
12
+ }
13
+ export declare class Playground extends EventTarget {
14
+ _width: number;
15
+ _height: number;
16
+ _refreshRate: number;
17
+ running: boolean;
18
+ frameCounter: number;
19
+ scenegraph: SpriteGroup;
20
+ _renderer: Renderer;
21
+ _nextId: number;
22
+ _callbacks: Map<number, CallbackObj>;
23
+ _idDraw: number | null;
24
+ _accumulator: number;
25
+ _currentTime: number;
26
+ _absLeft: number;
27
+ _absTop: number;
28
+ get width(): number;
29
+ get height(): number;
30
+ get halfWidth(): number;
31
+ get halfHeight(): number;
32
+ get refreshRate(): number;
33
+ constructor(renderer: Renderer, options?: Partial<PlaygroundOptions>);
34
+ registerCallback(callback: () => void, rate?: number): number;
35
+ removeCallback(callbackId: number | null, options?: {
36
+ suppressWarning?: boolean;
37
+ }): this;
38
+ clearCallbacks(): this;
39
+ startGame(): this;
40
+ stopGame(): this;
41
+ forceRedraw(): this;
42
+ framesFromMs(ms: number): number;
43
+ msFromFrames(frames: number): number;
44
+ _update(): void;
45
+ _draw: (timestamp: number) => void;
46
+ _insidePlayground(left: number, top: number, width: number, height: number): boolean;
47
+ }
48
+ export {};
@@ -0,0 +1,167 @@
1
+ import { SpriteGroup } from "./SpriteGroup.js";
2
+ export class Playground extends EventTarget {
3
+ _width = 0;
4
+ _height = 0;
5
+ _refreshRate = 1000 / 60;
6
+ running = false;
7
+ frameCounter = 0;
8
+ scenegraph;
9
+ // Implementation details
10
+ _renderer;
11
+ _nextId = 1; // Start from 1 to guarantee that callbackId is always truthy
12
+ _callbacks = new Map();
13
+ _idDraw = null;
14
+ _accumulator = 0;
15
+ _currentTime = 0;
16
+ _absLeft = 0;
17
+ _absTop = 0;
18
+ get width() {
19
+ return this._width;
20
+ }
21
+ get height() {
22
+ return this._height;
23
+ }
24
+ get halfWidth() {
25
+ return this._width / 2;
26
+ }
27
+ get halfHeight() {
28
+ return this._height / 2;
29
+ }
30
+ get refreshRate() {
31
+ return this._refreshRate;
32
+ }
33
+ constructor(renderer, options) {
34
+ super();
35
+ this._renderer = renderer;
36
+ const [width, height] = renderer.initPlayground(this, options);
37
+ this._width = width;
38
+ this._height = height;
39
+ if (options?.refreshRate !== undefined) {
40
+ this._refreshRate = Number(options.refreshRate) || 1;
41
+ }
42
+ this.scenegraph = new SpriteGroup({ width, height });
43
+ this.scenegraph._playground = new WeakRef(this);
44
+ this.scenegraph._initRenderer();
45
+ this.startGame();
46
+ }
47
+ // Public functions
48
+ registerCallback(callback, rate) {
49
+ const callbackId = this._nextId;
50
+ this._nextId += 1;
51
+ this._callbacks.set(callbackId, {
52
+ callback: callback,
53
+ rate: this.framesFromMs(rate || 0),
54
+ idleCounter: 0,
55
+ });
56
+ return callbackId;
57
+ }
58
+ removeCallback(callbackId, options) {
59
+ if (callbackId === null) {
60
+ if (typeof console !== "undefined" &&
61
+ options?.suppressWarning === false) {
62
+ console.warn("callbackId is null");
63
+ console.trace();
64
+ }
65
+ return this;
66
+ }
67
+ const deleted = this._callbacks.delete(callbackId);
68
+ if (!deleted &&
69
+ typeof console !== "undefined" &&
70
+ options?.suppressWarning === false) {
71
+ console.warn("No callbacks removed");
72
+ console.trace();
73
+ }
74
+ return this;
75
+ }
76
+ clearCallbacks() {
77
+ this._callbacks.clear();
78
+ this.dispatchEvent(new Event("clearCallbacks"));
79
+ return this;
80
+ }
81
+ startGame() {
82
+ this.running = true;
83
+ if (this._idDraw === null) {
84
+ this._accumulator = 0;
85
+ this._currentTime = performance.now();
86
+ this._idDraw = requestAnimationFrame(this._draw);
87
+ }
88
+ return this;
89
+ }
90
+ stopGame() {
91
+ this.running = false;
92
+ // The cancelAnimationFrame is optional, since this._draw will not call
93
+ // this._update and requestAnimationFrame if this.running is false
94
+ if (this._idDraw !== null) {
95
+ cancelAnimationFrame(this._idDraw);
96
+ this._idDraw = null;
97
+ }
98
+ return this;
99
+ }
100
+ forceRedraw() {
101
+ if (this._idDraw === null) {
102
+ this._idDraw = requestAnimationFrame(this._draw);
103
+ }
104
+ return this;
105
+ }
106
+ framesFromMs(ms) {
107
+ return Math.max(Math.round(ms / this._refreshRate), 1) || 1;
108
+ }
109
+ msFromFrames(frames) {
110
+ return frames * this._refreshRate || 0;
111
+ }
112
+ // Implementation details
113
+ _update() {
114
+ this.scenegraph._update();
115
+ for (const callback_obj of this._callbacks.values()) {
116
+ callback_obj.idleCounter += 1;
117
+ if (callback_obj.idleCounter >= callback_obj.rate) {
118
+ callback_obj.idleCounter = 0;
119
+ const callback = callback_obj.callback;
120
+ callback();
121
+ }
122
+ }
123
+ }
124
+ _draw = (timestamp) => {
125
+ const dt = this._refreshRate;
126
+ let accumulator = this._accumulator;
127
+ if (this.running) {
128
+ this._idDraw = requestAnimationFrame(this._draw);
129
+ accumulator += timestamp - this._currentTime;
130
+ this._currentTime = timestamp;
131
+ if (accumulator >= dt) {
132
+ let numUpdateSteps = 0;
133
+ while (accumulator >= dt) {
134
+ this._update();
135
+ accumulator -= dt;
136
+ this.frameCounter += 1;
137
+ // Avoid the spiral of death
138
+ numUpdateSteps += 1;
139
+ if (numUpdateSteps >= 240) {
140
+ accumulator = 0;
141
+ // TODO: Maybe a callback should be called here
142
+ if (typeof console !== "undefined") {
143
+ console.warn("Spiral of death");
144
+ }
145
+ break;
146
+ }
147
+ }
148
+ }
149
+ this._accumulator = accumulator;
150
+ }
151
+ else {
152
+ this._idDraw = null;
153
+ }
154
+ const interp = accumulator / dt;
155
+ this._renderer.drawPlaygroundBeforeChildren(this, interp);
156
+ this.scenegraph._draw(interp);
157
+ this._renderer.drawPlaygroundAfterChildren(this, interp);
158
+ };
159
+ _insidePlayground(left, top, width, height) {
160
+ const sprite_left = this._absLeft + left;
161
+ const sprite_top = this._absTop + top;
162
+ return !(sprite_top + height <= 0 ||
163
+ sprite_top >= this._height ||
164
+ sprite_left >= this._width ||
165
+ sprite_left + width <= 0);
166
+ }
167
+ }
package/dist/Rect.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ export interface RectPosX {
2
+ left: number;
3
+ right: number;
4
+ centerx: number;
5
+ }
6
+ export interface RectPosY {
7
+ top: number;
8
+ bottom: number;
9
+ centery: number;
10
+ }
11
+ export interface RectPos extends RectPosX, RectPosY {
12
+ }
13
+ export interface RectSizeX {
14
+ width: number;
15
+ halfWidth: number;
16
+ radius: number;
17
+ }
18
+ export interface RectSizeY {
19
+ height: number;
20
+ halfHeight: number;
21
+ radius: number;
22
+ }
23
+ export interface RectSize extends RectSizeX, RectSizeY {
24
+ }
25
+ export interface RectOptions extends RectPos, RectSize {
26
+ }
27
+ export declare class Rect implements RectOptions {
28
+ _left: number;
29
+ _top: number;
30
+ _width: number;
31
+ _height: number;
32
+ _last_x: keyof RectPosX;
33
+ _last_y: keyof RectPosY;
34
+ get left(): number;
35
+ set left(value: number);
36
+ get right(): number;
37
+ set right(value: number);
38
+ get centerx(): number;
39
+ set centerx(value: number);
40
+ get top(): number;
41
+ set top(value: number);
42
+ get bottom(): number;
43
+ set bottom(value: number);
44
+ get centery(): number;
45
+ set centery(value: number);
46
+ get width(): number;
47
+ set width(value: number);
48
+ get halfWidth(): number;
49
+ set halfWidth(value: number);
50
+ get height(): number;
51
+ set height(value: number);
52
+ get halfHeight(): number;
53
+ set halfHeight(value: number);
54
+ get radius(): number;
55
+ set radius(value: number);
56
+ constructor(options?: Partial<RectOptions>);
57
+ collideRect(otherRect: Rect): boolean;
58
+ collideRectPoint(x: number, y: number): boolean;
59
+ collideRectCircle(otherRect: Rect): boolean;
60
+ collideCircle(otherRect: Rect): boolean;
61
+ collideCirclePoint(x: number, y: number): boolean;
62
+ collideCircleRect(otherRect: Rect): boolean;
63
+ }
package/dist/Rect.js ADDED
@@ -0,0 +1,155 @@
1
+ import { clamp, pick } from "./utils.js";
2
+ export class Rect {
3
+ // Implementation details
4
+ _left = 0;
5
+ _top = 0;
6
+ _width = 0;
7
+ _height = 0;
8
+ _last_x = "left";
9
+ _last_y = "top";
10
+ get left() {
11
+ return this._left;
12
+ }
13
+ set left(value) {
14
+ this._left = value;
15
+ this._last_x = "left";
16
+ }
17
+ get right() {
18
+ return this._left + this._width;
19
+ }
20
+ set right(value) {
21
+ this._left = value - this._width;
22
+ this._last_x = "right";
23
+ }
24
+ get centerx() {
25
+ return this._left + this._width / 2;
26
+ }
27
+ set centerx(value) {
28
+ this._left = value - this._width / 2;
29
+ this._last_x = "centerx";
30
+ }
31
+ get top() {
32
+ return this._top;
33
+ }
34
+ set top(value) {
35
+ this._top = value;
36
+ this._last_y = "top";
37
+ }
38
+ get bottom() {
39
+ return this._top + this._height;
40
+ }
41
+ set bottom(value) {
42
+ this._top = value - this._height;
43
+ this._last_y = "bottom";
44
+ }
45
+ get centery() {
46
+ return this._top + this._height / 2;
47
+ }
48
+ set centery(value) {
49
+ this._top = value - this._height / 2;
50
+ this._last_y = "centery";
51
+ }
52
+ get width() {
53
+ return this._width;
54
+ }
55
+ set width(value) {
56
+ const old_x = this[this._last_x];
57
+ this._width = value;
58
+ this[this._last_x] = old_x;
59
+ }
60
+ get halfWidth() {
61
+ return this._width / 2;
62
+ }
63
+ set halfWidth(value) {
64
+ const old_x = this[this._last_x];
65
+ this._width = value * 2;
66
+ this[this._last_x] = old_x;
67
+ }
68
+ get height() {
69
+ return this._height;
70
+ }
71
+ set height(value) {
72
+ const old_y = this[this._last_y];
73
+ this._height = value;
74
+ this[this._last_y] = old_y;
75
+ }
76
+ get halfHeight() {
77
+ return this._height / 2;
78
+ }
79
+ set halfHeight(value) {
80
+ const old_y = this[this._last_y];
81
+ this._height = value * 2;
82
+ this[this._last_y] = old_y;
83
+ }
84
+ get radius() {
85
+ return this._width / 2;
86
+ }
87
+ set radius(value) {
88
+ const old_x = this[this._last_x];
89
+ const old_y = this[this._last_y];
90
+ const new_value = value * 2;
91
+ this._width = new_value;
92
+ this._height = new_value;
93
+ this[this._last_x] = old_x;
94
+ this[this._last_y] = old_y;
95
+ }
96
+ constructor(options) {
97
+ if (options !== undefined) {
98
+ Object.assign(this, pick(options, [
99
+ "left",
100
+ "right",
101
+ "centerx",
102
+ "top",
103
+ "bottom",
104
+ "centery",
105
+ "width",
106
+ "halfWidth",
107
+ "height",
108
+ "halfHeight",
109
+ "radius",
110
+ ]));
111
+ }
112
+ }
113
+ // Collision detection
114
+ collideRect(otherRect) {
115
+ return !(this.bottom <= otherRect.top ||
116
+ this.top >= otherRect.bottom ||
117
+ this.left >= otherRect.right ||
118
+ this.right <= otherRect.left);
119
+ }
120
+ collideRectPoint(x, y) {
121
+ return x >= this.left && x < this.right && y >= this.top && y < this.bottom;
122
+ }
123
+ collideRectCircle(otherRect) {
124
+ const centerx = otherRect.centerx;
125
+ const centery = otherRect.centery;
126
+ const radius = otherRect.radius;
127
+ const nearest_x = clamp(centerx, this.left, this.right);
128
+ const nearest_y = clamp(centery, this.top, this.bottom);
129
+ const dx = centerx - nearest_x;
130
+ const dy = centery - nearest_y;
131
+ return dx * dx + dy * dy < radius * radius;
132
+ }
133
+ collideCircle(otherRect) {
134
+ const dx = otherRect.centerx - this.centerx;
135
+ const dy = otherRect.centery - this.centery;
136
+ const radii = this.radius + otherRect.radius;
137
+ return dx * dx + dy * dy < radii * radii;
138
+ }
139
+ collideCirclePoint(x, y) {
140
+ const dx = x - this.centerx;
141
+ const dy = y - this.centery;
142
+ const radius = this.radius;
143
+ return dx * dx + dy * dy < radius * radius;
144
+ }
145
+ collideCircleRect(otherRect) {
146
+ const centerx = this.centerx;
147
+ const centery = this.centery;
148
+ const radius = this.radius;
149
+ const nearest_x = clamp(centerx, otherRect.left, otherRect.right);
150
+ const nearest_y = clamp(centery, otherRect.top, otherRect.bottom);
151
+ const dx = centerx - nearest_x;
152
+ const dy = centery - nearest_y;
153
+ return dx * dx + dy * dy < radius * radius;
154
+ }
155
+ }
@@ -0,0 +1,31 @@
1
+ import type { BaseSpriteOptions } from "./BaseSprite.js";
2
+ import { BaseSprite } from "./BaseSprite.js";
3
+ import type { ColorArr, ColorObj } from "./Gradient.js";
4
+ import { Gradient } from "./Gradient.js";
5
+ import type { SpriteRef } from "./utils.js";
6
+ export interface RectangleOptions extends BaseSpriteOptions {
7
+ background: Gradient | Partial<ColorObj> | Partial<ColorArr> | null;
8
+ borderRadius: number;
9
+ borderWidth: number;
10
+ borderColor: Gradient | Partial<ColorObj> | Partial<ColorArr> | null;
11
+ }
12
+ export declare class Rectangle extends BaseSprite implements RectangleOptions {
13
+ _background: Gradient | null;
14
+ _borderRadius: number;
15
+ _borderWidth: number;
16
+ _borderColor: Gradient | null;
17
+ get background(): Gradient | null;
18
+ set background(value: Gradient | Partial<ColorObj> | Partial<ColorArr> | null);
19
+ get borderRadius(): number;
20
+ set borderRadius(value: number);
21
+ get borderWidth(): number;
22
+ set borderWidth(value: number);
23
+ get borderColor(): Gradient | null;
24
+ set borderColor(value: Gradient | Partial<ColorObj> | Partial<ColorArr> | null);
25
+ constructor(options?: Partial<RectangleOptions & {
26
+ ref?: SpriteRef<Rectangle>;
27
+ }>);
28
+ _initRenderer(): void;
29
+ _draw(interp: number): void;
30
+ _remove(): void;
31
+ }
@@ -0,0 +1,69 @@
1
+ import { BaseSprite } from "./BaseSprite.js";
2
+ import { Gradient } from "./Gradient.js";
3
+ import { pick } from "./utils.js";
4
+ export class Rectangle extends BaseSprite {
5
+ _background = null;
6
+ _borderRadius = 0;
7
+ _borderWidth = 1;
8
+ _borderColor = null;
9
+ get background() {
10
+ return this._background;
11
+ }
12
+ set background(value) {
13
+ if (value === null || value instanceof Gradient) {
14
+ this._background = value;
15
+ }
16
+ else {
17
+ this._background = new Gradient(value);
18
+ }
19
+ }
20
+ get borderRadius() {
21
+ return this._borderRadius;
22
+ }
23
+ set borderRadius(value) {
24
+ this._borderRadius = value;
25
+ }
26
+ get borderWidth() {
27
+ return this._borderWidth;
28
+ }
29
+ set borderWidth(value) {
30
+ this._borderWidth = value;
31
+ }
32
+ get borderColor() {
33
+ return this._borderColor;
34
+ }
35
+ set borderColor(value) {
36
+ if (value === null || value instanceof Gradient) {
37
+ this._borderColor = value;
38
+ }
39
+ else {
40
+ this._borderColor = new Gradient(value);
41
+ }
42
+ }
43
+ constructor(options) {
44
+ super(options);
45
+ if (options !== undefined) {
46
+ Object.assign(this, pick(options, [
47
+ "background",
48
+ "borderRadius",
49
+ "borderWidth",
50
+ "borderColor",
51
+ ]));
52
+ if (options.ref !== undefined) {
53
+ options.ref.current = this;
54
+ }
55
+ }
56
+ this.teleport();
57
+ }
58
+ // Implementation details
59
+ _initRenderer() {
60
+ this.playground?._renderer.initRectangle(this);
61
+ }
62
+ _draw(interp) {
63
+ super._draw(interp);
64
+ this.playground?._renderer.drawRectangle(this, interp);
65
+ }
66
+ _remove() {
67
+ this.playground?._renderer.removeRectangle(this);
68
+ }
69
+ }
@@ -0,0 +1,23 @@
1
+ import type { Playground, PlaygroundOptions } from "./Playground.js";
2
+ import type { Rectangle } from "./Rectangle.js";
3
+ import type { Sprite } from "./Sprite.js";
4
+ import type { SpriteGroup } from "./SpriteGroup.js";
5
+ export interface RendererElement {
6
+ offsetWidth: number;
7
+ offsetHeight: number;
8
+ }
9
+ export interface Renderer {
10
+ initPlayground(playground: Playground, options?: Partial<PlaygroundOptions>): [number, number];
11
+ drawPlaygroundBeforeChildren(playground: Playground, interp: number): void;
12
+ drawPlaygroundAfterChildren(playground: Playground, interp: number): void;
13
+ initGroup(group: SpriteGroup): void;
14
+ removeGroup(group: SpriteGroup): void;
15
+ drawGroupBeforeChildren(group: SpriteGroup, interp: number): void;
16
+ drawGroupAfterChildren(group: SpriteGroup, interp: number): void;
17
+ initSprite(sprite: Sprite): void;
18
+ removeSprite(sprite: Sprite): void;
19
+ drawSprite(sprite: Sprite, interp: number): void;
20
+ initRectangle(rectangle: Rectangle): void;
21
+ removeRectangle(rectangle: Rectangle): void;
22
+ drawRectangle(rectangle: Rectangle, interp: number): void;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ export interface Resource {
2
+ complete: () => boolean;
3
+ onLoad: () => void;
4
+ }
5
+ export declare class ResourceManager {
6
+ loadCallback: ((percent: number) => void) | null;
7
+ _idPreload: number | null;
8
+ _preloadList: Resource[];
9
+ _resolveCallback: ((value?: undefined) => void) | null;
10
+ _rejectCallback: (() => void) | null;
11
+ _complete: boolean;
12
+ complete(): boolean;
13
+ percent(): number;
14
+ addResource<T extends Resource>(resource: T): T;
15
+ removeResource(resource: Resource | null, options?: {
16
+ suppressWarning?: boolean;
17
+ }): void;
18
+ clear(): void;
19
+ preload(): Promise<void>;
20
+ _doPreload: () => void;
21
+ }