cyrb128 string seeds

This commit is contained in:
Laetitia (O-01-67) 2023-02-21 16:52:48 -05:00 committed by GitHub
parent 3bc7961010
commit 61df43961c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 12 deletions

View File

@ -13,7 +13,7 @@ if(enabledMods.includes(variablesMod)) {
}; };
if(enabledMods.includes("mods/code_library.js")) { if(enabledMods.includes("mods/code_library.js")) {
commandHelpObject.stars = "Clears the screen and replaces it with random stars. Usage: stars <density (number, default: 0.001)> <seed (number, no default value)>\nDon't include framing characters <>.\nArguments in <angle brackets> are optional." commandHelpObject.stars = "Clears the screen and replaces it with random stars. Usage: stars <density (number, default: 0.001)> <seed (string or number, no default value)>\nDon't include framing characters <>.\nArguments in <angle brackets> are optional."
commandHelpObject.starseed = "Alerts the last used seed for stars. Usage: starseed"; commandHelpObject.starseed = "Alerts the last used seed for stars. Usage: starseed";
var lastStarSeed = "[None]"; var lastStarSeed = "[None]";
}; };
@ -410,21 +410,26 @@ if(enabledMods.includes(variablesMod)) {
}; };
}; };
if(seed == undefined) { var stringSeed = false;
seed = null; var seedString = null;
if(seed === undefined) {
seed = Math.random();
stringSeed = false;
} else { } else {
seed = parseFloat(seed); if(isNaN(parseFloat(seed))) {
if(isNaN(seed)) { stringSeed = true;
alert("seed was NaN, ignoring"); seedString = seed;
seed = null; seed = cyrb128(seed)[2];
} else {
stringSeed = false;
seed = parseFloat(seed);
}; };
}; };
if(seed == null) { lastStarSeed = stringSeed ? seedString : seed;
seed = Math.random(); //console.log(stringSeed);
}; //console.log(lastStarSeed);
lastStarSeed = seed;
var randomFunction = mulberry32(seed); var randomFunction = mulberry32(seed);
if(!enabledMods.includes("mods/code_library.js")) { if(!enabledMods.includes("mods/code_library.js")) {