/
index.html
190 lines (166 loc) · 6.16 KB
/
index.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<html>
<head>
<title>Prison Architect Escape Tunnel Finder</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.3.1/lodash.min.js"></script>
<style>
#prison {
width: 100%;
position: relative;
}
#prison > div {
position: absolute;
width: 10px;
height: 10px;
}
#prison > div.wall {
background-color: #000;
}
#prison > div.tunnel {
background-color: #ffa200;
}
#prison > div.tunnel.wall {
background-color: #5f4829;
}
#drop_zone {
border: 2px dashed #bbb;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
padding: 25px;
text-align: center;
font: 20pt bold;
color: #bbb;
margin-top: 2em;
margin-bottom: 1em;
}
footer {
position: absolute;
top: 5px;
right: 5px;
text-align: right;
}
img { vertical-align: middle; }
</style>
</head>
<body>
<div id="drop_zone">Drop Prison-Architect savegame here and find escape-tunnels!<br />
<small>known to work with: alpha-20 to alpha-30a</div>
<output id="list"></output>
<script>
var states = {
scan: 1,
end: 0,
cells: 2,
tunnels: 3,
version: 4
};
var types = {
nothing: 0,
wall: 1,
tunnel: 2,
wall_and_tunnel: 3
};
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files; // FileList object.
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
if (!_.endsWith(f.name, '.prison')) { continue; }
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var prison_lines = _.map(e.target.result.split('\n'), _.trim);
var line_count = prison_lines.length;
var state = states.scan;
var pointer = 0;
var prison = { p: {}};
var update = function(rem){
document.getElementById("prison").innerHTML = 'Progress: ' + Math.trunc(100*(1.0 - (1.0 * rem / line_count)))+'%';
};
var step = function() {
update(prison_lines.length);
var count = 0;
while (state !== states.end) {
count++;
if (count === 1000) {_.defer(step); return; }
if (pointer >= line_count) { state = states.end; continue; }
line = prison_lines[pointer];
if (state === states.scan) {
if (_.startsWith(line, 'Version')) { state = states.version; continue; }
if (line == 'BEGIN Cells') { state = states.cells; continue; }
if (line == 'BEGIN Tunnels') { state = states.tunnels; continue; }
pointer++; continue;
}
if (state === states.version) {
prison.version = _.trim(line.substr('Version'.length));
pointer++;
state = states.scan; continue;
}
if (state === states.cells) {
if (line == 'BEGIN Cells') { pointer++; continue; }
if (line == 'END') { state = states.scan; continue; }
if (line.search(/(BrickWall)|(ConcreteWall)|(Fence)|(PerimeterWall)/) !== -1) {
var regex_match = line.match(/(\d+) (\d+)/);
var x = regex_match[1], y = regex_match[2];
prison.p[[x,y]] = types.nothing + types.wall;
}
pointer++; continue;
}
if (state === states.tunnels) {
if (line == 'BEGIN Tunnels') { pointer++; continue; }
if (line == 'END') { state = states.scan; continue; }
if (line.search(/Dug 1.0+/) !== -1) {
var regex_match = line.match(/(\d+) (\d+)/);
var x = regex_match[1], y = regex_match[2];
if (prison.p[[x,y]] === types.wall) { prison.p[[x,y]] = types.wall + types.tunnel; }
else { prison.p[[x,y]] = types.nothing + types.tunnel; }
}
pointer++; continue;
}
}
// End
// clear prison div
var main = document.getElementById("prison"); main.innerHTML = '';
var leftmost = 10000;
var topmost = 10000;
_.forOwn(prison.p, function(value, key) {
var regex_match = key.match(/(\d+),(\d+)/);
var x = parseInt(regex_match[1]), y = parseInt(regex_match[2]);
leftmost = Math.min(leftmost, x);
topmost = Math.min(topmost, y);
});
var cls = ['', 'wall', 'tunnel', 'wall tunnel'];
_.forOwn(prison.p, function(value, key) {
var el = document.createElement("div");
var regex_match = key.match(/(\d+),(\d+)/);
var x = (parseInt(regex_match[1])-leftmost)*10, y = (parseInt(regex_match[2])-topmost)*10;
el.className = cls[value];
el.style.left = x;
el.style.top = y;
main.appendChild(el);
});
};
_.defer(step);
};
})(f);
reader.readAsText(f);
}
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
// Setup the dnd listeners.
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
</script>
<div id="prison"></div>
<footer><a href="http://www.introversion.co.uk/prisonarchitect/">Prison Architect is owned by Introversion Software</a><br />
Coding by maweki // <a href="https://twitter.com/maweki1">twitter @maweki1</a> // <a href="https://github.com/maweki/pa-tunnelfinder">github</a> //
<a href="https://flattr.com/submit/auto?user_id=maweki&url=http%3A%2F%2Fmaweki.de%2Fpa-tunnelfinder" target="_blank"><img src="//button.flattr.com/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0"></a></footer>
</body>
</html>