react-simple-game-engine 0.2.24 → 0.2.25
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/scaler.d.ts
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
import { LayoutMode } from "../export-enums";
|
2
2
|
import { Size } from "../export-types";
|
3
3
|
export declare class Scaler {
|
4
|
-
private readonly
|
4
|
+
private readonly _screenSize;
|
5
5
|
private readonly _canvasSize;
|
6
6
|
private _layoutMode;
|
7
7
|
private _value;
|
8
|
-
constructor(
|
8
|
+
constructor(_screenSize: Size, _canvasSize: Size, _layoutMode: LayoutMode);
|
9
9
|
get value(): number;
|
10
10
|
get layoutMode(): LayoutMode;
|
11
11
|
get canvasSize(): Size;
|
12
|
-
|
12
|
+
get screenSize(): Size;
|
13
|
+
set screenSize(_screenSize: Size);
|
13
14
|
set canvasSize(_canvasSize: Size);
|
14
15
|
set layoutMode(_layoutMode: LayoutMode);
|
16
|
+
screenUnitToCanvasUnit(px: number): number;
|
15
17
|
private update;
|
16
18
|
}
|
17
19
|
//# sourceMappingURL=scaler.d.ts.map
|
@@ -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;IAGf,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,WAAW;IAJrB,OAAO,CAAC,MAAM,CAAS;gBAEJ,WAAW,EAAE,IAAI,EACjB,WAAW,EAAE,IAAI,EAC1B,WAAW,EAAE,UAAU;IAKjC,IAAI,KAAK,WAER;IAED,IAAI,UAAU,
|
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;IAGf,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,WAAW;IAJrB,OAAO,CAAC,MAAM,CAAS;gBAEJ,WAAW,EAAE,IAAI,EACjB,WAAW,EAAE,IAAI,EAC1B,WAAW,EAAE,UAAU;IAKjC,IAAI,KAAK,WAER;IAED,IAAI,UAAU,IA6Bc,UAAU,CA3BrC;IAED,IAAI,UAAU,IAoBc,IAAI,CAlB/B;IAED,IAAI,UAAU,IAWc,IAAI,CAT/B;IASD,IAAI,UAAU,CAAC,WAAW,EAAE,IAAI,EAG/B;IAED,IAAI,UAAU,CAAC,WAAW,EAAE,IAAI,EAG/B;IAED,IAAI,UAAU,CAAC,WAAW,EAAE,UAAU,EAGrC;IAED,sBAAsB,CAAC,EAAE,EAAE,MAAM;IAIjC,OAAO,CAAC,MAAM;CAef"}
|
package/lib/classes/scaler.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { LayoutMode } from "../export-enums";
|
2
2
|
import { copyProperties } from "../utils";
|
3
3
|
var Scaler = /** @class */ (function () {
|
4
|
-
function Scaler(
|
5
|
-
this.
|
4
|
+
function Scaler(_screenSize, _canvasSize, _layoutMode) {
|
5
|
+
this._screenSize = _screenSize;
|
6
6
|
this._canvasSize = _canvasSize;
|
7
7
|
this._layoutMode = _layoutMode;
|
8
8
|
this.update();
|
@@ -36,35 +36,41 @@ var Scaler = /** @class */ (function () {
|
|
36
36
|
enumerable: false,
|
37
37
|
configurable: true
|
38
38
|
});
|
39
|
-
Object.defineProperty(Scaler.prototype, "
|
39
|
+
Object.defineProperty(Scaler.prototype, "screenSize", {
|
40
|
+
get: function () {
|
41
|
+
return this._screenSize;
|
42
|
+
},
|
40
43
|
// private get scaledSize() {
|
41
44
|
// return {
|
42
45
|
// width: this._canvasSize.width * this._value,
|
43
46
|
// height: this._canvasSize.height * this._value,
|
44
47
|
// };
|
45
48
|
// }
|
46
|
-
set: function (
|
47
|
-
copyProperties(this.
|
49
|
+
set: function (_screenSize) {
|
50
|
+
copyProperties(this._screenSize, _screenSize);
|
48
51
|
this.update();
|
49
52
|
},
|
50
53
|
enumerable: false,
|
51
54
|
configurable: true
|
52
55
|
});
|
56
|
+
Scaler.prototype.screenUnitToCanvasUnit = function (px) {
|
57
|
+
return px / this._value;
|
58
|
+
};
|
53
59
|
Scaler.prototype.update = function () {
|
54
60
|
if (this._layoutMode === LayoutMode.LANDSCAPE) {
|
55
|
-
if (this.
|
56
|
-
this._value = this.
|
61
|
+
if (this._screenSize.width >= this._screenSize.height) {
|
62
|
+
this._value = this._screenSize.width / this._canvasSize.width;
|
57
63
|
}
|
58
64
|
else {
|
59
|
-
this._value = this.
|
65
|
+
this._value = this._screenSize.height / this._canvasSize.height;
|
60
66
|
}
|
61
67
|
}
|
62
68
|
else {
|
63
|
-
if (this.
|
64
|
-
this._value = this.
|
69
|
+
if (this._screenSize.height >= this._screenSize.width) {
|
70
|
+
this._value = this._screenSize.width / this._canvasSize.width;
|
65
71
|
}
|
66
72
|
else {
|
67
|
-
this._value = this.
|
73
|
+
this._value = this._screenSize.height / this._canvasSize.height;
|
68
74
|
}
|
69
75
|
}
|
70
76
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../src/classes/scene.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,
|
1
|
+
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../src/classes/scene.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,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AC,SAAS,UAAU,EAAE,KAAK,EAAE;QACrC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;KACjC,GAAG,MAAM,CAAC,CAAC,CAAC;IAIb,kBAAkB;IAelB,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,YAAY;IAEpD,OAAO,CAAC,aAAa;IAIrB,SAAS,CAAC,YAAY,EAAE,YAAY;IAuCpC,SAAS,CAAC,MAAM;IAChB,SAAS,CAAC,QAAQ;IAElB,MAAM;CAUP"}
|
@@ -20,15 +20,15 @@ export function SceneRunner(_a) {
|
|
20
20
|
var width = _a.width, height = _a.height, current = _a.current, _b = _a.layoutMode, layoutMode = _b === void 0 ? LayoutMode.LANDSCAPE : _b,
|
21
21
|
//
|
22
22
|
voidSpace = _a.voidSpace, assetsDelay = _a.assetsDelay, assetsFailBehavior = _a.assetsFailBehavior, AssetsLoader = _a.assetsLoader;
|
23
|
-
var
|
24
|
-
var refScaler = useRef(new Scaler(
|
23
|
+
var screenSize = useWindowSize();
|
24
|
+
var refScaler = useRef(new Scaler(screenSize, { width: width, height: height }, layoutMode));
|
25
25
|
var _c = useState(false), isBootDone = _c[0], setBootDone = _c[1];
|
26
26
|
useMemo(function () {
|
27
27
|
refScaler.current.canvasSize = {
|
28
|
-
width:
|
29
|
-
height:
|
28
|
+
width: screenSize.width,
|
29
|
+
height: screenSize.height,
|
30
30
|
};
|
31
|
-
}, [
|
31
|
+
}, [screenSize]);
|
32
32
|
useMemo(function () {
|
33
33
|
if (window.Renderer) {
|
34
34
|
window.Renderer.resizeCanvas(width, height);
|
@@ -59,8 +59,8 @@ export function SceneRunner(_a) {
|
|
59
59
|
return (AssetsLoader !== null && AssetsLoader !== void 0 ? AssetsLoader : _jsx("div", { children: "Assets loading..." }));
|
60
60
|
}, [AssetsLoader]);
|
61
61
|
return (_jsxs("div", __assign({ style: {
|
62
|
-
width:
|
63
|
-
height:
|
62
|
+
width: screenSize.width,
|
63
|
+
height: screenSize.height,
|
64
64
|
overflow: "hidden",
|
65
65
|
position: "relative",
|
66
66
|
boxSizing: "border-box",
|