react-simple-game-engine 0.1.84 → 0.1.87
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/lib/classes/p5.d.ts +4 -0
- package/lib/classes/p5.d.ts.map +1 -1
- package/lib/classes/p5.js +28 -0
- package/lib/classes/particle.js +2 -2
- package/lib/classes/scaler.d.ts +11 -10
- package/lib/classes/scaler.d.ts.map +1 -1
- package/lib/classes/scaler.js +34 -26
- package/lib/classes/sprites/sprite.js +2 -2
- package/lib/ui-components/scene-runner.d.ts.map +1 -1
- package/lib/ui-components/scene-runner.js +14 -18
- package/package.json +1 -1
package/lib/classes/p5.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export declare class P5 extends p5 {
|
|
|
7
7
|
scaler: Scaler;
|
|
8
8
|
running: boolean;
|
|
9
9
|
constructor(sketch: (p5: P5) => void, scaler: Scaler);
|
|
10
|
+
get gameWidth(): number;
|
|
11
|
+
get gameHeight(): number;
|
|
12
|
+
get gameMouseX(): number;
|
|
13
|
+
get gameMouseY(): number;
|
|
10
14
|
choose<I = any>(collection: Collection<I>): I;
|
|
11
15
|
}
|
|
12
16
|
export {};
|
package/lib/classes/p5.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p5.d.ts","sourceRoot":"","sources":["../../src/classes/p5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,aAAK,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACtC,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEvB,oBAAY,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnE,qBAAa,EAAG,SAAQ,EAAE;IAGqB,MAAM,EAAE,MAAM;IAF3D,OAAO,UAAQ;gBAEH,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,IAAI,EAAS,MAAM,EAAE,MAAM;IAK3D,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;CA+B9C"}
|
|
1
|
+
{"version":3,"file":"p5.d.ts","sourceRoot":"","sources":["../../src/classes/p5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,aAAK,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACtC,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEvB,oBAAY,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnE,qBAAa,EAAG,SAAQ,EAAE;IAGqB,MAAM,EAAE,MAAM;IAF3D,OAAO,UAAQ;gBAEH,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,IAAI,EAAS,MAAM,EAAE,MAAM;IAK3D,IAAI,SAAS,WAEZ;IAED,IAAI,UAAU,WAEb;IAED,IAAI,UAAU,WAEb;IAED,IAAI,UAAU,WAEb;IAED,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;CA+B9C"}
|
package/lib/classes/p5.js
CHANGED
|
@@ -23,6 +23,34 @@ var P5 = /** @class */ (function (_super) {
|
|
|
23
23
|
window.Renderer = _this;
|
|
24
24
|
return _this;
|
|
25
25
|
}
|
|
26
|
+
Object.defineProperty(P5.prototype, "gameWidth", {
|
|
27
|
+
get: function () {
|
|
28
|
+
return this.scaler.gameSize.width;
|
|
29
|
+
},
|
|
30
|
+
enumerable: false,
|
|
31
|
+
configurable: true
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(P5.prototype, "gameHeight", {
|
|
34
|
+
get: function () {
|
|
35
|
+
return this.scaler.gameSize.height;
|
|
36
|
+
},
|
|
37
|
+
enumerable: false,
|
|
38
|
+
configurable: true
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(P5.prototype, "gameMouseX", {
|
|
41
|
+
get: function () {
|
|
42
|
+
return this.mouseX + this.scaler.deltaOfScale.x;
|
|
43
|
+
},
|
|
44
|
+
enumerable: false,
|
|
45
|
+
configurable: true
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(P5.prototype, "gameMouseY", {
|
|
48
|
+
get: function () {
|
|
49
|
+
return this.mouseY + this.scaler.deltaOfScale.y;
|
|
50
|
+
},
|
|
51
|
+
enumerable: false,
|
|
52
|
+
configurable: true
|
|
53
|
+
});
|
|
26
54
|
P5.prototype.choose = function (collection) {
|
|
27
55
|
var lastItem = collection[collection.length - 1];
|
|
28
56
|
var restItems = collection.slice(0, collection.length - 1);
|
package/lib/classes/particle.js
CHANGED
|
@@ -82,8 +82,8 @@ var Particle = /** @class */ (function (_super) {
|
|
|
82
82
|
Particle.prototype.draw = function () {
|
|
83
83
|
Renderer.push();
|
|
84
84
|
Renderer.noStroke();
|
|
85
|
-
var
|
|
86
|
-
Renderer.translate(this.x - this.camera.x +
|
|
85
|
+
var deltaOfScale = Renderer.scaler.deltaOfScale;
|
|
86
|
+
Renderer.translate(this.x - this.camera.x + deltaOfScale.x, this.y - this.camera.y + deltaOfScale.y);
|
|
87
87
|
Renderer.rotate(this.angle);
|
|
88
88
|
var color = __spreadArray([], this.color, true);
|
|
89
89
|
var alpha = Renderer.map(this.lifetimeRemain, 0, this.lifetime, 0, 255);
|
package/lib/classes/scaler.d.ts
CHANGED
|
@@ -5,23 +5,24 @@ export declare class Scaler {
|
|
|
5
5
|
private readonly _gameSize;
|
|
6
6
|
private _layoutMode;
|
|
7
7
|
private _value;
|
|
8
|
+
private _deltaOfScale;
|
|
9
|
+
private _deltaOfScaleForUI;
|
|
8
10
|
constructor(_canvasSize: Size, _gameSize: Size, _layoutMode: LayoutMode);
|
|
9
|
-
get
|
|
10
|
-
get gameSize(): Size;
|
|
11
|
-
get canvasSize(): Size;
|
|
12
|
-
get layoutMode(): LayoutMode;
|
|
13
|
-
get scaledSize(): {
|
|
14
|
-
width: number;
|
|
15
|
-
height: number;
|
|
16
|
-
};
|
|
17
|
-
get deltaToCenterForCanvas(): {
|
|
11
|
+
get deltaOfScaleForUI(): {
|
|
18
12
|
x: number;
|
|
19
13
|
y: number;
|
|
20
14
|
};
|
|
21
|
-
get
|
|
15
|
+
get deltaOfScale(): {
|
|
22
16
|
x: number;
|
|
23
17
|
y: number;
|
|
24
18
|
};
|
|
19
|
+
get value(): number;
|
|
20
|
+
get gameSize(): Size;
|
|
21
|
+
get canvasSize(): Size;
|
|
22
|
+
get layoutMode(): LayoutMode;
|
|
23
|
+
private get scaledSize();
|
|
24
|
+
private updateDeltaOfScale;
|
|
25
|
+
private updateDeltaOfScaleForUI;
|
|
25
26
|
set gameSize(_gameSize: Size);
|
|
26
27
|
set canvasSize(_canvasSize: Size);
|
|
27
28
|
set layoutMode(_layoutMode: LayoutMode);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaler.d.ts","sourceRoot":"","sources":["../../src/classes/scaler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAGvC,qBAAa,MAAM;
|
|
1
|
+
{"version":3,"file":"scaler.d.ts","sourceRoot":"","sources":["../../src/classes/scaler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAGvC,qBAAa,MAAM;IAKf,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,WAAW;IANrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,kBAAkB,CAA2B;gBAElC,WAAW,EAAE,IAAI,EACjB,SAAS,EAAE,IAAI,EACxB,WAAW,EAAE,UAAU;IAKjC,IAAI,iBAAiB;;;MAEpB;IAED,IAAI,YAAY;;;MAEf;IAED,IAAI,KAAK,WAER;IAED,IAAI,QAAQ,IAuCY,IAAI,CArC3B;IAED,IAAI,UAAU,IAwCc,IAAI,CAtC/B;IAED,IAAI,UAAU,IAyCc,UAAU,CAvCrC;IAED,OAAO,KAAK,UAAU,GAKrB;IAED,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,uBAAuB;IAU/B,IAAI,QAAQ,CAAC,SAAS,EAAE,IAAI,EAG3B;IAED,IAAI,UAAU,CAAC,WAAW,EAAE,IAAI,EAG/B;IAED,IAAI,UAAU,CAAC,WAAW,EAAE,UAAU,EAGrC;IAED,OAAO,CAAC,MAAM;CAkBf"}
|
package/lib/classes/scaler.js
CHANGED
|
@@ -7,6 +7,20 @@ var Scaler = /** @class */ (function () {
|
|
|
7
7
|
this._layoutMode = _layoutMode;
|
|
8
8
|
this.update();
|
|
9
9
|
}
|
|
10
|
+
Object.defineProperty(Scaler.prototype, "deltaOfScaleForUI", {
|
|
11
|
+
get: function () {
|
|
12
|
+
return this._deltaOfScaleForUI;
|
|
13
|
+
},
|
|
14
|
+
enumerable: false,
|
|
15
|
+
configurable: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(Scaler.prototype, "deltaOfScale", {
|
|
18
|
+
get: function () {
|
|
19
|
+
return this._deltaOfScale;
|
|
20
|
+
},
|
|
21
|
+
enumerable: false,
|
|
22
|
+
configurable: true
|
|
23
|
+
});
|
|
10
24
|
Object.defineProperty(Scaler.prototype, "value", {
|
|
11
25
|
get: function () {
|
|
12
26
|
return this._value;
|
|
@@ -57,32 +71,24 @@ var Scaler = /** @class */ (function () {
|
|
|
57
71
|
enumerable: false,
|
|
58
72
|
configurable: true
|
|
59
73
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
x: deltaW / 2,
|
|
80
|
-
y: deltaH / 2,
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
enumerable: false,
|
|
84
|
-
configurable: true
|
|
85
|
-
});
|
|
74
|
+
Scaler.prototype.updateDeltaOfScale = function () {
|
|
75
|
+
var _scaleSize = this.scaledSize;
|
|
76
|
+
var deltaW = Math.abs(this._canvasSize.width - _scaleSize.width);
|
|
77
|
+
var deltaH = Math.abs(this._canvasSize.height - _scaleSize.height);
|
|
78
|
+
this._deltaOfScale = {
|
|
79
|
+
x: deltaW / this._value / 2,
|
|
80
|
+
y: deltaH / this._value / 2,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
Scaler.prototype.updateDeltaOfScaleForUI = function () {
|
|
84
|
+
var _scaleSize = this.scaledSize;
|
|
85
|
+
var deltaW = Math.abs(this._canvasSize.width - _scaleSize.width);
|
|
86
|
+
var deltaH = Math.abs(this._canvasSize.height - _scaleSize.height);
|
|
87
|
+
this._deltaOfScaleForUI = {
|
|
88
|
+
x: deltaW / 2,
|
|
89
|
+
y: deltaH / 2,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
86
92
|
Scaler.prototype.update = function () {
|
|
87
93
|
if (this._layoutMode === LayoutMode.LANDSCAPE) {
|
|
88
94
|
if (this._canvasSize.width >= this._canvasSize.height) {
|
|
@@ -100,6 +106,8 @@ var Scaler = /** @class */ (function () {
|
|
|
100
106
|
this._value = this._canvasSize.height / this._gameSize.height;
|
|
101
107
|
}
|
|
102
108
|
}
|
|
109
|
+
this.updateDeltaOfScale();
|
|
110
|
+
this.updateDeltaOfScaleForUI();
|
|
103
111
|
};
|
|
104
112
|
return Scaler;
|
|
105
113
|
}());
|
|
@@ -44,8 +44,8 @@ var Sprite = /** @class */ (function () {
|
|
|
44
44
|
var _a = this.entity, body = _a.body, position = _a.position, camera = _a.camera;
|
|
45
45
|
Renderer.push();
|
|
46
46
|
Renderer.noStroke();
|
|
47
|
-
var
|
|
48
|
-
Renderer.translate(position.x - camera.x +
|
|
47
|
+
var deltaOfScale = Renderer.scaler.deltaOfScale;
|
|
48
|
+
Renderer.translate(position.x - camera.x + deltaOfScale.x, position.y - camera.y + deltaOfScale.y);
|
|
49
49
|
Renderer.rotate(body.angle);
|
|
50
50
|
this.onDraw();
|
|
51
51
|
Renderer.pop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scene-runner.d.ts","sourceRoot":"","sources":["../../src/ui-components/scene-runner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,SAAS,EAKV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAKzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,oBAAY,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,CAAC;AAEF,aAAK,gBAAgB,GAAG,sBAAsB,GAAG;IAC/C,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAC1B,WAAW,EACX,OAAO,EACP,KAAK,EACL,MAAM,EACN,YAAY,EAAE,YAAY,EAC1B,UAAiC,GAClC,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"scene-runner.d.ts","sourceRoot":"","sources":["../../src/ui-components/scene-runner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,SAAS,EAKV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAKzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,oBAAY,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,CAAC;AAEF,aAAK,gBAAgB,GAAG,sBAAsB,GAAG;IAC/C,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAC1B,WAAW,EACX,OAAO,EACP,KAAK,EACL,MAAM,EACN,YAAY,EAAE,YAAY,EAC1B,UAAiC,GAClC,EAAE,gBAAgB,eA2GlB"}
|
|
@@ -54,29 +54,25 @@ export function SceneRunner(_a) {
|
|
|
54
54
|
}
|
|
55
55
|
return (AssetsLoader !== null && AssetsLoader !== void 0 ? AssetsLoader : _jsx("div", { children: "Assets loading..." }));
|
|
56
56
|
}, [AssetsLoader]);
|
|
57
|
-
return (
|
|
57
|
+
return (_jsxs("div", __assign({ style: {
|
|
58
58
|
width: windowSize.width,
|
|
59
59
|
height: windowSize.height,
|
|
60
60
|
overflow: "hidden",
|
|
61
61
|
position: "relative",
|
|
62
62
|
boxSizing: "border-box",
|
|
63
|
-
} }, { children: current.loadedAssets
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
} }, { children: [current.loadedAssets && (_jsx(Sketch, { onSetup: setup, onDraw: draw, scaler: refScaler.current })), _jsx("div", __assign({ style: {
|
|
64
|
+
position: "absolute",
|
|
65
|
+
top: 0,
|
|
66
|
+
left: 0,
|
|
67
|
+
width: "100%",
|
|
68
|
+
height: "100%",
|
|
69
|
+
userSelect: "none",
|
|
70
|
+
zIndex: 2,
|
|
71
|
+
} }, { children: _jsx("div", __assign({ style: __assign({ width: width, height: height, transform: "scale(".concat(refScaler.current.value, ")"), transformOrigin: "left top", position: "relative" }, (function () {
|
|
72
|
+
var deltaOfScaleForUI = refScaler.current.deltaOfScaleForUI;
|
|
73
|
+
return { left: deltaOfScaleForUI.x, top: deltaOfScaleForUI.y };
|
|
74
|
+
})()) }, { children: !current.loadedAssets ? (assetsLoader) : (_jsx(_Fragment, { children: isBootDone ? (_jsx("div", __assign({ style: {
|
|
75
75
|
width: "100%",
|
|
76
76
|
height: "100%",
|
|
77
|
-
} }, { children: _jsx(current.UI, __assign({ scene: current }, current.UIProps)) }))) : (_jsx("div", {})) })) }))] }))
|
|
78
|
-
width: "100%",
|
|
79
|
-
height: "100%",
|
|
80
|
-
transform: "scale(".concat(refScaler.current.value, ")"),
|
|
81
|
-
} }, { children: assetsLoader }))) })));
|
|
77
|
+
} }, { children: _jsx(current.UI, __assign({ scene: current }, current.UIProps)) }))) : (_jsx("div", {})) })) })) }))] })));
|
|
82
78
|
}
|