Commit 70d3afbb authored by 范雪寒's avatar 范雪寒

feat: 修改uuid,适应流水线

parent d40d81d9
// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({ cc.Class({
extends: cc.Component, extends: cc.Component,
properties: {},
properties: {
// foo: { getData(callBack) {
// // ATTRIBUTES: const uri = 'syllabus/v1/getdata';
// default: null, // The default value will be used only when the component attaching const data = {
// // to a node for the first time syllabusid: this.syllabus_id
// type: cc.SpriteFrame, // optional, default is typeof default };
// serializable: true, // optional, default is true console.log('data = ' + JSON.stringify(data));
// }, this.callNetworkApiGet(uri, data, callBack);
// bar: { },
// get () {
// return this._bar; onHomeworkFinish(callBack) {
// }, if (this.role == 'teacher') {
// set (value) { return;
// this._bar = value; }
// } const uri = 'app_source/v1/student/homework/finished';
// }, const data = {
}, syllabus_id: this.syllabus_id,
homework_id: this.homework_id,
// LIFE-CYCLE CALLBACKS: token: this.token,
score: 100
// onLoad () {}, };
console.log('data = ' + JSON.stringify(data));
start () { this.callNetworkApiPost(uri, data, callBack);
},
},
callNetworkApiGet(uri, data, callBack) {
// update (dt) {}, let queryStr = '?';
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
const value = data[key];
queryStr += `${key}=${value}`;
}
}
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
const responseData = JSON.parse(xhr.responseText);
callBack(JSON.parse(responseData.data));
}
};
const url = `${this.baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
},
callNetworkApiPost(uri, data, callBack) {
const xhr = new XMLHttpRequest();
const url = `${this.baseUrl}${uri}`;
xhr.open("POST", url, true);
xhr.setRequestHeader('content-type', 'application/json');
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
callBack(JSON.parse(xhr.responseText));
}
}
xhr.send(JSON.stringify(data));
},
start() {
this.node.zIndex = 9999;
this.showWaitingLetters();
cc.game.addPersistRootNode(this.node);
this.initListener();
this.getBundleInfoList();
},
getBundleInfoList() {
const jsonStr = this.callNativeFunction({ name: 'loadSceneList', value: '' });
const { bundleInfoList, defaultBundleIdx } = JSON.parse(jsonStr);
this.bundleInfoList = bundleInfoList;
if (this.bundleInfoList.length < 2) {
const btnLeft = this.node.getChildByName('BtnLeft');
const btnRight = this.node.getChildByName('BtnRight');
btnLeft.active = false;
btnRight.active = false;
}
this.jumpToBundleByIndex(defaultBundleIdx);
},
jumpToBundleByIndex(index) {
this.currentBundleIndex = index;
const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex];
this.baseUrl = currentBundleInfo.baseUrl;
this.token = currentBundleInfo.token;
this.homework_id = currentBundleInfo.homework_id;
this.syllabus_id = currentBundleInfo.syllabus_id;
this.role = currentBundleInfo.role;
cc.assetManager.loadBundle(currentBundleInfo.bondleUrl, { version: currentBundleInfo.version }, (err, bundle) => {
if (err) {
return console.error(err);
}
bundle.loadScene(currentBundleInfo.sceneName, (err, scene) => {
this.hideWaitingLetters();
cc.director.runScene(scene);
});
});
},
loadDefaultBundle() {
const jsonStr = this.callNativeFunction({ name: 'loadScene', value: '' });
const {
sceneName,
version,
bondleUrl,
token,
baseUrl,
homework_id,
syllabus_id,
role
} = JSON.parse(jsonStr);
this.baseUrl = baseUrl;
this.token = token;
this.homework_id = homework_id;
this.syllabus_id = syllabus_id;
this.role = role;
cc.assetManager.loadBundle(bondleUrl, { version: version }, (err, bundle) => {
if (err) {
return console.error(err);
}
bundle.loadScene(sceneName, (err, scene) => {
this.hideWaitingLetters();
cc.director.runScene(scene);
});
});
},
initListener() {
const exitBtn = this.node.getChildByName('ExitBtn');
exitBtn.on('click', () => {
cc.tween(exitBtn)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 })
.to(0.1, { scaleX: 1.1, scaleY: 0.9 })
.to(0.1, { scaleX: 1, scaleY: 1 })
.call(() => {
cc.game.removePersistRootNode(this.node);
cc.director.loadScene("emptyScene", () => {
this.callNativeFunction({ name: 'exit', value: '' });
});
})
.start();
});
const btnLeft = this.node.getChildByName('BtnLeft');
btnLeft.on('click', () => {
if (this.currentBundleIndex - 1 < 0) {
this.jumpToBundleByIndex(this.bundleInfoList.length - 1);
} else {
this.jumpToBundleByIndex(this.currentBundleIndex - 1);
}
});
const btnRight = this.node.getChildByName('BtnRight');
btnRight.on('click', () => {
if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) {
this.jumpToBundleByIndex(0);
} else {
this.jumpToBundleByIndex(this.currentBundleIndex + 1);
}
});
},
callNativeFunction(param) {
const paramStr = JSON.stringify(param);
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
return jsb.reflection.callStaticMethod('CocosMng', 'cocosWithNativeProtocol:', paramStr);
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) {
return jsb.reflection.callStaticMethod('com/iplayabc/cocos/AppActivity', 'cocosWithNativeProtocol', '(Ljava/lang/String;)Ljava/lang/String;', paramStr);
} else {
throw ('非源生环境');
}
},
showWaitingLetters() {
const colorList = this.getRainbowColorList();
const layout = cc.find('middleLayer/layout');
layout.active = true;
const str = 'Now Loading...';
str.split('').forEach((word, idx) => {
const node = new cc.Node();
const label = node.addComponent(cc.Label);
label.string = word;
node.parent = layout;
node.color = colorList[idx];
cc.tween(node)
.delay(idx / 4)
.by(0.3, { y: 50 }, { easing: 'sineOut' })
.by(0.3, { y: -50 }, { easing: 'sineIn' })
.delay((str.length - idx) / 4)
.union()
.repeatForever()
.start();
});
const totalWidth = layout.children.reduce((width, node, idx) => {
return width + node.width;
}, 0);
layout.width = totalWidth;
},
hideWaitingLetters() {
const layout = cc.find('middleLayer/layout');
layout.active = false;
},
showLog(str) {
console.log('str = ' + str);
const node = new cc.Node();
const label = node.addComponent(cc.RichText);
label.string = `<outline color=black width=3>${str}</outline>`;
label.maxWidth = this.node.width / 2;
node.x = this.node.width / 2;
node.y = this.node.height / 2;
node.parent = this.node;
cc.tween(node)
.to(5, { y: this.node.height })
.call(() => {
node.removeFromParent();
})
.start();
},
getRainbowColorList() {
return [
cc.color(128, 0, 255),
cc.color(255, 0, 255),
cc.color(255, 0, 128),
cc.color(0, 0, 0),
cc.color(255, 0, 0),
cc.color(255, 128, 0),
cc.color(255, 255, 0),
cc.color(128, 255, 0),
cc.color(0, 255, 0),
cc.color(0, 255, 128),
cc.color(0, 255, 255),
cc.color(0, 128, 255),
cc.color(0, 0, 255),
cc.color(128, 0, 255),
];
}
}); });
{ {
"ver": "1.0.8", "ver": "1.0.8",
"uuid": "363f36a9-434f-4848-85d3-82d42a168145", "uuid": "f4ede462-f8d7-4069-ba80-915611c058ca",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
......
cc.Class({ cc.Class({
extends: cc.Component, extends: cc.Component,
properties: {}, properties: {},
getData(callBack) { getData(callBack) {
const uri = 'syllabus/v1/getdata'; const uri = 'syllabus/v1/getdata';
const data = { const data = {
syllabusid: this.syllabus_id syllabusid: this.syllabus_id
}; };
console.log('data = ' + JSON.stringify(data)); console.log('data = ' + JSON.stringify(data));
this.callNetworkApiGet(uri, data, callBack); this.callNetworkApiGet(uri, data, callBack);
}, },
onHomeworkFinish(callBack) { onHomeworkFinish(callBack) {
if (this.role == 'teacher') { if (this.role == 'teacher') {
return; return;
} }
const uri = 'app_source/v1/student/homework/finished'; const uri = 'app_source/v1/student/homework/finished';
const data = { const data = {
syllabus_id: this.syllabus_id, syllabus_id: this.syllabus_id,
homework_id: this.homework_id, homework_id: this.homework_id,
token: this.token, token: this.token,
score: 100 score: 100
}; };
console.log('data = ' + JSON.stringify(data)); console.log('data = ' + JSON.stringify(data));
this.callNetworkApiPost(uri, data, callBack); this.callNetworkApiPost(uri, data, callBack);
}, },
callNetworkApiGet(uri, data, callBack) { callNetworkApiGet(uri, data, callBack) {
let queryStr = '?'; let queryStr = '?';
for (const key in data) { for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) { if (Object.hasOwnProperty.call(data, key)) {
const value = data[key]; const value = data[key];
queryStr += `${key}=${value}`; queryStr += `${key}=${value}`;
} }
} }
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
const responseData = JSON.parse(xhr.responseText); const responseData = JSON.parse(xhr.responseText);
callBack(JSON.parse(responseData.data)); callBack(JSON.parse(responseData.data));
} }
}; };
const url = `${this.baseUrl}${uri}${queryStr}`; const url = `${this.baseUrl}${uri}${queryStr}`;
console.log('url = ' + url); console.log('url = ' + url);
xhr.open('GET', url, true); xhr.open('GET', url, true);
xhr.send(); xhr.send();
}, },
callNetworkApiPost(uri, data, callBack) { callNetworkApiPost(uri, data, callBack) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
const url = `${this.baseUrl}${uri}`; const url = `${this.baseUrl}${uri}`;
xhr.open("POST", url, true); xhr.open("POST", url, true);
xhr.setRequestHeader('content-type', 'application/json'); xhr.setRequestHeader('content-type', 'application/json');
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
if (xhr.readyState == 4) { if (xhr.readyState == 4) {
callBack(JSON.parse(xhr.responseText)); callBack(JSON.parse(xhr.responseText));
} }
} }
xhr.send(JSON.stringify(data)); xhr.send(JSON.stringify(data));
}, },
start() { start() {
this.node.zIndex = 9999; this.node.zIndex = 9999;
this.showWaitingLetters(); this.showWaitingLetters();
cc.game.addPersistRootNode(this.node); cc.game.addPersistRootNode(this.node);
this.initListener(); this.initListener();
this.getBundleInfoList(); this.getBundleInfoList();
}, },
getBundleInfoList() { getBundleInfoList() {
const jsonStr = this.callNativeFunction({ name: 'loadSceneList', value: '' }); const jsonStr = this.callNativeFunction({ name: 'loadSceneList', value: '' });
const { bundleInfoList, defaultBundleIdx } = JSON.parse(jsonStr); const { bundleInfoList, defaultBundleIdx } = JSON.parse(jsonStr);
this.bundleInfoList = bundleInfoList; this.bundleInfoList = bundleInfoList;
if (this.bundleInfoList.length < 2) { if (this.bundleInfoList.length < 2) {
const btnLeft = this.node.getChildByName('BtnLeft'); const btnLeft = this.node.getChildByName('BtnLeft');
const btnRight = this.node.getChildByName('BtnRight'); const btnRight = this.node.getChildByName('BtnRight');
btnLeft.active = false; btnLeft.active = false;
btnRight.active = false; btnRight.active = false;
} }
this.jumpToBundleByIndex(defaultBundleIdx); this.jumpToBundleByIndex(defaultBundleIdx);
}, },
jumpToBundleByIndex(index) { jumpToBundleByIndex(index) {
this.currentBundleIndex = index; this.currentBundleIndex = index;
const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex]; const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex];
this.baseUrl = currentBundleInfo.baseUrl; this.baseUrl = currentBundleInfo.baseUrl;
this.token = currentBundleInfo.token; this.token = currentBundleInfo.token;
this.homework_id = currentBundleInfo.homework_id; this.homework_id = currentBundleInfo.homework_id;
this.syllabus_id = currentBundleInfo.syllabus_id; this.syllabus_id = currentBundleInfo.syllabus_id;
this.role = currentBundleInfo.role; this.role = currentBundleInfo.role;
cc.assetManager.loadBundle(currentBundleInfo.bondleUrl, { version: currentBundleInfo.version }, (err, bundle) => { cc.assetManager.loadBundle(currentBundleInfo.bondleUrl, { version: currentBundleInfo.version }, (err, bundle) => {
if (err) { if (err) {
return console.error(err); return console.error(err);
} }
bundle.loadScene(currentBundleInfo.sceneName, (err, scene) => { bundle.loadScene(currentBundleInfo.sceneName, (err, scene) => {
this.hideWaitingLetters(); this.hideWaitingLetters();
cc.director.runScene(scene); cc.director.runScene(scene);
}); });
}); });
}, },
loadDefaultBundle() { loadDefaultBundle() {
const jsonStr = this.callNativeFunction({ name: 'loadScene', value: '' }); const jsonStr = this.callNativeFunction({ name: 'loadScene', value: '' });
const { const {
sceneName, sceneName,
version, version,
bondleUrl, bondleUrl,
token, token,
baseUrl, baseUrl,
homework_id, homework_id,
syllabus_id, syllabus_id,
role role
} = JSON.parse(jsonStr); } = JSON.parse(jsonStr);
this.baseUrl = baseUrl; this.baseUrl = baseUrl;
this.token = token; this.token = token;
this.homework_id = homework_id; this.homework_id = homework_id;
this.syllabus_id = syllabus_id; this.syllabus_id = syllabus_id;
this.role = role; this.role = role;
cc.assetManager.loadBundle(bondleUrl, { version: version }, (err, bundle) => { cc.assetManager.loadBundle(bondleUrl, { version: version }, (err, bundle) => {
if (err) { if (err) {
return console.error(err); return console.error(err);
} }
bundle.loadScene(sceneName, (err, scene) => { bundle.loadScene(sceneName, (err, scene) => {
this.hideWaitingLetters(); this.hideWaitingLetters();
cc.director.runScene(scene); cc.director.runScene(scene);
}); });
}); });
}, },
initListener() { initListener() {
const exitBtn = this.node.getChildByName('ExitBtn'); const exitBtn = this.node.getChildByName('ExitBtn');
exitBtn.on('click', () => { exitBtn.on('click', () => {
cc.tween(exitBtn) cc.tween(exitBtn)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 }) .to(0.1, { scaleX: 0.9, scaleY: 1.1 })
.to(0.1, { scaleX: 1.1, scaleY: 0.9 }) .to(0.1, { scaleX: 1.1, scaleY: 0.9 })
.to(0.1, { scaleX: 1, scaleY: 1 }) .to(0.1, { scaleX: 1, scaleY: 1 })
.call(() => { .call(() => {
cc.game.removePersistRootNode(this.node); cc.game.removePersistRootNode(this.node);
cc.director.loadScene("emptyScene", () => { cc.director.loadScene("emptyScene", () => {
this.callNativeFunction({ name: 'exit', value: '' }); this.callNativeFunction({ name: 'exit', value: '' });
}); });
}) })
.start(); .start();
}); });
const btnLeft = this.node.getChildByName('BtnLeft'); const btnLeft = this.node.getChildByName('BtnLeft');
btnLeft.on('click', () => { btnLeft.on('click', () => {
if (this.currentBundleIndex - 1 < 0) { if (this.currentBundleIndex - 1 < 0) {
this.jumpToBundleByIndex(this.bundleInfoList.length - 1); this.jumpToBundleByIndex(this.bundleInfoList.length - 1);
} else { } else {
this.jumpToBundleByIndex(this.currentBundleIndex - 1); this.jumpToBundleByIndex(this.currentBundleIndex - 1);
} }
}); });
const btnRight = this.node.getChildByName('BtnRight'); const btnRight = this.node.getChildByName('BtnRight');
btnRight.on('click', () => { btnRight.on('click', () => {
if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) { if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) {
this.jumpToBundleByIndex(0); this.jumpToBundleByIndex(0);
} else { } else {
this.jumpToBundleByIndex(this.currentBundleIndex + 1); this.jumpToBundleByIndex(this.currentBundleIndex + 1);
} }
}); });
}, },
callNativeFunction(param) { callNativeFunction(param) {
const paramStr = JSON.stringify(param); const paramStr = JSON.stringify(param);
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) { if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
return jsb.reflection.callStaticMethod('CocosMng', 'cocosWithNativeProtocol:', paramStr); return jsb.reflection.callStaticMethod('CocosMng', 'cocosWithNativeProtocol:', paramStr);
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) { } else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) {
return jsb.reflection.callStaticMethod('com/iplayabc/cocos/AppActivity', 'cocosWithNativeProtocol', '(Ljava/lang/String;)Ljava/lang/String;', paramStr); return jsb.reflection.callStaticMethod('com/iplayabc/cocos/AppActivity', 'cocosWithNativeProtocol', '(Ljava/lang/String;)Ljava/lang/String;', paramStr);
} else { } else {
throw ('非源生环境'); throw ('非源生环境');
} }
}, },
showWaitingLetters() { showWaitingLetters() {
const colorList = this.getRainbowColorList(); const colorList = this.getRainbowColorList();
const layout = cc.find('middleLayer/layout'); const layout = cc.find('middleLayer/layout');
layout.active = true; layout.active = true;
const str = 'Now Loading...'; const str = 'Now Loading...';
str.split('').forEach((word, idx) => { str.split('').forEach((word, idx) => {
const node = new cc.Node(); const node = new cc.Node();
const label = node.addComponent(cc.Label); const label = node.addComponent(cc.Label);
label.string = word; label.string = word;
node.parent = layout; node.parent = layout;
node.color = colorList[idx]; node.color = colorList[idx];
cc.tween(node) cc.tween(node)
.delay(idx / 4) .delay(idx / 4)
.by(0.3, { y: 50 }, { easing: 'sineOut' }) .by(0.3, { y: 50 }, { easing: 'sineOut' })
.by(0.3, { y: -50 }, { easing: 'sineIn' }) .by(0.3, { y: -50 }, { easing: 'sineIn' })
.delay((str.length - idx) / 4) .delay((str.length - idx) / 4)
.union() .union()
.repeatForever() .repeatForever()
.start(); .start();
}); });
const totalWidth = layout.children.reduce((width, node, idx) => { const totalWidth = layout.children.reduce((width, node, idx) => {
return width + node.width; return width + node.width;
}, 0); }, 0);
layout.width = totalWidth; layout.width = totalWidth;
}, },
hideWaitingLetters() { hideWaitingLetters() {
const layout = cc.find('middleLayer/layout'); const layout = cc.find('middleLayer/layout');
layout.active = false; layout.active = false;
}, },
showLog(str) { showLog(str) {
console.log('str = ' + str); console.log('str = ' + str);
const node = new cc.Node(); const node = new cc.Node();
const label = node.addComponent(cc.RichText); const label = node.addComponent(cc.RichText);
label.string = `<outline color=black width=3>${str}</outline>`; label.string = `<outline color=black width=3>${str}</outline>`;
label.maxWidth = this.node.width / 2; label.maxWidth = this.node.width / 2;
node.x = this.node.width / 2; node.x = this.node.width / 2;
node.y = this.node.height / 2; node.y = this.node.height / 2;
node.parent = this.node; node.parent = this.node;
cc.tween(node) cc.tween(node)
.to(5, { y: this.node.height }) .to(5, { y: this.node.height })
.call(() => { .call(() => {
node.removeFromParent(); node.removeFromParent();
}) })
.start(); .start();
}, },
getRainbowColorList() { getRainbowColorList() {
return [ return [
cc.color(128, 0, 255), cc.color(128, 0, 255),
cc.color(255, 0, 255), cc.color(255, 0, 255),
cc.color(255, 0, 128), cc.color(255, 0, 128),
cc.color(0, 0, 0), cc.color(0, 0, 0),
cc.color(255, 0, 0), cc.color(255, 0, 0),
cc.color(255, 128, 0), cc.color(255, 128, 0),
cc.color(255, 255, 0), cc.color(255, 255, 0),
cc.color(128, 255, 0), cc.color(128, 255, 0),
cc.color(0, 255, 0), cc.color(0, 255, 0),
cc.color(0, 255, 128), cc.color(0, 255, 128),
cc.color(0, 255, 255), cc.color(0, 255, 255),
cc.color(0, 128, 255), cc.color(0, 128, 255),
cc.color(0, 0, 255), cc.color(0, 0, 255),
cc.color(128, 0, 255), cc.color(128, 0, 255),
]; ];
} }
}); });
{ {
"ver": "1.0.8", "ver": "1.0.8",
"uuid": "f4ede462-f8d7-4069-ba80-915611c058ca", "uuid": "363f36a9-434f-4848-85d3-82d42a168145",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
......
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