Commit 7f8d797d authored by huoshizhe's avatar huoshizhe

feat:

parent 2b52fed8
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
/publish/publish/play /publish/publish/play
/publish/publish/form /publish/publish/form
/publish/publish/android /publish/publish/android
/publish/publish/web_desktop
/publish/publish/ios /publish/publish/ios
/publish/publish/*.zip /publish/publish/*.zip
/node_modules /publish/publish/config.json
\ No newline at end of file /publish/publish/Release*
/node_modules
/play/build_android
/play/build_ios
/play/build_web_desktop
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{ {"ver":"1.1.2","uuid":"d3ad24ed-9c8b-421d-934f-f93f1acf3060","isBundle":false,"bundleName":"","priority":1,"compressionType":{},"optimizeHotUpdate":{},"inlineSpriteFrames":{},"isRemoteBundle":{"ios":false,"android":false},"subMetas":{}}
"ver": "1.1.2", \ No newline at end of file
"uuid": "d3ad24ed-9c8b-421d-934f-f93f1acf3060",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
...@@ -45,6 +45,9 @@ cc.Class({ ...@@ -45,6 +45,9 @@ cc.Class({
}, },
onTouchStart() { onTouchStart() {
if (g.data_mgr.nodPlayer) {
g.data_mgr.nodPlayer.onStopAudio();
}
if (this._playing) return if (this._playing) return
if (this.audioId) return if (this.audioId) return
if (this.data) { if (this.data) {
...@@ -67,7 +70,8 @@ cc.Class({ ...@@ -67,7 +70,8 @@ cc.Class({
this.quan.active = true this.quan.active = true
if (!this._playing) { if (!this._playing) {
this._playing = true this._playing = true;
g.data_mgr.nodPlayer = this;
cc.systemEvent.once('stopMusic', this.onStopAudio, this) cc.systemEvent.once('stopMusic', this.onStopAudio, this)
// if (onlyOne != this) { // if (onlyOne != this) {
// this._playing = false // this._playing = false
...@@ -124,6 +128,7 @@ cc.Class({ ...@@ -124,6 +128,7 @@ cc.Class({
this.stopAudio() this.stopAudio()
}, },
stopAudio() { stopAudio() {
g.data_mgr.nodPlayer = null;
this._playing = false this._playing = false
if (this.audioId != null) { if (this.audioId != null) {
cc.audioEngine.stop(this.audioId) cc.audioEngine.stop(this.audioId)
......
const tools = require("../script/tools"); const tools = require("../script/tools");
var picNode = cc.Class({ var picNode = cc.Class({
extends: cc.Component, extends: cc.Component,
properties: { properties: {
hitPre: cc.Prefab, hitPre: cc.Prefab,
quan: cc.Node, quan: cc.Node,
}, },
onLoad() { onLoad() {
}, },
ctor: function () { ctor: function () {
picNode.inst = this; picNode.inst = this;
g.picNode = picNode; g.picNode = picNode;
}, },
onEnable() { onEnable() {
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this) this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this)
}, },
onDisable() { onDisable() {
this.node.off(cc.Node.EventType.TOUCH_START, this.onTouchStart, this) this.node.off(cc.Node.EventType.TOUCH_START, this.onTouchStart, this)
}, },
onTouchStart() { onTouchStart() {
g.speaker.inst.playEffect(g.enum.E_Audio.Error); if (g.data_mgr.nodPlayer) {
}, g.data_mgr.nodPlayer.onStopAudio();
}
g.speaker.inst.playEffect(g.enum.E_Audio.Error);
},
onShow(data) { onShow(data) {
this._hitItem = [] this._hitItem = []
this._sprite = this.getComponentInChildren(cc.Sprite) this._sprite = this.getComponentInChildren(cc.Sprite)
this._items = this.quan; this._items = this.quan;
this.initWithData(data); this.initWithData(data);
}, },
initWithData(data) { initWithData(data) {
this.clearItems() this.clearItems()
tools.getSpriteFrimeByUrl(data.bgItem.url, (sp) => { tools.getSpriteFrimeByUrl(data.bgItem.url, (sp) => {
//设置图片 //设置图片
this._sprite.spriteFrame = sp this._sprite.spriteFrame = sp
this.photoScare(this._sprite.node); this.photoScare(this._sprite.node);
this._items.width = this.node.width this._items.width = this.node.width
this._items.height = this.node.height this._items.height = this.node.height
this._items.x = -this.node.width / 2 this._items.x = -this.node.width / 2
this._items.y = this.node.height / 2 this._items.y = this.node.height / 2
if (this._items.height / data.bgItem.rect.height < this._items.width / data.bgItem.rect.width) { if (this._items.height / data.bgItem.rect.height < this._items.width / data.bgItem.rect.width) {
var scale = this.node.height / data.bgItem.rect.height var scale = this.node.height / data.bgItem.rect.height
//X不够补X偏移量 //X不够补X偏移量
var Xvalue = (this.node.width - data.bgItem.rect.width * scale) / 2 var Xvalue = (this.node.width - data.bgItem.rect.width * scale) / 2
var Yvalue = 0; var Yvalue = 0;
} else { } else {
var scale = this.node.width / data.bgItem.rect.width var scale = this.node.width / data.bgItem.rect.width
//Y不够补Y偏移量 //Y不够补Y偏移量
var Xvalue = 0; var Xvalue = 0;
var Yvalue = (this.node.height - data.bgItem.rect.height * scale) / 2 var Yvalue = (this.node.height - data.bgItem.rect.height * scale) / 2
} }
//初始化点击区域 //初始化点击区域
let node, comp let node, comp
for (let data of data.hotZoneItemArr) { for (let data of data.hotZoneItemArr) {
node = cc.instantiate(this.hitPre) node = cc.instantiate(this.hitPre)
comp = node.getComponent('hitItem') comp = node.getComponent('hitItem')
comp.initWithData(data, scale, Xvalue, Yvalue); comp.initWithData(data, scale, Xvalue, Yvalue);
this._items.addChild(node) this._items.addChild(node)
this._hitItem.push(node) this._hitItem.push(node)
} }
}) })
}, },
//图片适配 //图片适配
photoScare: function (node) { photoScare: function (node) {
var height = 580; var height = 580;
var width = 1012; var width = 1012;
// var maxNum = type == 0 ? 50 : 280; // var maxNum = type == 0 ? 50 : 280;
let maxSize = Math.min(height / node.height, width / node.width); let maxSize = Math.min(height / node.height, width / node.width);
if (node.perScale == undefined) { if (node.perScale == undefined) {
node.perScale = node.scaleX; node.perScale = node.scaleX;
} else { } else {
node.scaleX = node.perScale; node.scaleX = node.perScale;
node.scaleY = node.perScale; node.scaleY = node.perScale;
} }
node.scaleX *= maxSize; node.scaleX *= maxSize;
node.scaleY *= maxSize; node.scaleY *= maxSize;
this.maxSize = maxSize; this.maxSize = maxSize;
}, },
/** 清除item */ /** 清除item */
clearItems() { clearItems() {
this._items.removeAllChildren(true) this._items.removeAllChildren(true)
this._hitItem.length = 0 this._hitItem.length = 0
} }
}); });
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
"_groupIndex": 0, "_groupIndex": 0,
"groupIndex": 0, "groupIndex": 0,
"autoReleaseAssets": true, "autoReleaseAssets": true,
"_id": "57ea7c61-9b8b-498a-b024-c98ee9124beb" "_id": "14c37636-02d3-4ff8-8d46-32898ddb9a11"
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
......
{ {
"ver": "1.2.9", "ver": "1.2.9",
"uuid": "57ea7c61-9b8b-498a-b024-c98ee9124beb", "uuid": "14c37636-02d3-4ff8-8d46-32898ddb9a11",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"autoReleaseAssets": true, "autoReleaseAssets": true,
"subMetas": {} "subMetas": {}
......
...@@ -140,7 +140,10 @@ var game = cc.Class({ ...@@ -140,7 +140,10 @@ var game = cc.Class({
//初始化标题 //初始化标题
g.titleType.inst.showTitle(question.title, question.title_audio_url); g.titleType.inst.showTitle(question.title, question.title_audio_url);
if (question.title_audio_url) { if (question.title_audio_url) {
g.titleType.inst.onBtnPlayEffect(); g.data_mgr.gameState = 2;
setTimeout(() => {
g.titleType.inst.onBtnPlayEffect();
}, 500)
} }
//设置中间图片 //设置中间图片
g.picNode.inst.onShow(question); g.picNode.inst.onShow(question);
......
...@@ -28,8 +28,12 @@ var speaker = cc.Class({ ...@@ -28,8 +28,12 @@ var speaker = cc.Class({
g.speaker = speaker; g.speaker = speaker;
}, },
//播放音效 // //播放音效
// playEffect: function (num, cb) {
// g.snd_mgr.playEffect(this.eff_audio[num], cb);
// },
playEffect: function (num, cb) { playEffect: function (num, cb) {
g.snd_mgr.playEffect(this.eff_audio[num], cb); g.snd_mgr.playMusic(this.eff_audio[num], 1, cb);
}, },
}); });
...@@ -22,6 +22,7 @@ var titleType = cc.Class({ ...@@ -22,6 +22,7 @@ var titleType = cc.Class({
this.unschedule(this.setSndEff); this.unschedule(this.setSndEff);
var nodTitle = this.checkNode(lab, audio); var nodTitle = this.checkNode(lab, audio);
this.lab = lab; this.lab = lab;
this.stopAudio();
this.audio = audio; this.audio = audio;
this.updateUi(nodTitle) this.updateUi(nodTitle)
...@@ -34,6 +35,10 @@ var titleType = cc.Class({ ...@@ -34,6 +35,10 @@ var titleType = cc.Class({
nodTitle.active = true; nodTitle.active = true;
}, },
stopAudio() {
cc.audioEngine.stop(this.audio)
},
//更新界面 //更新界面
updateUi(nodTitle) { updateUi(nodTitle) {
nodTitle.getChildByName("title") && (nodTitle.getChildByName("title").getComponent(cc.Label).string = this.lab) nodTitle.getChildByName("title") && (nodTitle.getChildByName("title").getComponent(cc.Label).string = this.lab)
......
...@@ -10,33 +10,49 @@ g.data_mgr = { ...@@ -10,33 +10,49 @@ g.data_mgr = {
startId: null,//星星id startId: null,//星星id
nowAnsId: null,//当前星星的问题 nowAnsId: null,//当前星星的问题
gameState: 2,//游戏状态1可操作 2不可操作
nodPlayer: null,//当前播放节点
//获得默认数据 //获得默认数据
getDefaultData() { getDefaultData() {
//http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3
const dataJson = { const dataJson = {
"starArr": [{ "starArr": [{
"queArr": [{ "queArr": [{
"bgItem": { "bgItem": {
"url": "http://staging-teach.cdn.ireadabc.com/bb4244d166b6d077617ff089f7fd46c4.png", "rect": { "x": 259.9654545454546, "y": 0, "width": 377.0690909090909, "height": 373 } "url": "http://staging-teach.cdn.ireadabc.com/bb4244d166b6d077617ff089f7fd46c4.png", "rect": { "x": 259.9654545454546, "y": 0, "width": 377.0690909090909, "height": 373 }
}, "hotZoneItemArr": [{ }, "hotZoneItemArr": [{
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
"index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": -1.97, "y": 112, "width": 95.01, "height": 95.01 } "index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": -1.97, "y": 112, "width": 95.01, "height": 95.01 }
}, { }, {
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
"index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 311.03, "y": 118, "width": 77.01, "height": 77.01 } "index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 311.03, "y": 118, "width": 77.01, "height": 77.01 }
}], "title": "3434", "title_audio_url": "" }], "title": "3434", "title_audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3"
}, { }, {
"bgItem": { "bgItem": {
"url": "http://staging-teach.cdn.ireadabc.com/685ead5fe409d20412a38aae23c75ad0.png", "rect": { "x": 116.9444444444444, "y": -2.842170943040401e-14, "width": 663.1111111111112, "height": 373.00000000000006 } "url": "http://staging-teach.cdn.ireadabc.com/685ead5fe409d20412a38aae23c75ad0.png", "rect": { "x": 116.9444444444444, "y": -2.842170943040401e-14, "width": 663.1111111111112, "height": 373.00000000000006 }
}, "hotZoneItemArr": [{ }, "hotZoneItemArr": [{
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
"index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 72.06, "y": 52, "width": 133, "height": 49 } "index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 72.06, "y": 52, "width": 133, "height": 49 }
}, { }, {
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
"index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 475.06, "y": 30, "width": 159, "height": 67 } "index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 475.06, "y": 30, "width": 159, "height": 67 }
}], "title": "666", "title_audio_url": "" }], "title": "666", "title_audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3"
}] }]
}, { }, {
"queArr": [{ "queArr": [{
"bgItem": { "url": "http://staging-teach.cdn.ireadabc.com/6326a8bc4896aaa1834bd35f2dac9fee.png", "rect": { "x": 273.3030303030303, "y": 0, "width": 350.3939393939394, "height": 373 } }, "hotZoneItemArr": [{ "index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": -5.3, "y": 214, "width": 65, "height": 65 } }, { "index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 294.7, "y": 148, "width": 71, "height": 71 } }], "title": "455", "title_audio_url": "" "bgItem": { "url": "http://staging-teach.cdn.ireadabc.com/6326a8bc4896aaa1834bd35f2dac9fee.png", "rect": { "x": 273.3030303030303, "y": 0, "width": 350.3939393939394, "height": 373 } },
"hotZoneItemArr": [{
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": -5.3, "y": 214, "width": 65, "height": 65 }
}, { "audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 294.7, "y": 148, "width": 71, "height": 71 } }], "title": "455", "title_audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3"
}, { }, {
"bgItem": { "url": "http://staging-teach.cdn.ireadabc.com/942fb8d28620d46d6c77d18909e86806.png", "rect": { "x": 116.9444444444444, "y": -2.842170943040401e-14, "width": 663.1111111111112, "height": 373.00000000000006 } }, "hotZoneItemArr": [{ "index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 247.06, "y": 217, "width": 97, "height": 97 } }, { "index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 515.06, "y": 108, "width": 57, "height": 57 } }], "title": "7777", "title_audio_url": "" "bgItem": { "url": "http://staging-teach.cdn.ireadabc.com/942fb8d28620d46d6c77d18909e86806.png", "rect": { "x": 116.9444444444444, "y": -2.842170943040401e-14, "width": 663.1111111111112, "height": 373.00000000000006 } },
"hotZoneItemArr": [{
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 247.06, "y": 217, "width": 97, "height": 97 }
}, {
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 515.06, "y": 108, "width": 57, "height": 57 }
}], "title": "7777", "title_audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3"
}] }]
}] }]
} }
......
...@@ -5,7 +5,8 @@ g.res_mgr = { ...@@ -5,7 +5,8 @@ g.res_mgr = {
//获得表数据数据 //获得表数据数据
getFormData() { getFormData() {
console.log('初始化数据'); console.log('初始化数据');
try {
if (window && window.courseware) {
window.courseware.getData((res) => { window.courseware.getData((res) => {
//存入数据管理器 //存入数据管理器
g.data_mgr.data = res; g.data_mgr.data = res;
...@@ -13,13 +14,27 @@ g.res_mgr = { ...@@ -13,13 +14,27 @@ g.res_mgr = {
g.data_mgr.proGameData(); g.data_mgr.proGameData();
console.log("获得表单数据:" + res); console.log("获得表单数据:" + res);
}); });
} catch (error) { return;
//console.error('没有查找到courseware.getData方法', error);
//获得默认数据
g.data_mgr.data = g.data_mgr.getDefaultData();
//数据处理
g.data_mgr.proGameData();
} }
const middleLayer = cc.find('middleLayer');
if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer');
middleLayerComponent.getData((res) => {
//存入数据管理器
g.data_mgr.data = res;
//数据处理
g.data_mgr.proGameData();
console.log("获得表单数据:" + res);
});
return;
}
//console.error('没有查找到courseware.getData方法', error);
//获得默认数据
g.data_mgr.data = g.data_mgr.getDefaultData();
//数据处理
g.data_mgr.proGameData();
}, },
//得到图片资源 //得到图片资源
......
...@@ -36,6 +36,7 @@ g.snd_mgr = { ...@@ -36,6 +36,7 @@ g.snd_mgr = {
// this.bgmId = cc.audioEngine.play(snd, loop); // this.bgmId = cc.audioEngine.play(snd, loop);
// return; // return;
// } // }
cc.audioEngine.stop()
this.bgmId = cc.audioEngine.playMusic(snd, loop); this.bgmId = cc.audioEngine.playMusic(snd, loop);
// 播放完成回调 // 播放完成回调
if (finishCB) { if (finishCB) {
...@@ -43,7 +44,6 @@ g.snd_mgr = { ...@@ -43,7 +44,6 @@ g.snd_mgr = {
finishCB(); finishCB();
}); });
} }
}, },
playEffect: function (snd, finishCB) { playEffect: function (snd, finishCB) {
if (!snd || this.effVol == 0) return; if (!snd || this.effVol == 0) return;
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
"packages": "packages", "packages": "packages",
"name": "play", "name": "play",
"id": "9af72fd2-44a6-4131-8ea3-3e1b3fa22231", "id": "9af72fd2-44a6-4131-8ea3-3e1b3fa22231",
"version": "2.4.5", "version": "2.4.4",
"isNew": false "isNew": false
} }
\ No newline at end of file
{ {
"title": "play", "title": "play",
"packageName": "org.cocos2d.demo", "packageName": "org.cocos2d.demo",
"startScene": "57ea7c61-9b8b-498a-b024-c98ee9124beb", "startScene": "f5b1b5a9-03b8-4bfd-b791-a1c7e640b256",
"excludeScenes": [], "excludeScenes": [],
"includeSDKBox": false, "includeSDKBox": false,
"orientation": { "orientation": {
......
import express from "express";
import os from "os";
import readline from "readline";
import { build } from "./buildCocos.js";
const networkInfo = os.networkInterfaces();
let host = '';
for (const infos of Object.values(networkInfo)) {
for (const info of infos) {
if (info.family == 'IPv4') {
if (info.address.split('.')[0] != "127") {
host = info.address;
}
}
}
}
var app = express();
app.use('/publish', express.static('publish'));
app.get('/', function (req, res) {
res.send('Hello World');
})
let port = '';
var server = app.listen(8081, function () {
port = server.address().port
console.log("测试服务已启动:%s:%s", host, port)
})
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.on('line', async (str) => {
if (str.trim() == 'build') {
await build();
console.log("测试服务已启动:%s:%s", host, port)
console.log('输入 build 构建。')
} else {
console.log("测试服务已启动:%s:%s", host, port)
console.log('输入 build 构建。')
}
})
cd ../form & npm install & npm run publish & cd ../play & CocosCreator.exe --path "./" --build "platform=web-desktop;debug=true" --force & cd ../publish & node build.js
pause
let fs = require('fs'); import { build } from "./buildCocos.js";
const compressing = require('compressing'); await build();
\ No newline at end of file
function fix2(num) {
if (num >= 10) {
return '' + num;
} else {
return '0' + num;
}
}
async function copyDir(src, dst) {
const exists = await fs.existsSync(dst);
if (!exists) {
await fs.mkdirSync(dst);
}
//读取目录
const paths = await fs.readdirSync(src);
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
const newSrc = `${src}/${path}`;
const newDst = `${dst}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('copy: ' + newDst);
const data = await fs.readFileSync(newSrc);
await fs.writeFileSync(newDst, data);
} else if (st.isDirectory()) {
copyDir(newSrc, newDst);
}
}
}
async function removeDir(src) {
const exists = await fs.existsSync(src);
if (!exists) {
return;
}
//读取目录
const st = await fs.statSync(src);
console.log(st);
const paths = await fs.readdirSync(src);
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
const newSrc = `${src}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('remove: ' + newSrc);
await fs.unlinkSync(newSrc);
} else if (st.isDirectory()) {
await removeDir(newSrc);
}
}
await fs.rmdirSync(src);
}
async function main() {
let date = new Date();
let fileName = `Release_${date.getFullYear()}${fix2(date.getMonth() + 1)}${fix2(date.getDate())} `;
fileName += `${fix2(date.getHours())}-${fix2(date.getMinutes())}-${fix2(date.getSeconds())}`;
await removeDir('./publish/play');
await removeDir('./publish/form');
await copyDir('../play/build/web-desktop', './publish/play');
const data = await fs.readFileSync('./index.html');
await fs.writeFileSync('./publish/play/index.html', data);
compressing.zip.uncompress('../form/publish/form.zip', './publish/form')
.then(() => {
const tarStream = new compressing.zip.Stream();
tarStream.addEntry('./publish/play');
tarStream.addEntry('./publish/form');
const destStream = fs.createWriteStream(`publish/${fileName}.zip`);
tarStream.pipe(destStream);
console.log('打包完成!');
});
}
main();
\ No newline at end of file
#!/bin/sh
cd publish
set -e
node build_check.js
set +e
cd ../form
npm install
npm run publish
cd ../publish
node build_step_0.js
cd ../play
/Applications/CocosCreator/Creator/2.4.0/CocosCreator.app/Contents/MacOS/CocosCreator --path "./" --build "platform=web-desktop;debug=true" --force
echo "生成 web desktop 完成~!"
cd ../publish
node build_step_1.js
echo "build_step_1 完成~!"
cd ../play
/Applications/CocosCreator/Creator/2.4.4/CocosCreator.app/Contents/MacOS/CocosCreator --path "./" --build "platform=ios;debug=false;md5Cache=true;buildPath=build_ios;encryptJs=true;xxteaKey=6bbfce23-28b4-4a;zipCompressJs=true" --force
echo "生成 ios 完成~!"
cd ../publish
node build_step_2.js
echo "build_step_2 完成~!"
cd ../play
/Applications/CocosCreator/Creator/2.4.4/CocosCreator.app/Contents/MacOS/CocosCreator --path "./" --build "platform=ios;debug=false;md5Cache=true;buildPath=build_android;appABIs=['armeabi-v7a','x86','x86_64','arm64-v8a'];encryptJs=true;xxteaKey=6bbfce23-28b4-4a;zipCompressJs=true" --force
echo "生成 android 完成~!"
cd ../publish
node build_step_3.js
echo "build_step_3 完成~!"
cd ../play
/Applications/CocosCreator/Creator/2.4.4/CocosCreator.app/Contents/MacOS/CocosCreator --path "./" --build "platform=web-desktop;debug=false;buildPath=build_web_desktop" --force
echo "生成 web-desktop 完成~!"
cd ../publish
node build_step_4.js
echo "build_step_4 完成~!"
\ No newline at end of file
This diff is collapsed.
let fs = require('fs');
const dirNames = __dirname.split('/');
const projectName = dirNames[dirNames.length - 2];
const path = '../play/assets'
let folderName = '';
fs.readdirSync(path).find(fileName => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
}
});
if (projectName != folderName) {
throw (`项目名(${projectName})与bundle文件夹名(${folderName})不相同`);
}
let same = false;
const files = fs.readdirSync(`${path}/${folderName}/scene`);
files.forEach(fileName => {
fileName.split('.').forEach((str, idx, arr) => {
if (str == 'fire') {
const sceneName = arr[idx - 1];
if (folderName == sceneName) {
same = true;
}
}
})
});
if (!same) {
throw (`bundle文件夹名称(${folderName})与scene名称不相同`);
}
\ No newline at end of file
let fs = require('fs');
const path = '../play/assets'
let folderName = '';
fs.readdirSync(path).find(fileName => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
}
});
const metaPath = `${path}/${folderName}.meta`;
const metaDataStr = fs.readFileSync(metaPath);
const metaData = JSON.parse(metaDataStr);
metaData.isBundle = false;
fs.writeFileSync(metaPath, JSON.stringify(metaData));
const { removeDir, copyDir, fix2 } = require('./utils');
const compressing = require('compressing');
let fs = require('fs');
async function main() {
await removeDir('./publish/play');
await removeDir('./publish/form');
await copyDir('../play/build/web-desktop', './publish/play');
compressing.zip.uncompress('../form/publish/form.zip', './publish/form');
const data = await fs.readFileSync('./index.html');
await fs.writeFileSync('./publish/play/index.html', data);
await removeDir('../play/build/web-desktop');
const path = '../play/assets'
let folderName = '';
fs.readdirSync(path).find(fileName => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
}
});
const metaPath = `${path}/${folderName}.meta`;
const metaDataStr = fs.readFileSync(metaPath);
const metaData = JSON.parse(metaDataStr);
metaData.isBundle = true;
metaData.isRemoteBundle = {
ios: true,
android: true
};
fs.writeFileSync(metaPath, JSON.stringify(metaData));
}
main();
\ No newline at end of file
const { removeDir, copyDir, fix2 } = require('./utils');
const compressing = require('compressing');
async function main() {
await removeDir('./publish/ios');
await copyDir('../play/build_ios/jsb-link/remote', './publish/ios');
await removeDir('../play/build_ios/jsb-link');
}
main();
\ No newline at end of file
const { removeDir, copyDir, fix2 } = require('./utils');
const compressing = require('compressing');
let fs = require('fs');
async function main() {
await removeDir('./publish/android');
await copyDir('../play/build_android/jsb-link/remote', './publish/android');
await removeDir('../play/build_android/jsb-link');
}
main();
\ No newline at end of file
const { removeDir, copyDir, fix2 } = require('./utils');
const compressing = require('compressing');
let fs = require('fs');
async function main() {
await removeDir('./publish/web_desktop');
const projectName = await getBundleName('../play/build_web_desktop/web-desktop/assets');
await copyDir(`../play/build_web_desktop/web-desktop/assets/${projectName}`, './publish/web_desktop');
await removeDir('../play/build_web_desktop');
const bundleData = {
ios: await getBundleData('./publish/ios'),
android: await getBundleData('./publish/android'),
}
fs.writeFileSync('./publish/config.json', JSON.stringify(bundleData));
const tarStream = new compressing.zip.Stream();
tarStream.addEntry('./publish/play');
tarStream.addEntry('./publish/form');
tarStream.addEntry('./publish/ios');
tarStream.addEntry('./publish/android');
tarStream.addEntry('./publish/web_desktop');
tarStream.addEntry('./publish/config.json');
const destStream = fs.createWriteStream(`publish/${getReleaseFileName()}.zip`);
tarStream.pipe(destStream);
console.log('打包完成!');
}
async function getBundleName(path) {
const paths = fs.readdirSync(path);
return paths.find(path => path != 'internal' && path !='main');
}
async function getBundleData(path) {
const bundleData = {
sceneName: '',
version: '',
}
const paths = fs.readdirSync(path);
bundleData.sceneName = paths[0];
const files = fs.readdirSync(path + '/' + bundleData.sceneName);
files.forEach(fileName => {
fileName.split('.').forEach((str, idx, arr) => {
if (str == 'config') {
bundleData.version = arr[idx + 1];
}
})
});
return bundleData;
}
function getReleaseFileName() {
let date = new Date();
let fileName = `Release_${date.getFullYear()}${fix2(date.getMonth() + 1)}${fix2(date.getDate())} `;
fileName += `${fix2(date.getHours())}-${fix2(date.getMinutes())}-${fix2(date.getSeconds())}`;
return fileName;
}
main();
\ No newline at end of file
This diff is collapsed.
...@@ -4,11 +4,18 @@ ...@@ -4,11 +4,18 @@
"description": "", "description": "",
"main": "build.js", "main": "build.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
"build": "node build.js",
"start": "node app.js"
}, },
"type": "module",
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"compressing": "^1.5.1" "child_process": "^1.0.2",
"compressing": "^1.5.1",
"express": "^4.17.1",
"js-base64": "^3.7.2",
"uuid": "^8.3.2"
} }
} }
let fs = require('fs'); import fs from 'fs';
module.exports = {
fix2: function (num) {
if (num >= 10) {
return '' + num;
} else {
return '0' + num;
}
},
copyDir: async function (src, dst) { export function fix2(num) {
const exists = await fs.existsSync(dst); if (num >= 10) {
if (!exists) { return '' + num;
await fs.mkdirSync(dst); } else {
} return '0' + num;
//读取目录 }
const paths = await fs.readdirSync(src); }
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
const newSrc = `${src}/${path}`;
const newDst = `${dst}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('copy: ' + newDst);
const data = await fs.readFileSync(newSrc);
await fs.writeFileSync(newDst, data);
} else if (st.isDirectory()) {
arguments.callee(newSrc, newDst);
}
}
},
removeDir: async function (src) { export async function copyDir(src, dst) {
const exists = await fs.existsSync(src); const exists = await fs.existsSync(dst);
if (!exists) { if (!exists) {
return; await fs.mkdirSync(dst);
}
//读取目录
const paths = await fs.readdirSync(src);
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
const newSrc = `${src}/${path}`;
const newDst = `${dst}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('copy: ' + newDst);
const data = await fs.readFileSync(newSrc);
await fs.writeFileSync(newDst, data);
} else if (st.isDirectory()) {
await copyDir(newSrc, newDst);
} }
}
}
//读取目录 export async function removeDir(src) {
const st = await fs.statSync(src); const exists = await fs.existsSync(src);
const paths = await fs.readdirSync(src); if (!exists) {
for (let i = 0; i < paths.length; i++) { return;
let path = paths[i]; }
const newSrc = `${src}/${path}`;
const st = await fs.statSync(newSrc); //读取目录
if (st.isFile()) { const st = await fs.statSync(src);
console.log('remove: ' + newSrc); const paths = await fs.readdirSync(src);
await fs.unlinkSync(newSrc); for (let i = 0; i < paths.length; i++) {
} else if (st.isDirectory()) { let path = paths[i];
await arguments.callee(newSrc); const newSrc = `${src}/${path}`;
} const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('remove: ' + newSrc);
await fs.unlinkSync(newSrc);
} else if (st.isDirectory()) {
await removeDir(newSrc);
} }
await fs.rmdirSync(src);
} }
} await fs.rmdirSync(src);
}
\ No newline at end of file
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