react-simple-game-engine 0.1.62 → 0.1.65
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/animations/animation.d.ts +14 -0
- package/lib/classes/animations/animation.d.ts.map +1 -0
- package/lib/classes/animations/animation.js +35 -0
- package/lib/classes/animations/avatar.animation.d.ts +16 -0
- package/lib/classes/animations/avatar.animation.d.ts.map +1 -0
- package/lib/classes/animations/avatar.animation.js +45 -0
- package/lib/classes/animations/color.animation.d.ts +9 -0
- package/lib/classes/animations/color.animation.d.ts.map +1 -0
- package/lib/classes/animations/color.animation.js +33 -0
- package/lib/classes/camera.d.ts.map +1 -0
- package/lib/classes/camera.js +34 -0
- package/lib/classes/entities/circle.entity.d.ts +15 -0
- package/lib/classes/entities/circle.entity.d.ts.map +1 -0
- package/lib/classes/entities/circle.entity.js +55 -0
- package/lib/classes/entities/entity-sult.d.ts +34 -0
- package/lib/classes/entities/entity-sult.d.ts.map +1 -0
- package/lib/classes/entities/entity-sult.js +108 -0
- package/lib/classes/entities/entity.d.ts +55 -0
- package/lib/classes/entities/entity.d.ts.map +1 -0
- package/lib/classes/entities/entity.js +180 -0
- package/lib/classes/entities/rect.entity.d.ts +17 -0
- package/lib/classes/entities/rect.entity.d.ts.map +1 -0
- package/lib/classes/entities/rect.entity.js +56 -0
- package/lib/classes/logic-component.d.ts.map +1 -0
- package/lib/classes/logic-component.js +77 -0
- package/lib/classes/p5.d.ts.map +1 -0
- package/lib/classes/p5.js +58 -0
- package/lib/classes/particle-system.d.ts.map +1 -0
- package/lib/classes/particle-system.js +98 -0
- package/lib/classes/particle.d.ts.map +1 -0
- package/lib/classes/particle.js +117 -0
- package/lib/classes/prefab.d.ts.map +1 -0
- package/lib/classes/prefab.js +24 -0
- package/lib/classes/saver.d.ts.map +1 -0
- package/lib/classes/saver.js +33 -0
- package/lib/classes/scene-management.d.ts.map +1 -0
- package/lib/classes/scene-management.js +58 -0
- package/lib/classes/scene.d.ts.map +1 -0
- package/lib/classes/scene.js +433 -0
- package/lib/classes/sound-watcher.d.ts.map +1 -0
- package/lib/classes/sound-watcher.js +33 -0
- package/lib/classes/sound.d.ts.map +1 -0
- package/lib/classes/sound.js +119 -0
- package/lib/classes/sprites/avatar.sprite.d.ts +20 -0
- package/lib/classes/sprites/avatar.sprite.d.ts.map +1 -0
- package/lib/classes/sprites/avatar.sprite.js +89 -0
- package/lib/classes/sprites/color.sprite.d.ts +7 -0
- package/lib/classes/sprites/color.sprite.d.ts.map +1 -0
- package/lib/classes/sprites/color.sprite.js +40 -0
- package/lib/classes/sprites/sprite.d.ts +26 -0
- package/lib/classes/sprites/sprite.d.ts.map +1 -0
- package/lib/classes/sprites/sprite.js +70 -0
- package/lib/classes/watcher.d.ts.map +1 -0
- package/lib/classes/watcher.js +44 -0
- package/lib/classes/world-management.d.ts.map +1 -0
- package/lib/classes/world-management.js +160 -0
- package/lib/decorators/scene-tag.decor.d.ts.map +1 -0
- package/lib/decorators/scene-tag.decor.js +5 -0
- package/lib/decorators/scene-ui.decor.d.ts.map +1 -0
- package/lib/decorators/scene-ui.decor.js +5 -0
- package/lib/decorators/sound-from.decor.d.ts.map +1 -0
- package/lib/decorators/sound-from.decor.js +17 -0
- package/lib/decorators/sprite-from.decor.d.ts.map +1 -0
- package/lib/decorators/sprite-from.decor.js +13 -0
- package/lib/export-enums.d.ts.map +1 -0
- package/lib/export-enums.js +5 -0
- package/lib/export-interfaces.d.ts.map +1 -0
- package/lib/export-interfaces.js +1 -0
- package/lib/export-types.d.ts.map +1 -0
- package/lib/export-types.js +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/ui-components/SceneRunner.d.ts.map +1 -0
- package/lib/ui-components/SceneRunner.js +43 -0
- package/lib/ui-components/ScenesProcess.d.ts.map +1 -0
- package/lib/ui-components/ScenesProcess.js +46 -0
- package/lib/ui-components/Sketch.d.ts.map +1 -0
- package/lib/ui-components/Sketch.js +33 -0
- package/lib/utilities.d.ts.map +1 -0
- package/lib/utilities.js +2 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +97 -0
- package/package.json +5 -8
@@ -0,0 +1,119 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
14
|
+
function step(op) {
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
16
|
+
while (_) try {
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
19
|
+
switch (op[0]) {
|
20
|
+
case 0: case 1: t = op; break;
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
24
|
+
default:
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
29
|
+
if (t[2]) _.ops.pop();
|
30
|
+
_.trys.pop(); continue;
|
31
|
+
}
|
32
|
+
op = body.call(thisArg, _);
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
35
|
+
}
|
36
|
+
};
|
37
|
+
var _a;
|
38
|
+
import { SoundType } from "../export-enums";
|
39
|
+
// cant not Sound extends Audio, because TS complite, make call new Audio like a function
|
40
|
+
var Sound = /** @class */ (function () {
|
41
|
+
function Sound(type) {
|
42
|
+
if (type === void 0) { type = SoundType.ONCE; }
|
43
|
+
this.type = type;
|
44
|
+
this.native = new Audio();
|
45
|
+
}
|
46
|
+
Object.defineProperty(Sound.prototype, "volumn", {
|
47
|
+
get: function () {
|
48
|
+
return this.native.volume;
|
49
|
+
},
|
50
|
+
set: function (vol) {
|
51
|
+
this.native.volume = vol;
|
52
|
+
},
|
53
|
+
enumerable: false,
|
54
|
+
configurable: true
|
55
|
+
});
|
56
|
+
Sound.prototype.playNow = function () {
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
58
|
+
var canPlay;
|
59
|
+
return __generator(this, function (_a) {
|
60
|
+
switch (_a.label) {
|
61
|
+
case 0:
|
62
|
+
canPlay = Sound.Management[this.type].canPlay;
|
63
|
+
if (!canPlay) return [3 /*break*/, 2];
|
64
|
+
this.native.currentTime = 0;
|
65
|
+
return [4 /*yield*/, this.play()];
|
66
|
+
case 1:
|
67
|
+
_a.sent();
|
68
|
+
_a.label = 2;
|
69
|
+
case 2: return [2 /*return*/];
|
70
|
+
}
|
71
|
+
});
|
72
|
+
});
|
73
|
+
};
|
74
|
+
Sound.prototype.stop = function () {
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
76
|
+
return __generator(this, function (_a) {
|
77
|
+
this.native.pause();
|
78
|
+
this.native.currentTime = 0;
|
79
|
+
this.native.src = "";
|
80
|
+
return [2 /*return*/];
|
81
|
+
});
|
82
|
+
});
|
83
|
+
};
|
84
|
+
Sound.prototype.play = function () {
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
86
|
+
var _a, canPlay, loop;
|
87
|
+
return __generator(this, function (_b) {
|
88
|
+
switch (_b.label) {
|
89
|
+
case 0:
|
90
|
+
_a = Sound.Management[this.type], canPlay = _a.canPlay, loop = _a.loop;
|
91
|
+
if (!canPlay) return [3 /*break*/, 2];
|
92
|
+
if (loop) {
|
93
|
+
this.native.loop = true;
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
this.native.loop = false;
|
97
|
+
}
|
98
|
+
return [4 /*yield*/, this.native.play()];
|
99
|
+
case 1:
|
100
|
+
_b.sent();
|
101
|
+
_b.label = 2;
|
102
|
+
case 2: return [2 /*return*/];
|
103
|
+
}
|
104
|
+
});
|
105
|
+
});
|
106
|
+
};
|
107
|
+
Sound.Management = (_a = {},
|
108
|
+
_a[SoundType.ONCE] = {
|
109
|
+
canPlay: true,
|
110
|
+
loop: false,
|
111
|
+
},
|
112
|
+
_a[SoundType.BACKGROUND] = {
|
113
|
+
canPlay: true,
|
114
|
+
loop: true,
|
115
|
+
},
|
116
|
+
_a);
|
117
|
+
return Sound;
|
118
|
+
}());
|
119
|
+
export { Sound };
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Avatar } from "../../export-types";
|
2
|
+
import { GetInitialParams, Sprite } from "./sprite";
|
3
|
+
declare type SpriteOffet = {
|
4
|
+
x: number;
|
5
|
+
y: number;
|
6
|
+
width: number;
|
7
|
+
height: number;
|
8
|
+
index: number;
|
9
|
+
};
|
10
|
+
declare type AvatarGetInitialParams<S extends AvatarSprite> = GetInitialParams<S> & {
|
11
|
+
offset?: Partial<SpriteOffet>;
|
12
|
+
};
|
13
|
+
export declare class AvatarSprite extends Sprite<Avatar | undefined | null> {
|
14
|
+
private _offset;
|
15
|
+
get offset(): SpriteOffet;
|
16
|
+
onDraw(): void;
|
17
|
+
initial(params?: AvatarGetInitialParams<this>): void;
|
18
|
+
}
|
19
|
+
export {};
|
20
|
+
//# sourceMappingURL=avatar.sprite.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"avatar.sprite.d.ts","sourceRoot":"","sources":["../../../src/classes/sprites/avatar.sprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEpD,aAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,aAAK,sBAAsB,CAAC,CAAC,SAAS,YAAY,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAAG;IAE1E,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/B,CAAC;AAEF,qBAAa,YAAa,SAAQ,MAAM,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjE,OAAO,CAAC,OAAO,CAMb;IAEF,IAAI,MAAM,gBAET;IAED,MAAM;IAuBN,OAAO,CAAC,MAAM,CAAC,EAAE,sBAAsB,CAAC,IAAI,CAAC;CAc9C"}
|
@@ -0,0 +1,89 @@
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
2
|
+
var extendStatics = function (d, b) {
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6
|
+
return extendStatics(d, b);
|
7
|
+
};
|
8
|
+
return function (d, b) {
|
9
|
+
if (typeof b !== "function" && b !== null)
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11
|
+
extendStatics(d, b);
|
12
|
+
function __() { this.constructor = d; }
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
|
+
};
|
15
|
+
})();
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
17
|
+
__assign = Object.assign || function(t) {
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
19
|
+
s = arguments[i];
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
21
|
+
t[p] = s[p];
|
22
|
+
}
|
23
|
+
return t;
|
24
|
+
};
|
25
|
+
return __assign.apply(this, arguments);
|
26
|
+
};
|
27
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
28
|
+
var t = {};
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
30
|
+
t[p] = s[p];
|
31
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
32
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
33
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
34
|
+
t[p[i]] = s[p[i]];
|
35
|
+
}
|
36
|
+
return t;
|
37
|
+
};
|
38
|
+
import { copyProperties } from "../../utils";
|
39
|
+
import { Sprite } from "./sprite";
|
40
|
+
var AvatarSprite = /** @class */ (function (_super) {
|
41
|
+
__extends(AvatarSprite, _super);
|
42
|
+
function AvatarSprite() {
|
43
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
44
|
+
_this._offset = {
|
45
|
+
x: 0,
|
46
|
+
y: 0,
|
47
|
+
index: 0,
|
48
|
+
width: 0,
|
49
|
+
height: 0,
|
50
|
+
};
|
51
|
+
return _this;
|
52
|
+
}
|
53
|
+
Object.defineProperty(AvatarSprite.prototype, "offset", {
|
54
|
+
get: function () {
|
55
|
+
return this._offset;
|
56
|
+
},
|
57
|
+
enumerable: false,
|
58
|
+
configurable: true
|
59
|
+
});
|
60
|
+
AvatarSprite.prototype.onDraw = function () {
|
61
|
+
if (this.source) {
|
62
|
+
if (this.animation) {
|
63
|
+
this.animation.draw();
|
64
|
+
}
|
65
|
+
else {
|
66
|
+
var _a = this._offset, x = _a.x, y = _a.y, width = _a.width, height = _a.height, index = _a.index;
|
67
|
+
Renderer.image(this.source,
|
68
|
+
// position on canvas
|
69
|
+
0, 0, this.width, this.height,
|
70
|
+
//crop on source image
|
71
|
+
index * width + x, y, width, height);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
};
|
75
|
+
AvatarSprite.prototype.initial = function (params) {
|
76
|
+
var _a = (params ||
|
77
|
+
{}), offset = _a.offset, source = _a.source, _params = __rest(_a, ["offset", "source"]);
|
78
|
+
if (source) {
|
79
|
+
this._offset.width = source.width;
|
80
|
+
this._offset.height = source.height;
|
81
|
+
}
|
82
|
+
if (offset) {
|
83
|
+
copyProperties(this._offset, offset);
|
84
|
+
}
|
85
|
+
_super.prototype.initial.call(this, __assign(__assign({}, _params), { source: source }));
|
86
|
+
};
|
87
|
+
return AvatarSprite;
|
88
|
+
}(Sprite));
|
89
|
+
export { AvatarSprite };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"color.sprite.d.ts","sourceRoot":"","sources":["../../../src/classes/sprites/color.sprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,WAAY,SAAQ,MAAM,CAAC,KAAK,CAAC;;IAK5C,MAAM;CAYP"}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
2
|
+
var extendStatics = function (d, b) {
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6
|
+
return extendStatics(d, b);
|
7
|
+
};
|
8
|
+
return function (d, b) {
|
9
|
+
if (typeof b !== "function" && b !== null)
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11
|
+
extendStatics(d, b);
|
12
|
+
function __() { this.constructor = d; }
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
|
+
};
|
15
|
+
})();
|
16
|
+
import { Sprite } from "./sprite";
|
17
|
+
var ColorSprite = /** @class */ (function (_super) {
|
18
|
+
__extends(ColorSprite, _super);
|
19
|
+
function ColorSprite() {
|
20
|
+
var _this = _super.call(this) || this;
|
21
|
+
_this.source = [255, 255, 255];
|
22
|
+
return _this;
|
23
|
+
}
|
24
|
+
ColorSprite.prototype.onDraw = function () {
|
25
|
+
if (this.animation) {
|
26
|
+
this.animation.draw();
|
27
|
+
}
|
28
|
+
else {
|
29
|
+
Renderer.fill.apply(Renderer, this.source);
|
30
|
+
}
|
31
|
+
if (this.entity.width != null) {
|
32
|
+
Renderer.rect(0, 0, this.width, this.height);
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
Renderer.circle(0, 0, this.width);
|
36
|
+
}
|
37
|
+
};
|
38
|
+
return ColorSprite;
|
39
|
+
}(Sprite));
|
40
|
+
export { ColorSprite };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { Avatar, Color } from "../../export-types";
|
2
|
+
import { AnimationSprite } from "../animations/animation";
|
3
|
+
import { Entity } from "../entities/entity";
|
4
|
+
import { LogicComponent } from "../logic-component";
|
5
|
+
export declare type SourceType = Avatar | Color | undefined | null;
|
6
|
+
export declare type GetInitialParams<S extends Sprite<any> = any> = {
|
7
|
+
source?: S["source"];
|
8
|
+
animation?: LogicComponent<AnimationSprite<S>>;
|
9
|
+
};
|
10
|
+
export declare abstract class Sprite<SpriteType extends SourceType> {
|
11
|
+
source: SpriteType;
|
12
|
+
private _entity;
|
13
|
+
private _width;
|
14
|
+
private _height;
|
15
|
+
private _animation;
|
16
|
+
set animation(ani: AnimationSprite<this>);
|
17
|
+
get animation(): AnimationSprite<this>;
|
18
|
+
set entity(entity: Entity);
|
19
|
+
get entity(): Entity;
|
20
|
+
get width(): number;
|
21
|
+
get height(): number;
|
22
|
+
draw(): void;
|
23
|
+
abstract onDraw(): void;
|
24
|
+
initial(params?: GetInitialParams<this>): void;
|
25
|
+
}
|
26
|
+
//# sourceMappingURL=sprite.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sprite.d.ts","sourceRoot":"","sources":["../../../src/classes/sprites/sprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,oBAAY,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC;AAE3D,oBAAY,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI;IAC1D,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;IACrB,SAAS,CAAC,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;CAChD,CAAC;AAEF,8BAAsB,MAAM,CAAC,UAAU,SAAS,UAAU;IACjD,MAAM,EAAG,UAAU,CAAC;IAC3B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,OAAO,CAAU;IAEzB,OAAO,CAAC,UAAU,CAAoC;IAEtD,IAAI,SAAS,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,CAAC,EAGvC;IAED,IAAI,SAAS,IAAI,eAAe,CAAC,IAAI,CAAC,CAErC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAKxB;IAED,IAAI,MAAM,IAPS,MAAM,CASxB;IAED,IAAI,KAAK,WAER;IAED,IAAI,MAAM,WAET;IAED,IAAI;IAUJ,QAAQ,CAAC,MAAM,IAAI,IAAI;IAEvB,OAAO,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC;CAexC"}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { LogicComponent } from "../logic-component";
|
2
|
+
var Sprite = /** @class */ (function () {
|
3
|
+
function Sprite() {
|
4
|
+
}
|
5
|
+
Object.defineProperty(Sprite.prototype, "animation", {
|
6
|
+
get: function () {
|
7
|
+
return this._animation;
|
8
|
+
},
|
9
|
+
set: function (ani) {
|
10
|
+
this._animation = ani;
|
11
|
+
this._animation.sprite = this;
|
12
|
+
},
|
13
|
+
enumerable: false,
|
14
|
+
configurable: true
|
15
|
+
});
|
16
|
+
Object.defineProperty(Sprite.prototype, "entity", {
|
17
|
+
get: function () {
|
18
|
+
return this._entity;
|
19
|
+
},
|
20
|
+
set: function (entity) {
|
21
|
+
this._entity = entity;
|
22
|
+
var _a = this._entity.onSpriteWidthHeightBinding(), width = _a.width, height = _a.height;
|
23
|
+
this._width = width;
|
24
|
+
this._height = height;
|
25
|
+
},
|
26
|
+
enumerable: false,
|
27
|
+
configurable: true
|
28
|
+
});
|
29
|
+
Object.defineProperty(Sprite.prototype, "width", {
|
30
|
+
get: function () {
|
31
|
+
return this._width;
|
32
|
+
},
|
33
|
+
enumerable: false,
|
34
|
+
configurable: true
|
35
|
+
});
|
36
|
+
Object.defineProperty(Sprite.prototype, "height", {
|
37
|
+
get: function () {
|
38
|
+
return this._height;
|
39
|
+
},
|
40
|
+
enumerable: false,
|
41
|
+
configurable: true
|
42
|
+
});
|
43
|
+
Sprite.prototype.draw = function () {
|
44
|
+
var _a = this.entity, body = _a.body, position = _a.position, camera = _a.camera;
|
45
|
+
Renderer.push();
|
46
|
+
Renderer.noStroke();
|
47
|
+
Renderer.translate(position.x - camera.x, position.y - camera.y);
|
48
|
+
Renderer.rotate(body.angle);
|
49
|
+
this.onDraw();
|
50
|
+
Renderer.pop();
|
51
|
+
};
|
52
|
+
Sprite.prototype.initial = function (params) {
|
53
|
+
if (params) {
|
54
|
+
for (var key in params) {
|
55
|
+
// @ts-ignore
|
56
|
+
var P = params[key];
|
57
|
+
if (P instanceof LogicComponent) {
|
58
|
+
// @ts-ignore
|
59
|
+
this[key] = P.output();
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
// @ts-ignore
|
63
|
+
this[key] = P;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
};
|
68
|
+
return Sprite;
|
69
|
+
}());
|
70
|
+
export { Sprite };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../src/classes/watcher.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,aAAK,YAAY,CAAC,EAAE,IAAI;IACtB,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,aAAa,EAAE,EAAE,CAAC;IAClB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,SAAS,CAAC;CACpC,CAAC;AACF,wBAAgB,OAAO,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAC5E,KAAK,EACL,KAAK,EAAE,MAAM,EACb,QAAQ,EACR,aAAa,GACd,EAAE,YAAY,CAAC,EAAE,CAAC,eAqBlB"}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
14
|
+
if (ar || !(i in from)) {
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
16
|
+
ar[i] = from[i];
|
17
|
+
}
|
18
|
+
}
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
20
|
+
};
|
21
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
22
|
+
import { useEffect, useState } from "react";
|
23
|
+
export function Watcher(_a) {
|
24
|
+
var scene = _a.scene, _names = _a.names, children = _a.children, initialValues = _a.initialValues;
|
25
|
+
var names = Array.isArray(_names) ? _names : [_names];
|
26
|
+
var _b = useState(initialValues), values = _b[0], setValues = _b[1];
|
27
|
+
useEffect(function () {
|
28
|
+
var unsubs = names.map(function (name) {
|
29
|
+
return scene.onEntityPropsChange(name, function (value) {
|
30
|
+
setValues(function (prev) {
|
31
|
+
var _a;
|
32
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[name] = value, _a)));
|
33
|
+
});
|
34
|
+
});
|
35
|
+
});
|
36
|
+
return function () {
|
37
|
+
for (var _i = 0, unsubs_1 = unsubs; _i < unsubs_1.length; _i++) {
|
38
|
+
var unsub = unsubs_1[_i];
|
39
|
+
unsub();
|
40
|
+
}
|
41
|
+
};
|
42
|
+
}, __spreadArray(__spreadArray([], names, true), [scene], false));
|
43
|
+
return _jsx(_Fragment, { children: children(values) });
|
44
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"world-management.d.ts","sourceRoot":"","sources":["../../src/classes/world-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuB,MAAM,WAAW,CAAC;AAIxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,qBAAa,eAAe;IAWd,OAAO,CAAC,OAAO;IAAU,OAAO,CAAC,MAAM;IAVnD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAC/D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAGtB;IACP,OAAO,CAAC,QAAQ,CAAC,YAAY,CACxB;IAEL,OAAO,CAAC,OAAO,CAAU;gBAEL,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,KAAK;IAgD1D,IAAI,MAAM,WAET;IAED,IAAI,MAAM,WAET;IAED,IAAI,KAAK,eAER;IAED,OAAO,CAAC,eAAe;IAuBvB,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,OAAO;IAWf,UAAU;IAKV,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM;IAK3D,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM;IAKpD,SAAS,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;IAK7D,SAAS,CAAC,MAAM,EAAE,UAAU;IAW5B,YAAY,CAAC,MAAM,EAAE,UAAU;IAe/B,MAAM;IAON,IAAI;CAKL"}
|
@@ -0,0 +1,160 @@
|
|
1
|
+
import { Engine, World, Events, Body } from "matter-js";
|
2
|
+
import { Entity } from "./entities/entity";
|
3
|
+
var WorldManagement = /** @class */ (function () {
|
4
|
+
function WorldManagement(_camera, _scene) {
|
5
|
+
var _this = this;
|
6
|
+
this._camera = _camera;
|
7
|
+
this._scene = _scene;
|
8
|
+
this.entitiesHash = {};
|
9
|
+
this.entitiesPool = {};
|
10
|
+
this.entitiesName = {};
|
11
|
+
this._engine = Engine.create();
|
12
|
+
Events.on(this.engine, "beforeUpdate", function () {
|
13
|
+
var gravity = _this.engine.gravity;
|
14
|
+
_this.iterateEntities(function (entity) {
|
15
|
+
if (entity instanceof Entity && !entity.enabledGravity) {
|
16
|
+
Body.applyForce(entity.body, entity.position, {
|
17
|
+
x: -gravity.x * gravity.scale * entity.body.mass,
|
18
|
+
y: -gravity.y * gravity.scale * entity.body.mass,
|
19
|
+
});
|
20
|
+
}
|
21
|
+
});
|
22
|
+
});
|
23
|
+
Events.on(this.engine, "collisionStart", function (event) {
|
24
|
+
var pairs = event.pairs;
|
25
|
+
for (var _i = 0, pairs_1 = pairs; _i < pairs_1.length; _i++) {
|
26
|
+
var pair = pairs_1[_i];
|
27
|
+
var _a = pair, bodyA = _a.bodyA, bodyB = _a.bodyB;
|
28
|
+
bodyA.entity.onCollision(bodyB.entity);
|
29
|
+
bodyB.entity.onCollision(bodyA.entity);
|
30
|
+
}
|
31
|
+
});
|
32
|
+
Events.on(this.engine, "collisionEnd", function (event) {
|
33
|
+
var pairs = event.pairs;
|
34
|
+
for (var _i = 0, pairs_2 = pairs; _i < pairs_2.length; _i++) {
|
35
|
+
var pair = pairs_2[_i];
|
36
|
+
var _a = pair, bodyA = _a.bodyA, bodyB = _a.bodyB;
|
37
|
+
bodyA.entity.onCollisionEnd(bodyB.entity);
|
38
|
+
bodyB.entity.onCollisionEnd(bodyA.entity);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
Events.on(this.engine, "collisionActive", function (event) {
|
42
|
+
var pairs = event.pairs;
|
43
|
+
for (var _i = 0, pairs_3 = pairs; _i < pairs_3.length; _i++) {
|
44
|
+
var pair = pairs_3[_i];
|
45
|
+
var _a = pair, bodyA = _a.bodyA, bodyB = _a.bodyB;
|
46
|
+
bodyA.entity.onCollisionActive(bodyB.entity);
|
47
|
+
bodyB.entity.onCollisionActive(bodyA.entity);
|
48
|
+
}
|
49
|
+
});
|
50
|
+
}
|
51
|
+
Object.defineProperty(WorldManagement.prototype, "engine", {
|
52
|
+
get: function () {
|
53
|
+
return this._engine;
|
54
|
+
},
|
55
|
+
enumerable: false,
|
56
|
+
configurable: true
|
57
|
+
});
|
58
|
+
Object.defineProperty(WorldManagement.prototype, "camera", {
|
59
|
+
get: function () {
|
60
|
+
return this._camera;
|
61
|
+
},
|
62
|
+
enumerable: false,
|
63
|
+
configurable: true
|
64
|
+
});
|
65
|
+
Object.defineProperty(WorldManagement.prototype, "scene", {
|
66
|
+
get: function () {
|
67
|
+
return this._scene;
|
68
|
+
},
|
69
|
+
enumerable: false,
|
70
|
+
configurable: true
|
71
|
+
});
|
72
|
+
WorldManagement.prototype.iterateEntities = function (action) {
|
73
|
+
var _a = this, entitiesPool = _a.entitiesPool, entitiesHash = _a.entitiesHash;
|
74
|
+
var indexes = Object.keys(this.entitiesPool).map(function (idx) { return +idx; });
|
75
|
+
indexes.sort();
|
76
|
+
for (var _i = 0, indexes_1 = indexes; _i < indexes_1.length; _i++) {
|
77
|
+
var index = indexes_1[_i];
|
78
|
+
var entitiesId = entitiesPool[index];
|
79
|
+
var isBreak = false;
|
80
|
+
for (var _b = 0, entitiesId_1 = entitiesId; _b < entitiesId_1.length; _b++) {
|
81
|
+
var id = entitiesId_1[_b];
|
82
|
+
var entity = entitiesHash[id];
|
83
|
+
isBreak = action(entity);
|
84
|
+
if (isBreak) {
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
if (isBreak) {
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
};
|
93
|
+
WorldManagement.prototype.joinPool = function (index, entity) {
|
94
|
+
this.entitiesPool[index] = this.entitiesPool[index] || [];
|
95
|
+
this.entitiesPool[index].push(entity.id);
|
96
|
+
};
|
97
|
+
WorldManagement.prototype.outPool = function (entity) {
|
98
|
+
var pool = this.entitiesPool[entity.layerIndex];
|
99
|
+
if (!pool) {
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
var delIndex = pool.indexOf(entity.id);
|
103
|
+
if (delIndex > -1) {
|
104
|
+
pool.splice(delIndex, 1);
|
105
|
+
}
|
106
|
+
};
|
107
|
+
WorldManagement.prototype.destructor = function () {
|
108
|
+
World.clear(this.engine.world, false);
|
109
|
+
Engine.clear(this.engine);
|
110
|
+
};
|
111
|
+
WorldManagement.prototype.changeEntityLayerIndex = function (entity, newIndex) {
|
112
|
+
this.outPool(entity);
|
113
|
+
this.joinPool(newIndex, entity);
|
114
|
+
};
|
115
|
+
WorldManagement.prototype.changeEntityName = function (entity, newName) {
|
116
|
+
delete this.entitiesName[entity.name];
|
117
|
+
this.entitiesName[newName] = entity.id;
|
118
|
+
};
|
119
|
+
WorldManagement.prototype.getEntity = function (name) {
|
120
|
+
var id = this.entitiesName[name];
|
121
|
+
return this.entitiesHash[id];
|
122
|
+
};
|
123
|
+
WorldManagement.prototype.addEntity = function (entity) {
|
124
|
+
this.joinPool(entity.layerIndex, entity);
|
125
|
+
this.entitiesHash[entity.id] = entity;
|
126
|
+
this.entitiesName[entity.name] = entity.id;
|
127
|
+
if (entity instanceof Entity) {
|
128
|
+
World.add(this.engine.world, entity.body);
|
129
|
+
}
|
130
|
+
entity.active(this);
|
131
|
+
};
|
132
|
+
WorldManagement.prototype.removeEntity = function (entity) {
|
133
|
+
if (entity instanceof Entity) {
|
134
|
+
World.remove(this.engine.world, entity.body);
|
135
|
+
}
|
136
|
+
for (var _i = 0, _a = entity.children; _i < _a.length; _i++) {
|
137
|
+
var child = _a[_i];
|
138
|
+
this.removeEntity(child);
|
139
|
+
}
|
140
|
+
if (entity.parent) {
|
141
|
+
entity.parent.unChild(entity);
|
142
|
+
}
|
143
|
+
delete this.entitiesName[entity.name];
|
144
|
+
delete this.entitiesHash[entity.id];
|
145
|
+
this.outPool(entity);
|
146
|
+
};
|
147
|
+
WorldManagement.prototype.update = function () {
|
148
|
+
Engine.update(this.engine);
|
149
|
+
this.iterateEntities(function (entity) {
|
150
|
+
entity.update();
|
151
|
+
});
|
152
|
+
};
|
153
|
+
WorldManagement.prototype.draw = function () {
|
154
|
+
this.iterateEntities(function (entity) {
|
155
|
+
entity.draw();
|
156
|
+
});
|
157
|
+
};
|
158
|
+
return WorldManagement;
|
159
|
+
}());
|
160
|
+
export { WorldManagement };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"scene-tag.decor.d.ts","sourceRoot":"","sources":["../../src/decorators/scene-tag.decor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,YACT;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,KAAK,CAAA;CAAE,UAGzD"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"scene-ui.decor.d.ts","sourceRoot":"","sources":["../../src/decorators/scene-ui.decor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,wBAAgB,OAAO,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,YACnB;IAAE,EAAE,CAAC,EAAE,cAAc,GAAG,CAAC,CAAC;IAAC,QAAQ,KAAK,CAAA;CAAE,UAGpE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sound-from.decor.d.ts","sourceRoot":"","sources":["../../src/decorators/sound-from.decor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,wBAAgB,SAAS,CACvB,OAAO,CAAC,EAAE,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EACpD,IAAI,GAAE,SAA0B,YAEP,GAAG,eAAe,MAAM,UAclD"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { SoundType } from "../export-enums";
|
2
|
+
export function SoundFrom(srcable, type) {
|
3
|
+
if (type === void 0) { type = SoundType.ONCE; }
|
4
|
+
return function (target, propertyKey) {
|
5
|
+
var _a = srcable
|
6
|
+
? typeof srcable === "string"
|
7
|
+
? { src: srcable, volumn: undefined }
|
8
|
+
: srcable
|
9
|
+
: { volumn: undefined, src: undefined }, volumn = _a.volumn, src = _a.src;
|
10
|
+
target.constructor.soundsDecor.push({
|
11
|
+
volumn: volumn,
|
12
|
+
propertyKey: propertyKey,
|
13
|
+
src: src,
|
14
|
+
type: type,
|
15
|
+
});
|
16
|
+
};
|
17
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sprite-from.decor.d.ts","sourceRoot":"","sources":["../../src/decorators/sprite-from.decor.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,YACnC,GAAG,eAAe,MAAM,UAYlD"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export function SpriteFrom(srcable) {
|
2
|
+
return function (target, propertyKey) {
|
3
|
+
var src = (srcable
|
4
|
+
? typeof srcable === "string"
|
5
|
+
? { src: srcable }
|
6
|
+
: srcable
|
7
|
+
: { src: undefined }).src;
|
8
|
+
target.constructor.spritesDecor.push({
|
9
|
+
propertyKey: propertyKey,
|
10
|
+
src: src,
|
11
|
+
});
|
12
|
+
};
|
13
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"export-enums.d.ts","sourceRoot":"","sources":["../src/export-enums.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,IAAI,IAAA;IACJ,UAAU,IAAA;CACX"}
|