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,86 @@
1
+ import { HZEngineCore } from "../index.js";
2
+ export declare class Storage {
3
+ private _core;
4
+ constructor(_core: HZEngineCore);
5
+ projectRoot: string | null;
6
+ cacheRoot: string | null;
7
+ saveRoot: string | null;
8
+ preloadedData: NonNullable<any> | null;
9
+ packageData: NonNullable<any> | null;
10
+ loadProject(options: {
11
+ projectPath: string;
12
+ cachePath: string;
13
+ savePath: string;
14
+ }): void;
15
+ loadPackageData(): void;
16
+ /**
17
+ * 全局数据
18
+ * 其中的数据不会跟随存档保存,而是直接存储在全局数据文件中
19
+ * 如:设置、CG解锁情况等
20
+ */
21
+ private _globalData;
22
+ get globalData(): NonNullable<Storage.JSONValue>;
23
+ /**
24
+ * alias globalData
25
+ */
26
+ get gd(): NonNullable<Storage.JSONValue>;
27
+ /**
28
+ * 存档数据
29
+ * 其中的数据会跟随存档保存
30
+ * 如:脚本执行位置即调用栈,攻略度等
31
+ */
32
+ private _archiveData;
33
+ get archiveData(): NonNullable<Storage.JSONValue>;
34
+ /**
35
+ * alias archiveData
36
+ */
37
+ get sd(): NonNullable<Storage.JSONValue>;
38
+ loadGlobalData(): void;
39
+ /**
40
+ * 保存全局数据
41
+ * 可以多次調用,實際上會異步儲存,也就是在一個宏任務中即使調用多次,也只會在宏任務結束後儲存一次
42
+ */
43
+ private _saveGlobalDataTimerId;
44
+ saveGlobalData(): void;
45
+ loadArchiveData(archiveFile?: string): void;
46
+ _saveArchiveDataTimerId: number | null;
47
+ /**
48
+ * 保存存档数据
49
+ * 可以多次調用,實際上會異步儲存,也就是在一個宏任務中即使調用多次,也只會在宏任務結束後儲存一次
50
+ * @param archiveFile 存档文件目錄及名字
51
+ */
52
+ saveArchiveData(archiveFile: string, immediate?: boolean): void;
53
+ getSaveableData(data: Storage.JSONValue, auto_correct: boolean, ...key_chain: string[]): NonNullable<Storage.JSONValue>;
54
+ setSaveableData(data: Storage.JSONValue, auto_correct: boolean, value: Storage.JSONValue, ...key_chain: string[]): void;
55
+ checkSaveableData(data: Storage.JSONValue, ...key_chain: string[]): NonNullable<Storage.JSONValue>;
56
+ preload(): void;
57
+ /**
58
+ * 预加载脚本
59
+ * 遍历出所有hzs文件和所有label,建立map
60
+ */
61
+ preloadScript(): void;
62
+ /**
63
+ * 预加载资源
64
+ * 遍历所有png文件,计算对应的name key,建立map
65
+ */
66
+ preloadImage(): void;
67
+ /**
68
+ * 預加載動畫profile
69
+ * 遍歷animation文件夾下的所有json文件,以文件名為key,json内容為value
70
+ */
71
+ preloadAnimation(): void;
72
+ }
73
+ export declare type HzsInfo = {
74
+ totalLines: number;
75
+ };
76
+ export declare namespace Storage {
77
+ export type JSONBaseType = number | string | boolean | null;
78
+ export type JSONValue = JSONBaseType | {
79
+ [key: string]: JSONValue;
80
+ } | JSONValue[];
81
+ export type Saveable<T> = {
82
+ [P in keyof T]: T[P] extends JSONValue ? T[P] : T[P] extends NotAssignableToJson ? never : Saveable<T[P]>;
83
+ } | JSONValue[] | JSONValue;
84
+ type NotAssignableToJson = bigint | symbol | Function;
85
+ export {};
86
+ }
@@ -0,0 +1,35 @@
1
+ import { HZEngineCore, Platform } from "../index.js";
2
+ export declare class System<PlatformType extends Platform> {
3
+ _core: HZEngineCore<PlatformType>;
4
+ constructor(_core: HZEngineCore<PlatformType>);
5
+ accessor condition: System.Condition;
6
+ _pauseTimer: number | null;
7
+ /**
8
+ * 暂停(可指定一段时间)
9
+ * 后调用的会覆盖之前pause的设定时间
10
+ * @param delayMs
11
+ */
12
+ pause(delayMs?: number): void;
13
+ /**
14
+ * 继续由于pause中断的游戏
15
+ */
16
+ continue(): void;
17
+ /**
18
+ * 阻塞
19
+ */
20
+ block(): void;
21
+ /**
22
+ * 取消阻塞
23
+ */
24
+ unBlock(): void;
25
+ run(): void;
26
+ start(initLabel?: string): void;
27
+ }
28
+ export declare namespace System {
29
+ enum Condition {
30
+ Free = 0,
31
+ Pause = 1,
32
+ Blocked = 2,
33
+ Gaming = 3
34
+ }
35
+ }
@@ -0,0 +1,167 @@
1
+ import { HZEngineCore, Platform } from "../index.js";
2
+ import { Storage } from "../storage/index.js";
3
+ export declare class UI<PlatformType extends Platform = any> {
4
+ _core: HZEngineCore<PlatformType>;
5
+ constructor(_core: HZEngineCore<PlatformType>);
6
+ private _initUI;
7
+ private _cleanUI;
8
+ resetUI(): void;
9
+ private accessor _layerList;
10
+ get layerList(): Map<string, UI.Layer<PlatformType>>;
11
+ addLayer(name: string, z_index: number): void;
12
+ getLayer(name: string): UI.Layer<PlatformType> | undefined;
13
+ private _viewClassMap;
14
+ registerView<PropType extends Storage.Saveable<PropType>>(name: string, cls: UI.ViewClass<PropType, PlatformType>): void;
15
+ private accessor _nextViewId;
16
+ private accessor _viewMap;
17
+ getView(id: number): UI.View<Storage.Saveable<unknown>, PlatformType> | null;
18
+ createView<PropType extends Storage.Saveable<PropType>>(name: string, layer: string, prop: PropType, isSave: boolean): UI.View<PropType, PlatformType>;
19
+ updateView<PropType extends Storage.Saveable<PropType>>(viewInstance: UI.View<PropType, PlatformType>, new_prop: PropType): void;
20
+ destroyView(viewInstance: UI.View<Storage.Saveable<unknown>, PlatformType>): void;
21
+ /**由調用者提供id,創建一個View,不會處理isSave,也不會更新viewMap */
22
+ private _produceViewWithId;
23
+ private accessor _routerMap;
24
+ getRouter(tag: string): UI.Router<PlatformType> | undefined;
25
+ addRouter(tag: string, layer: string, isSave?: boolean): UI.Router<PlatformType>;
26
+ getScreenSize(): {
27
+ width: number;
28
+ height: number;
29
+ };
30
+ /**
31
+ * 根据 BasicUniversalProp 计算屏幕上的位置
32
+ * @param prop 包含 BasicUniversalProp 的 prop
33
+ * @param size (可选)图像的尺寸,若不指定,返回的anchor坐标和origin坐标一样
34
+ * @returns
35
+ */
36
+ calcPosition(prop: UI.BasicUniversalProp, size?: UI.Size): {
37
+ /** 锚点(算上偏移)的屏幕位置 */
38
+ anchor: UI.Coordinate;
39
+ /** 图像左上角的屏幕位置 */
40
+ origin: UI.Coordinate;
41
+ };
42
+ }
43
+ export declare namespace UI {
44
+ type ViewClass<PropType extends Storage.Saveable<PropType>, PlatformType extends Platform> = {
45
+ new (layer: string, core: HZEngineCore<PlatformType>): View<PropType, PlatformType>;
46
+ };
47
+ abstract class View<PropType extends Storage.Saveable<PropType>, PlatformType extends Platform = any> {
48
+ layer: string;
49
+ core: HZEngineCore<PlatformType>;
50
+ id: number | null;
51
+ name: string | null;
52
+ isSave: boolean;
53
+ private _prop;
54
+ get prop(): PropType | null;
55
+ private set prop(value);
56
+ constructor(layer: string, core: HZEngineCore<PlatformType>);
57
+ create(prop: PropType): void;
58
+ protected abstract onCreate(prop: PropType): void;
59
+ commit(prop: PropType): void;
60
+ protected abstract onCommit(prop: PropType): void;
61
+ destroy(): void;
62
+ protected abstract onDestroy(): void;
63
+ serialize(): View.Serialized;
64
+ }
65
+ namespace View {
66
+ interface Serialized {
67
+ name: string;
68
+ layer: string;
69
+ prop: Storage.Saveable<unknown>;
70
+ }
71
+ }
72
+ interface BasicUniversalProp {
73
+ alpha?: number;
74
+ xalign?: number;
75
+ yalign?: number;
76
+ xanchor?: number;
77
+ yanchor?: number;
78
+ xoffset?: number;
79
+ yoffset?: number;
80
+ }
81
+ interface Message {
82
+ who: string;
83
+ what: string;
84
+ }
85
+ abstract class MessageView<PlatformType extends Platform> extends View<Message, PlatformType> {
86
+ }
87
+ interface MenuItemData {
88
+ text: string;
89
+ position: [path: string, index: number];
90
+ enable_js_expression?: string;
91
+ }
92
+ type MenuViewProp = {
93
+ itemList: MenuItemData[];
94
+ };
95
+ abstract class MenuView<PlatformType extends Platform> extends View<MenuViewProp, PlatformType> {
96
+ }
97
+ type Coordinate = {
98
+ x: number;
99
+ y: number;
100
+ };
101
+ type Size = {
102
+ width: number;
103
+ height: number;
104
+ };
105
+ /**
106
+ * 立绘/道具等显示在`fg`layer上的图片View
107
+ */
108
+ type FgImgViewProp = {
109
+ imgPath: string;
110
+ offset: Coordinate;
111
+ size: Size;
112
+ };
113
+ abstract class FgImgView<PlatformType extends Platform> extends View<FgImgViewProp, PlatformType> {
114
+ }
115
+ /**
116
+ * cg等显示在`bg`layer上的图片View
117
+ */
118
+ type BgImgViewProp = {
119
+ imgPath: string;
120
+ offset: Coordinate;
121
+ size: Size;
122
+ };
123
+ abstract class BgImgView<PlatformType extends Platform> extends View<FgImgViewProp, PlatformType> {
124
+ }
125
+ class Layer<PlatformType extends Platform> {
126
+ _core: HZEngineCore<PlatformType>;
127
+ name: string;
128
+ z_index: number;
129
+ widgetFactory: ReturnType<PlatformType["createUILayer"]>;
130
+ constructor(_core: HZEngineCore<PlatformType>, name: string, z_index: number);
131
+ destroy(): void;
132
+ }
133
+ namespace Layer {
134
+ }
135
+ class Router<PlatformType extends Platform> {
136
+ private _ui;
137
+ tag: string;
138
+ layer: string;
139
+ isSave: boolean;
140
+ constructor(_ui: UI<PlatformType>, tag: string, layer: string, isSave?: boolean);
141
+ serialize(): Router.Serialized;
142
+ defaultRouteStrategy: Router.RouteStrategy;
143
+ static deserialize<PlatformType extends Platform>(ui: UI<PlatformType>, data: Router.Serialized): Router<PlatformType>;
144
+ viewStack: [view_name: string, prop: Storage.Saveable<unknown>][];
145
+ get length(): number;
146
+ activeViewInstance: View<Storage.Saveable<unknown>, PlatformType> | null;
147
+ push<T extends Storage.Saveable<T>>(view_name: string, prop: T, strategy?: Router.RouteStrategy): void;
148
+ pop<T extends Storage.Saveable<T>>(back_prop?: T, strategy?: Router.RouteStrategy): void;
149
+ replace<T extends Storage.Saveable<T>>(view_name: string, prop: T, strategy?: Router.RouteStrategy): void;
150
+ update<T extends Storage.Saveable<T>>(prop: T, strategy?: Router.RouteStrategy): void;
151
+ clear(strategy?: Router.RouteStrategy): void;
152
+ }
153
+ namespace Router {
154
+ interface Serialized {
155
+ tag: string;
156
+ layer: string;
157
+ isSave: boolean;
158
+ viewStack: [view_name: string, prop: Storage.Saveable<unknown>][];
159
+ activeViewId: number | null;
160
+ }
161
+ interface RouteStrategy<PropType extends Storage.Saveable<PropType> = Storage.Saveable<unknown>, PlatformType extends Platform = any> {
162
+ destroy?(viewInstance: View<PropType, PlatformType>, ui: UI<PlatformType>): void;
163
+ create?(viewName: string, layer: string, prop: PropType, ui: UI<PlatformType>, isSave: boolean): View<Storage.Saveable<PropType>, PlatformType>;
164
+ update?(viewInstance: View<PropType, PlatformType>, prop: PropType, ui: UI<PlatformType>): void;
165
+ }
166
+ }
167
+ }
@@ -0,0 +1,84 @@
1
+ export default posix;
2
+ declare namespace posix {
3
+ /**
4
+ * 解析路径,将相对路径转换为绝对路径
5
+ * @param {...string} paths - 要解析的路径
6
+ * @returns {string} - 解析后的绝对路径
7
+ */
8
+ function resolve(...args: string[]): string;
9
+ /**
10
+ * 规范化路径,去除多余的斜杠和当前目录
11
+ * @param {string} path - 输入的路径字符串
12
+ * @returns {string} - 规范化后的路径
13
+ */
14
+ function normalize(path: string): string;
15
+ /**
16
+ * 检查路径是否为绝对路径
17
+ * @param {string} path - 输入的路径字符串
18
+ * @returns {boolean} - 如果路径为绝对路径,则返回 true
19
+ */
20
+ function isAbsolute(path: string): boolean;
21
+ /**
22
+ * 连接多个路径段为一个路径
23
+ * @param {...string} segments - 要连接的路径段
24
+ * @returns {string} - 连接后的路径
25
+ */
26
+ function join(...args: string[]): string;
27
+ /**
28
+ * 计算相对路径
29
+ * @param {string} from - 起始路径
30
+ * @param {string} to - 目标路径
31
+ * @returns {string} - 相对路径
32
+ */
33
+ function relative(from: string, to: string): string;
34
+ /**
35
+ * 获取路径的目录名
36
+ * @param {string} path - 输入的路径字符串
37
+ * @returns {string} - 目录名
38
+ */
39
+ function dirname(path: string): string;
40
+ /**
41
+ * 获取路径的基本名
42
+ * @param {string} path - 输入的路径字符串
43
+ * @param {string} [ext] - 可选的扩展名,如果提供则将其从基本名中去除
44
+ * @returns {string} - 基本名
45
+ */
46
+ function basename(path: string, ext?: string | undefined): string;
47
+ /**
48
+ * 获取路径的扩展名
49
+ * @param {string} path - 输入的路径字符串
50
+ * @returns {string} - 扩展名
51
+ */
52
+ function extname(path: string): string;
53
+ /**
54
+ * 格式化路径对象为路径字符串
55
+ * @param {Object} pathObject - 路径对象
56
+ * @param {string} pathObject.root - 根路径
57
+ * @param {string} pathObject.dir - 目录路径
58
+ * @param {string} pathObject.base - 基本文件名
59
+ * @param {string} pathObject.ext - 扩展名
60
+ * @param {string} pathObject.name - 文件名(不包含扩展名)
61
+ * @returns {string} - 格式化后的路径字符串
62
+ */
63
+ function format(pathObject: {
64
+ root: string;
65
+ dir: string;
66
+ base: string;
67
+ ext: string;
68
+ name: string;
69
+ }): string;
70
+ /**
71
+ * 解析路径字符串为路径对象
72
+ * @param {string} pathString - 输入的路径字符串
73
+ * @returns {{root: string, dir: string, base: string, ext: string, name: string}} - 路径对象
74
+ */
75
+ function parse(pathString: string): {
76
+ root: string;
77
+ dir: string;
78
+ base: string;
79
+ ext: string;
80
+ name: string;
81
+ };
82
+ let sep: string;
83
+ let delimiter: string;
84
+ }