Skip to content

Commit

Permalink
fix busted compiler.html
Browse files Browse the repository at this point in the history
  • Loading branch information
dfabulich committed Jan 11, 2015
1 parent ec71d4d commit 77267c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 11 additions & 3 deletions compile.html
Expand Up @@ -43,8 +43,9 @@
}


function slurpFile(url) {
function slurpFile(url, throwOnError) {
xhr = new XMLHttpRequest();
var loadFailed = false;
try {
xhr.open("GET", url, false); //IE errors on xhr.open
xhr.send();
Expand All @@ -64,7 +65,7 @@
loadFailed = true;
}

if (loadFailed) {
if (loadFailed && throwOnError) {
doneLoading();
console.log("EXPORT FAILED");
console.log("Error: Could not open " + url);
Expand All @@ -73,7 +74,7 @@
if (typeof InstallTrigger == 'undefined') {
console.log("Your browser may not be supported. We recommend using Mozilla Firefox with compile.html.");
}
return;
throw new Error("Error: Could not open " + url);
}

if (success) {
Expand All @@ -84,6 +85,13 @@
exit();
}
}

function doneLoading() {
var loading = document.getElementById('loading');
if (loading) loading.parentNode.removeChild(loading);
// TODO update header?
}

</script>
<script src=compile.js></script>
</head>
Expand Down
14 changes: 8 additions & 6 deletions compile.js
Expand Up @@ -4,11 +4,12 @@ var success = true;
var skip = false;
var loadFailed = false;

var rootDir;

if (typeof process != "undefined") {
var outputFile = process.argv[2];
if (!outputFile) throw new Error("Specify an output file on the command line");
var rootDir = process.argv[3];
if (!rootDir) rootDir = "web";
rootDir = process.argv[3];
rootDir += "/";
fs = require('fs');
path = require('path');
Expand All @@ -24,20 +25,21 @@ if (typeof process != "undefined") {
fs.writeFileSync(outputFile, compile(), "utf8");
}

if (!rootDir) rootDir = "web/";

function compile(){

function safeSlurpFile(file) {
try {
return slurpFile(file);
return slurpFile(file, false);
} catch (e) {
return null;
}
}

//1. Grab the game's html file
var url = rootDir+"mygame/index.html";
var game_html = slurpFile(url);
var game_html = slurpFile(url, true);

//2. Find and extract all .js file data
var next_file = "";
Expand All @@ -62,7 +64,7 @@ function compile(){
while (doesMatch = patt.exec(game_html)) {
// console.log(doesMatch[0]);
console.log(doesMatch[1]);
next_file = slurpFile(rootDir+'mygame/' + doesMatch[1]);
next_file = slurpFile(rootDir+'mygame/' + doesMatch[1], true);
if (next_file != "undefined" && next_file !== null) {
cssStore = cssStore + next_file;
}
Expand Down Expand Up @@ -92,7 +94,7 @@ function compile(){
//Check startup.txt for a *scene_list
var sceneList = false;
scene = new Scene("startup");
var scene_data = slurpFile(rootDir+'mygame/scenes/startup.txt');
var scene_data = slurpFile(rootDir+'mygame/scenes/startup.txt', true);
scene.loadLines(scene_data);
patt = /^\*scene_list$/gim;
for (i = 0; i < scene["lines"].length; i++) {
Expand Down

0 comments on commit 77267c7

Please sign in to comment.