sapdon 3.0.1 → 3.0.2

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 (206) hide show
  1. package/README.md +3 -1
  2. package/doc/cli.md +24 -0
  3. package/doc/sapdon-ts.md +17 -5
  4. package/package.json +2 -2
  5. package/dist/cli/build.d.ts +0 -7
  6. package/dist/cli/build.js +0 -232
  7. package/dist/cli/dev-server/client.d.ts +0 -2
  8. package/dist/cli/dev-server/client.js +0 -20
  9. package/dist/cli/dev-server/config.d.ts +0 -3
  10. package/dist/cli/dev-server/config.js +0 -3
  11. package/dist/cli/dev-server/hmr.d.ts +0 -1
  12. package/dist/cli/dev-server/hmr.js +0 -13
  13. package/dist/cli/dev-server/index.d.ts +0 -3
  14. package/dist/cli/dev-server/index.js +0 -11
  15. package/dist/cli/dev-server/server.d.ts +0 -6
  16. package/dist/cli/dev-server/server.js +0 -50
  17. package/dist/cli/dev-server/syncFiles.d.ts +0 -3
  18. package/dist/cli/dev-server/syncFiles.js +0 -36
  19. package/dist/cli/index.d.ts +0 -1
  20. package/dist/cli/index.js +0 -1
  21. package/dist/cli/init.d.ts +0 -9
  22. package/dist/cli/init.js +0 -80
  23. package/dist/cli/load.d.ts +0 -3
  24. package/dist/cli/load.js +0 -94
  25. package/dist/cli/start.d.ts +0 -2
  26. package/dist/cli/start.js +0 -156
  27. package/dist/cli/tools/textureSet.d.ts +0 -13
  28. package/dist/cli/tools/textureSet.js +0 -103
  29. package/dist/cli/utils.d.ts +0 -13
  30. package/dist/cli/utils.js +0 -89
  31. package/dist/core/addon/biome.d.ts +0 -22
  32. package/dist/core/addon/biome.js +0 -27
  33. package/dist/core/addon/block/block.d.ts +0 -41
  34. package/dist/core/addon/block/block.js +0 -46
  35. package/dist/core/addon/controllers/animationController.d.ts +0 -43
  36. package/dist/core/addon/controllers/animationController.js +0 -73
  37. package/dist/core/addon/entity/clientEntity.d.ts +0 -107
  38. package/dist/core/addon/entity/clientEntity.js +0 -149
  39. package/dist/core/addon/entity/entity.d.ts +0 -42
  40. package/dist/core/addon/entity/entity.js +0 -50
  41. package/dist/core/addon/feature/oreFeature.d.ts +0 -19
  42. package/dist/core/addon/feature/oreFeature.js +0 -24
  43. package/dist/core/addon/featureRule.d.ts +0 -20
  44. package/dist/core/addon/featureRule.js +0 -25
  45. package/dist/core/addon/item/attachable.d.ts +0 -94
  46. package/dist/core/addon/item/attachable.js +0 -134
  47. package/dist/core/addon/item/item.d.ts +0 -19
  48. package/dist/core/addon/item/item.js +0 -26
  49. package/dist/core/addon/manifest.d.ts +0 -49
  50. package/dist/core/addon/manifest.js +0 -65
  51. package/dist/core/addon/menuCategory.d.ts +0 -6
  52. package/dist/core/addon/menuCategory.js +0 -7
  53. package/dist/core/addon/recipe/baseRecipe.d.ts +0 -12
  54. package/dist/core/addon/recipe/baseRecipe.js +0 -23
  55. package/dist/core/addon/recipe/data.d.ts +0 -66
  56. package/dist/core/addon/recipe/data.js +0 -74
  57. package/dist/core/addon/recipe/furnace.d.ts +0 -17
  58. package/dist/core/addon/recipe/furnace.js +0 -43
  59. package/dist/core/addon/recipe/shaped.d.ts +0 -26
  60. package/dist/core/addon/recipe/shaped.js +0 -53
  61. package/dist/core/addon/recipe/shapeless.d.ts +0 -18
  62. package/dist/core/addon/recipe/shapeless.js +0 -36
  63. package/dist/core/biome/biome.d.ts +0 -14
  64. package/dist/core/biome/biome.js +0 -23
  65. package/dist/core/biome/biomeComponent.d.ts +0 -46
  66. package/dist/core/biome/biomeComponent.js +0 -77
  67. package/dist/core/block/basicBlock.d.ts +0 -48
  68. package/dist/core/block/basicBlock.js +0 -105
  69. package/dist/core/block/block.d.ts +0 -32
  70. package/dist/core/block/block.js +0 -92
  71. package/dist/core/block/blockComponent.d.ts +0 -187
  72. package/dist/core/block/blockComponent.js +0 -500
  73. package/dist/core/block/cropBlock.d.ts +0 -4
  74. package/dist/core/block/cropBlock.js +0 -27
  75. package/dist/core/block/geometryBlock.d.ts +0 -12
  76. package/dist/core/block/geometryBlock.js +0 -16
  77. package/dist/core/block/oreBlock.d.ts +0 -9
  78. package/dist/core/block/oreBlock.js +0 -25
  79. package/dist/core/block/rotatableBlock.d.ts +0 -27
  80. package/dist/core/block/rotatableBlock.js +0 -107
  81. package/dist/core/block/tileBlock.d.ts +0 -17
  82. package/dist/core/block/tileBlock.js +0 -125
  83. package/dist/core/entity/basicEntity.d.ts +0 -111
  84. package/dist/core/entity/basicEntity.js +0 -170
  85. package/dist/core/entity/behavior/followMob.d.ts +0 -12
  86. package/dist/core/entity/behavior/followMob.js +0 -35
  87. package/dist/core/entity/behavior/followParent.d.ts +0 -7
  88. package/dist/core/entity/behavior/followParent.js +0 -15
  89. package/dist/core/entity/behavior/randomStroll.d.ts +0 -31
  90. package/dist/core/entity/behavior/randomStroll.js +0 -63
  91. package/dist/core/entity/behavior/tempt.d.ts +0 -73
  92. package/dist/core/entity/behavior/tempt.js +0 -134
  93. package/dist/core/entity/bundles/basicBundle.d.ts +0 -13
  94. package/dist/core/entity/bundles/basicBundle.js +0 -45
  95. package/dist/core/entity/clientEntity.d.ts +0 -20
  96. package/dist/core/entity/clientEntity.js +0 -37
  97. package/dist/core/entity/componets/entityComponet.d.ts +0 -202
  98. package/dist/core/entity/componets/entityComponet.js +0 -347
  99. package/dist/core/entity/data/nativeEntityData.d.ts +0 -9
  100. package/dist/core/entity/data/nativeEntityData.js +0 -38
  101. package/dist/core/entity/entity.d.ts +0 -15
  102. package/dist/core/entity/entity.js +0 -18
  103. package/dist/core/entity/nativeEntity.d.ts +0 -8
  104. package/dist/core/entity/nativeEntity.js +0 -28
  105. package/dist/core/entity/navigation/walk.d.ts +0 -23
  106. package/dist/core/entity/navigation/walk.js +0 -56
  107. package/dist/core/entity/projectile.d.ts +0 -3
  108. package/dist/core/entity/projectile.js +0 -7
  109. package/dist/core/factory/biomeFactory.d.ts +0 -4
  110. package/dist/core/factory/biomeFactory.js +0 -13
  111. package/dist/core/factory/blockFactory.d.ts +0 -34
  112. package/dist/core/factory/blockFactory.js +0 -143
  113. package/dist/core/factory/entityFactory.d.ts +0 -17
  114. package/dist/core/factory/entityFactory.js +0 -75
  115. package/dist/core/factory/featureFactory.d.ts +0 -6
  116. package/dist/core/factory/featureFactory.js +0 -23
  117. package/dist/core/factory/itemExtra.d.ts +0 -8
  118. package/dist/core/factory/itemExtra.js +0 -9
  119. package/dist/core/factory/itemFactory.d.ts +0 -27
  120. package/dist/core/factory/itemFactory.js +0 -112
  121. package/dist/core/factory/recipeFactory.d.ts +0 -18
  122. package/dist/core/factory/recipeFactory.js +0 -39
  123. package/dist/core/factory/uiFactory.d.ts +0 -11
  124. package/dist/core/factory/uiFactory.js +0 -32
  125. package/dist/core/feature/oreFeature.d.ts +0 -10
  126. package/dist/core/feature/oreFeature.js +0 -11
  127. package/dist/core/feature-rule/condition/biomeFilter.d.ts +0 -26
  128. package/dist/core/feature-rule/condition/biomeFilter.js +0 -36
  129. package/dist/core/feature-rule/condition/featureConditions.d.ts +0 -27
  130. package/dist/core/feature-rule/condition/featureConditions.js +0 -37
  131. package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +0 -17
  132. package/dist/core/feature-rule/distribution/coordinateDistribution.js +0 -23
  133. package/dist/core/feature-rule/distribution/featureDistribution.d.ts +0 -31
  134. package/dist/core/feature-rule/distribution/featureDistribution.js +0 -41
  135. package/dist/core/feature-rule/featureRule.d.ts +0 -17
  136. package/dist/core/feature-rule/featureRule.js +0 -26
  137. package/dist/core/index.d.ts +0 -24
  138. package/dist/core/index.js +0 -21
  139. package/dist/core/item/armor.d.ts +0 -21
  140. package/dist/core/item/armor.js +0 -90
  141. package/dist/core/item/attachable.d.ts +0 -6
  142. package/dist/core/item/attachable.js +0 -26
  143. package/dist/core/item/food.d.ts +0 -24
  144. package/dist/core/item/food.js +0 -38
  145. package/dist/core/item/item.d.ts +0 -36
  146. package/dist/core/item/item.js +0 -69
  147. package/dist/core/item/itemComponents.d.ts +0 -113
  148. package/dist/core/item/itemComponents.js +0 -225
  149. package/dist/core/registry.d.ts +0 -12
  150. package/dist/core/registry.js +0 -16
  151. package/dist/core/texture.d.ts +0 -18
  152. package/dist/core/texture.js +0 -38
  153. package/dist/core/ui/buttonMapping.d.ts +0 -97
  154. package/dist/core/ui/buttonMapping.js +0 -132
  155. package/dist/core/ui/dataBindingObject.d.ts +0 -97
  156. package/dist/core/ui/dataBindingObject.js +0 -134
  157. package/dist/core/ui/elements/button.d.ts +0 -21
  158. package/dist/core/ui/elements/button.js +0 -101
  159. package/dist/core/ui/elements/collectionPanel.d.ts +0 -12
  160. package/dist/core/ui/elements/collectionPanel.js +0 -53
  161. package/dist/core/ui/elements/grid.d.ts +0 -8
  162. package/dist/core/ui/elements/grid.js +0 -33
  163. package/dist/core/ui/elements/image.d.ts +0 -13
  164. package/dist/core/ui/elements/image.js +0 -55
  165. package/dist/core/ui/elements/label.d.ts +0 -14
  166. package/dist/core/ui/elements/label.js +0 -61
  167. package/dist/core/ui/elements/panel.d.ts +0 -11
  168. package/dist/core/ui/elements/panel.js +0 -49
  169. package/dist/core/ui/elements/scrollingPanel.d.ts +0 -14
  170. package/dist/core/ui/elements/scrollingPanel.js +0 -59
  171. package/dist/core/ui/elements/stackPanel.d.ts +0 -14
  172. package/dist/core/ui/elements/stackPanel.js +0 -37
  173. package/dist/core/ui/elements/uiElement.d.ts +0 -53
  174. package/dist/core/ui/elements/uiElement.js +0 -129
  175. package/dist/core/ui/properties/control.d.ts +0 -214
  176. package/dist/core/ui/properties/control.js +0 -286
  177. package/dist/core/ui/properties/dataBinding.d.ts +0 -6
  178. package/dist/core/ui/properties/dataBinding.js +0 -16
  179. package/dist/core/ui/properties/factory.d.ts +0 -37
  180. package/dist/core/ui/properties/factory.js +0 -62
  181. package/dist/core/ui/properties/gridProp.d.ts +0 -65
  182. package/dist/core/ui/properties/gridProp.js +0 -90
  183. package/dist/core/ui/properties/input.d.ts +0 -97
  184. package/dist/core/ui/properties/input.js +0 -134
  185. package/dist/core/ui/properties/layout.d.ts +0 -105
  186. package/dist/core/ui/properties/layout.js +0 -145
  187. package/dist/core/ui/properties/scrollView.d.ts +0 -105
  188. package/dist/core/ui/properties/scrollView.js +0 -145
  189. package/dist/core/ui/properties/sound.d.ts +0 -47
  190. package/dist/core/ui/properties/sound.js +0 -66
  191. package/dist/core/ui/properties/sprite.d.ts +0 -161
  192. package/dist/core/ui/properties/sprite.js +0 -222
  193. package/dist/core/ui/properties/text.d.ts +0 -135
  194. package/dist/core/ui/properties/text.js +0 -187
  195. package/dist/core/ui/registry/uiSystemRegistry.d.ts +0 -8
  196. package/dist/core/ui/registry/uiSystemRegistry.js +0 -26
  197. package/dist/core/ui/systems/chest.d.ts +0 -4
  198. package/dist/core/ui/systems/chest.js +0 -21
  199. package/dist/core/ui/systems/containerUISystem.d.ts +0 -64
  200. package/dist/core/ui/systems/containerUISystem.js +0 -206
  201. package/dist/core/ui/systems/guidebook.d.ts +0 -8
  202. package/dist/core/ui/systems/guidebook.js +0 -206
  203. package/dist/core/ui/systems/serverForm.d.ts +0 -12
  204. package/dist/core/ui/systems/serverForm.js +0 -116
  205. package/dist/core/ui/systems/system.d.ts +0 -16
  206. package/dist/core/ui/systems/system.js +0 -37
package/dist/cli/load.js DELETED
@@ -1,94 +0,0 @@
1
- import path from "path";
2
- import { saveFile } from "./utils.js";
3
- import { generateBlockTextureJson, generateItemTextureJson } from "./tools/textureSet.js";
4
- import { FlipbookTextures, ItemTextureManager, terrainTextureManager } from "../core/texture.js";
5
- import { writeAddon } from './dev-server/client.js';
6
- /**
7
- * 处理 blocks.json 数据
8
- * @param {Object} data blocks.json 数据
9
- * @returns {Object} 处理后的 blocks 数据
10
- */
11
- export const processBlocksData = (data) => {
12
- const textures_arr = data.textures;
13
- // 检查 textures 数组长度
14
- if (textures_arr.length !== 6) {
15
- console.warn(`blocks.json 的 textures 数组长度不为 6,实际长度: ${textures_arr.length}`);
16
- return {};
17
- }
18
- // 构建 blocks 数据
19
- const blocks = {};
20
- blocks[data.identifier] = {
21
- textures: {
22
- up: textures_arr[0],
23
- down: textures_arr[1],
24
- east: textures_arr[2],
25
- west: textures_arr[3],
26
- south: textures_arr[4],
27
- north: textures_arr[5]
28
- }
29
- };
30
- return blocks;
31
- };
32
- export const generateAddonClient = async (modPath, buildPath, projectName) => {
33
- writeAddon(modPath, buildPath, projectName);
34
- };
35
- /**
36
- * Server
37
- * 加载并执行模组文件
38
- * @param {string} modPath 模组文件路径
39
- * @param {string} buildPath 构建目录路径
40
- * @param {string} projectName 项目名
41
- */
42
- export const generateAddon = (GRegistry, UISystemRegistry) => async (modPath, buildPath, projectName) => {
43
- try {
44
- const buildBehDirPath = path.join(buildPath, `${projectName}_BP`);
45
- const buildResDirPath = path.join(buildPath, `${projectName}_RP`);
46
- const resDir = name => path.join(buildResDirPath, name);
47
- // 初始化 blocks.json 数据
48
- const blocksJsonPath = path.join(buildBehDirPath, "blocks.json");
49
- const blocks = { "format_version": "1.20.20" };
50
- //生成item_texture.json
51
- const item_texture_dir = resDir("textures/items");
52
- const item_texture_json_path = resDir("textures/item_texture.json");
53
- generateItemTextureJson(item_texture_dir, item_texture_json_path, projectName, ItemTextureManager.getItemTextures());
54
- //生成terrain_texture.json
55
- const terrain_texture_dir = resDir("textures/blocks");
56
- const terrain_texture_json_path = resDir("textures/terrain_texture.json");
57
- generateBlockTextureJson(terrain_texture_dir, terrain_texture_json_path, projectName, terrainTextureManager.getTerrainTextures());
58
- //生成flipbook_textures.json
59
- const flipbook_textures_path = resDir("textures/flipbook_textures.json");
60
- saveFile(flipbook_textures_path, JSON.stringify(FlipbookTextures.flipbook_textures, null, 2));
61
- //_ui_defs.json
62
- const ui_def = UISystemRegistry.getUIdefList();
63
- saveFile(resDir("ui/_ui_defs.json"), JSON.stringify({ "ui_defs": ui_def }, null, 2));
64
- UISystemRegistry.getUISystemList().forEach((ui_system) => {
65
- saveFile(resDir(ui_system.path, `${ui_system.name}.json`), JSON.stringify(ui_system.toJson(), null, 2));
66
- });
67
- // 从全局注册表中获取数据
68
- const dataList = GRegistry.getDataList();
69
- // console.log("dataList:", dataList)
70
- // 遍历数据并保存到相应的目录
71
- dataList.forEach(({ name, root, path: dataPath, data }) => {
72
- // 处理 blocks.json 数据
73
- if (dataPath === "blocks/") {
74
- const processedBlocks = processBlocksData(data);
75
- Object.assign(blocks, processedBlocks);
76
- }
77
- // 根据数据类型确定根目录
78
- const rootPath = root === "behavior" ? `${projectName}_BP` : `${projectName}_RP`;
79
- const buildRootPath = path.join(buildPath, rootPath);
80
- // 拼接文件路径
81
- const filePath = path.join(buildRootPath, dataPath, `${name}.json`);
82
- // 保存文件
83
- saveFile(filePath, JSON.stringify(data.toJson(), null, 2));
84
- });
85
- // 保存 blocks.json
86
- console.log("保存 blocks.json 文件:", blocksJsonPath);
87
- saveFile(blocksJsonPath, JSON.stringify(blocks, null, 2));
88
- console.log(`已加载并执行 ${modPath} 文件!`);
89
- }
90
- catch (err) {
91
- console.error(`加载或执行 ${modPath} 失败:${err.message}`);
92
- console.error(err.stack); // 打印堆栈跟踪以便调试
93
- }
94
- };
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/cli/start.js DELETED
@@ -1,156 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program } from 'commander';
3
- import inquirer from 'inquirer';
4
- import path from 'path';
5
- import os from 'os';
6
- import { initMojangPath, initNPMProject, initProject, readPackageJson } from './init.js';
7
- import { buildProject, projectCanBuild } from './build.js';
8
- import { readFile } from "./utils.js";
9
- import fs from "fs";
10
- import { fileURLToPath } from "url";
11
- import { writeLib } from './dev-server/syncFiles.js';
12
- const __filename = fileURLToPath(import.meta.url);
13
- const __dirname = path.dirname(__filename);
14
- process.removeAllListeners('warning');
15
- function start() {
16
- // 额外添加的init方法
17
- program.command("init").description("初始化一个基于NodeJS的项目").action(() => {
18
- const currentDir = process.cwd();
19
- const packageJsonPath = path.join(currentDir, 'package.json');
20
- let packageJsonData;
21
- if (!fs.existsSync(packageJsonPath)) {
22
- console.error("没有找到package.json文件,请使改用create命令进行创建。");
23
- return;
24
- }
25
- try {
26
- packageJsonData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
27
- }
28
- catch (error) {
29
- console.error("读取package.json文件时出错:", error);
30
- console.log("请使改用create命令进行创建。");
31
- return;
32
- }
33
- // 添加或更新scripts字段
34
- packageJsonData.scripts = {
35
- ...packageJsonData.scripts,
36
- init: "sapdon init",
37
- pack: "sapdon pack",
38
- config: "sapdon config"
39
- };
40
- try {
41
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonData, null, 2), 'utf-8');
42
- }
43
- catch (error) {
44
- console.error("写入package.json文件时出错:", error);
45
- return;
46
- }
47
- inquirer.prompt([
48
- {
49
- type: "input",
50
- name: "min_engine_version",
51
- message: "最低引擎版本:",
52
- default: "1.19.50"
53
- }
54
- ]).then((answers) => {
55
- initNPMProject(currentDir, { ...readPackageJson(currentDir), ...answers });
56
- console.log("请使用命令sapdon config配置框架的build.config文件。");
57
- });
58
- });
59
- program.command("create <project-name>").description("Create a new project").action((projectName) => {
60
- inquirer.prompt([
61
- {
62
- type: "input",
63
- name: "name",
64
- message: "Project Name:",
65
- default: path.basename(projectName)
66
- },
67
- {
68
- type: "input",
69
- name: "description",
70
- message: "Project Description:",
71
- default: "A new sapdon project"
72
- },
73
- {
74
- type: "input",
75
- name: "author",
76
- message: "Author Name:",
77
- default: "Sapdon"
78
- },
79
- {
80
- type: "input",
81
- name: "version",
82
- message: "Project Version:",
83
- default: "1.0.0"
84
- },
85
- {
86
- type: "input",
87
- name: "min_engine_version",
88
- message: "Minimum Engine Version:",
89
- default: "1.19.50",
90
- },
91
- {
92
- type: "input",
93
- name: "language",
94
- message: "Language:(js/ts)",
95
- default: "ts",
96
- },
97
- ]).then((answers) => {
98
- const projectPath = path.join(process.cwd(), projectName);
99
- console.log('项目路径:', projectPath);
100
- initProject(projectPath, answers);
101
- initMojangPath(projectPath);
102
- writeLib(projectPath);
103
- });
104
- });
105
- program.command("build <project-name>").description("Build the project").action((projectName) => {
106
- console.log("Building the project...");
107
- const projectPath = path.join(process.cwd(), projectName);
108
- if (projectCanBuild(projectPath)) {
109
- buildProject(projectPath, path.basename(projectPath));
110
- }
111
- });
112
- // pack 命令
113
- program.command("pack").description("Pack the current project").action(() => {
114
- console.log("Packing the current project...");
115
- const projectPath = process.cwd();
116
- if (projectCanBuild(projectPath)) {
117
- buildProject(projectPath, path.basename(projectPath));
118
- }
119
- });
120
- // 配置build.config文件的命令
121
- program.command("config").description("Configure build.config file").action(() => {
122
- const buildConfigPath = path.join(__dirname, "./build.config");
123
- let buildConfigData;
124
- try {
125
- buildConfigData = JSON.parse(readFile(buildConfigPath));
126
- }
127
- catch (error) {
128
- console.error("读取build.config文件时出错:", error);
129
- return;
130
- }
131
- inquirer.prompt([
132
- {
133
- type: "input",
134
- name: "mojangPath",
135
- message: "Mojang Path (must end with LocalState/games/com.mojang/):",
136
- default: path.join(os.homedir(), "AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/")
137
- },
138
- {
139
- type: "input",
140
- name: "mojangBetaPath",
141
- message: "Mojang Beta Path (must end with LocalState/games/com.mojang/):",
142
- default: path.join(os.homedir(), "AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/")
143
- }
144
- ]).then((answers) => {
145
- try {
146
- fs.writeFileSync(buildConfigPath, JSON.stringify({ ...buildConfigData, ...answers }, null, 2), 'utf-8');
147
- console.log("build.config文件已更新。");
148
- }
149
- catch (error) {
150
- console.error("写入build.config文件时出错:", error);
151
- }
152
- });
153
- });
154
- program.parse(program.argv);
155
- }
156
- start();
@@ -1,13 +0,0 @@
1
- /**
2
- * 生成 block_texture.json 文件
3
- * @param {string} itemTexturesPath - 包含 PNG 文件的根目录
4
- * @param {string} outputPath - 输出的 JSON 文件路径
5
- * @param {string} projectName - 项目名称
6
- */
7
- export function generateBlockTextureJson(itemTexturesPath: string, outputPath: string, projectName: string, userTerrainTextures: any): Promise<void>;
8
- /**
9
- * 生成 item_texture.json 文件
10
- * @param {string} itemTexturesPath - 包含 PNG 文件的根目录
11
- * @param {string} outputPath - 输出的 JSON 文件路径
12
- */
13
- export function generateItemTextureJson(itemTexturesPath: string, outputPath: string, projectName: any, userItemTextures: any): Promise<void>;
@@ -1,103 +0,0 @@
1
- import fs from "fs/promises";
2
- import path from "path";
3
- /**
4
- * 递归遍历目录,收集所有 PNG 文件的路径
5
- * @param {string} directory - 要遍历的目录
6
- * @param {string} basePath - 基础路径(用于计算相对路径)
7
- * @param {string} prefix - 路径前缀(如 "textures/items/")
8
- * @returns {Promise<Object>} - 返回一个对象,键为文件名,值为相对路径(不带 .png 后缀)
9
- */
10
- const traverseDirectory = async (directory, basePath, prefix = "") => {
11
- const texturesSet = {};
12
- const files = await fs.readdir(directory);
13
- for (const file of files) {
14
- const filePath = path.join(directory, file);
15
- const fileStats = await fs.stat(filePath);
16
- if (fileStats.isDirectory()) {
17
- // 如果是目录,递归遍历
18
- const subDirectoryTextures = await traverseDirectory(filePath, basePath, prefix);
19
- Object.assign(texturesSet, subDirectoryTextures);
20
- }
21
- else if (file.endsWith(".png")) {
22
- // 如果是 PNG 文件,提取文件名并生成 texture_data
23
- const fileName = path.basename(file, ".png"); // 去掉 .png 后缀
24
- const relativePath = path.relative(basePath, filePath).replace(/\.png$/, ""); // 去掉 .png 后缀
25
- const normalizedPath = `${prefix}${relativePath.replace(/\\/g, "/")}`; // 确保路径使用正斜杠
26
- texturesSet[fileName] = {
27
- textures: normalizedPath,
28
- };
29
- }
30
- }
31
- return texturesSet;
32
- };
33
- /**
34
- * 生成 JSON 文件
35
- * @param {string} outputPath - 输出的 JSON 文件路径
36
- * @param {Object} jsonData - 要写入的 JSON 数据
37
- * @param {string} successMessage - 成功时的日志消息
38
- */
39
- const generateJsonFile = async (outputPath, jsonData, successMessage) => {
40
- try {
41
- const jsonString = JSON.stringify(jsonData, null, 2);
42
- await fs.writeFile(outputPath, jsonString);
43
- console.log(successMessage);
44
- }
45
- catch (err) {
46
- console.error("Error writing JSON file:", err);
47
- }
48
- };
49
- /**
50
- * 生成 block_texture.json 文件
51
- * @param {string} itemTexturesPath - 包含 PNG 文件的根目录
52
- * @param {string} outputPath - 输出的 JSON 文件路径
53
- * @param {string} projectName - 项目名称
54
- */
55
- export async function generateBlockTextureJson(itemTexturesPath, outputPath, projectName, userTerrainTextures) {
56
- try {
57
- // 递归遍历目录,获取所有 PNG 文件的路径
58
- const itemTexturesSet = await traverseDirectory(itemTexturesPath, itemTexturesPath, "textures/blocks/");
59
- // 合并用户自定义的texture_data
60
- if (userTerrainTextures) {
61
- Object.assign(itemTexturesSet, userTerrainTextures);
62
- }
63
- // 生成 JSON 数据
64
- const jsonData = {
65
- texture_name: "atlas.terrain",
66
- resource_pack_name: projectName,
67
- padding: 8,
68
- num_mip_levels: 4,
69
- texture_data: itemTexturesSet,
70
- };
71
- // 写入文件
72
- await generateJsonFile(outputPath, jsonData, "Block texture JSON file generated successfully.");
73
- }
74
- catch (err) {
75
- console.error("Error generating block texture JSON:", err);
76
- }
77
- }
78
- /**
79
- * 生成 item_texture.json 文件
80
- * @param {string} itemTexturesPath - 包含 PNG 文件的根目录
81
- * @param {string} outputPath - 输出的 JSON 文件路径
82
- */
83
- export async function generateItemTextureJson(itemTexturesPath, outputPath, projectName, userItemTextures) {
84
- try {
85
- // 递归遍历目录,获取所有 PNG 文件的路径
86
- const itemTexturesSet = await traverseDirectory(itemTexturesPath, itemTexturesPath, "textures/items/");
87
- // 合并用户自定义的texture_data
88
- if (userItemTextures) {
89
- Object.assign(itemTexturesSet, userItemTextures);
90
- }
91
- // 生成 JSON 数据
92
- const jsonData = {
93
- resource_pack_name: projectName,
94
- texture_name: "atlas.items",
95
- texture_data: itemTexturesSet,
96
- };
97
- // 写入文件
98
- await generateJsonFile(outputPath, jsonData, "Item texture JSON file generated successfully.");
99
- }
100
- catch (err) {
101
- console.error("Error generating item texture JSON:", err);
102
- }
103
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * 同步复制文件
3
- * @param {string} src 源文件路径
4
- * @param {string} dest 目标文件路径
5
- */
6
- export function copyFileSync(src: string, dest: string): void;
7
- export function dirname(importMeta: any): string;
8
- export function asyncImport(path: any): Promise<any>;
9
- export function generateUUID(): `${string}-${string}-${string}-${string}-${string}`;
10
- export function pathNotExist(filePath: any): boolean;
11
- export function readFile(filePath: any): string;
12
- export function saveFile(filePath: string, data: string): void;
13
- export function copyFolder(sourcePath: any, destinationPath: any): void;
package/dist/cli/utils.js DELETED
@@ -1,89 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { randomUUID } from "crypto";
4
- import { fileURLToPath } from "node:url";
5
- export const generateUUID = () => {
6
- return randomUUID();
7
- };
8
- /**
9
- * 同步复制文件
10
- * @param {string} src 源文件路径
11
- * @param {string} dest 目标文件路径
12
- */
13
- export function copyFileSync(src, dest) {
14
- try {
15
- fs.copyFileSync(src, dest);
16
- }
17
- catch (err) {
18
- console.error("文件复制失败:", err);
19
- }
20
- }
21
- //检查路径
22
- export const pathNotExist = filePath => {
23
- return !fs.existsSync(filePath);
24
- };
25
- //读取文件
26
- export const readFile = filePath => {
27
- try {
28
- return fs.readFileSync(filePath, "utf8");
29
- }
30
- catch (error) {
31
- console.log(error);
32
- }
33
- return null;
34
- };
35
- /**
36
- * 保存文件
37
- * @param {string} filePath 绝对路径
38
- * @param {string} data 数据
39
- */
40
- export const saveFile = (filePath, data) => {
41
- // 确保目录存在
42
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
43
- // 创建文件并写入内容
44
- fs.writeFile(filePath, data, err => {
45
- if (err) {
46
- return console.error(err);
47
- }
48
- });
49
- };
50
- export const copyFolder = (sourcePath, destinationPath) => {
51
- // 确保目录存在
52
- fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
53
- // 检查源路径是否存在
54
- if (!fs.existsSync(sourcePath)) {
55
- console.log(`Source path ${sourcePath} does not exist.`);
56
- return;
57
- }
58
- // 检查目标路径是否存在,如果不存在则创建它
59
- if (!fs.existsSync(destinationPath)) {
60
- fs.mkdirSync(destinationPath);
61
- }
62
- // 获取源路径下的所有文件和文件夹
63
- const files = fs.readdirSync(sourcePath);
64
- // 遍历文件和文件夹
65
- files.forEach(file => {
66
- const sourceFile = path.join(sourcePath, file);
67
- const destinationFile = path.join(destinationPath, file);
68
- // 判断是文件还是文件夹
69
- if (fs.lstatSync(sourceFile).isDirectory()) {
70
- // 如果是文件夹,则递归调用copyFolder函数
71
- copyFolder(sourceFile, destinationFile);
72
- }
73
- else {
74
- // 如果是文件,则直接复制到目标路径
75
- fs.copyFileSync(sourceFile, destinationFile);
76
- }
77
- });
78
- };
79
- export function dirname(importMeta) {
80
- const __filename = fileURLToPath(importMeta.url);
81
- const __dirname = path.dirname(__filename);
82
- return __dirname;
83
- }
84
- export function asyncImport(path) {
85
- if (!path.startsWith('.')) {
86
- return import('file://' + path);
87
- }
88
- return import(path);
89
- }
@@ -1,22 +0,0 @@
1
- export class AddonBiome {
2
- constructor(format_version: any, definition: any);
3
- format_version: any;
4
- definition: any;
5
- toJson(): {
6
- format_version: any;
7
- "minecraft:biome": any;
8
- };
9
- }
10
- export class AddonBiomeDescription {
11
- constructor(identifier: any);
12
- identifier: any;
13
- }
14
- export class AddonBiomeDefinition {
15
- /**
16
- *
17
- * @param {AddonBiomeDescription} description
18
- */
19
- constructor(description: AddonBiomeDescription, components: any);
20
- description: AddonBiomeDescription;
21
- components: any;
22
- }
@@ -1,27 +0,0 @@
1
- export class AddonBiome {
2
- constructor(format_version, definition) {
3
- this.format_version = format_version;
4
- this.definition = definition;
5
- }
6
- toJson() {
7
- return {
8
- format_version: this.format_version,
9
- ["minecraft:biome"]: this.definition
10
- };
11
- }
12
- }
13
- export class AddonBiomeDescription {
14
- constructor(identifier) {
15
- this.identifier = identifier;
16
- }
17
- }
18
- export class AddonBiomeDefinition {
19
- /**
20
- *
21
- * @param {AddonBiomeDescription} description
22
- */
23
- constructor(description, components) {
24
- this.description = description;
25
- this.components = components;
26
- }
27
- }
@@ -1,41 +0,0 @@
1
- export class AddonBlock {
2
- /**
3
- * Addon方块类
4
- * @param {string} format_version 格式版本
5
- * @param {AddonBlockDefinition} definitions 方块定义
6
- */
7
- constructor(format_version: string, definitions: AddonBlockDefinition);
8
- format_version: string;
9
- definitions: AddonBlockDefinition;
10
- toJson(): {
11
- format_version: string;
12
- "minecraft:block": AddonBlockDefinition;
13
- };
14
- }
15
- export class AddonBlockDefinition {
16
- /**
17
- * 方块定义类
18
- * @param {AddonBlockDescription} description 方块描述
19
- * @param {Object} components 方块组件
20
- * @param {Array} permutations 方块变体
21
- */
22
- constructor(description: AddonBlockDescription, components: any, permutations?: any[]);
23
- description: AddonBlockDescription;
24
- components: any;
25
- permutations: any[];
26
- }
27
- export class AddonBlockDescription {
28
- /**
29
- * 方块描述类
30
- * @param {string} identifier 唯一标识符
31
- * @param {map} traits 方块特性
32
- * @param {map} states 方块状态
33
- * @param {AddonMenuCategory} menu_category
34
- */
35
- constructor(identifier: string, traits: map, states: map, menu_category: AddonMenuCategory);
36
- identifier: string;
37
- traits: map;
38
- states: map;
39
- menu_category: AddonMenuCategory;
40
- }
41
- import { AddonMenuCategory } from "../menuCategory.js";
@@ -1,46 +0,0 @@
1
- import { AddonMenuCategory } from "../menuCategory.js";
2
- export class AddonBlock {
3
- /**
4
- * Addon方块类
5
- * @param {string} format_version 格式版本
6
- * @param {AddonBlockDefinition} definitions 方块定义
7
- */
8
- constructor(format_version, definitions) {
9
- this.format_version = format_version;
10
- this.definitions = definitions;
11
- }
12
- toJson() {
13
- return {
14
- format_version: this.format_version,
15
- ["minecraft:block"]: this.definitions
16
- };
17
- }
18
- }
19
- export class AddonBlockDefinition {
20
- /**
21
- * 方块定义类
22
- * @param {AddonBlockDescription} description 方块描述
23
- * @param {Object} components 方块组件
24
- * @param {Array} permutations 方块变体
25
- */
26
- constructor(description, components, permutations = []) {
27
- this.description = description;
28
- this.components = components;
29
- this.permutations = permutations;
30
- }
31
- }
32
- export class AddonBlockDescription {
33
- /**
34
- * 方块描述类
35
- * @param {string} identifier 唯一标识符
36
- * @param {map} traits 方块特性
37
- * @param {map} states 方块状态
38
- * @param {AddonMenuCategory} menu_category
39
- */
40
- constructor(identifier, traits, states, menu_category) {
41
- this.identifier = identifier;
42
- this.traits = traits;
43
- this.states = states;
44
- this.menu_category = menu_category;
45
- }
46
- }
@@ -1,43 +0,0 @@
1
- export class AddonAnimationController {
2
- constructor(format_version: any, definition: any);
3
- format_version: any;
4
- definition: any;
5
- toJson(): {
6
- format_version: any;
7
- animation_controllers: any;
8
- };
9
- }
10
- export class AddonAnimationStateMachine {
11
- constructor(identifier: any);
12
- identifier: any;
13
- namespace: any;
14
- name: any;
15
- initialState: string;
16
- states: Map<any, any>;
17
- /**
18
- * 设置状态机的初始状态。
19
- * @param {string} stateName - 初始状态的名称。
20
- * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
21
- */
22
- setInitialState(stateName: string): AddonAnimationStateMachine;
23
- /**
24
- * 添加一个新状态到状态机。
25
- * @param {string} stateName - 状态的名称。
26
- * @param {string[]} animations - 该状态播放的动画列表。
27
- * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
28
- */
29
- addState(stateName: string, animations?: string[]): AddonAnimationStateMachine;
30
- /**
31
- * 添加一个状态之间的过渡条件。
32
- * @param {string} fromState - 过渡的起始状态名称。
33
- * @param {string} toState - 过渡的目标状态名称。
34
- * @param {string} condition - 触发过渡的条件(例如 "q.is_on_ground")。
35
- * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
36
- */
37
- addTransition(fromState: string, toState: string, condition: string): AddonAnimationStateMachine;
38
- /**
39
- * 将整个状态机转换为 JSON 兼容的对象。
40
- * @returns {object} - 包含格式版本的完整动画控制器定义。
41
- */
42
- toJson(): object;
43
- }