Skip to content

Commit 86f1b15

Browse files
committed
tweak to url sharing of seed and flags; inputting flag number will check boxes
1 parent 89584e4 commit 86f1b15

File tree

4 files changed

+135
-67
lines changed

4 files changed

+135
-67
lines changed

CNAME

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sml2r.download

index.html

+35-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<table class="tstyle">
3434
<tr>
3535
<td><h1>Super Mario Land 2 Randomizer</h1></td>
36-
<td class="ralign"><a href="#" title="v2.0.1 released 11 March 2018"><img src="images/FriendlyFinger.png" alt="Wario giving thumbs up" style="width:81px;height:65px;"></a></td>
36+
<td class="ralign"><a href="#" title="v2.0.2 released 13 March 2018"><img src="images/FriendlyFinger.png" alt="Wario giving thumbs up" style="width:81px;height:65px;"></a></td>
3737
</tr>
3838
</table>
3939

@@ -145,9 +145,14 @@ <h2>Options:</h2>
145145
</table>
146146

147147
<div id="changelog" title="Changelog">
148+
<h3>v2.0.2</h3>
149+
<ui>
150+
<li>Changes the ROM version text to the URL with the seed and flag numbers, and clicking it copies it to the user's clipboard.</li>
151+
<li>After flags are inserted in the flags field, the checkboxes are checked automatically.</li>
152+
<li>Seed and flag fields only accept valid inputs via URL, and only output what would be valid inputs.</li>
148153
<h3>v2.0.1</h3>
149154
<ui>
150-
<li>Accepts seed and flags via URL in the format "#seed-flags" after .html.</li>
155+
<li>Accepts seed and flags via URL in the format "/?s=SEED&f=FLAGS" at the end of the URL.</li>
151156
<h3>v2.0</h3>
152157
<ui>
153158
<li>Rewritten in JavaScript; now available online.</li>
@@ -166,6 +171,7 @@ <h3>v2.0</h3>
166171
<script src="https://fastcdn.org/FileSaver.js/1.1.20151003/FileSaver.min.js"></script>
167172
<script src="js/logistics.js"></script>
168173
<script src="js/randomizer.js"></script>
174+
<script src="js/copy.js"></script>
169175
<script>
170176

171177
$("#controlgroup1").controlgroup({
@@ -188,7 +194,8 @@ <h3>v2.0</h3>
188194

189195
$("#changelog").dialog({
190196
autoOpen: false,
191-
width: 400,
197+
width: 450,
198+
height: 500,
192199
buttons: [
193200
{
194201
text: "Close",
@@ -207,13 +214,32 @@ <h3>v2.0</h3>
207214
}
208215
});
209216

217+
$("#flags").change(function() {
218+
var ftext = $("#flags").val().toUpperCase();
219+
if (ftext.length == 3 && parseInt(ftext, 16).toString(16).toUpperCase() === ftext) {
220+
checkboxes();
221+
}
222+
});
223+
224+
$("#romVersion").click(function() {
225+
if ($("#romVersion").hasClass('clickable')) {
226+
var url = $("#romVersion").text();
227+
copy(url);
228+
}
229+
});
230+
210231
$(document).ready(function() {
211-
var url = document.createElement('a');
212-
url.href = window.location.href;
213-
if (url.hash != null) {
214-
var hash = url.hash;
215-
document.getElementById("seed").value = hash.substr(1,8).toUpperCase();
216-
document.getElementById("flags").value = hash.substr(10,3).toUpperCase();
232+
var url = new URL(window.location.href);
233+
if (url.searchParams.has("s") && url.searchParams.has("f")) {
234+
var seed = url.searchParams.get("s").toUpperCase();
235+
var flags = url.searchParams.get("f").toUpperCase();
236+
if (seed.length == 8 && parseInt(seed, 16).toString(16).toUpperCase() === seed) {
237+
document.getElementById("seed").value = seed;
238+
}
239+
if (flags.length == 3 && parseInt(flags, 16).toString(16).toUpperCase() === flags) {
240+
document.getElementById("flags").value = flags;
241+
checkboxes();
242+
}
217243
}
218244
});
219245

js/copy.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function copy(text) {
2+
var textArea = document.createElement("textarea");
3+
textArea.style.position = 'fixed';
4+
textArea.style.top = 0;
5+
textArea.style.left = 0;
6+
textArea.style.width = '2em';
7+
textArea.style.height = '2em';
8+
textArea.style.padding = 0;
9+
textArea.style.border = 'none';
10+
textArea.style.outline = 'none';
11+
textArea.style.boxShadow = 'none';
12+
textArea.style.background = 'transparent';
13+
textArea.value = text;
14+
document.body.appendChild(textArea);
15+
textArea.select();
16+
document.execCommand('copy');
17+
document.body.removeChild(textArea);
18+
}

js/logistics.js

+81-58
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $("#fileupload").change(function() {
1212

1313
$("#randomizeRom").click(function(){
1414
seedGenerator(document.getElementById("seed").value.toUpperCase());
15-
flagGenerator(document.getElementById("flags").value.toUpperCase());
15+
flagGenerator();
1616
var file = document.getElementById("fileupload").files[0];
1717
var reader = new FileReader();
1818
reader.onloadend = function(e) {
@@ -63,64 +63,84 @@ function seedGenerator(custom = null) {
6363
}
6464
}
6565

66-
function flagGenerator(custom = null) {
66+
function checkboxes() {
67+
var f = document.getElementById("flags").value;
68+
var flags = parseInt(f, 16);
69+
$("#randomizeLevels").prop("checked", function() {
70+
return (flags & 0x001) != 0;
71+
}).checkboxradio('refresh');
72+
$("#swapExits").prop("checked", function() {
73+
return (flags & 0x002) != 0;
74+
}).checkboxradio('refresh');
75+
$("#randomizeBosses").prop("checked", function() {
76+
return (flags & 0x004) != 0;
77+
}).checkboxradio('refresh');
78+
$("#randomizeEnemies").prop("checked", function() {
79+
return (flags & 0x008) != 0;
80+
}).checkboxradio('refresh');
81+
$("#randomizePowerups").prop("checked", function() {
82+
return (flags & 0x010) != 0;
83+
}).checkboxradio('refresh');
84+
$("#randomizePlatforms").prop("checked", function() {
85+
return (flags & 0x020) != 0;
86+
}).checkboxradio('refresh');
87+
$("#randomizePhysics").prop("checked", function() {
88+
return (flags & 0x040) != 0;
89+
}).checkboxradio('refresh');
90+
$("#randomizeScrolling").prop("checked", function() {
91+
return (flags & 0x080) != 0;
92+
}).checkboxradio('refresh');
93+
$("#randomizeMusic").prop("checked", function() {
94+
return (flags & 0x100) != 0;
95+
}).checkboxradio('refresh');
96+
$("#beastMode").prop("checked", function() {
97+
return (flags & 0x200) != 0;
98+
}).checkboxradio('refresh');
99+
}
100+
101+
function flagGenerator() {
67102
var flags = 0;
68-
if (custom != null && (parseInt(custom, 16).toString(16).toUpperCase() === custom) && custom.length == 3) {
69-
flags = parseInt(custom, 16);
70-
doLevels = (flags & 0x001) != 0;
71-
doExits = (flags & 0x002) != 0;
72-
doBosses = (flags & 0x004) != 0;
73-
doEnemies = (flags & 0x008) != 0;
74-
doPowerups = (flags & 0x010) != 0;
75-
doPlatforms = (flags & 0x020) != 0;
76-
doPhysics = (flags & 0x040) != 0;
77-
doScrolling = (flags & 0x080) != 0;
78-
doMusic = (flags & 0x100) != 0;
79-
beastMode = (flags & 0x200) != 0;
80-
document.getElementById("flags").value = custom.toUpperCase();
81-
} else {
82-
if (document.getElementById("randomizeLevels").checked) {
83-
doLevels = true;
84-
flags |= 0x001;
85-
}
86-
if (document.getElementById("swapExits").checked) {
87-
doExits = true;
88-
flags |= 0x002;
89-
}
90-
if (document.getElementById("randomizeBosses").checked) {
91-
doBosses = true;
92-
flags |= 0x004;
93-
}
94-
if (document.getElementById("randomizeEnemies").checked) {
95-
doEnemies = true;
96-
flags |= 0x008;
97-
}
98-
if (document.getElementById("randomizePowerups").checked) {
99-
doPowerups = true;
100-
flags |= 0x010;
101-
}
102-
if (document.getElementById("randomizePlatforms").checked) {
103-
doPlatforms = true;
104-
flags |= 0x020;
105-
}
106-
if (document.getElementById("randomizePhysics").checked) {
107-
doPhysics = true;
108-
flags |= 0x040;
109-
}
110-
if (document.getElementById("randomizeScrolling").checked) {
111-
doScrolling = true;
112-
flags |= 0x080;
113-
}
114-
if (document.getElementById("randomizeMusic").checked) {
115-
doMusic = true;
116-
flags |= 0x100;
117-
}
118-
if (document.getElementById("beastMode").checked) {
119-
beastMode = true;
120-
flags |= 0x200;
121-
}
122-
document.getElementById("flags").value = ("00" + flags.toString(16).toUpperCase()).substr(-3);
103+
if (document.getElementById("randomizeLevels").checked) {
104+
doLevels = true;
105+
flags |= 0x001;
106+
}
107+
if (document.getElementById("swapExits").checked) {
108+
doExits = true;
109+
flags |= 0x002;
110+
}
111+
if (document.getElementById("randomizeBosses").checked) {
112+
doBosses = true;
113+
flags |= 0x004;
114+
}
115+
if (document.getElementById("randomizeEnemies").checked) {
116+
doEnemies = true;
117+
flags |= 0x008;
118+
}
119+
if (document.getElementById("randomizePowerups").checked) {
120+
doPowerups = true;
121+
flags |= 0x010;
122+
}
123+
if (document.getElementById("randomizePlatforms").checked) {
124+
doPlatforms = true;
125+
flags |= 0x020;
126+
}
127+
if (document.getElementById("randomizePhysics").checked) {
128+
doPhysics = true;
129+
flags |= 0x040;
130+
}
131+
if (document.getElementById("randomizeScrolling").checked) {
132+
doScrolling = true;
133+
flags |= 0x080;
134+
}
135+
if (document.getElementById("randomizeMusic").checked) {
136+
doMusic = true;
137+
flags |= 0x100;
138+
}
139+
if (document.getElementById("beastMode").checked) {
140+
beastMode = true;
141+
flags |= 0x200;
123142
}
143+
document.getElementById("flags").value = ("00" + flags.toString(16).toUpperCase()).substr(-3);
124144
};
125145

126146
function doRandomize(buffer) {
@@ -156,7 +176,10 @@ function doRandomize(buffer) {
156176
randomizeBossHealth(rom);
157177
}
158178
checksum(rom);
179+
var flags = document.getElementById("flags").value;
180+
document.getElementById("romVersion").innerHTML = "sml2r.download/?s=" + prng.printSeed + "&f=" + flags;
181+
$("#romVersion").addClass('clickable');
159182
var ifDx = rom[0x148] == 0x05 ? "DX-" : "";
160-
var filename = "sml2r-" + ifDx + prng.printSeed + "-" + document.getElementById("flags").value + ".gb";
183+
var filename = "sml2r-" + ifDx + prng.printSeed + "-" + flags + ".gb";
161184
saveAs(new Blob([buffer], {type: "octet/stream"}), filename);
162185
}

0 commit comments

Comments
 (0)