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,8 +1,9 @@
1
- export class Debug {
2
- constructor(_core) {
3
- this._core = _core;
4
- }
5
- log(...args) {
6
- console.log("[HZEngine]", ...args);
7
- }
8
- }
1
+ export class Debug {
2
+ _core;
3
+ constructor(_core) {
4
+ this._core = _core;
5
+ }
6
+ log(...args) {
7
+ console.log("[HZEngine]", ...args);
8
+ }
9
+ }
package/dist/index.js CHANGED
@@ -1,103 +1,108 @@
1
- /**
2
- * HZEngineCore
3
- * @copyright Copyright (c) 2024 CuberQAQ. All rights reserved.
4
- */
5
- import { Async } from "./async/index.js";
6
- import { Audio } from "./audio/index.js";
7
- import { Config } from "./config/index.js";
8
- import { Debug } from "./debug/index.js";
9
- import { basic_command } from "./plugins/basic_command/index.js";
10
- import { global_gesture } from "./plugins/global_gesture/index.js";
11
- import { registerPlugin } from "./plugins/transform/index.js";
12
- import { Script } from "./script/index.js";
13
- import { Storage } from "./storage/index.js";
14
- import { System } from "./system/index.js";
15
- import { UI } from "./ui/index.js";
16
- class HZEngineCore {
17
- constructor(platform) {
18
- this.platform = platform;
19
- this._eventCallbacks = new Map();
20
- this.plugins = new Map();
21
- // 請不要調整這裡的初始化順序,不然會有問題(裝飾器裡有時候要用到前面初始化的東西)
22
- this.storage = new Storage(this);
23
- this.async = new Async(this);
24
- this.ui = new UI(this);
25
- this.script = new Script(this);
26
- this.system = new System(this);
27
- this.config = new Config(this);
28
- this.audio = new Audio(this);
29
- this.debug = new Debug(this);
30
- // internal plugin
31
- this.loadPlugin("global_gesture", global_gesture);
32
- this.loadPlugin("transform", registerPlugin);
33
- this.loadPlugin("basic_command", basic_command);
34
- }
35
- loadProject(options) {
36
- this.storage.loadProject(options);
37
- }
38
- start(callback) {
39
- // this.system.start()
40
- Async.nextTick(() => {
41
- var _a;
42
- this.debug.log("[HZEngine] Game Start");
43
- let title = (_a = this.storage.packageData) === null || _a === void 0 ? void 0 : _a.name;
44
- if (title == null) {
45
- throw `[HZEngine] project name is null, please loadProject first or check your project.json format`;
46
- }
47
- this.ui.getRouter("page").push("title", {
48
- title,
49
- });
50
- // this.on("gameEnd", () => {
51
- // let router = this.ui.getRouter("page")!;
52
- // if (router.length > 0) return;
53
- // router.push("title", {
54
- // title,
55
- // });
56
- // });
57
- callback === null || callback === void 0 ? void 0 : callback();
58
- });
59
- }
60
- end() {
61
- var _a;
62
- this.debug.log("[HZEngine] Game End, return to title");
63
- let title = (_a = this.storage.packageData) === null || _a === void 0 ? void 0 : _a.name;
64
- if (title == null) {
65
- throw `[HZEngine] project name is null, please loadProject first or check your project.json format`;
66
- }
67
- this.system.condition = System.Condition.Free;
68
- this.ui.resetUI();
69
- if (this.ui.getRouter("page").length > 0)
70
- return;
71
- this.ui.getRouter("page").push("title", {
72
- title,
73
- });
74
- }
75
- // Load Plugin
76
- loadPlugin(name, plugin) {
77
- this.debug.log(`[HZEngine] load plugin [${name}]`);
78
- let slot = plugin(this);
79
- if (slot != undefined)
80
- this.plugins.set(name, slot);
81
- }
82
- // Event Bus
83
- on(event, cb) {
84
- if (this._eventCallbacks.has(event)) {
85
- this._eventCallbacks.get(event).add(cb);
86
- }
87
- else {
88
- this._eventCallbacks.set(event, new Set().add(cb));
89
- }
90
- }
91
- off(event, cb) {
92
- var _a;
93
- return !!((_a = this._eventCallbacks.get(event)) === null || _a === void 0 ? void 0 : _a.delete(cb));
94
- }
95
- emit(event, ...args) {
96
- var _a;
97
- (_a = this._eventCallbacks.get(event)) === null || _a === void 0 ? void 0 : _a.forEach((cb) => {
98
- cb(...args);
99
- });
100
- }
101
- }
102
- export { HZEngineCore, UI, Storage, Script, System, Async };
103
- export * as TransformPlugin from "./plugins/transform/index.js";
1
+ /**
2
+ * HZEngineCore
3
+ * @copyright Copyright (c) 2024 CuberQAQ. All rights reserved.
4
+ */
5
+ import { Async } from "./async/index.js";
6
+ import { Audio } from "./audio/index.js";
7
+ import { Config } from "./config/index.js";
8
+ import { Debug } from "./debug/index.js";
9
+ import { basic_command } from "./plugins/basic_command/index.js";
10
+ import { global_gesture } from "./plugins/global_gesture/index.js";
11
+ import { registerPlugin } from "./plugins/transform/index.js";
12
+ import { Script } from "./script/index.js";
13
+ import { Storage } from "./storage/index.js";
14
+ import { System } from "./system/index.js";
15
+ import { UI } from "./ui/index.js";
16
+ class HZEngineCore {
17
+ platform;
18
+ _eventCallbacks = new Map();
19
+ storage;
20
+ async;
21
+ ui;
22
+ script;
23
+ system;
24
+ config;
25
+ audio;
26
+ debug;
27
+ constructor(platform) {
28
+ this.platform = platform;
29
+ // 請不要調整這裡的初始化順序,不然會有問題(裝飾器裡有時候要用到前面初始化的東西)
30
+ this.storage = new Storage(this);
31
+ this.async = new Async(this);
32
+ this.ui = new UI(this);
33
+ this.script = new Script(this);
34
+ this.system = new System(this);
35
+ this.config = new Config(this);
36
+ this.audio = new Audio(this);
37
+ this.debug = new Debug(this);
38
+ // internal plugin
39
+ this.loadPlugin("global_gesture", global_gesture);
40
+ this.loadPlugin("transform", registerPlugin);
41
+ this.loadPlugin("basic_command", basic_command);
42
+ }
43
+ loadProject(options) {
44
+ this.storage.loadProject(options);
45
+ }
46
+ start(callback) {
47
+ // this.system.start()
48
+ Async.nextTick(() => {
49
+ this.debug.log("[HZEngine] Game Start");
50
+ let title = this.storage.packageData?.name;
51
+ if (title == null) {
52
+ throw `[HZEngine] project name is null, please loadProject first or check your project.json format`;
53
+ }
54
+ this.ui.getRouter("page").push("title", {
55
+ title,
56
+ });
57
+ // this.on("gameEnd", () => {
58
+ // let router = this.ui.getRouter("page")!;
59
+ // if (router.length > 0) return;
60
+ // router.push("title", {
61
+ // title,
62
+ // });
63
+ // });
64
+ callback?.();
65
+ });
66
+ }
67
+ end() {
68
+ this.debug.log("[HZEngine] Game End, return to title");
69
+ let title = this.storage.packageData?.name;
70
+ if (title == null) {
71
+ throw `[HZEngine] project name is null, please loadProject first or check your project.json format`;
72
+ }
73
+ this.system.condition = System.Condition.Free;
74
+ this.ui.resetUI();
75
+ if (this.ui.getRouter("page").length > 0)
76
+ return;
77
+ this.ui.getRouter("page").push("title", {
78
+ title,
79
+ });
80
+ }
81
+ plugins = new Map();
82
+ // Load Plugin
83
+ loadPlugin(name, plugin) {
84
+ this.debug.log(`[HZEngine] load plugin [${name}]`);
85
+ let slot = plugin(this);
86
+ if (slot != undefined)
87
+ this.plugins.set(name, slot);
88
+ }
89
+ // Event Bus
90
+ on(event, cb) {
91
+ if (this._eventCallbacks.has(event)) {
92
+ this._eventCallbacks.get(event).add(cb);
93
+ }
94
+ else {
95
+ this._eventCallbacks.set(event, new Set().add(cb));
96
+ }
97
+ }
98
+ off(event, cb) {
99
+ return !!this._eventCallbacks.get(event)?.delete(cb);
100
+ }
101
+ emit(event, ...args) {
102
+ this._eventCallbacks.get(event)?.forEach((cb) => {
103
+ cb(...args);
104
+ });
105
+ }
106
+ }
107
+ export { HZEngineCore, UI, Storage, Script, System, Async };
108
+ export * as TransformPlugin from "./plugins/transform/index.js";