Commit c349b15f authored by 李帅's avatar 李帅

优化完成

parent 05f8ab0c
{
"ver": "1.1.2",
"uuid": "c35bb2f6-f24a-4850-ae44-643f2fdc7541",
"isBundle": true,
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {
"ios": true,
"android": true
"ios": false,
"android": false
},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"ver": "1.2.9",
"uuid": "0737ce42-24f0-45c6-8e1a-8bdab4f74ba3",
"asyncLoadAssets": false,
"autoReleaseAssets": true,
"subMetas": {}
}
\ No newline at end of file
import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
this._imageResList.push({ url: this.data.pic_url });
this._imageResList.push({ url: this.data.pic_url_2 });
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: this.data.audio_url });
}
addPreloadAnima() {
}
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_cantouch = null;
initData() {
// 所有全局变量 默认都是null
this._cantouch = true;
}
initView() {
this.initBg();
this.initPic();
this.initBtn();
this.initIcon();
}
initBg() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
}
pic1 = null;
pic2 = null;
initPic() {
const canvas = cc.find('Canvas');
const maxW = canvas.width * 0.7;
this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
const picNode1 = sprNode;
picNode1.scale = maxW / picNode1.width;
picNode1.baseX = picNode1.x;
canvas.addChild(picNode1);
this.pic1 = picNode1;
const labelNode = new cc.Node();
labelNode.color = cc.Color.YELLOW;
const label = labelNode.addComponent(cc.Label);
label.string = this.data.text;
label.fontSize = 60;
label.lineHeight = 60;
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
picNode1.addChild(labelNode);
});
this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
const picNode2 = sprNode;
picNode2.scale = maxW / picNode2.width;
canvas.addChild(picNode2);
picNode2.x = canvas.width;
picNode2.baseX = picNode2.x;
this.pic2 = picNode2;
const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.RichText);
const size = 60
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
label.lineHeight = size;
picNode2.addChild(labelNode);
});
}
initIcon() {
const iconNode = this.getSprNode('icon');
iconNode.zIndex = 5;
iconNode.anchorX = 1;
iconNode.anchorY = 1;
iconNode.parent = cc.find('Canvas');
iconNode.x = iconNode.parent.width / 2 - 10;
iconNode.y = iconNode.parent.height / 2 - 10;
iconNode.on(cc.Node.EventType.TOUCH_START, () => {
this.playAudioByUrl(this.data.audio_url);
})
}
curPage = null;
initBtn() {
this.curPage = 0;
const bottomPart = cc.find('Canvas/bottomPart');
bottomPart.zIndex = 5; // 提高层级
bottomPart.x = bottomPart.parent.width / 2;
bottomPart.y = -bottomPart.parent.height / 2;
const leftBtnNode = bottomPart.getChildByName('btn_left');
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 0) {
return;
}
this.curPage = 0
this.leftMove();
this.playLocalAudio('btn');
})
const rightBtnNode = bottomPart.getChildByName('btn_right');
//节点中添加了button组件 则可以添加click事件监听
rightBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 1) {
return;
}
this.curPage = 1
this.rightMove();
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish();
this.playLocalAudio('btn');
})
}
leftMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
}
rightMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
}
// update (dt) {},
initListener() {
}
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
const id = cc.audioEngine.playEffect(audio.clip, false);
cc.audioEngine.setFinishCallback(id, () => {
resolve(id);
});
})
}
}
{
"ver": "1.0.8",
"uuid": "408a67f8-65fa-4cf1-8cf2-83e20e1a0fd5",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -4,9 +4,9 @@
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"premultiplyAlpha": true,
"genMipmaps": false,
"packable": true,
"packable": false,
"width": 378,
"height": 192,
"platformSettings": {},
......
const { spawn } = require("child_process");
const fs = require("fs");
const { spawn } = require('child_process');
const fs = require('fs');
const compressing = require('compressing');
const { v4, parse } = require('uuid');
const { Base64 } = require('js-base64');
const { copyDir, removeDir, fix2 } = require("./utils");
const { copyDir, removeDir, fix2 } = require('./utils');
async function buildForm() {
const paths = fs.readdirSync('form');
......@@ -30,11 +30,7 @@ async function buildForm() {
function execCmd(cmd, params, path) {
return new Promise((resolve, reject) => {
const buffer = spawn(
cmd,
params,
{ cwd: path }
);
const buffer = spawn(cmd, params, { cwd: path });
buffer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
......@@ -51,18 +47,13 @@ function execCmd(cmd, params, path) {
});
}
let creatorBasePath = 'CocosCreator';
let creatorBasePath = 'D:/install/CocosDashboard_1.0.6/resources/.editors/Creator/2.4.5/CocosCreator.exe';
if (process.platform !== 'win32') {
creatorBasePath = "/Applications/CocosCreator/Creator/2.4.5/CocosCreator.app/Contents/MacOS/CocosCreator";
creatorBasePath = '/Applications/CocosCreator/Creator/2.4.5/CocosCreator.app/Contents/MacOS/CocosCreator';
}
const buildCocos = function (args) {
return new Promise((resolve, reject) => {
const buffer = spawn(
creatorBasePath,
args,
{ cwd: '.' }
);
const buffer = spawn(creatorBasePath, args, { cwd: '.' });
buffer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
......@@ -88,7 +79,7 @@ function getReleaseFileName(projectName) {
function getFolderName(path) {
let folderName = '';
fs.readdirSync(path).find(fileName => {
fs.readdirSync(path).find((fileName) => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
......@@ -103,7 +94,7 @@ function editFolderMeta(path, folderName, isBundle) {
metaData.isBundle = isBundle;
metaData.isRemoteBundle = {
ios: isBundle,
android: isBundle
android: isBundle,
};
fs.writeFileSync(metaPath, JSON.stringify(metaData));
}
......@@ -119,52 +110,52 @@ async function buildAndroidBundle() {
}
async function buildIosBundle() {
const args = ['--path', './', '--build', "platform=ios;debug=false;md5Cache=true;buildPath=build_ios;encryptJs=true;xxteaKey=6bbfce23-28b4-4a;zipCompressJs=true", '--force'];
const args = ['--path', './', '--build', 'platform=ios;debug=false;md5Cache=true;buildPath=build_ios;encryptJs=true;xxteaKey=6bbfce23-28b4-4a;zipCompressJs=true', '--force'];
await buildCocos(args);
}
async function buildWebBundle() {
const args = ['--path', './', '--build', "platform=web-desktop;debug=false;buildPath=build_web_desktop", '--force'];
const args = ['--path', './', '--build', 'platform=web-desktop;debug=false;buildPath=build_web_desktop', '--force'];
await buildCocos(args);
}
function createConfigFile (projectName, type) {
let iosVersion = "";
let androidVersion = "";
if(!type){
function createConfigFile(projectName, type) {
let iosVersion = '';
let androidVersion = '';
if (!type) {
const androidPaths = fs.readdirSync(`dist/android/${projectName}`);
const androidConfigFileName = androidPaths.find(path => path.indexOf('config') == 0);
const androidConfigFileName = androidPaths.find((path) => path.indexOf('config') == 0);
androidVersion = androidConfigFileName.split('.')[1];
const iosPaths = fs.readdirSync(`dist/ios/${projectName}`);
const iosConfigFileName = iosPaths.find(path => path.indexOf('config') == 0);
const iosConfigFileName = iosPaths.find((path) => path.indexOf('config') == 0);
iosVersion = iosConfigFileName.split('.')[1];
} else {
if(type=="android"){
if (type == 'android') {
const androidPaths = fs.readdirSync(`dist/android/${projectName}`);
const androidConfigFileName = androidPaths.find(path => path.indexOf('config') == 0);
const androidConfigFileName = androidPaths.find((path) => path.indexOf('config') == 0);
androidVersion = androidConfigFileName.split('.')[1];
}else{
} else {
const iosPaths = fs.readdirSync(`dist/ios/${projectName}`);
const iosConfigFileName = iosPaths.find(path => path.indexOf('config') == 0);
const iosConfigFileName = iosPaths.find((path) => path.indexOf('config') == 0);
iosVersion = iosConfigFileName.split('.')[1];
}
}
const config = {
"ios": {
"sceneName": projectName,
"version": iosVersion
ios: {
sceneName: projectName,
version: iosVersion,
},
"android": {
"sceneName": projectName,
"version": androidVersion
}
}
android: {
sceneName: projectName,
version: androidVersion,
},
};
fs.writeFileSync('dist/config.json', JSON.stringify(config));
}
function compressAll (projectName) {
function compressAll(projectName) {
const tarStream = new compressing.zip.Stream();
tarStream.addEntry('dist/play');
tarStream.addEntry('dist/form');
......@@ -176,12 +167,12 @@ function compressAll (projectName) {
tarStream.pipe(destStream);
}
function build_check () {
function build_check() {
const dirNames = process.cwd().split(/\/|\\/);
const projectName = dirNames[dirNames.length - 1];
const path = 'assets'
const path = 'assets';
let folderName = '';
fs.readdirSync(path).find(fileName => {
fs.readdirSync(path).find((fileName) => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
......@@ -189,11 +180,11 @@ function build_check () {
});
if (projectName != folderName) {
throw (`项目名(${projectName})与bundle文件夹名(${folderName})不相同`);
throw `项目名(${projectName})与bundle文件夹名(${folderName})不相同`;
}
let same = false;
const files = fs.readdirSync(`${path}/${folderName}/scene`);
files.forEach(fileName => {
files.forEach((fileName) => {
fileName.split('.').forEach((str, idx, arr) => {
if (str == 'fire') {
const sceneName = arr[idx - 1];
......@@ -201,36 +192,35 @@ function build_check () {
same = true;
}
}
})
});
});
if (!same) {
throw (`bundle文件夹名称(${folderName})与scene名称不相同`);
throw `bundle文件夹名称(${folderName})与scene名称不相同`;
}
return projectName;
}
function changeSettingToWebDesktop () {
const path = 'assets'
function changeSettingToWebDesktop() {
const path = 'assets';
const folderName = getFolderName(path);
editFolderMeta(path, folderName, false);
}
function changeSettingsToBundle () {
const path = 'assets'
function changeSettingsToBundle() {
const path = 'assets';
const folderName = getFolderName(path);
editFolderMeta(path, folderName, true);
}
function replaceUuids () {
function replaceUuids() {
console.log('build_step_0 开始~!');
const path = 'assets'
const path = 'assets';
function getFolderName(path) {
let folderName = '';
fs.readdirSync(path).find(fileName => {
fs.readdirSync(path).find((fileName) => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
......@@ -276,7 +266,7 @@ function replaceUuids () {
}
const fileStr = fs.readFileSync(path);
const newFileStr = fileStr.toString().replace(new RegExp(replaceStr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), 'g'), newStr);
const newFileStr = fileStr.toString().replace(new RegExp(replaceStr.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), newStr);
fs.writeFileSync(path, newFileStr);
}
function getShortUuid(uuid) {
......@@ -303,15 +293,13 @@ function replaceUuids () {
console.log('build_step_0 完成~!');
}
function replaceIndexHtml () {
function replaceIndexHtml() {
const data = fs.readFileSync('index.html');
fs.writeFileSync('dist/play/index.html', data);
}
module.exports = {
build: async function () {
const startTime = new Date().getTime();
// 构建前检查
......@@ -373,7 +361,6 @@ module.exports = {
},
buildAndroid: async function () {
// 构建前检查
const projectName = build_check();
// 替换uuid
......@@ -387,13 +374,12 @@ module.exports = {
// 改设置为非bundle
changeSettingToWebDesktop();
createConfigFile(projectName, "android");
createConfigFile(projectName, 'android');
await removeDir('build_android');
console.log('构建 android bundle 成功!');
},
buildIos: async function () {
// 构建前检查
const projectName = build_check();
// 替换uuid
......@@ -407,9 +393,8 @@ module.exports = {
// 改设置为非bundle
changeSettingToWebDesktop();
createConfigFile(projectName, "ios");
createConfigFile(projectName, 'ios');
await removeDir('build_ios');
console.log('构建 ios bundle 成功!');
}
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment