@ives_xxz/packages 1.0.3 → 1.0.5
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.
- package/FWLayerGenerator/main.js +134 -133
- package/FWMultiSkin/main.js +1 -1
- package/package.json +1 -1
package/FWLayerGenerator/main.js
CHANGED
|
@@ -2,18 +2,15 @@ const Path = require('path');
|
|
|
2
2
|
const Fs = require('fs');
|
|
3
3
|
|
|
4
4
|
function capitalize(str) {
|
|
5
|
-
|
|
5
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
// 生成Layer类模板
|
|
9
|
-
function generateLayerTemplate(bundleName, featureName,subDir) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const { ccclass, property } = cc._decorator;
|
|
14
|
-
|
|
9
|
+
function generateLayerTemplate(bundleName, featureName, subDir) {
|
|
10
|
+
const className = `${capitalize(bundleName)}${capitalize(featureName)}Layer`;
|
|
11
|
+
return `const { ccclass, property } = cc._decorator;
|
|
15
12
|
@ccclass
|
|
16
|
-
export default class ${className} extends
|
|
13
|
+
export default class ${className} extends FW.Layer {
|
|
17
14
|
public onLoad(): void {
|
|
18
15
|
super.onLoad();
|
|
19
16
|
}
|
|
@@ -35,20 +32,21 @@ function generateLayerTemplate(bundleName, featureName,subDir) {
|
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
}`;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
import {
|
|
46
|
-
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 生成LayerController类模板
|
|
38
|
+
function generateControllerTemplate(bundleName, featureName, subDir) {
|
|
39
|
+
const className = `${capitalize(bundleName)}${capitalize(featureName)}LayerController`;
|
|
40
|
+
const layerClassName = `${capitalize(bundleName)}${capitalize(featureName)}Layer`;
|
|
41
|
+
return `
|
|
42
|
+
import ${layerClassName} from '../${subDir ? `../` : ''}layer/${
|
|
43
|
+
subDir ? `${subDir}/` : ''
|
|
44
|
+
}${layerClassName}';
|
|
47
45
|
|
|
48
|
-
export class ${className} extends
|
|
49
|
-
public renderOrder: number;
|
|
46
|
+
export class ${className} extends FW.LayerController {
|
|
47
|
+
public renderOrder: number = FW.SystemDefine.RenderOrder.PERMANENT;
|
|
50
48
|
public layer: ${layerClassName};
|
|
51
|
-
public layerType:
|
|
49
|
+
public layerType: FW.SystemDefine.FWLayerType = FW.SystemDefine.FWLayerType.POPUP_DISPOSABLE;
|
|
52
50
|
public get layerAssetProperty(): FW.AssetProperty {
|
|
53
51
|
return;
|
|
54
52
|
}
|
|
@@ -62,125 +60,128 @@ function generateLayerTemplate(bundleName, featureName,subDir) {
|
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
module.exports = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Editor.Panel.open('layer-generator');
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
'generate-files'(event, params) {
|
|
73
|
-
try{
|
|
74
|
-
const { bundleName, featureName ,subDir} = params;
|
|
75
|
-
const assetsPath = Path.join(Editor.Project.path, 'assets');
|
|
76
|
-
const bundleRootPath = Path.join(assetsPath, 'bundle');
|
|
77
|
-
// 递归查找bundle
|
|
78
|
-
function findBundlePath(dirPath) {
|
|
79
|
-
const items = Fs.readdirSync(dirPath);
|
|
80
|
-
for (const item of items) {
|
|
81
|
-
const fullPath = Path.join(dirPath, item);
|
|
82
|
-
const stats = Fs.statSync(fullPath);
|
|
83
|
-
|
|
84
|
-
if (stats.isDirectory()) {
|
|
85
|
-
// 检查是否是同名文件夹
|
|
86
|
-
if (Path.basename(fullPath) === bundleName) {
|
|
87
|
-
// 检查是否配置为bundle
|
|
88
|
-
const metaPath = `${fullPath}.meta`;
|
|
89
|
-
if (Fs.existsSync(metaPath)) {
|
|
90
|
-
try {
|
|
91
|
-
const metaContent = Fs.readFileSync(metaPath, 'utf8');
|
|
92
|
-
if (metaContent.includes('"isBundle": true')) {
|
|
93
|
-
return fullPath;
|
|
94
|
-
}
|
|
95
|
-
} catch (err) {
|
|
96
|
-
// 读取meta文件失败,继续搜索
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// 递归搜索子目录
|
|
102
|
-
const foundPath = findBundlePath(fullPath);
|
|
103
|
-
if (foundPath) {
|
|
104
|
-
return foundPath;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const bundlePath = findBundlePath(bundleRootPath);
|
|
112
|
-
|
|
113
|
-
if (!bundlePath) {
|
|
114
|
-
Editor.error(`Cannot find bundle "${bundleName}" or it is not configured as a bundle!`);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
63
|
+
messages: {
|
|
64
|
+
'create-layer'() {
|
|
65
|
+
Editor.Panel.open('layer-generator');
|
|
66
|
+
},
|
|
117
67
|
|
|
68
|
+
'generate-files'(event, params) {
|
|
69
|
+
try {
|
|
70
|
+
const { bundleName, featureName, subDir } = params;
|
|
71
|
+
const assetsPath = Path.join(Editor.Project.path, 'assets');
|
|
72
|
+
const bundleRootPath = Path.join(assetsPath, 'bundle');
|
|
73
|
+
// 递归查找bundle
|
|
74
|
+
function findBundlePath(dirPath) {
|
|
75
|
+
const items = Fs.readdirSync(dirPath);
|
|
76
|
+
for (const item of items) {
|
|
77
|
+
const fullPath = Path.join(dirPath, item);
|
|
78
|
+
const stats = Fs.statSync(fullPath);
|
|
118
79
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
dirs.forEach(dir => {
|
|
130
|
-
if (!Fs.existsSync(dir)) {
|
|
131
|
-
Fs.mkdirSync(dir, { recursive: true });
|
|
80
|
+
if (stats.isDirectory()) {
|
|
81
|
+
// 检查是否是同名文件夹
|
|
82
|
+
if (Path.basename(fullPath) === bundleName) {
|
|
83
|
+
// 检查是否配置为bundle
|
|
84
|
+
const metaPath = `${fullPath}.meta`;
|
|
85
|
+
if (Fs.existsSync(metaPath)) {
|
|
86
|
+
try {
|
|
87
|
+
const metaContent = Fs.readFileSync(metaPath, 'utf8');
|
|
88
|
+
if (metaContent.includes('"isBundle": true')) {
|
|
89
|
+
return fullPath;
|
|
132
90
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// const prefabPath = Path.join( prefabDir, `${capitalize(bundleName)}${capitalize(featureName)}Layer.prefab`);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.refreshAssetDB(layerDir);
|
|
149
|
-
this.refreshAssetDB(controllerDir);
|
|
150
|
-
}
|
|
151
|
-
catch(err){
|
|
152
|
-
Editor.error("生成Layer失败:",err);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
// 读取meta文件失败,继续搜索
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// 递归搜索子目录
|
|
98
|
+
const foundPath = findBundlePath(fullPath);
|
|
99
|
+
if (foundPath) {
|
|
100
|
+
return foundPath;
|
|
101
|
+
}
|
|
153
102
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// Editor.Scene.callSceneScript('layer-generator', 'create-node', {
|
|
158
|
-
// name: `${capitalize(bundleName)}${capitalize(featureName)}Layer`,
|
|
159
|
-
// prefabPath: prefabPath,
|
|
160
|
-
// scriptName: `${capitalize(bundleName)}${capitalize(featureName)}Layer`
|
|
161
|
-
// }, (err, nodeUuid) => {
|
|
162
|
-
// if (err) {
|
|
163
|
-
// Editor.error('创建Layer失败:', err);
|
|
164
|
-
// return;
|
|
165
|
-
// }
|
|
166
|
-
// Editor.success('Layer files generated successfully!');
|
|
167
|
-
// });
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
168
106
|
|
|
107
|
+
const bundlePath = findBundlePath(bundleRootPath);
|
|
169
108
|
|
|
109
|
+
if (!bundlePath) {
|
|
110
|
+
Editor.error(`Cannot find bundle "${bundleName}" or it is not configured as a bundle!`);
|
|
111
|
+
return;
|
|
170
112
|
}
|
|
171
|
-
},
|
|
172
113
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
114
|
+
const layerDir = Path.join(bundlePath, `script/layer${subDir ? `/${subDir}` : ''}`);
|
|
115
|
+
const controllerDir = Path.join(
|
|
116
|
+
bundlePath,
|
|
117
|
+
`script/controller${subDir ? `/${subDir}` : ''}`
|
|
118
|
+
);
|
|
119
|
+
const prefabDir = Path.join(bundlePath, `res/prefab/layer${subDir ? `/${subDir}` : ''}`);
|
|
120
|
+
// 创建必要的目录
|
|
121
|
+
const dirs = [
|
|
122
|
+
layerDir,
|
|
123
|
+
controllerDir,
|
|
124
|
+
// prefabDir
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
dirs.forEach((dir) => {
|
|
128
|
+
if (!Fs.existsSync(dir)) {
|
|
129
|
+
Fs.mkdirSync(dir, { recursive: true });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// 生成Layer类文件
|
|
134
|
+
const layerPath = Path.join(
|
|
135
|
+
layerDir,
|
|
136
|
+
`${capitalize(bundleName)}${capitalize(featureName)}Layer.ts`
|
|
137
|
+
);
|
|
138
|
+
Fs.writeFileSync(layerPath, generateLayerTemplate(bundleName, featureName, subDir));
|
|
139
|
+
|
|
140
|
+
// 生成Controller类文件
|
|
141
|
+
const controllerPath = Path.join(
|
|
142
|
+
controllerDir,
|
|
143
|
+
`${capitalize(bundleName)}${capitalize(featureName)}LayerController.ts`
|
|
144
|
+
);
|
|
145
|
+
Fs.writeFileSync(
|
|
146
|
+
controllerPath,
|
|
147
|
+
generateControllerTemplate(bundleName, featureName, subDir)
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
// 创建预制体路径
|
|
151
|
+
// const prefabPath = Path.join( prefabDir, `${capitalize(bundleName)}${capitalize(featureName)}Layer.prefab`);
|
|
152
|
+
|
|
153
|
+
this.refreshAssetDB(layerDir);
|
|
154
|
+
this.refreshAssetDB(controllerDir);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
Editor.error('生成Layer失败:', err);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// // 在场景中创建节点
|
|
160
|
+
// Editor.Scene.callSceneScript('layer-generator', 'create-node', {
|
|
161
|
+
// name: `${capitalize(bundleName)}${capitalize(featureName)}Layer`,
|
|
162
|
+
// prefabPath: prefabPath,
|
|
163
|
+
// scriptName: `${capitalize(bundleName)}${capitalize(featureName)}Layer`
|
|
164
|
+
// }, (err, nodeUuid) => {
|
|
165
|
+
// if (err) {
|
|
166
|
+
// Editor.error('创建Layer失败:', err);
|
|
167
|
+
// return;
|
|
168
|
+
// }
|
|
169
|
+
// Editor.success('Layer files generated successfully!');
|
|
170
|
+
// });
|
|
185
171
|
},
|
|
186
|
-
}
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
refreshAssetDB(outputBase) {
|
|
175
|
+
const relativePath = Path.relative(Editor.Project.path, outputBase);
|
|
176
|
+
|
|
177
|
+
const url = 'db://' + relativePath.replace(/\\/g, '/');
|
|
178
|
+
|
|
179
|
+
Editor.assetdb.refresh(url, (err) => {
|
|
180
|
+
if (err) {
|
|
181
|
+
Editor.error(`刷新资源失败: ${err}`);
|
|
182
|
+
} else {
|
|
183
|
+
Editor.log(`已刷新目录: ${url}`);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
};
|
package/FWMultiSkin/main.js
CHANGED