Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config.json no longer gets converted to Base64 #36

Merged
merged 2 commits into from Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions engine-patches/one-page-app-configure-json.js
@@ -0,0 +1,17 @@
(function () {
pc.Application.prototype.configure = function (json, callback) {
const props = json.application_properties;
const scenes = json.scenes;
const assets = json.assets;

this._parseApplicationProperties(props, (err) => {
this._parseScenes(scenes);
this._parseAssets(assets);
if (!err) {
callback(null);
} else {
callback(err);
}
});
};
})();
23 changes: 21 additions & 2 deletions one-page.js
Expand Up @@ -54,6 +54,11 @@ function inlineAssets(projectPath) {
addPatchFile('one-page-inline-game-scripts.js');
}

// Patch the engine app configure function to take a JSON object instead of a URL
// so we don't need to Base64 the config.json and take another ~30% hit on file size
console.log("↪️ Adding app configure engine patch");
addPatchFile('one-page-app-configure-json.js');

// MRAID support needs to include the mraid.js file and also force the app to use filltype NONE
// so that it fits in the canvas that is sized by the MRAID implementation on the app. This requires
// patching the CSS too to ensure it is placed correctly in the Window
Expand Down Expand Up @@ -267,7 +272,7 @@ function inlineAssets(projectPath) {


// 7. In __settings__.js, change the SCENE_PATH to a base64 string of the scene file.
// 8. In __settings__.js, change the CONFIG_FILENAME to a base64 string of the config.json file.
// 8. In __settings__.js, inline the JSON from the config.json file and assign it to CONFIG_FILENAME
(function() {
console.log("↪️ Base64 encode the scene JSON and config JSON files");

Expand All @@ -285,8 +290,22 @@ function inlineAssets(projectPath) {
contents = replaceString(contents, match[1], "data:application/json;base64," + b64);
};

var assignJsonObject = function(regex) {
var match = contents.match(regex);

// Assume match
var filepath = path.resolve(projectPath, match[2]);
var jsonContents = fs.readFileSync(filepath, 'utf-8');

// Copy the JSON string here but parse at runtime
// JSON.stringify the JSON string to escape characters properly
var code = "JSON.parse(" + JSON.stringify(jsonContents) + ")";

contents = replaceString(contents, match[1], code);
}

jsonToBase64(/SCENE_PATH = "(.*)";/i);
jsonToBase64(/CONFIG_FILENAME = "(.*)"/i);
assignJsonObject(/CONFIG_FILENAME = ("(.*)")/i);

fs.writeFileSync(location, contents);
})();
Expand Down