hzengine-core 0.1.2-dev → 0.1.3

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.
@@ -1,144 +1,131 @@
1
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
- var _, done = false;
7
- for (var i = decorators.length - 1; i >= 0; i--) {
8
- var context = {};
9
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
- if (kind === "accessor") {
14
- if (result === void 0) continue;
15
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
- if (_ = accept(result.get)) descriptor.get = _;
17
- if (_ = accept(result.set)) descriptor.set = _;
18
- if (_ = accept(result.init)) initializers.unshift(_);
19
- }
20
- else if (_ = accept(result)) {
21
- if (kind === "field") initializers.unshift(_);
22
- else descriptor[key] = _;
23
- }
24
- }
25
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
- done = true;
27
- };
28
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
- var useValue = arguments.length > 2;
30
- for (var i = 0; i < initializers.length; i++) {
31
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
- }
33
- return useValue ? value : void 0;
34
- };
35
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
36
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
37
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
38
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
39
- };
40
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
41
- if (kind === "m") throw new TypeError("Private method is not writable");
42
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
43
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
44
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
45
- };
46
- import { Save } from "../storage/decorator.js";
47
- let System = (() => {
48
- var _a, _System_condition_accessor_storage;
49
- let _condition_decorators;
50
- let _condition_initializers = [];
51
- let _condition_extraInitializers = [];
52
- return _a = class System {
53
- constructor(_core) {
54
- this._core = _core;
55
- _System_condition_accessor_storage.set(this, __runInitializers(this, _condition_initializers, _a.Condition.Free));
56
- this._pauseTimer = (__runInitializers(this, _condition_extraInitializers), null);
57
- _core.on("system.continue", () => {
58
- this._pauseTimer = null;
59
- this.continue();
60
- });
61
- }
62
- get condition() { return __classPrivateFieldGet(this, _System_condition_accessor_storage, "f"); }
63
- set condition(value) { __classPrivateFieldSet(this, _System_condition_accessor_storage, value, "f"); }
64
- /**
65
- * 暂停(可指定一段时间)
66
- * 后调用的会覆盖之前pause的设定时间
67
- * @param delayMs
68
- */
69
- pause(delayMs) {
70
- this._core.debug.log(`Pause`);
71
- if (this.condition === _a.Condition.Gaming) {
72
- this.condition = _a.Condition.Pause;
73
- }
74
- else
75
- throw `pause but condition error (todo)`; // TODO
76
- if (this._pauseTimer) {
77
- this._core.async.removeTask(this._pauseTimer);
78
- this._pauseTimer = null;
79
- }
80
- if (delayMs !== undefined) {
81
- this._pauseTimer = this._core.async.addDelayTask("system.continue", [], delayMs);
82
- }
83
- }
84
- /**
85
- * 继续由于pause中断的游戏
86
- */
87
- continue() {
88
- if (this.condition !== _a.Condition.Pause)
89
- return;
90
- this.condition = _a.Condition.Gaming;
91
- this.run();
92
- }
93
- /**
94
- * 阻塞
95
- */
96
- block() {
97
- if (this.condition !== _a.Condition.Gaming)
98
- throw `block but condition error (todo)`;
99
- this.condition = _a.Condition.Blocked;
100
- }
101
- /**
102
- * 取消阻塞
103
- */
104
- unBlock() {
105
- if (this.condition !== _a.Condition.Blocked)
106
- return;
107
- this.condition = _a.Condition.Gaming;
108
- this.run();
109
- }
110
- run() {
111
- this.condition = _a.Condition.Gaming;
112
- while (this.condition === _a.Condition.Gaming) {
113
- // console.log("Run Single Line");
114
- this._core.script.runSingleLine();
115
- }
116
- }
117
- start(initLabel = "start") {
118
- // 初始化存档
119
- this._core.storage.archiveData;
120
- this._core.debug.log("Game Start");
121
- this._core.script.clear();
122
- this._core.script.jumpLabel(initLabel);
123
- this.run();
124
- }
125
- },
126
- _System_condition_accessor_storage = new WeakMap(),
127
- (() => {
128
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
129
- _condition_decorators = [Save("system.condition")];
130
- __esDecorate(_a, null, _condition_decorators, { kind: "accessor", name: "condition", static: false, private: false, access: { has: obj => "condition" in obj, get: obj => obj.condition, set: (obj, value) => { obj.condition = value; } }, metadata: _metadata }, _condition_initializers, _condition_extraInitializers);
131
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
132
- })(),
133
- _a;
134
- })();
135
- export { System };
136
- (function (System) {
137
- let Condition;
138
- (function (Condition) {
139
- Condition[Condition["Free"] = 0] = "Free";
140
- Condition[Condition["Pause"] = 1] = "Pause";
141
- Condition[Condition["Blocked"] = 2] = "Blocked";
142
- Condition[Condition["Gaming"] = 3] = "Gaming";
143
- })(Condition = System.Condition || (System.Condition = {}));
144
- })(System || (System = {}));
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ import { Save } from "../storage/decorator.js";
36
+ let System = (() => {
37
+ let _condition_decorators;
38
+ let _condition_initializers = [];
39
+ let _condition_extraInitializers = [];
40
+ return class System {
41
+ static {
42
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
43
+ _condition_decorators = [Save("system.condition")];
44
+ __esDecorate(this, null, _condition_decorators, { kind: "accessor", name: "condition", static: false, private: false, access: { has: obj => "condition" in obj, get: obj => obj.condition, set: (obj, value) => { obj.condition = value; } }, metadata: _metadata }, _condition_initializers, _condition_extraInitializers);
45
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
46
+ }
47
+ _core;
48
+ constructor(_core) {
49
+ this._core = _core;
50
+ _core.on("system.continue", () => {
51
+ this._pauseTimer = null;
52
+ this.continue();
53
+ });
54
+ }
55
+ #condition_accessor_storage = __runInitializers(this, _condition_initializers, System.Condition.Free);
56
+ get condition() { return this.#condition_accessor_storage; }
57
+ set condition(value) { this.#condition_accessor_storage = value; }
58
+ _pauseTimer = (__runInitializers(this, _condition_extraInitializers), null);
59
+ /**
60
+ * 暂停(可指定一段时间)
61
+ * 后调用的会覆盖之前pause的设定时间
62
+ * @param delayMs
63
+ */
64
+ pause(delayMs) {
65
+ this._core.debug.log(`Pause`);
66
+ if (this.condition === System.Condition.Gaming) {
67
+ this.condition = System.Condition.Pause;
68
+ }
69
+ else
70
+ throw `pause but condition error (todo)`; // TODO
71
+ if (this._pauseTimer) {
72
+ this._core.async.removeTask(this._pauseTimer);
73
+ this._pauseTimer = null;
74
+ }
75
+ if (delayMs !== undefined) {
76
+ this._pauseTimer = this._core.async.addDelayTask("system.continue", [], delayMs);
77
+ }
78
+ }
79
+ /**
80
+ * 继续由于pause中断的游戏
81
+ */
82
+ continue() {
83
+ if (this.condition !== System.Condition.Pause)
84
+ return;
85
+ this.condition = System.Condition.Gaming;
86
+ this.run();
87
+ }
88
+ /**
89
+ * 阻塞
90
+ */
91
+ block() {
92
+ if (this.condition !== System.Condition.Gaming)
93
+ throw `block but condition error (todo)`;
94
+ this.condition = System.Condition.Blocked;
95
+ }
96
+ /**
97
+ * 取消阻塞
98
+ */
99
+ unBlock() {
100
+ if (this.condition !== System.Condition.Blocked)
101
+ return;
102
+ this.condition = System.Condition.Gaming;
103
+ this.run();
104
+ }
105
+ run() {
106
+ this.condition = System.Condition.Gaming;
107
+ while (this.condition === System.Condition.Gaming) {
108
+ // console.log("Run Single Line");
109
+ this._core.script.runSingleLine();
110
+ }
111
+ }
112
+ start(initLabel = "start") {
113
+ // 初始化存档
114
+ this._core.storage.archiveData;
115
+ this._core.debug.log("Game Start");
116
+ this._core.script.clear();
117
+ this._core.script.jumpLabel(initLabel);
118
+ this.run();
119
+ }
120
+ };
121
+ })();
122
+ export { System };
123
+ (function (System) {
124
+ let Condition;
125
+ (function (Condition) {
126
+ Condition[Condition["Free"] = 0] = "Free";
127
+ Condition[Condition["Pause"] = 1] = "Pause";
128
+ Condition[Condition["Blocked"] = 2] = "Blocked";
129
+ Condition[Condition["Gaming"] = 3] = "Gaming";
130
+ })(Condition = System.Condition || (System.Condition = {}));
131
+ })(System || (System = {}));