Make previous/random/next ignore id's with issues
This commit is contained in:
parent
309eb33fa8
commit
46b37b1a4f
@ -132,16 +132,33 @@ function current_id() {
|
||||
|
||||
// Returns id if id is valid, otherwise increments increment to it, or chooses a random id if increment is null
|
||||
function try_get_id(id, increment) {
|
||||
let random_id = Math.floor(Math.random() * (ID_MAX + 1));
|
||||
let returned = id;
|
||||
|
||||
let returned = random_id;
|
||||
if (id === null || isNaN(id) || id < 0 || id > ID_MAX) {
|
||||
returned = random_id;
|
||||
returned = get_random_id();
|
||||
} else {
|
||||
if (increment) {
|
||||
returned = (id + increment + ID_MAX + 1) % (ID_MAX + 1);
|
||||
}
|
||||
}
|
||||
|
||||
while (ISSUES.includes(returned) && increment) {
|
||||
returned = (returned + increment + ID_MAX + 1) % (ID_MAX + 1);
|
||||
}
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
// Get an entirely random id
|
||||
function get_random_id() {
|
||||
let random_id = Math.floor(Math.random() * (ID_MAX + 1));
|
||||
while (ISSUES.includes(random_id)) {
|
||||
console.log("Skipped issue: " + random_id);
|
||||
random_id = Math.floor(Math.random() * (ID_MAX + 1));
|
||||
}
|
||||
return random_id;
|
||||
}
|
||||
|
||||
// Load the swf with current_id(), and set_up_link() previous, random and next
|
||||
function load_current_id() {
|
||||
let flavourtext = POSSIBLE_FLAVOURTEXTS[Math.floor(Math.random() * POSSIBLE_FLAVOURTEXTS.length)].trim();
|
||||
@ -155,9 +172,9 @@ function load_current_id() {
|
||||
|
||||
CURRENT_SWF = url;
|
||||
|
||||
let previous_id = (id + ID_MAX) % (ID_MAX + 1);
|
||||
let next_id = (id + ID_MAX + 2) % (ID_MAX + 1);
|
||||
let random_id = Math.floor(Math.random() * (ID_MAX + 1));
|
||||
let previous_id = try_get_id(id, -1);
|
||||
let next_id = try_get_id(id, 1);
|
||||
let random_id = get_random_id();
|
||||
set_up_link("previous", previous_id);
|
||||
set_up_link("random", random_id);
|
||||
set_up_link("next", next_id);
|
||||
|
Loading…
Reference in New Issue
Block a user