first commit
This commit is contained in:
31
extensions/app/engine/dist/panel/components/app-create.js
vendored
Normal file
31
extensions/app/engine/dist/panel/components/app-create.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = require("fs");
|
||||
const path_1 = require("path");
|
||||
const vue_1 = __importDefault(require("../../../../vue"));
|
||||
const create_controller_1 = __importDefault(require("./create-controller"));
|
||||
const create_manager_1 = __importDefault(require("./create-manager"));
|
||||
const create_model_1 = __importDefault(require("./create-model"));
|
||||
const create_res_1 = __importDefault(require("./create-res"));
|
||||
const create_sound_1 = __importDefault(require("./create-sound"));
|
||||
const create_view_1 = __importDefault(require("./create-view"));
|
||||
const Assets = path_1.join(__dirname, '../../../res/panel');
|
||||
const Menus = ['ViewComponent', 'ManagerComponent', 'ControllerComponent', 'ModelComponent', 'SoundComponent', 'ResComponent'];
|
||||
exports.default = vue_1.default.extend({
|
||||
components: { ViewComponent: create_view_1.default, ManagerComponent: create_manager_1.default, ControllerComponent: create_controller_1.default, ModelComponent: create_model_1.default, SoundComponent: create_sound_1.default, ResComponent: create_res_1.default },
|
||||
template: fs_1.readFileSync(path_1.join(Assets, 'components/app.html'), 'utf-8'),
|
||||
data() {
|
||||
return {
|
||||
menus: ['View', 'Manager', 'Controller', 'Model', 'Sound', '资源目录'],
|
||||
content: 'ViewComponent'
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onClick(index) {
|
||||
this.content = Menus[index];
|
||||
}
|
||||
},
|
||||
});
|
||||
31
extensions/app/engine/dist/panel/components/app.js
vendored
Normal file
31
extensions/app/engine/dist/panel/components/app.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = require("fs");
|
||||
const path_1 = require("path");
|
||||
const vue_1 = __importDefault(require("../../../../vue"));
|
||||
const create_controller_1 = __importDefault(require("./create-controller"));
|
||||
const create_manager_1 = __importDefault(require("./create-manager"));
|
||||
const create_model_1 = __importDefault(require("./create-model"));
|
||||
const create_res_1 = __importDefault(require("./create-res"));
|
||||
const create_sound_1 = __importDefault(require("./create-sound"));
|
||||
const create_view_1 = __importDefault(require("./create-view"));
|
||||
const Assets = path_1.join(__dirname, '../../../res/panel');
|
||||
const Menus = ['ViewComponent', 'ManagerComponent', 'ControllerComponent', 'ModelComponent', 'SoundComponent', 'ResComponent'];
|
||||
exports.default = vue_1.default.extend({
|
||||
components: { ViewComponent: create_view_1.default, ManagerComponent: create_manager_1.default, ControllerComponent: create_controller_1.default, ModelComponent: create_model_1.default, SoundComponent: create_sound_1.default, ResComponent: create_res_1.default },
|
||||
template: fs_1.readFileSync(path_1.join(Assets, 'components/app.html'), 'utf-8'),
|
||||
data() {
|
||||
return {
|
||||
menus: ['View', 'Manager', 'Controller', 'Model', 'Sound', '资源目录'],
|
||||
content: 'ViewComponent'
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onClick(index) {
|
||||
this.content = Menus[index];
|
||||
}
|
||||
},
|
||||
});
|
||||
83
extensions/app/engine/dist/panel/components/create-controller.js
vendored
Normal file
83
extensions/app/engine/dist/panel/components/create-controller.js
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = require("fs");
|
||||
const vue_1 = __importDefault(require("../../../../vue"));
|
||||
const utils_1 = require("../../utils");
|
||||
/**
|
||||
* 根据语言获取脚本内容
|
||||
*/
|
||||
function getScript(name) {
|
||||
const basePath = '../../../extensions/app/assets/base/BaseController';
|
||||
return 'import BaseController from \'' + basePath + '\';\r\n' +
|
||||
'export class ' + name + ' extends BaseController<' + name + ', {\r\n' +
|
||||
' // 定义了事件,并同时定义参数列表和返回值\r\n' +
|
||||
' Refresh: (a: number) => boolean\r\n' +
|
||||
'}>() {\r\n' +
|
||||
' // Controller中发射事件, UI中监听事件:\r\n' +
|
||||
' // 1、UI中需要将 「extends BaseView」 改为=> 「extends BaseView.bindController(' + name + ')」\r\n' +
|
||||
' // 2、UI中使用「this.controller.on/once」监听事件, 使用「this.controller.emit」发射事件, 使用「this.controller.off/targetOff」取消监听事件\r\n' +
|
||||
' // 3、在外部(无法使用this.controller的地方)可以通过「app.controller.xxx」来调用对外导出的方法, 比如下面的refresh方法\r\n' +
|
||||
' refresh() {\r\n' +
|
||||
' this.emit(' + name + '.Event.Refresh, 1000); // 参数类型正确\r\n' +
|
||||
' this.emit(' + name + '.Event.Refresh, true); // 参数类型错误\r\n' +
|
||||
' const result = this.call(' + name + '.Event.Refresh, 1000); // 自动推导返回值类型\r\n' +
|
||||
' }\r\n' +
|
||||
'}';
|
||||
}
|
||||
exports.default = vue_1.default.extend({
|
||||
template: utils_1.getResPanel('create-controller'),
|
||||
data() {
|
||||
return {
|
||||
inputName: '',
|
||||
display: '',
|
||||
showLoading: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async onClickCreate() {
|
||||
const name = this.inputName;
|
||||
if (/^[a-z][a-z0-9-]*[a-z0-9]+$/.test(name) === false) {
|
||||
this.display = '[错误] 名字不合法\n1、不能以数字开头\n2、不能有大写字母\n3、分隔符只能使用-\n4、不能以分隔符开头或结尾';
|
||||
return;
|
||||
}
|
||||
const rootPath = 'db://assets/app-builtin/app-controller';
|
||||
const controlName = `${utils_1.stringCase(name)}Controller`;
|
||||
const scriptUrl = `${rootPath}/${controlName}.ts`;
|
||||
// 创建前确认
|
||||
const createResponse = await Editor.Dialog.info('请确认', { detail: controlName, buttons: ['创建并打开', '仅创建', '取消'], default: 0, cancel: 2 });
|
||||
if (createResponse.response == 2) {
|
||||
return;
|
||||
}
|
||||
this.display = '创建中';
|
||||
this.showLoading = true;
|
||||
if (fs_1.existsSync(utils_1.convertUrlToPath(scriptUrl))) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 文件已存在, 请删除\n${scriptUrl}`;
|
||||
return;
|
||||
}
|
||||
// 目录如果不存在则创建
|
||||
if (!await utils_1.createFolderByUrl(rootPath, { meta: utils_1.getResMeta('app-controller'), readme: utils_1.getResReadme('app-controller') })) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建目录失败\n${rootPath}`;
|
||||
return;
|
||||
}
|
||||
// 创建script
|
||||
const createScriptResult = await Editor.Message.request('asset-db', 'create-asset', scriptUrl, getScript(controlName)).catch(_ => null);
|
||||
if (!createScriptResult) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建脚本失败\n${scriptUrl}`;
|
||||
return;
|
||||
}
|
||||
this.showLoading = false;
|
||||
this.display = `[成功] 创建成功\n${rootPath}`;
|
||||
Editor.Message.send('assets', 'twinkle', scriptUrl);
|
||||
// 是否打开
|
||||
if (createResponse.response == 0) {
|
||||
Editor.Message.request('asset-db', 'open-asset', scriptUrl);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
107
extensions/app/engine/dist/panel/components/create-manager.js
vendored
Normal file
107
extensions/app/engine/dist/panel/components/create-manager.js
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = require("fs");
|
||||
const vue_1 = __importDefault(require("../../../../vue"));
|
||||
const utils_1 = require("../../utils");
|
||||
/**
|
||||
* 根据语言获取脚本内容
|
||||
*/
|
||||
function getScript(name) {
|
||||
const basePath = '../../../../extensions/app/assets/base/BaseManager';
|
||||
return 'import { _decorator } from \'cc\';\r\n' +
|
||||
'import BaseManager from \'' + basePath + '\';\r\n' +
|
||||
'const { ccclass, property } = _decorator;\r\n' +
|
||||
'@ccclass(\'' + name + '\')\r\n' +
|
||||
'export class ' + name + ' extends BaseManager {\r\n' +
|
||||
' // [无序] 加载完成时触发\r\n' +
|
||||
' protected onLoad() { }\r\n\r\n' +
|
||||
' // [无序] 自身初始化完成, init执行完毕后被调用\r\n' +
|
||||
' protected onInited() { }\r\n\r\n' +
|
||||
' // [无序] 所有manager初始化完成\r\n' +
|
||||
' protected onFinished() { }\r\n\r\n' +
|
||||
' // [无序] 初始化manager,在初始化完成后,调用finish方法\r\n' +
|
||||
' protected init(finish: Function) {\r\n' +
|
||||
' super.init(finish);\r\n' +
|
||||
' }\r\n' +
|
||||
'}';
|
||||
}
|
||||
exports.default = vue_1.default.extend({
|
||||
template: utils_1.getResPanel('create-manager'),
|
||||
data() {
|
||||
return {
|
||||
inputName: '',
|
||||
display: '',
|
||||
showLoading: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async onClickCreate() {
|
||||
const name = this.inputName;
|
||||
if (/^[a-z][a-z0-9-]*[a-z0-9]+$/.test(name) === false) {
|
||||
this.display = '[错误] 名字不合法\n1、不能以数字开头\n2、不能有大写字母\n3、分隔符只能使用-\n4、不能以分隔符开头或结尾';
|
||||
return;
|
||||
}
|
||||
const rootPath = 'db://assets/app-builtin/app-manager';
|
||||
const managerName = `${utils_1.stringCase(name)}Manager`;
|
||||
const folderName = name;
|
||||
const folderPath = `${rootPath}/${folderName}`;
|
||||
const scriptUrl = `${folderPath}/${managerName}.ts`;
|
||||
const prefabUrl = `${folderPath}/${managerName}.prefab`;
|
||||
// 创建前确认
|
||||
const createResponse = await Editor.Dialog.info('请确认', { detail: managerName, buttons: ['创建并打开', '仅创建', '取消'], default: 0, cancel: 2 });
|
||||
if (createResponse.response == 2) {
|
||||
return;
|
||||
}
|
||||
this.display = '创建中';
|
||||
this.showLoading = true;
|
||||
if (fs_1.existsSync(utils_1.convertUrlToPath(folderPath))) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 目录已存在, 请删除\n${folderPath}`;
|
||||
return;
|
||||
}
|
||||
// 目录如果不存在则创建
|
||||
if (!await utils_1.createFolderByUrl(rootPath, {
|
||||
meta: utils_1.getResMeta('app-manager'),
|
||||
readme: utils_1.getResReadme('app-manager'),
|
||||
subFolders: [
|
||||
{
|
||||
folder: folderName,
|
||||
readme: `1、${managerName}所在文件夹, 通过app.manager.${utils_1.stringCase(name, true)}的方式调用\n2、如不再需要,可以直接删除此文件夹`
|
||||
}
|
||||
]
|
||||
})) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建目录失败\n${folderPath}`;
|
||||
return;
|
||||
}
|
||||
// 创建script
|
||||
const createScriptResult = await Editor.Message.request('asset-db', 'create-asset', scriptUrl, getScript(managerName)).catch(_ => null);
|
||||
if (!createScriptResult) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建脚本失败\n${scriptUrl}`;
|
||||
return;
|
||||
}
|
||||
// 创建prefab
|
||||
const createPrefabResult = await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
name: 'app',
|
||||
method: 'createPrefab',
|
||||
args: [managerName, prefabUrl]
|
||||
});
|
||||
if (!createPrefabResult) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建预制体失败\n${prefabUrl}`;
|
||||
return;
|
||||
}
|
||||
this.showLoading = false;
|
||||
this.display = `[成功] 创建成功\n${rootPath}`;
|
||||
Editor.Message.send('assets', 'twinkle', scriptUrl);
|
||||
// 是否打开
|
||||
if (createResponse.response == 0) {
|
||||
Editor.Message.request('asset-db', 'open-asset', scriptUrl);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
105
extensions/app/engine/dist/panel/components/create-model.js
vendored
Normal file
105
extensions/app/engine/dist/panel/components/create-model.js
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = require("fs");
|
||||
const vue_1 = __importDefault(require("../../../../vue"));
|
||||
const utils_1 = require("../../utils");
|
||||
/**
|
||||
* 根据语言获取脚本内容
|
||||
*/
|
||||
function getScript(type, className) {
|
||||
if (type === 'data') {
|
||||
const BaseModel = '../../../extensions/app/assets/base/BaseModel';
|
||||
return 'import { IModel } from \'' + BaseModel + '\';\r\n' +
|
||||
'// data中不能定义任何方法(更建议使用store)\r\n' +
|
||||
'export default class ' + className + ' implements IModel<' + className + '> {\r\n' +
|
||||
'}';
|
||||
}
|
||||
else if (type === 'config') {
|
||||
const BaseModel = '../../../extensions/app/assets/base/BaseModel';
|
||||
return 'import { IModel } from \'' + BaseModel + '\';\r\n' +
|
||||
'// config中不能定义任何方法, 任何变量在外部访问都是readonly\r\n' +
|
||||
'// 如果config中的内容是服务器下发的,可以使用Object.assign覆盖config中的内容\r\n' +
|
||||
'export default class ' + className + ' implements IModel<' + className + '> {\r\n' +
|
||||
'}';
|
||||
}
|
||||
else if (type === 'store') {
|
||||
const BaseModel = '../../../extensions/app/assets/base/BaseModel';
|
||||
return 'import { IStore } from \'' + BaseModel + '\';\r\n' +
|
||||
'// store中只允许在根路径下定义方法,任何变量在外部访问都是readonly\r\n' +
|
||||
'// store类型的引入是借鉴了Web前端框架中全局状态管理的思路,意图是让数据更安全,更可控。同时框架中还提供了数据绑定的扩展包,可以通过pkg的方式安装,实现「数据->视图」的单向绑定。\r\n' +
|
||||
'export default class ' + className + ' implements IStore<' + className + '> {\r\n' +
|
||||
' count = 0;\r\n' +
|
||||
' setCount(v: number) {\r\n' +
|
||||
' this.count = v;\r\n' +
|
||||
' }\r\n' +
|
||||
'}';
|
||||
}
|
||||
else {
|
||||
return '// 🔥切记: 当前文件处于分包中, 由于加载顺序的原因,不可以在「主包」中使用此文件内导出的变量\r\n' +
|
||||
'// 存放直接导出的interface、type或enum等\r\n\r\n' +
|
||||
'// export type IString = string;\r\n' +
|
||||
'// export enum Type { None };';
|
||||
}
|
||||
}
|
||||
exports.default = vue_1.default.extend({
|
||||
template: utils_1.getResPanel('create-model'),
|
||||
data() {
|
||||
return {
|
||||
inputName: '',
|
||||
display: '',
|
||||
typeSelects: ['store', 'data', 'config', 'export'],
|
||||
typeSelectIndex: 0,
|
||||
showLoading: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onChangeTypeSelect(index) {
|
||||
this.typeSelectIndex = Number(index);
|
||||
},
|
||||
async onClickCreate() {
|
||||
const type = this.typeSelects[this.typeSelectIndex];
|
||||
const name = this.inputName;
|
||||
if (/^[a-z][a-z0-9-]*[a-z0-9]+$/.test(name) === false) {
|
||||
this.display = '[错误] 名字不合法\n1、不能以数字开头\n2、不能有大写字母\n3、分隔符只能使用-\n4、不能以分隔符开头或结尾';
|
||||
return;
|
||||
}
|
||||
const rootPath = 'db://assets/app-builtin/app-model';
|
||||
const modelName = `${type}.${name}`;
|
||||
const scriptUrl = `${rootPath}/${modelName}.ts`;
|
||||
// 创建前确认
|
||||
const createResponse = await Editor.Dialog.info('请确认', { detail: modelName, buttons: ['创建并打开', '仅创建', '取消'], default: 0, cancel: 2 });
|
||||
if (createResponse.response == 2) {
|
||||
return;
|
||||
}
|
||||
this.display = '创建中';
|
||||
this.showLoading = true;
|
||||
// 目录如果不存在则创建
|
||||
if (!await utils_1.createFolderByUrl(rootPath, { meta: utils_1.getResMeta('app-model'), readme: utils_1.getResReadme('app-model') })) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建目录失败\n${rootPath}`;
|
||||
return;
|
||||
}
|
||||
if (fs_1.existsSync(utils_1.convertUrlToPath(scriptUrl))) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 文件已存在, 请删除\n${scriptUrl}`;
|
||||
return;
|
||||
}
|
||||
const createScriptResult = await Editor.Message.request('asset-db', 'create-asset', scriptUrl, getScript(type, utils_1.stringCase(name))).catch(_ => null);
|
||||
if (!createScriptResult) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建脚本失败\n${scriptUrl}`;
|
||||
return;
|
||||
}
|
||||
this.showLoading = false;
|
||||
this.display = `[成功] 创建成功\n${rootPath}`;
|
||||
Editor.Message.send('assets', 'twinkle', scriptUrl);
|
||||
// 是否打开
|
||||
if (createResponse.response == 0) {
|
||||
Editor.Message.request('asset-db', 'open-asset', scriptUrl);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
62
extensions/app/engine/dist/panel/components/create-res.js
vendored
Normal file
62
extensions/app/engine/dist/panel/components/create-res.js
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const vue_1 = __importDefault(require("../../../../vue"));
|
||||
const utils_1 = require("../../utils");
|
||||
const typeNames = ['res-native', 'res-bundle', 'resources'];
|
||||
exports.default = vue_1.default.extend({
|
||||
template: utils_1.getResPanel('create-res'),
|
||||
data() {
|
||||
return {
|
||||
inputName: '',
|
||||
display: '',
|
||||
typeSelects: ['公共静态目录', '公共动态目录', 'resources'],
|
||||
typeSelectIndex: 0,
|
||||
showLoading: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onChangeTypeSelect(index) {
|
||||
this.typeSelectIndex = Number(index);
|
||||
},
|
||||
async onClickCreate() {
|
||||
const folderName = typeNames[this.typeSelectIndex];
|
||||
const folderPath = `db://assets/${folderName}`;
|
||||
const name = utils_1.stringCase(this.inputName, true);
|
||||
if (/^[a-z][a-z0-9-]*[a-z0-9]+$/.test(this.inputName) === false) {
|
||||
this.display = '[错误] 名字不合法\n1、不能以数字开头\n2、不能有大写字母\n3、分隔符只能使用-\n4、不能以分隔符开头或结尾';
|
||||
return;
|
||||
}
|
||||
if (name === 'resources') {
|
||||
this.display = '[错误] 名字不合法\n1、不能使用resources作为名字';
|
||||
return;
|
||||
}
|
||||
// 创建前确认
|
||||
const createResponse = await Editor.Dialog.info('请确认', { detail: name, buttons: ['创建', '取消'], default: 0, cancel: 1 });
|
||||
if (createResponse.response == 1) {
|
||||
return;
|
||||
}
|
||||
this.display = '创建中';
|
||||
this.showLoading = true;
|
||||
if (!await utils_1.createFolderByUrl(folderPath, {
|
||||
readme: utils_1.getResReadme(folderName),
|
||||
meta: folderName === 'resources' ? utils_1.getResMeta('resources') : undefined,
|
||||
subFolders: [
|
||||
{
|
||||
folder: name,
|
||||
meta: folderName === 'res-bundle' ? utils_1.getResMeta('custom-bundle') : undefined
|
||||
}
|
||||
]
|
||||
})) {
|
||||
this.showLoading = false;
|
||||
this.display = '[错误] 创建失败';
|
||||
return;
|
||||
}
|
||||
this.showLoading = false;
|
||||
this.display = `[成功] 创建成功\n${folderPath}`;
|
||||
Editor.Message.send('assets', 'twinkle', folderPath);
|
||||
}
|
||||
},
|
||||
});
|
||||
45
extensions/app/engine/dist/panel/components/create-sound.js
vendored
Normal file
45
extensions/app/engine/dist/panel/components/create-sound.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const vue_1 = __importDefault(require("../../../../vue"));
|
||||
const utils_1 = require("../../utils");
|
||||
exports.default = vue_1.default.extend({
|
||||
template: utils_1.getResPanel('create-sound'),
|
||||
data() {
|
||||
return {
|
||||
display: '',
|
||||
typeSelects: ['音乐', '音效'],
|
||||
typeSelectIndex: 0,
|
||||
showLoading: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onChangeTypeSelect(index) {
|
||||
this.typeSelectIndex = Number(index);
|
||||
},
|
||||
async onClickCreate() {
|
||||
this.display = '创建中';
|
||||
this.showLoading = true;
|
||||
const rootPath = 'db://assets/app-bundle/app-sound';
|
||||
if (!await utils_1.createFolderByUrl(rootPath, {
|
||||
meta: utils_1.getResMeta('app-sound'),
|
||||
readme: utils_1.getResReadme('app-sound'),
|
||||
subFolders: [
|
||||
{
|
||||
folder: this.typeSelectIndex === 0 ? 'music' : 'effect',
|
||||
readme: utils_1.getResReadme(this.typeSelectIndex === 0 ? 'sound-music' : 'sound-effect')
|
||||
}
|
||||
]
|
||||
})) {
|
||||
this.showLoading = false;
|
||||
this.display = '[错误] 创建失败';
|
||||
return;
|
||||
}
|
||||
this.showLoading = false;
|
||||
this.display = `[成功] 创建成功\n${rootPath}`;
|
||||
Editor.Message.send('assets', 'twinkle', rootPath);
|
||||
}
|
||||
},
|
||||
});
|
||||
249
extensions/app/engine/dist/panel/components/create-view.js
vendored
Normal file
249
extensions/app/engine/dist/panel/components/create-view.js
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = require("fs");
|
||||
const path_1 = require("path");
|
||||
const vue_1 = __importDefault(require("../../../../vue"));
|
||||
const utils_1 = require("../../utils");
|
||||
/**
|
||||
* 获取脚本内容
|
||||
*/
|
||||
function getComScript(name = 'NewClass') {
|
||||
const isPage = name.toLowerCase().startsWith('page');
|
||||
const isPaper = name.toLowerCase().startsWith('paper');
|
||||
const basePath = isPaper ? '../../../../../../../extensions/app/assets/base/BaseView' : '../../../../../../extensions/app/assets/base/BaseView';
|
||||
return 'import { _decorator, Node } from \'cc\';\r\n' +
|
||||
'import BaseView from \'' + basePath + '\';\r\n' +
|
||||
`${isPage ? 'import { IMiniViewNames } from \'../../../../../app-builtin/app-admin/executor\';\r\n' : ''}` +
|
||||
'const { ccclass, property } = _decorator;\r\n' +
|
||||
'@ccclass(\'' + name + '\')\r\n' +
|
||||
'export class ' + name + ' extends BaseView {\r\n' +
|
||||
` ${isPage ? '// 子界面列表,数组顺序为子界面排列顺序\r\n' : ''}` +
|
||||
` ${isPage ? 'protected miniViews: IMiniViewNames = [];\r\n\r\n' : '\r\n'}` +
|
||||
' // 初始化的相关逻辑写在这\r\n' +
|
||||
' onLoad() {}\r\n\r\n' +
|
||||
' // 界面打开时的相关逻辑写在这(onShow可被多次调用-它与onHide不成对)\r\n' +
|
||||
' onShow(params: any) {\r\n' +
|
||||
` ${isPage ? 'this.showMiniViews({ views: this.miniViews });' : ''}\r\n` +
|
||||
' }\r\n\r\n' +
|
||||
' // 界面关闭时的相关逻辑写在这(已经关闭的界面不会触发onHide)\r\n' +
|
||||
' onHide(result: undefined) {\r\n' +
|
||||
` ${isPaper ? '' : '// app.manager.ui.show<' + name + '>({name: \'' + name + '\', onHide:(result) => { 接收到return的数据,并且有类型提示 }})\r\n'}` +
|
||||
` ${isPaper ? '' : 'return result;'}\r\n` +
|
||||
' }\r\n' +
|
||||
'}';
|
||||
}
|
||||
function getNaMetaUserData(name = 'new-class') {
|
||||
return Object.assign(Object.assign({}, utils_1.getResMeta('view-native')), { 'bundleName': `${name}` });
|
||||
}
|
||||
function getResMetaUserData(name = 'new-class') {
|
||||
return Object.assign(Object.assign({}, utils_1.getResMeta('view-resources')), { 'bundleName': `${name}-res` });
|
||||
}
|
||||
/**
|
||||
* UI类型(小写)
|
||||
*/
|
||||
const TypeSelects = ['page', 'paper', 'pop', 'top'];
|
||||
/**
|
||||
* 大驼峰UI名(带page前缀) => 串式UI目录名(不带page前缀)
|
||||
*/
|
||||
const PageNames = new Map();
|
||||
function updatePages() {
|
||||
PageNames.clear();
|
||||
// page目录
|
||||
const pageRootPath = path_1.join(Editor.Project.path, 'assets/app-bundle/app-view/page');
|
||||
// 读取page目录下所有文件
|
||||
const folderNames = fs_1.existsSync(pageRootPath) ? fs_1.readdirSync(pageRootPath) : [];
|
||||
// 大驼峰命名的UI名
|
||||
folderNames.forEach((folderName) => {
|
||||
// folderName为串式命名法
|
||||
const pagePath = path_1.join(pageRootPath, folderName);
|
||||
const isDirectory = fs_1.statSync(pagePath).isDirectory();
|
||||
if (isDirectory) {
|
||||
PageNames.set(`Page${utils_1.stringCase(folderName)}`, folderName);
|
||||
}
|
||||
});
|
||||
PageNames.set('通用', 'all');
|
||||
return Array.from(PageNames.keys());
|
||||
}
|
||||
exports.default = vue_1.default.extend({
|
||||
template: utils_1.getResPanel('create-view'),
|
||||
data() {
|
||||
return {
|
||||
showLoading: false,
|
||||
showSelectPage: false,
|
||||
showSelectGroup: true,
|
||||
inputName: '',
|
||||
display: '',
|
||||
typeSelects: TypeSelects,
|
||||
typeSelectIndex: 0,
|
||||
groupSelects: ['2D', '3D'],
|
||||
groupSelectIndex: 0,
|
||||
pageSelects: [],
|
||||
pageSelectIndex: 0,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onChangeGroupSelect(index) {
|
||||
this.groupSelectIndex = Number(index);
|
||||
},
|
||||
onChangeTypeSelect(index) {
|
||||
this.typeSelectIndex = Number(index);
|
||||
if (index == '0') {
|
||||
this.showSelectGroup = true;
|
||||
}
|
||||
else {
|
||||
this.showSelectGroup = false;
|
||||
}
|
||||
if (index == '1') {
|
||||
this.pageSelectIndex = 0;
|
||||
this.pageSelects = updatePages();
|
||||
this.showSelectPage = true;
|
||||
}
|
||||
else {
|
||||
this.showSelectPage = false;
|
||||
}
|
||||
},
|
||||
onChangePageSelect(index) {
|
||||
this.pageSelectIndex = Number(index);
|
||||
},
|
||||
async onClickCreate() {
|
||||
const isPage = this.typeSelectIndex == 0;
|
||||
const isPaper = this.typeSelectIndex == 1;
|
||||
// ui归属(大驼峰)
|
||||
const owner = this.pageSelects[this.pageSelectIndex];
|
||||
// ui类型(小写)
|
||||
const type = this.typeSelects[this.typeSelectIndex];
|
||||
// ui名字(串式)
|
||||
const name = this.inputName;
|
||||
if (/^[a-z][a-z0-9-]*[a-z0-9]+$/.test(name) === false) {
|
||||
this.display = '[错误] 名字不合法\n1、不能以数字开头\n2、不能有大写字母\n3、分隔符只能使用-\n4、不能以分隔符开头或结尾';
|
||||
return;
|
||||
}
|
||||
if (name === 'all' || name === 'page' || name === 'paper' || name === 'pop' || name === 'top') {
|
||||
this.display = '[错误] 名字不合法\n1、不能使用all、page、paper、pop、top作为名字';
|
||||
return;
|
||||
}
|
||||
const is3D = isPage && this.groupSelectIndex == 1;
|
||||
const ownerName = PageNames.get(owner);
|
||||
const uiName = isPaper ?
|
||||
`${utils_1.stringCase(type)}${utils_1.stringCase(ownerName)}${utils_1.stringCase(name)}` :
|
||||
`${utils_1.stringCase(type)}${utils_1.stringCase(name)}`;
|
||||
const bundleName = isPaper ?
|
||||
`${type}-${ownerName}-${name}` :
|
||||
`${type}-${name}`;
|
||||
const bundleFolderUrl = 'db://assets/app-bundle';
|
||||
const viewFolderUrl = `${bundleFolderUrl}/app-view`;
|
||||
const typeFolderUrl = `${viewFolderUrl}/${type}`;
|
||||
const uiFolderUrl = isPaper ?
|
||||
`${typeFolderUrl}/${ownerName}/${name}` :
|
||||
`${typeFolderUrl}/${name}`;
|
||||
const nativeUrl = `${uiFolderUrl}/native`;
|
||||
const resourcesUrl = `${uiFolderUrl}/resources`;
|
||||
const expansionUrl = `${nativeUrl}/expansion`;
|
||||
const scriptUrl = `${nativeUrl}/${uiName}.ts`;
|
||||
const prefabUrl = `${nativeUrl}/${uiName}.prefab`;
|
||||
const sceneUrl = `${nativeUrl}/${uiName}.scene`;
|
||||
const singleColorUrl = `${resourcesUrl}/singleColor.png`;
|
||||
// 创建前确认
|
||||
const createResponse = await Editor.Dialog.info('请确认', { detail: uiName, buttons: ['创建并打开', '仅创建', '取消'], default: 0, cancel: 2 });
|
||||
if (createResponse.response == 2) {
|
||||
return;
|
||||
}
|
||||
this.display = '创建中';
|
||||
this.showLoading = true;
|
||||
// 创建目录
|
||||
if (!await utils_1.createFolderByUrl(uiFolderUrl, { subPaths: ['native', 'resources', 'native/expansion'] })) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建目录失败\n${uiFolderUrl}`;
|
||||
return;
|
||||
}
|
||||
// 设置native分包
|
||||
await utils_1.delayFileExistsByUrl(`${nativeUrl}.meta`);
|
||||
const queryNativeMeta = await Editor.Message.request('asset-db', 'query-asset-meta', nativeUrl).catch(_ => null);
|
||||
if (!queryNativeMeta) {
|
||||
this.showLoading = false;
|
||||
this.display = '[错误] 设置native分包配置失败';
|
||||
return;
|
||||
}
|
||||
queryNativeMeta.userData = getNaMetaUserData(bundleName);
|
||||
await Editor.Message.request('asset-db', 'save-asset-meta', nativeUrl, JSON.stringify(queryNativeMeta)).catch(_ => null);
|
||||
// 设置resources分包
|
||||
await utils_1.delayFileExistsByUrl(`${resourcesUrl}.meta`);
|
||||
const queryResMeta = await Editor.Message.request('asset-db', 'query-asset-meta', resourcesUrl).catch(_ => null);
|
||||
if (!queryResMeta) {
|
||||
this.showLoading = false;
|
||||
this.display = '[错误] 设置resources分包配置失败';
|
||||
return;
|
||||
}
|
||||
queryResMeta.userData = getResMetaUserData(bundleName);
|
||||
await Editor.Message.request('asset-db', 'save-asset-meta', resourcesUrl, JSON.stringify(queryResMeta)).catch(_ => null);
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(bundleFolderUrl), '.app-bundle.md'), utils_1.getResReadme('app-bundle'));
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(viewFolderUrl), '.app-view.md'), utils_1.getResReadme('app-view'));
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(typeFolderUrl), `.${type}.md`), `1、所有${type}类型UI的根目录\n2、如不再需要,可以直接删除此文件夹`);
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(nativeUrl), '.native.md'), utils_1.getResReadme('view-native'));
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(resourcesUrl), '.resources.md'), utils_1.getResReadme('view-resources'));
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(expansionUrl), '.expansion.md'), utils_1.getResReadme('view-expansion'));
|
||||
if (isPaper) {
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(`${typeFolderUrl}/${ownerName}`), `.${ownerName}.md`), (ownerName === 'all' ? '1、归属于全体Page' : `1、归属于Page${utils_1.stringCase(ownerName)}`) + '\n2、如不再需要,可以直接删除此文件夹');
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(uiFolderUrl), `.${name}.md`), `${uiName}所在文件夹\n1、通过${ownerName === 'all' ? '在任意Page中配置miniViews属性并调用showMiniViews方法' : `在${owner}中配置miniViews属性并调用showMiniViews方法`}的方式加载\n2、如不再需要,可以直接删除此文件夹`);
|
||||
}
|
||||
else {
|
||||
fs_1.writeFileSync(path_1.join(utils_1.convertUrlToPath(uiFolderUrl), `.${name}.md`), `${uiName}所在文件夹\n1、通过app.manager.ui.show({ name:'${uiName}' })的方式加载\n2、如不再需要,可以直接删除此文件夹`);
|
||||
}
|
||||
// 创建script
|
||||
if (!fs_1.existsSync(utils_1.convertUrlToPath(scriptUrl))) {
|
||||
const createScriptResult = await Editor.Message.request('asset-db', 'create-asset', scriptUrl, getComScript(uiName)).catch(_ => null);
|
||||
if (!createScriptResult) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建脚本失败\n${scriptUrl}`;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 创建view
|
||||
if (!fs_1.existsSync(utils_1.convertUrlToPath(prefabUrl)) && !fs_1.existsSync(utils_1.convertUrlToPath(sceneUrl))) {
|
||||
if (is3D && isPage) {
|
||||
const createSceneResult = await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
name: 'app',
|
||||
method: 'createScene',
|
||||
args: [uiName, sceneUrl]
|
||||
}).catch(_ => null);
|
||||
if (!createSceneResult) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建场景失败\n${sceneUrl}`;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const createPrefabResult = await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
name: 'app',
|
||||
method: 'createPrefab',
|
||||
args: [uiName, prefabUrl, is3D]
|
||||
}).catch(_ => null);
|
||||
if (!createPrefabResult) {
|
||||
this.showLoading = false;
|
||||
this.display = `[错误] 创建预制体失败\n${prefabUrl}`;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.showLoading = false;
|
||||
this.display = `[成功] 创建成功\n${uiFolderUrl}`;
|
||||
Editor.Message.send('assets', 'twinkle', scriptUrl);
|
||||
// 是否打开
|
||||
if (createResponse.response == 0) {
|
||||
if (is3D) {
|
||||
Editor.Message.request('asset-db', 'open-asset', sceneUrl);
|
||||
}
|
||||
else {
|
||||
Editor.Message.request('asset-db', 'open-asset', prefabUrl);
|
||||
}
|
||||
Editor.Message.request('asset-db', 'open-asset', scriptUrl);
|
||||
}
|
||||
const base64 = 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQMAAABIeJ9nAAAAA1BMVEX///+nxBvIAAAACklEQVQI12MAAgAABAABINItbwAAAABJRU5ErkJggg==';
|
||||
fs_1.writeFileSync(utils_1.convertUrlToPath(singleColorUrl), new Buffer(base64, 'base64'));
|
||||
Editor.Message.request('asset-db', 'refresh-asset', singleColorUrl).catch(_ => null);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user