Skip to content

Commit

Permalink
fix cconb file
Browse files Browse the repository at this point in the history
  • Loading branch information
minzhi3 committed Mar 9, 2022
1 parent 96f848c commit 99bc99b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "playable-build-tool",
"title": "Playable build tool",
"package_version": 2,
"version": "1.0.0",
"version": "1.0.1",
"author": "minzhi",
"description": "i18n:playable-build-tool.description",
"contributions": {
Expand Down
17 changes: 8 additions & 9 deletions source/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const import_map_match_key = "<!--IMPORT_MAP-->";
const dapi_match_key = "<!--DAPI_HEAD-->";
const google_match_key = "<!--GOOGLE_HEAD-->";
const start_match_key = "<!--START-->";
const fileByteList = [".png", ".bin", ".mp3"];
const excludeList = ["/index.js"];
const base64PreList = new Map<string, string>([
[".png", "data:image/png;base64,"],
[".bin", "data:application/octet-stream;base64,"],
[".mp3", "data:audio/mpeg;base64,"],
[".cconb", "data:application/octet-stream;base64,"],
[".ttf", ""],
]);
export class MergeBuilder {
Expand Down Expand Up @@ -208,9 +208,7 @@ export class MergeBuilder {
switch (adNetwork) {
case "mintegral":
const mintegral_str =
"<script>\n" +
this.readFile(this.mintegral_path) +
"\n</script>\n";
"<script>\n" + this.readFile(this.mintegral_path) + "\n</script>\n";
html_str = html_str.replace(start_match_key, mintegral_str);
break;
case "ironsource":
Expand All @@ -219,7 +217,8 @@ export class MergeBuilder {
html_str = html_str.replace(start_match_key, dapi_body_str);
break;
case "unity":
const unity_path = "<script>\n" + this.readFile(this.unity_path) + "</script>\n";
const unity_path =
"<script>\n" + this.readFile(this.unity_path) + "</script>\n";
html_str = html_str.replace(start_match_key, unity_path);
break;
case "applovin":
Expand All @@ -235,24 +234,24 @@ export class MergeBuilder {

//bundle
const bundle_str =
"<script>\nfunction loadBundle(){\n" +
"<script>\nfunction loadMyBundle(){\n" +
this.readFile(this.bundle_path) +
"}\n</script>\n";
"\n}\n</script>\n";
html_str = this.simpleReplace(html_str, bundle_match_key, bundle_str);

//engine
const engine_str =
"<script>\nfunction loadCC(){\n" +
this.readFile(this.engine_path) +
"}\n</script>\n";
"\n}\n</script>\n";
html_str = this.simpleReplace(html_str, engine_match_key, engine_str);

// resmap
const resStr = this.getResMapScript();
const cc_index_str =
"<script>\nfunction loadCCIndex(){\n" +
this.readFile(this.cc_index_js_path) +
"}\n</script>\n";
"\n}\n</script>\n";
const setting_str =
"<script>window._CCSettings = " +
this.readFile(this.setting_path) +
Expand Down
16 changes: 16 additions & 0 deletions static/download-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,25 @@ function downloadAudio(url, options, onComplete) {
oldHook(url, options, onComplete)
}

function downloadCCONB(url, options, onComplete) {
downloadArrayBuffer(url, options, function (err, arrayBuffer) {
if (err) {
onComplete(err);
return;
}
try {
var ccon = cc.internal.decodeCCONBinary(new Uint8Array(arrayBuffer));
onComplete(null, ccon);
} catch (err) {
onComplete(err);
}
});
}

window.hook = function (cc) {
console.log('run hook')
cc.assetManager.downloader.register('.bin', downloadArrayBuffer);
cc.assetManager.downloader.register('.cconb', downloadCCONB);
cc.assetManager.downloader.register('.png', downloadDomImage);
cc.assetManager.downloader.register('.json', downloadJson);
cc.assetManager.downloader.register('.js', downloadScript);
Expand Down
2 changes: 1 addition & 1 deletion static/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function load(name){
loadCC()
return true
}else if (name === "bundle.js"){
loadBundle()
loadMyBundle()
return true
}else {
return false
Expand Down

0 comments on commit 99bc99b

Please # to comment.