mani-game-engine 1.0.0-pre.7 → 1.0.0-pre.71
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/LICENSE +1 -1
- package/lib/clock.d.ts +57 -0
- package/lib/clock.js +121 -0
- package/lib/clock.js.map +1 -0
- package/lib/ecsInjector.d.ts +45 -0
- package/lib/ecsInjector.js +220 -0
- package/lib/ecsInjector.js.map +1 -0
- package/lib/entity.d.ts +37 -0
- package/lib/entity.js +176 -0
- package/lib/entity.js.map +1 -0
- package/lib/gameEngine.d.ts +96 -0
- package/lib/gameEngine.js +445 -0
- package/lib/gameEngine.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +37 -0
- package/lib/index.js.map +1 -0
- package/lib/injector.d.ts +130 -0
- package/lib/injector.js +324 -0
- package/lib/injector.js.map +1 -0
- package/lib/scope/scopeContext.d.ts +76 -0
- package/lib/scope/scopeContext.js +306 -0
- package/lib/scope/scopeContext.js.map +1 -0
- package/lib/systemContext.d.ts +15 -0
- package/lib/systemContext.js +39 -0
- package/lib/systemContext.js.map +1 -0
- package/lib/types.d.ts +83 -0
- package/lib/types.js +20 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/map2k.d.ts +6 -0
- package/lib/utils/map2k.js +44 -0
- package/lib/utils/map2k.js.map +1 -0
- package/package.json +12 -15
- package/src/clock.ts +133 -81
- package/src/ecsInjector.ts +131 -36
- package/src/entity.ts +105 -5
- package/src/gameEngine.ts +483 -353
- package/src/index.ts +25 -9
- package/src/injector.ts +410 -0
- package/src/scope/scopeContext.ts +118 -32
- package/src/systemContext.ts +20 -2
- package/src/types.ts +24 -10
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopeContext = exports.SCOPE_CONTEXT = exports.OnScopeSignal = exports.scopeSignalHandlers = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const ecsInjector_1 = require("../ecsInjector");
|
|
6
|
+
const injector_1 = require("../injector");
|
|
7
|
+
exports.scopeSignalHandlers = new Map();
|
|
8
|
+
const OnScopeSignal = (id, options) => (target, propertyKey, descriptor) => {
|
|
9
|
+
if (target instanceof Function) {
|
|
10
|
+
throw new Error('only allowed on non static methods');
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const mappingList = (0, injector_1.putIfAbsent)(exports.scopeSignalHandlers, target.constructor, () => []);
|
|
14
|
+
mappingList.push([propertyKey, id, options]);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.OnScopeSignal = OnScopeSignal;
|
|
18
|
+
exports.SCOPE_CONTEXT = {
|
|
19
|
+
log: true,
|
|
20
|
+
};
|
|
21
|
+
class ScopeSignalBinding {
|
|
22
|
+
constructor(signalBinding, options) {
|
|
23
|
+
this.signalBinding = signalBinding;
|
|
24
|
+
this.keepAlive = options === null || options === void 0 ? void 0 : options.keepAlive;
|
|
25
|
+
this.group = options === null || options === void 0 ? void 0 : options.group;
|
|
26
|
+
}
|
|
27
|
+
activate() {
|
|
28
|
+
this.signalBinding.setActive(true);
|
|
29
|
+
}
|
|
30
|
+
deactivate() {
|
|
31
|
+
this.signalBinding.setActive(false);
|
|
32
|
+
}
|
|
33
|
+
detach() {
|
|
34
|
+
this.signalBinding.detach();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class ScopeStack {
|
|
38
|
+
constructor(rootScope) {
|
|
39
|
+
this.rootScope = rootScope;
|
|
40
|
+
this.stack = [];
|
|
41
|
+
this.queuedScopeChanges = [];
|
|
42
|
+
this.ongoingChange = false;
|
|
43
|
+
this.stack.push(rootScope);
|
|
44
|
+
}
|
|
45
|
+
get rootContext() {
|
|
46
|
+
return this.stack[0];
|
|
47
|
+
}
|
|
48
|
+
get activeContext() {
|
|
49
|
+
return this.stack[this.stack.length - 1];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class ScopeContext {
|
|
53
|
+
get runtime() {
|
|
54
|
+
return (performance.now() - this.creationTime) / 1000;
|
|
55
|
+
}
|
|
56
|
+
constructor(injector, scopeClass, mapping, parent, resolve) {
|
|
57
|
+
this.parent = parent;
|
|
58
|
+
this.signalBindings = [];
|
|
59
|
+
this.serviceBindings = [];
|
|
60
|
+
this.closed = false;
|
|
61
|
+
this.muteKeepAliveSignals = false;
|
|
62
|
+
this.onEnter = new index_1.Signal();
|
|
63
|
+
this.onExit = new index_1.Signal();
|
|
64
|
+
this.onSubReturn = new index_1.Signal();
|
|
65
|
+
this.onSubExit = new index_1.Signal();
|
|
66
|
+
this.onActivate = new index_1.Signal();
|
|
67
|
+
this.onDeactivate = new index_1.Signal();
|
|
68
|
+
this.creationTime = performance.now();
|
|
69
|
+
if (!parent) {
|
|
70
|
+
this.stack = new ScopeStack(this);
|
|
71
|
+
this.onScopeChange = new index_1.Signal();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.stack = parent.stack;
|
|
75
|
+
this.onScopeChange = parent.onScopeChange;
|
|
76
|
+
this.stack.stack.push(this);
|
|
77
|
+
}
|
|
78
|
+
this.injector = injector.createChild();
|
|
79
|
+
this.injector.map(scopeClass).toSingleton();
|
|
80
|
+
this.injector.map(ScopeContext).toValue(this);
|
|
81
|
+
const result = mapping === null || mapping === void 0 ? void 0 : mapping({
|
|
82
|
+
injector: this.injector,
|
|
83
|
+
registerScopeService: serviceClass => {
|
|
84
|
+
this.injector.map(serviceClass).toSingleton();
|
|
85
|
+
this.mapServiceSignals(this.injector.get(serviceClass));
|
|
86
|
+
},
|
|
87
|
+
onEnter: this.onEnter,
|
|
88
|
+
onExit: this.onExit,
|
|
89
|
+
onSubReturn: this.onSubReturn,
|
|
90
|
+
onSubExit: this.onSubExit,
|
|
91
|
+
onActivate: this.onActivate,
|
|
92
|
+
onDeactivate: this.onDeactivate,
|
|
93
|
+
});
|
|
94
|
+
const completeScopeChange = () => {
|
|
95
|
+
var _a, _b, _c, _d;
|
|
96
|
+
this.scope = this.injector.get(scopeClass);
|
|
97
|
+
this.mapScopeSignals();
|
|
98
|
+
this.updateSignalBindings();
|
|
99
|
+
(_b = (_a = this.scope).onEnter) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
100
|
+
this.onEnter.dispatch(this);
|
|
101
|
+
(_d = (_c = this.scope).onActivate) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
102
|
+
this.onActivate.dispatch(this);
|
|
103
|
+
resolve === null || resolve === void 0 ? void 0 : resolve();
|
|
104
|
+
};
|
|
105
|
+
if (result instanceof Promise) {
|
|
106
|
+
result.then(completeScopeChange);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
completeScopeChange();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
get isRoot() {
|
|
113
|
+
return this === this.stack.rootScope;
|
|
114
|
+
}
|
|
115
|
+
get target() {
|
|
116
|
+
return this.stack.target;
|
|
117
|
+
}
|
|
118
|
+
get isActive() {
|
|
119
|
+
return this === this.stack.activeContext;
|
|
120
|
+
}
|
|
121
|
+
get activeContext() { return this.stack.activeContext; }
|
|
122
|
+
async enterScope(scopeClass, mapping) {
|
|
123
|
+
let newContext;
|
|
124
|
+
const doChange = async () => {
|
|
125
|
+
var _a, _b, _c, _d;
|
|
126
|
+
const oldContext = this.activeContext;
|
|
127
|
+
(_b = (_a = this.activeContext.scope).onSubExit) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
128
|
+
this.activeContext.onSubExit.dispatch(this);
|
|
129
|
+
(_d = (_c = this.activeContext.scope).onDeactivate) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
130
|
+
this.activeContext.onDeactivate.dispatch(this);
|
|
131
|
+
await new Promise(resolve => {
|
|
132
|
+
newContext = new ScopeContext(this.activeContext.injector, scopeClass, mapping, this.activeContext, resolve);
|
|
133
|
+
});
|
|
134
|
+
this.logStack();
|
|
135
|
+
this.onScopeChange.dispatch({
|
|
136
|
+
from: oldContext,
|
|
137
|
+
to: newContext,
|
|
138
|
+
});
|
|
139
|
+
const nextChange = this.stack.queuedScopeChanges.shift();
|
|
140
|
+
if (nextChange) {
|
|
141
|
+
await nextChange();
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.stack.ongoingChange = false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
if (!this.stack.ongoingChange) {
|
|
148
|
+
this.stack.ongoingChange = true;
|
|
149
|
+
await doChange();
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
this.stack.queuedScopeChanges.push(doChange);
|
|
153
|
+
}
|
|
154
|
+
return newContext;
|
|
155
|
+
}
|
|
156
|
+
async exitScope(target) {
|
|
157
|
+
const doChange = async () => {
|
|
158
|
+
if (this.closed)
|
|
159
|
+
throw new Error(`Scope already closed`);
|
|
160
|
+
this.stack.target = target || this.scope.constructor;
|
|
161
|
+
while (true) {
|
|
162
|
+
const ctx = this.stack.stack.pop();
|
|
163
|
+
if (!ctx) {
|
|
164
|
+
throw new Error('no scope in stack');
|
|
165
|
+
}
|
|
166
|
+
ctx.exitThis();
|
|
167
|
+
if (ctx.scope.constructor === this.stack.target) {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this.stack.target = undefined;
|
|
172
|
+
const nextChange = this.stack.queuedScopeChanges.shift();
|
|
173
|
+
if (nextChange) {
|
|
174
|
+
await nextChange();
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
this.stack.ongoingChange = false;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
if (!this.stack.ongoingChange) {
|
|
181
|
+
this.stack.ongoingChange = true;
|
|
182
|
+
await doChange();
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
this.stack.queuedScopeChanges.push(doChange);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
closeSubScopes() {
|
|
189
|
+
this.stack.target = this.scope.constructor;
|
|
190
|
+
while (!this.isActive) {
|
|
191
|
+
const ctx = this.stack.stack.pop();
|
|
192
|
+
if (!ctx) {
|
|
193
|
+
throw new Error('no scope in stack');
|
|
194
|
+
}
|
|
195
|
+
ctx.exitThis();
|
|
196
|
+
}
|
|
197
|
+
this.stack.target = undefined;
|
|
198
|
+
}
|
|
199
|
+
logStack() {
|
|
200
|
+
if (exports.SCOPE_CONTEXT.log) {
|
|
201
|
+
console.debug('%c' + this.stack.stack.map(c => c.scope.constructor.name).join(' -> '), 'color:yellow');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
getStackClasses() {
|
|
205
|
+
return this.stack.stack.map(context => context.scope.constructor);
|
|
206
|
+
}
|
|
207
|
+
addScopeSignal(signal, callback, params) {
|
|
208
|
+
const signalBinding = new ScopeSignalBinding(signal.add(callback, params === null || params === void 0 ? void 0 : params.context), params);
|
|
209
|
+
this.signalBindings.push(signalBinding);
|
|
210
|
+
}
|
|
211
|
+
disableKeepAliveSignals() {
|
|
212
|
+
this.muteKeepAliveSignals = true;
|
|
213
|
+
this.updateSignalBindings();
|
|
214
|
+
}
|
|
215
|
+
enableKeepAliveSignals() {
|
|
216
|
+
this.muteKeepAliveSignals = false;
|
|
217
|
+
this.updateSignalBindings();
|
|
218
|
+
}
|
|
219
|
+
updateSignalBindings(muteKeepAlive = false) {
|
|
220
|
+
var _a;
|
|
221
|
+
for (const binding of this.signalBindings) {
|
|
222
|
+
if (this.isActive) {
|
|
223
|
+
binding.activate();
|
|
224
|
+
}
|
|
225
|
+
else if (muteKeepAlive) {
|
|
226
|
+
binding.deactivate();
|
|
227
|
+
}
|
|
228
|
+
else if (binding.keepAlive === true) {
|
|
229
|
+
binding.activate();
|
|
230
|
+
}
|
|
231
|
+
else if (!!(binding.keepAlive)) {
|
|
232
|
+
if (binding.keepAlive.indexOf(this.activeContext.scope.constructor) != -1) {
|
|
233
|
+
binding.activate();
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
binding.deactivate();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
binding.deactivate();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
muteKeepAlive = muteKeepAlive || this.muteKeepAliveSignals;
|
|
244
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.updateSignalBindings(muteKeepAlive);
|
|
245
|
+
}
|
|
246
|
+
detachSignalBindings() {
|
|
247
|
+
for (const signalBinding of this.signalBindings) {
|
|
248
|
+
signalBinding.detach();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
mapScopeSignals() {
|
|
252
|
+
const handlers = exports.scopeSignalHandlers.get(this.scope.constructor);
|
|
253
|
+
if (!handlers)
|
|
254
|
+
return;
|
|
255
|
+
for (const [field, id, options] of handlers) {
|
|
256
|
+
const signal = this.injector.getSignal(id);
|
|
257
|
+
const callback = this.scope[field];
|
|
258
|
+
this.addScopeSignal(signal, callback, Object.assign(Object.assign({}, options), { context: this.scope }));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
mapServiceSignals(scopeService) {
|
|
262
|
+
const handlers = ecsInjector_1.signalHandlers.get(scopeService.constructor);
|
|
263
|
+
if (!handlers)
|
|
264
|
+
return;
|
|
265
|
+
for (const [field, id] of handlers) {
|
|
266
|
+
const signal = this.injector.getSignal(id);
|
|
267
|
+
const signalBinding = signal.add(scopeService[field], scopeService);
|
|
268
|
+
this.serviceBindings.push(signalBinding);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
detachServiceBindings() {
|
|
272
|
+
for (const binding of this.serviceBindings) {
|
|
273
|
+
binding.detach();
|
|
274
|
+
}
|
|
275
|
+
this.serviceBindings = [];
|
|
276
|
+
}
|
|
277
|
+
exitThis() {
|
|
278
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
279
|
+
if (!this.parent) {
|
|
280
|
+
throw new Error('can\'t exit root scope?!');
|
|
281
|
+
}
|
|
282
|
+
this.logStack();
|
|
283
|
+
this.detachSignalBindings();
|
|
284
|
+
this.detachServiceBindings();
|
|
285
|
+
(_b = (_a = this.scope).onDeactivate) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
286
|
+
this.onDeactivate.dispatch(this);
|
|
287
|
+
(_d = (_c = this.scope).onExit) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
288
|
+
this.onExit.dispatch(this);
|
|
289
|
+
this.onScopeChange.dispatch({ from: this, to: this.parent });
|
|
290
|
+
this.injector._dispose();
|
|
291
|
+
this.parent.updateSignalBindings();
|
|
292
|
+
(_f = (_e = this.parent.scope).onSubReturn) === null || _f === void 0 ? void 0 : _f.call(_e);
|
|
293
|
+
this.onSubReturn.dispatch(this);
|
|
294
|
+
(_h = (_g = this.parent.scope).onActivate) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
295
|
+
this.parent.onActivate.dispatch(this);
|
|
296
|
+
this.closed = true;
|
|
297
|
+
this.onEnter.detachAll();
|
|
298
|
+
this.onExit.detachAll();
|
|
299
|
+
this.onSubReturn.detachAll();
|
|
300
|
+
this.onSubExit.detachAll();
|
|
301
|
+
this.onActivate.detachAll();
|
|
302
|
+
this.onDeactivate.detachAll();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
exports.ScopeContext = ScopeContext;
|
|
306
|
+
//# sourceMappingURL=scopeContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopeContext.js","sourceRoot":"","sources":["../../src/scope/scopeContext.ts"],"names":[],"mappings":";;;AAAA,oCAAmF;AACnF,gDAA8C;AAC9C,0CAA4C;AAI/B,QAAA,mBAAmB,GAAG,IAAI,GAAG,EAA+C,CAAC;AAEnF,MAAM,aAAa,GAAG,CAAC,EAAM,EAAE,OAA4B,EAAE,EAAE,CAAC,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;IACxI,IAAI,MAAM,YAAY,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAA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AA,MAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAC,WAAW,kDAAI,CAAC;QAClC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChC,MAAA,MAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAC,UAAU,kDAAI,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACxB,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAC5B,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC;IAElC,CAAC;CACJ;AAxSD,oCAwSC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { System } from './types';
|
|
2
|
+
import { Entity, ID, Signal, SignalCallback } from './index';
|
|
3
|
+
export declare const entitySignalHandlers: Map<Object, [string, ID][]>;
|
|
4
|
+
export declare const OnEntitySignal: (id: ID) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
5
|
+
export declare class SystemContext<T extends System = System> {
|
|
6
|
+
readonly entity: Entity;
|
|
7
|
+
readonly system: T;
|
|
8
|
+
readonly onDispose: Signal<unknown>;
|
|
9
|
+
private signalBindings;
|
|
10
|
+
constructor(entity: Entity);
|
|
11
|
+
addSignalById<S>(signalId: string | symbol, callback: SignalCallback<S>, thisArg?: unknown): void;
|
|
12
|
+
addSignal<S>(signal: Signal<S>, callback: SignalCallback<S>, thisArg?: unknown): void;
|
|
13
|
+
addSignalOnce<S>(signal: Signal<S>, callback: SignalCallback<S>, thisArg?: unknown): void;
|
|
14
|
+
dispose(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SystemContext = exports.OnEntitySignal = exports.entitySignalHandlers = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
exports.entitySignalHandlers = new Map();
|
|
6
|
+
const OnEntitySignal = (id) => (target, propertyKey, descriptor) => {
|
|
7
|
+
if (target instanceof Function) {
|
|
8
|
+
throw new Error('only allowed on non static methods');
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
const mappingList = (0, index_1.putIfAbsent)(exports.entitySignalHandlers, target.constructor, () => []);
|
|
12
|
+
mappingList.push([propertyKey, id]);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.OnEntitySignal = OnEntitySignal;
|
|
16
|
+
class SystemContext {
|
|
17
|
+
constructor(entity) {
|
|
18
|
+
this.entity = entity;
|
|
19
|
+
this.onDispose = new index_1.Signal();
|
|
20
|
+
this.signalBindings = [];
|
|
21
|
+
}
|
|
22
|
+
addSignalById(signalId, callback, thisArg) {
|
|
23
|
+
this.signalBindings.push(this.entity.gameEngine.getSignal(signalId).add(callback, thisArg));
|
|
24
|
+
}
|
|
25
|
+
addSignal(signal, callback, thisArg) {
|
|
26
|
+
this.signalBindings.push(signal.add(callback, thisArg));
|
|
27
|
+
}
|
|
28
|
+
addSignalOnce(signal, callback, thisArg) {
|
|
29
|
+
this.signalBindings.push(signal.addOnce(callback, thisArg));
|
|
30
|
+
}
|
|
31
|
+
dispose() {
|
|
32
|
+
for (const binding of this.signalBindings)
|
|
33
|
+
binding.detach();
|
|
34
|
+
this.onDispose.dispatch();
|
|
35
|
+
this.onDispose.detachAll();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.SystemContext = SystemContext;
|
|
39
|
+
//# sourceMappingURL=systemContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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Ac,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,OAAO;QACH,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,cAAc;YAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QAC5D,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC1B,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;IAC/B,CAAC;CACJ;AA1BD,sCA0BC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { GameEngine } from './gameEngine';
|
|
2
|
+
import { Entity } from './entity';
|
|
3
|
+
export interface System {
|
|
4
|
+
[propName: string]: any;
|
|
5
|
+
onPrepare?(): Promise<void>;
|
|
6
|
+
onStart?(): void;
|
|
7
|
+
onEnd?(): void | Promise<void>;
|
|
8
|
+
onPreFixedUpdate?(time: number, deltaTime: number): void;
|
|
9
|
+
onFixedUpdate?(time: number, deltaTime: number): void;
|
|
10
|
+
onPhysicsUpdate?(time: number, deltaTime: number): void;
|
|
11
|
+
onUpdate?(time: number, deltaTime: number, alpha: number): void;
|
|
12
|
+
onLateUpdate?(time: number, deltaTime: number, alpha: number): void;
|
|
13
|
+
onPrePhysicsUpdate?(time: number, deltaTime: number): void;
|
|
14
|
+
onPostPhysicsUpdate?(time: number, deltaTime: number): void;
|
|
15
|
+
onLateFixedUpdate?(time: number, deltaTime: number): void;
|
|
16
|
+
onRender?(time: number, deltaTime: number, alpha: number): void;
|
|
17
|
+
onAddEntity?(entity: Entity): void;
|
|
18
|
+
onRemoveEntity?(entity: Entity): void;
|
|
19
|
+
}
|
|
20
|
+
export interface Service {
|
|
21
|
+
[propName: string]: any;
|
|
22
|
+
onPrepare?(): Promise<void>;
|
|
23
|
+
onStart?(): void;
|
|
24
|
+
onEnd?(): void;
|
|
25
|
+
onPreFixedUpdate?(time: number, deltaTime: number): void;
|
|
26
|
+
onPostPhysicsUpdate?(time: number, deltaTime: number): void;
|
|
27
|
+
onLateFixedUpdate?(time: number, deltaTime: number): void;
|
|
28
|
+
onFixedUpdate?(time: number, deltaTime: number): void;
|
|
29
|
+
onPhysicsUpdate?(time: number, deltaTime: number): void;
|
|
30
|
+
onPrePhysicsUpdate?(time: number, deltaTime: number): void;
|
|
31
|
+
onUpdate?(time: number, deltaTime: number, alpha: number): void;
|
|
32
|
+
onLateUpdate?(time: number, deltaTime: number, alpha: number): void;
|
|
33
|
+
onRender?(time: number, deltaTime: number, alpha: number): void;
|
|
34
|
+
onAddEntity?(entity: Entity): void;
|
|
35
|
+
onRemoveEntity?(entity: Entity): void;
|
|
36
|
+
}
|
|
37
|
+
type GameEngineCallback = (gameEngine: GameEngine) => void;
|
|
38
|
+
export interface GameEnginePlugin {
|
|
39
|
+
onPrepare?: GameEngineCallback;
|
|
40
|
+
onStart?: GameEngineCallback;
|
|
41
|
+
}
|
|
42
|
+
export interface CommandClass {
|
|
43
|
+
name?: string;
|
|
44
|
+
new (...args: any[]): any;
|
|
45
|
+
}
|
|
46
|
+
export type OnUpdateParams = {
|
|
47
|
+
time: number;
|
|
48
|
+
deltaTime: number;
|
|
49
|
+
alpha: number;
|
|
50
|
+
};
|
|
51
|
+
export type OnFixedUpdateParams = {
|
|
52
|
+
time: number;
|
|
53
|
+
deltaTime: number;
|
|
54
|
+
};
|
|
55
|
+
export type OnEarlyUpdateParams = {
|
|
56
|
+
time: number;
|
|
57
|
+
deltaTime: number;
|
|
58
|
+
};
|
|
59
|
+
export type AsyncAction<T = unknown> = (gameEngine: GameEngine) => Promise<T>;
|
|
60
|
+
export type Action<T = any> = (gameEngine: GameEngine) => T;
|
|
61
|
+
export type Class<T = any> = {
|
|
62
|
+
new (...args: any[]): T;
|
|
63
|
+
};
|
|
64
|
+
export declare const EngineSignals: {
|
|
65
|
+
OnStart: symbol;
|
|
66
|
+
OnEnd: symbol;
|
|
67
|
+
OnUpdate: symbol;
|
|
68
|
+
OnLateUpdate: symbol;
|
|
69
|
+
OnFixedUpdate: symbol;
|
|
70
|
+
OnPreFixedUpdate: symbol;
|
|
71
|
+
OnPrePhysicsUpdate: symbol;
|
|
72
|
+
OnPhysicsUpdate: symbol;
|
|
73
|
+
OnPostPhysicsUpdate: symbol;
|
|
74
|
+
onLateFixedUpdate: symbol;
|
|
75
|
+
OnRender: symbol;
|
|
76
|
+
OnPrepare: symbol;
|
|
77
|
+
OnAddEntity: symbol;
|
|
78
|
+
OnRemoveEntity: symbol;
|
|
79
|
+
};
|
|
80
|
+
export interface Disposable {
|
|
81
|
+
onDispose(): void;
|
|
82
|
+
}
|
|
83
|
+
export {};
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EngineSignals = void 0;
|
|
4
|
+
exports.EngineSignals = {
|
|
5
|
+
OnStart: Symbol('OnStart'),
|
|
6
|
+
OnEnd: Symbol('OnEnd'),
|
|
7
|
+
OnUpdate: Symbol('OnUpdate'),
|
|
8
|
+
OnLateUpdate: Symbol('OnLateUpdate'),
|
|
9
|
+
OnFixedUpdate: Symbol('OnFixedUpdate'),
|
|
10
|
+
OnPreFixedUpdate: Symbol('OnPreFixedUpdate'),
|
|
11
|
+
OnPrePhysicsUpdate: Symbol('OnPrePhysicsUpdate'),
|
|
12
|
+
OnPhysicsUpdate: Symbol('OnPhysicsUpdate'),
|
|
13
|
+
OnPostPhysicsUpdate: Symbol('OnPostPhysicsUpdate'),
|
|
14
|
+
onLateFixedUpdate: Symbol('onLateFixedUpdate'),
|
|
15
|
+
OnRender: Symbol('OnRender'),
|
|
16
|
+
OnPrepare: Symbol('OnPrepare'),
|
|
17
|
+
OnAddEntity: Symbol('OnAddEntity'),
|
|
18
|
+
OnRemoveEntity: Symbol('OnRemoveEntity'),
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA+Ea,QAAA,aAAa,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC,UAAU,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC,cAAc,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,eAAe,CAAC;IACtC,gBAAgB,EAAE,MAAM,CAAC,kBAAkB,CAAC;IAC5C,kBAAkB,EAAE,MAAM,CAAC,oBAAoB,CAAC;IAChD,eAAe,EAAE,MAAM,CAAC,iBAAiB,CAAC;IAC1C,mBAAmB,EAAE,MAAM,CAAC,qBAAqB,CAAC;IAClD,iBAAiB,EAAE,MAAM,CAAC,mBAAmB,CAAC;IAC9C,QAAQ,EAAE,MAAM,CAAC,UAAU,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC,aAAa,CAAC;IAClC,cAAc,EAAE,MAAM,CAAC,gBAAgB,CAAC;CAC3C,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Map2k = void 0;
|
|
4
|
+
class Map2k {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.map = new Map();
|
|
7
|
+
}
|
|
8
|
+
set(key1, key2, value) {
|
|
9
|
+
let first = this.map.get(key1);
|
|
10
|
+
if (!first) {
|
|
11
|
+
first = new Map();
|
|
12
|
+
this.map.set(key1, first);
|
|
13
|
+
}
|
|
14
|
+
let second = this.map.get(key2);
|
|
15
|
+
if (!second) {
|
|
16
|
+
second = new Map();
|
|
17
|
+
this.map.set(key2, second);
|
|
18
|
+
}
|
|
19
|
+
first.set(key2, value);
|
|
20
|
+
second.set(key1, value);
|
|
21
|
+
}
|
|
22
|
+
get(key1, key2) {
|
|
23
|
+
const first = this.map.get(key1);
|
|
24
|
+
return first && first.get(key2);
|
|
25
|
+
}
|
|
26
|
+
delete(key1, key2) {
|
|
27
|
+
let first = this.map.get(key1);
|
|
28
|
+
if (first) {
|
|
29
|
+
first.delete(key2);
|
|
30
|
+
if (first.size === 0) {
|
|
31
|
+
this.map.delete(key1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let second = this.map.get(key2);
|
|
35
|
+
if (second) {
|
|
36
|
+
second.delete(key1);
|
|
37
|
+
if (second.size === 0) {
|
|
38
|
+
this.map.delete(key2);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Map2k = Map2k;
|
|
44
|
+
//# sourceMappingURL=map2k.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map2k.js","sourceRoot":"","sources":["../../src/utils/map2k.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAK;IAAlB;QACI,QAAG,GAAG,IAAI,GAAG,EAAgB,CAAC;IAkDlC,CAAC;IAhDG,GAAG,CAAC,IAAO,EAAE,IAAO,EAAE,KAAQ;QAC1B,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAG,CAAC,KAAK,EAAE,CAAC;YACR,KAAK,GAAG,IAAI,GAAG,EAAQ,CAAC;YACxB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,IAAG,CAAC,MAAM,EAAE,CAAC;YACT,MAAM,GAAG,IAAI,GAAG,EAAQ,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/B,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACvB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAaD,GAAG,CAAC,IAAO,EAAE,IAAO;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,KAAK,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,IAAM,EAAE,IAAM;QACjB,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,KAAK,EAAE,CAAC;YACR,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACnB,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBACnB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACzB,CAAC;QACL,CAAC;QACD,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACpB,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBACpB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACzB,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AAnDD,sBAmDC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mani-game-engine",
|
|
3
3
|
"author": "Jan Mankopf",
|
|
4
|
-
"version": "1.0.0-pre.
|
|
4
|
+
"version": "1.0.0-pre.71",
|
|
5
5
|
"description": "entity component system game engine for typescript",
|
|
6
6
|
"private": false,
|
|
7
7
|
"scripts": {
|
|
@@ -21,21 +21,18 @@
|
|
|
21
21
|
"typings": "lib/index.d.ts",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@fluffy-spoon/substitute": "^1.
|
|
25
|
-
"@types/jest": "^
|
|
26
|
-
"jest": "^
|
|
27
|
-
"reflect-metadata": "^0.1
|
|
28
|
-
"rimraf": "^
|
|
29
|
-
"ts-jest": "^
|
|
30
|
-
"ts-node": "^9.
|
|
31
|
-
"tslib": "^2.
|
|
32
|
-
"typescript": "^
|
|
24
|
+
"@fluffy-spoon/substitute": "^1.208.0",
|
|
25
|
+
"@types/jest": "^29.5.11",
|
|
26
|
+
"jest": "^29.7.0",
|
|
27
|
+
"reflect-metadata": "^0.2.1",
|
|
28
|
+
"rimraf": "^5.0.5",
|
|
29
|
+
"ts-jest": "^29.1.1",
|
|
30
|
+
"ts-node": "^10.9.2",
|
|
31
|
+
"tslib": "^2.6.2",
|
|
32
|
+
"typescript": "^5.3.3",
|
|
33
|
+
"mani-signal": "^1.0.9"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"reflect-metadata": "^0.1
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"mani-injector": "0.0.3",
|
|
39
|
-
"mani-signal": "^1.0.6"
|
|
36
|
+
"reflect-metadata": "^0.2.1"
|
|
40
37
|
}
|
|
41
38
|
}
|