hzengine-core 0.1.2-dev

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.
Files changed (103) hide show
  1. package/dist/async/index.js +162 -0
  2. package/dist/async/zeppos_timer.js +58 -0
  3. package/dist/audio/index.js +260 -0
  4. package/dist/config/index.js +57 -0
  5. package/dist/debug/index.js +8 -0
  6. package/dist/index.js +103 -0
  7. package/dist/platform/index.js +1 -0
  8. package/dist/plugins/basic_command/$.js +8 -0
  9. package/dist/plugins/basic_command/audio.js +40 -0
  10. package/dist/plugins/basic_command/basic.js +124 -0
  11. package/dist/plugins/basic_command/character.js +112 -0
  12. package/dist/plugins/basic_command/conditional.js +260 -0
  13. package/dist/plugins/basic_command/config.js +22 -0
  14. package/dist/plugins/basic_command/decorator.js +24 -0
  15. package/dist/plugins/basic_command/eval.js +67 -0
  16. package/dist/plugins/basic_command/img.js +249 -0
  17. package/dist/plugins/basic_command/index.js +22 -0
  18. package/dist/plugins/basic_command/menu.js +140 -0
  19. package/dist/plugins/global_gesture/index.js +25 -0
  20. package/dist/plugins/transform/animation.js +440 -0
  21. package/dist/plugins/transform/commands.js +38 -0
  22. package/dist/plugins/transform/example_profiles.js +32 -0
  23. package/dist/plugins/transform/hz_anime.js +211 -0
  24. package/dist/plugins/transform/index.js +93 -0
  25. package/dist/script/index.js +537 -0
  26. package/dist/script/readscript.js +15 -0
  27. package/dist/script/strtools.js +157 -0
  28. package/dist/storage/decorator.js +260 -0
  29. package/dist/storage/fs.js +96 -0
  30. package/dist/storage/index.js +442 -0
  31. package/dist/system/index.js +144 -0
  32. package/dist/ui/index.js +535 -0
  33. package/dist/utils/path.js +289 -0
  34. package/license.txt +202 -0
  35. package/package.json +26 -0
  36. package/src/async/index.ts +124 -0
  37. package/src/async/zeppos_timer.js +65 -0
  38. package/src/audio/index.ts +224 -0
  39. package/src/config/index.ts +80 -0
  40. package/src/debug/index.ts +11 -0
  41. package/src/index.ts +122 -0
  42. package/src/platform/index.ts +158 -0
  43. package/src/plugins/basic_command/$.ts +11 -0
  44. package/src/plugins/basic_command/audio.ts +53 -0
  45. package/src/plugins/basic_command/basic.ts +145 -0
  46. package/src/plugins/basic_command/character.ts +144 -0
  47. package/src/plugins/basic_command/conditional.ts +349 -0
  48. package/src/plugins/basic_command/config.ts +29 -0
  49. package/src/plugins/basic_command/decorator.ts +29 -0
  50. package/src/plugins/basic_command/eval.ts +88 -0
  51. package/src/plugins/basic_command/img.ts +317 -0
  52. package/src/plugins/basic_command/index.ts +24 -0
  53. package/src/plugins/basic_command/menu.ts +178 -0
  54. package/src/plugins/global_gesture/index.ts +29 -0
  55. package/src/plugins/transform/animation.ts +542 -0
  56. package/src/plugins/transform/commands.ts +53 -0
  57. package/src/plugins/transform/example_profiles.ts +36 -0
  58. package/src/plugins/transform/hz_anime.ts +214 -0
  59. package/src/plugins/transform/index.ts +141 -0
  60. package/src/plugins/transform/readme.md +1 -0
  61. package/src/script/index.ts +623 -0
  62. package/src/script/readscript.ts +17 -0
  63. package/src/script/strtools.ts +159 -0
  64. package/src/storage/decorator.ts +473 -0
  65. package/src/storage/fs.ts +104 -0
  66. package/src/storage/index.ts +541 -0
  67. package/src/system/index.ts +95 -0
  68. package/src/ui/index.ts +699 -0
  69. package/src/utils/path.js +338 -0
  70. package/tsconfig.json +111 -0
  71. package/types/async/index.d.ts +24 -0
  72. package/types/async/zeppos_timer.d.ts +14 -0
  73. package/types/audio/index.d.ts +64 -0
  74. package/types/config/index.d.ts +9 -0
  75. package/types/debug/index.d.ts +6 -0
  76. package/types/index.d.ts +41 -0
  77. package/types/platform/index.d.ts +134 -0
  78. package/types/plugins/basic_command/$.d.ts +2 -0
  79. package/types/plugins/basic_command/audio.d.ts +2 -0
  80. package/types/plugins/basic_command/basic.d.ts +3 -0
  81. package/types/plugins/basic_command/character.d.ts +2 -0
  82. package/types/plugins/basic_command/conditional.d.ts +2 -0
  83. package/types/plugins/basic_command/config.d.ts +2 -0
  84. package/types/plugins/basic_command/decorator.d.ts +2 -0
  85. package/types/plugins/basic_command/eval.d.ts +2 -0
  86. package/types/plugins/basic_command/img.d.ts +2 -0
  87. package/types/plugins/basic_command/index.d.ts +2 -0
  88. package/types/plugins/basic_command/menu.d.ts +2 -0
  89. package/types/plugins/global_gesture/index.d.ts +2 -0
  90. package/types/plugins/transform/animation.d.ts +131 -0
  91. package/types/plugins/transform/commands.d.ts +7 -0
  92. package/types/plugins/transform/example_profiles.d.ts +2 -0
  93. package/types/plugins/transform/hz_anime.d.ts +51 -0
  94. package/types/plugins/transform/index.d.ts +13 -0
  95. package/types/script/index.d.ts +123 -0
  96. package/types/script/readscript.d.ts +2 -0
  97. package/types/script/strtools.d.ts +31 -0
  98. package/types/storage/decorator.d.ts +41 -0
  99. package/types/storage/fs.d.ts +1 -0
  100. package/types/storage/index.d.ts +86 -0
  101. package/types/system/index.d.ts +35 -0
  102. package/types/ui/index.d.ts +167 -0
  103. package/types/utils/path.d.ts +84 -0
@@ -0,0 +1,211 @@
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, CustomSave, } from "../../storage/decorator.js";
47
+ import { Animation } from "./animation.js";
48
+ // import { Time } from "@zos/sensor";
49
+ let AnimationPlugin = (() => {
50
+ var _a, _AnimationPlugin__nextAnimationId_accessor_storage, _AnimationPlugin__animationMap_accessor_storage;
51
+ let __nextAnimationId_decorators;
52
+ let __nextAnimationId_initializers = [];
53
+ let __nextAnimationId_extraInitializers = [];
54
+ let __animationMap_decorators;
55
+ let __animationMap_initializers = [];
56
+ let __animationMap_extraInitializers = [];
57
+ return _a = class AnimationPlugin {
58
+ constructor(_core) {
59
+ this._core = _core;
60
+ _AnimationPlugin__nextAnimationId_accessor_storage.set(this, __runInitializers(this, __nextAnimationId_initializers, 1));
61
+ _AnimationPlugin__animationMap_accessor_storage.set(this, (__runInitializers(this, __nextAnimationId_extraInitializers), __runInitializers(this, __animationMap_initializers, {})));
62
+ // private _timeSensor = new Time();
63
+ this._lastCbUtc = __runInitializers(this, __animationMap_extraInitializers);
64
+ this._nextTempAnimationId = -1; // self-decrement
65
+ this._tempAnimationMap = {};
66
+ console.log("[AnimationPlugin] init");
67
+ _core.loadPlugin("animation", () => this);
68
+ _core.on("anime.cb", this._timerCb.bind(this));
69
+ _core.async.addRepeatTask("anime.cb", [], 0); // 此處周期應考慮加個sync update
70
+ this._lastCbUtc = this._core.platform.getTime();
71
+ }
72
+ get _nextAnimationId() { return __classPrivateFieldGet(this, _AnimationPlugin__nextAnimationId_accessor_storage, "f"); } // self-increment
73
+ set _nextAnimationId(value) { __classPrivateFieldSet(this, _AnimationPlugin__nextAnimationId_accessor_storage, value, "f"); }
74
+ get _animationMap() { return __classPrivateFieldGet(this, _AnimationPlugin__animationMap_accessor_storage, "f"); }
75
+ set _animationMap(value) { __classPrivateFieldSet(this, _AnimationPlugin__animationMap_accessor_storage, value, "f"); }
76
+ applyAnimation({ profile, targetView, options, }) {
77
+ var _b, _c, _d;
78
+ const id = this._nextAnimationId++;
79
+ let animation = new Animation(profile, {
80
+ // @ts-ignore
81
+ initProps: (_b = targetView.prop) !== null && _b !== void 0 ? _b : {},
82
+ wrappers: options === null || options === void 0 ? void 0 : options.customWrappers,
83
+ });
84
+ if (!targetView.id)
85
+ throw "targetView.id must be not null";
86
+ this._animationMap[id] = {
87
+ destroyOnEnd: (_c = options === null || options === void 0 ? void 0 : options.destroyOnEnd) !== null && _c !== void 0 ? _c : false,
88
+ isSave: (_d = options === null || options === void 0 ? void 0 : options.isSave) !== null && _d !== void 0 ? _d : true,
89
+ instance: animation,
90
+ targetViewId: targetView.id,
91
+ };
92
+ this._linkAnimationCb(animation, id);
93
+ animation.goto(0);
94
+ this._core.on("afterLoadArchive", () => {
95
+ this._lastCbUtc = this._core.platform.getTime();
96
+ });
97
+ return id;
98
+ }
99
+ stopAnimation(id) {
100
+ if (this._animationMap[id] !== undefined) {
101
+ this._animationMap[id].instance.stop();
102
+ delete this._animationMap[id];
103
+ }
104
+ }
105
+ createTempAnimation({ profile, onFrame, onEnd, initProps, wrappers, }) {
106
+ let id = this._nextTempAnimationId--;
107
+ let animation = new Animation(profile, {
108
+ initProps,
109
+ wrappers,
110
+ });
111
+ animation.onFrame = onFrame !== null && onFrame !== void 0 ? onFrame : null;
112
+ animation.onEnd = () => {
113
+ if (onEnd)
114
+ onEnd();
115
+ delete this._tempAnimationMap[id];
116
+ };
117
+ this._tempAnimationMap[id] = animation;
118
+ return id;
119
+ }
120
+ clearTempAnimation(id) {
121
+ if (this._tempAnimationMap[id] !== undefined) {
122
+ this._tempAnimationMap[id].stop();
123
+ delete this._tempAnimationMap[id];
124
+ }
125
+ }
126
+ _timerCb() {
127
+ let utc = this._core.platform.getTime();
128
+ let delta_time = (utc - this._lastCbUtc) / 1000;
129
+ this._lastCbUtc = utc;
130
+ // this._core.debug.log(`delta time: ${delta_time}`);
131
+ for (let id in this._animationMap) {
132
+ this._animationMap[id].instance.step(delta_time);
133
+ }
134
+ for (let id in this._tempAnimationMap) {
135
+ this._tempAnimationMap[id].step(delta_time);
136
+ }
137
+ }
138
+ _frameCb(props, id) {
139
+ if (this._animationMap[id] !== undefined) {
140
+ let view = this._core.ui.getView(this._animationMap[id].targetViewId);
141
+ if (!view) {
142
+ this._core.debug.log(`view ${id} not found, stop animation`);
143
+ this.stopAnimation(id); // TODO
144
+ return;
145
+ }
146
+ view.commit(props);
147
+ // this._core.debug.log(`update view ${view.name} with ${JSON.stringify(props)}`);
148
+ }
149
+ }
150
+ _linkAnimationCb(animation, id) {
151
+ animation.onFrame = (props) => {
152
+ // console.log("onFrame cb");
153
+ this._frameCb(props, id);
154
+ };
155
+ animation.onEnd = () => this._endCb(id);
156
+ }
157
+ _endCb(id) {
158
+ if (this._animationMap[id] !== undefined) {
159
+ if (this._animationMap[id].destroyOnEnd) {
160
+ let view = this._core.ui.getView(id);
161
+ if (view)
162
+ this._core.ui.destroyView(view);
163
+ }
164
+ delete this._animationMap[id];
165
+ console.log("map item", this._animationMap[id]);
166
+ }
167
+ else
168
+ console.log("nf map item", this._animationMap[id]);
169
+ }
170
+ },
171
+ _AnimationPlugin__nextAnimationId_accessor_storage = new WeakMap(),
172
+ _AnimationPlugin__animationMap_accessor_storage = new WeakMap(),
173
+ (() => {
174
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
175
+ __nextAnimationId_decorators = [Save("anime.nid")];
176
+ __animationMap_decorators = [CustomSave("anime.map", function (obj) {
177
+ let res = {};
178
+ for (let id in obj) {
179
+ if (!obj[id].isSave)
180
+ continue;
181
+ res[id] = {
182
+ destroyOnEnd: obj[id].destroyOnEnd,
183
+ isSave: obj[id].isSave,
184
+ targetViewId: obj[id].targetViewId,
185
+ serializedInstance: obj[id].instance.serialize(),
186
+ };
187
+ }
188
+ return res;
189
+ }, function (obj) {
190
+ let res = {};
191
+ for (let id in obj) {
192
+ if (!obj[id].isSave)
193
+ continue;
194
+ let animation = Animation.unserialize(obj[id].serializedInstance);
195
+ this._linkAnimationCb(animation, Number(id));
196
+ res[id] = {
197
+ destroyOnEnd: obj[id].destroyOnEnd,
198
+ isSave: obj[id].isSave,
199
+ targetViewId: obj[id].targetViewId,
200
+ instance: animation,
201
+ };
202
+ }
203
+ return res;
204
+ })];
205
+ __esDecorate(_a, null, __nextAnimationId_decorators, { kind: "accessor", name: "_nextAnimationId", static: false, private: false, access: { has: obj => "_nextAnimationId" in obj, get: obj => obj._nextAnimationId, set: (obj, value) => { obj._nextAnimationId = value; } }, metadata: _metadata }, __nextAnimationId_initializers, __nextAnimationId_extraInitializers);
206
+ __esDecorate(_a, null, __animationMap_decorators, { kind: "accessor", name: "_animationMap", static: false, private: false, access: { has: obj => "_animationMap" in obj, get: obj => obj._animationMap, set: (obj, value) => { obj._animationMap = value; } }, metadata: _metadata }, __animationMap_initializers, __animationMap_extraInitializers);
207
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
208
+ })(),
209
+ _a;
210
+ })();
211
+ export { AnimationPlugin };
@@ -0,0 +1,93 @@
1
+ import { AnimationPlugin } from "./hz_anime.js";
2
+ import { Animation, Profile } from "./animation.js";
3
+ // import hmFS from "@zos/fs";
4
+ import { getTransitionMap, registerHzscriptCommands } from "./commands.js";
5
+ export function registerPlugin(core) {
6
+ let animationPlugin = new AnimationPlugin(core);
7
+ let profileMap = {};
8
+ registerHzscriptCommands(core);
9
+ core.on("afterLoadProject", () => {
10
+ profileMap = core.storage.getSaveableData(core.storage.preloadedData, false, "animation", "profileMap");
11
+ });
12
+ function getProfile(name) {
13
+ let profile_item = profileMap[name];
14
+ if (!profile_item) {
15
+ core.debug.log(`Animation profile [${name}] not found`);
16
+ return null;
17
+ }
18
+ let str = core.platform.readFileSync({
19
+ path: profile_item[0],
20
+ options: {
21
+ encoding: "utf8",
22
+ },
23
+ });
24
+ if (typeof str !== "string") {
25
+ core.debug.log(`Animation profile file [${name}] not found`);
26
+ return null;
27
+ }
28
+ try {
29
+ return JSON.parse(str);
30
+ }
31
+ catch (error) {
32
+ core.debug.log(`Animation profile file [${name}] parse error:`, error);
33
+ }
34
+ return null;
35
+ }
36
+ function applyTransform(names, target, isSave = false, destroyOnEnd = false) {
37
+ let profile = null;
38
+ if (names.length === 1) {
39
+ profile = getProfile(names[0]);
40
+ }
41
+ else if (names.length > 1) {
42
+ let syncs = [];
43
+ for (let i = 0; i < names.length; i++) {
44
+ let profile = getProfile(names[i]);
45
+ if (profile)
46
+ syncs.push(profile);
47
+ }
48
+ profile = { syncs };
49
+ }
50
+ if (!profile)
51
+ profile = [];
52
+ animationPlugin.applyAnimation({
53
+ profile,
54
+ targetView: target,
55
+ options: {
56
+ isSave,
57
+ destroyOnEnd,
58
+ },
59
+ });
60
+ }
61
+ class TransformRouteStrategy {
62
+ constructor(outTransforms, inTransforms) {
63
+ this.outTransforms = outTransforms;
64
+ this.inTransforms = inTransforms;
65
+ }
66
+ create(viewName, layer, prop, ui, isSave) {
67
+ let view = ui.createView(viewName, layer, prop, isSave);
68
+ this.inTransforms && applyTransform(this.inTransforms, view, isSave);
69
+ return view;
70
+ }
71
+ destroy(viewInstance, ui) {
72
+ if (this.outTransforms) {
73
+ applyTransform(this.outTransforms, viewInstance, viewInstance.isSave, true);
74
+ }
75
+ else {
76
+ ui.destroyView(viewInstance);
77
+ }
78
+ }
79
+ }
80
+ return {
81
+ applyTransform,
82
+ getProfile,
83
+ createStrategy(outTransforms, inTransforms) {
84
+ return new TransformRouteStrategy(outTransforms, inTransforms);
85
+ },
86
+ animationPlugin,
87
+ getTransition(name) {
88
+ var _a;
89
+ return (_a = getTransitionMap(core)[name]) !== null && _a !== void 0 ? _a : null;
90
+ }
91
+ };
92
+ }
93
+ export { Animation, Profile, AnimationPlugin };