-
Notifications
You must be signed in to change notification settings - Fork 123
/
compile.html
executable file
·118 lines (108 loc) · 3.37 KB
/
compile.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html>
<head>
<script src=web/scene.js></script>
<script src=web/navigator.js></script>
<script src=web/util.js></script>
<script src=web/mygame/mygame.js></script>
<script src=mygamegenerator.js></script>
<script>
var oldLog = console.log;
console.log = function() {
var msg = arguments[0];
printBody(msg);
var br = document.createElement("br");
document.body.appendChild(br);
br.scrollIntoView();
oldLog.apply(this, arguments);
}
function printBody(msg, parent) {
if (msg === null || msg === undefined || msg === "") return;
if (!parent) parent = document.body;
if (msg == " ") {
// IE7 doesn't like innerHTML that's nothing but " "
parent.appendChild(document.createTextNode(" "));
return;
}
msg = (msg+"").replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/\[b\]/g, '<b>')
.replace(/\[\/b\]/g, '</b>')
.replace(/\[i\]/g, '<i>')
.replace(/\[\/i\]/g, '</i>');
var frag = document.createDocumentFragment();
temp = document.createElement('div');
temp.innerHTML = msg;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
parent.appendChild(frag);
}
function slurpFile(url, throwOnError) {
xhr = new XMLHttpRequest();
var loadFailed = false;
try {
xhr.open("GET", url, false); //IE errors on xhr.open
xhr.send();
}
catch (x) {
if (window.location.protocol == "file:" && /Chrome/.test(navigator.userAgent)) {
doneLoading();
console.log("We're sorry, Google Chrome has blocked ChoiceScript from functioning. (\"file:\" URLs cannot "+
"load files in Chrome.) ChoiceScript works just fine in Chrome, but only on a published website like "+
"choiceofgames.com. For the time being, please try another browser like Mozilla Firefox.");
success = false;
}
loadFailed = true;
}
if (xhr.status && xhr.status != 200) {
loadFailed = true;
}
if (loadFailed && throwOnError) {
doneLoading();
console.log("EXPORT FAILED");
console.log("Error: Could not open " + url);
success = false;
//only Firefox:
if (typeof InstallTrigger == 'undefined') {
console.log("Your browser may not be supported. We recommend using Mozilla Firefox with compile.html.");
}
throw new Error("Error: Could not open " + url);
}
if (success) {
return loadFailed ? "" : xhr.responseText;
}
else {
console.log("An unknown error occurred, please email dan at fabulich.com with details");
exit();
}
}
function slurpFileLines(url, throwOnError) {
return slurpFile(url).split(/\r?\n/);
}
function doneLoading() {
var loading = document.getElementById('loading');
if (loading) loading.parentNode.removeChild(loading);
// TODO update header?
}
</script>
</head>
<body>
<div id="loading">Loading...</div>
<script src=compile.js></script>
<script>
function finish(compiledResult) {
var blob = new Blob([compiledResult.content], {type: "text/html"});
var bloburl = URL.createObjectURL(blob);
var title = compiledResult.title || 'output';
var fileName = title.replace(/[^a-zA-Z0-9\-]/g, '_') + '.html';
console.log("Export Complete!");
document.body.insertAdjacentHTML("beforeend", "Click <a download='"+fileName+"' href='" + bloburl + "'>here</a> to download your compiled game.");
}
var compiledResult = compile();
if (compiledResult) finish(compiledResult);
</script>
</body>
</html>