Hell yeah, Open Source for the win!


1: <?php if ($_GET['mode']=="getblockid") { ?>
2: <script>
3: function refreshResult()  {
4:     var form = document.getElementById('form1');
5:     var id = parseInt(form.elements["id"].value);
6:     var group = parseInt(form.elements["group"].value);
7:     var status = document.getElementById('status');
8:     var glob = document.getElementById('glob');
9:     var temp1 = id+group;
10:     var temp2 = Math.floor(temp1/75);
11:     var temp3 = temp1-(temp2*75);
12:     if (temp2+49>127 || temp3+49>127) {
13:         status.innerHTML="Error... temp1="+temp1+", temp2="+temp2+", temp3="+temp3;
14:         glob.innerHTML="";
15:     } else {
16:         status.innerHTML=String.fromCharCode(temp2+49,temp3+49);
17:         glob.innerHTML=temp1;
18:     }
19: }
20:
21: function calcGlobBlock()  {
22:     var form = document.getElementById('form2');
23:     var temp1 = parseInt(form.elements["id"].value);
24:     var status = document.getElementById('glob2ascii');
25:     var temp2 = Math.floor(temp1/75);
26:     var temp3 = temp1-(temp2*75);
27:     if (temp2+49>127 || temp3+49>127) {
28:         status.innerHTML="Error... temp1="+temp1+", temp2="+temp2+", temp3="+temp3;
29:     } else {
30:         status.innerHTML=String.fromCharCode(temp2+49,temp3+49);
31:     }
32: }
33: </script>
34: <a href="suyoslevelutilities.php">Back to overview</a><br /><br /><br />
35: <form id="form1">
36: Select Block Group: <select name="group">
37: <option value="100">Jungle</option>
38: <option value="150">Interactive</option>
39: <option value="200">Bricks #1</option>
40: <option value="250">Bricks #2</option>
41: <option value="300">Grass</option>
42: <option value="350">Cave</option>
43: <option value="400">Snow #1</option>
44: <option value="450">Snow #2</option>
45: <option value="500">Volcano</option>
46: <option value="550">Desert</option>
47: <option value="600">Castle</option>
48: <option value="650">Other</option>
49: </select><br />
50: Enter Block Number: <input type="text" id="id" /><br />
51: <button type="button" onclick="refreshResult();">Process</button><br />
52: <br />
53: <b>GLOBAL BLOCK NUMBER: </b><span id="glob">0</span><br />
54: <b>BLOCK ID: </b><span id="status">0</span>
55: </form><br /><br /><br />And because it was so much fun, let's do it the other way<br />
56: <form id="form2">
57: Enter Global Block Number: <input type="text" id="id" /><br />
58: <button type="button" onclick="calcGlobBlock();">Process</button><br />
59: <br />
60: <b>BLOCK ID: </b><span id="glob2ascii">0</span>
61: </form>
62: <?php } else if ($_GET['mode']=="removesprites") { ?>
63: <script>
64: function removeSprites()  {
65:     var form = document.getElementById('form');
66:     var code = form.elements["code"].value;
67:     var out = form.elements["out"];
68:     var partsArray = code.split("~");
69:     var spritesArray = partsArray[2].split("|");
70:     var propsArray;
71:     var sizeArray = partsArray[0].split("x");
72:     var xsize = parseInt(sizeArray[0])*32-32;
73:     var ysize = parseInt(sizeArray[1])*32-32;
74:     
75:     for (var i=0;i<spritesArray.length;i++) {
76:         propsArray = spritesArray[i].split(",");
77:         // Fuck effective coding
78:         if (parseInt(propsArray[1])>xsize) {
79:             spritesArray.splice(i,1);
80:             i--;
81:             continue;
82:         } else if (parseInt(propsArray[2])>ysize) {
83:             spritesArray.splice(i,1);
84:             i--;
85:             continue;
86:         } else if (parseInt(propsArray[1])<-32) {
87:             spritesArray.splice(i,1);
88:             i--;
89:             continue;
90:         } else if (parseInt(propsArray[2])<-32) {
91:             spritesArray.splice(i,1);
92:             i--;
93:             continue;
94:         }
95:     }
96:     
97:     partsArray[2] = spritesArray.join("|");
98:     out.value = partsArray.join("~");
99: }
100: </script>
101:
102: <a href="suyoslevelutilities.php">Back to overview</a><br /><br /><br />
103: Oh noes! You have resized your level and there are tons of sprites in inaccessible places now? Do not worry!<br />
104: <b>A little warning though:</b> This will go strictly by the x and y positions of the items in the code. That means some sprites could be removed which aren't completly offscreen, or the start position could be nuked. Backup your code, and playtest afterwards! Do not trust my coding skills! (You should have learned to do these three things a long time ago)<br />
105: Also, this might obviously take longer with bigger levels - you browser may lock up and want to stop the script, don't do that, let it run. Pro Tip: Open a different browser (for example, if you are using Firefox, open a window of Chromium) and let the script run there. Be able to browse like you usually would while the other browser works is ass off. Profit!<br /><br /><br />
106: Alright, here we go! Give me your level code!<br />
107: <form id="form"><textarea name="code" id="code" rows="5" cols="30"></textarea><br />
108: <br />
109: Ready? <button type="button" onclick="removeSprites();">Yes!</button><br />
110: <br />
111: <br />
112: <br />
113: Result will appear here!<br />
114: <textarea name="out" id="out" rows="5" cols="30" readonly></textarea></form>
115: <?php } else if ($_GET['mode']=="sourcecode") { ?>
116: Hell yeah, Open Source for the win!<br /><br /><br />
117: <?php function renderFile($filename) {
118:         if(file_exists($filename) && is_file($filename)) {
119:             $code highlight_file($filenametrue);
120:             $counter 1;
121:             $arr explode('<br />'$code);
122:             echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-family: monospace;">' "\r\n";
123:             foreach($arr as $line) {
124:                 echo '<tr>' "\r\n";
125:                     echo '<td width="65px" nowrap style="color: #666;">' $counter ':</td>' "\r\n";
126:
127:                     // fix multi-line comment bug
128:                     if((strstr($line'<span style="color: #FF8000">/*') !== false) && (strstr($line'*/') !== false)) { // single line comment using /* */
129:                         $comments false;
130:                         $startcolor "orange";
131:                     }  
132:                     elseif(strstr($line'<span style="color: #FF8000">/*') !== false) { // multi line comment using /* */
133:                         $startcolor "orange";
134:                         $comments true;
135:                     }  
136:                     else { // no comment marks found
137:                         $startcolor "green";
138:                         if($comments) { // continuation of multi line comment
139:                             if(strstr($line'*/') !== false) {
140:                                 $comments false;
141:                                 $startcolor "orange";
142:                             }  
143:                             else {
144:                                 $comments true;
145:                             }  
146:                         }  
147:                         else { // normal line  
148:                             $comments false;
149:                             $startcolor "green";
150:                         }  
151:                     }  
152:                     // end fix multi-line comment bug
153:
154:                     if($comments)
155:                         echo '<td width="100%" nowrap style="color: orange;">' $line '</td>' "\r\n";
156:                     else
157:                         echo '<td width="100%" nowrap style="color: ' $startcolor ';">' $line '</td>' "\r\n";
158:
159:                     echo '</tr>' "\r\n";
160:                     $counter++;
161:             }  
162:             echo '</table>' "\r\n";
163:         }  
164:         else {
165:             echo "<p>The file <i>$filename</i> could not be opened.</p>\r\n";
166:             return;
167:         }  
168:     } 
169: renderFile("suyoslevelutilities.php");
170: } else { ?>
171: Good day, level maker! You have found the extraordinary and stylish page of SM63 Level Code Utilities by Suyo. How can I help you today?<br />
172: <br />
173: <a href="suyoslevelutilities.php?mode=getblockid">I want to calculate some block IDs!</a><br />
174: <a href="suyoslevelutilities.php?mode=removesprites">Can you remove all the sprites outside my level boundaries?</a><br /><br /><br />
175: <a href="suyoslevelutilities.php?mode=sourcecode">Is this wreck open source?</a>
176: <?php ?>