commit
7de250bf97
|
|
@ -1,4 +1,4 @@
|
||||||
/*Version 1.2.0 Pseudorandom world generator*/
|
/*Version 1.2.1 Pseudorandom world generator*/
|
||||||
function pseudorandom(key, num, max = 1){
|
function pseudorandom(key, num, max = 1){
|
||||||
return (Math.log(key)*(num*Math.log(1625.4986772154357))) % max;
|
return (Math.log(key)*(num*Math.log(1625.4986772154357))) % max;
|
||||||
};
|
};
|
||||||
|
|
@ -14,6 +14,134 @@ let oreChances = {
|
||||||
uranium: 0.805,
|
uranium: 0.805,
|
||||||
aluminum: 1
|
aluminum: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let promptMenus = {};
|
||||||
|
let keys = ["OK", "Cancel", "Confirm", "Input", "Choices", "Dirs", "Dropdown"];
|
||||||
|
Object.defineProperty(String.prototype, 'capitalize', {
|
||||||
|
value: function() {
|
||||||
|
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||||
|
},
|
||||||
|
enumerable: false
|
||||||
|
});
|
||||||
|
runAfterLoad(()=>{
|
||||||
|
let dropDown = document.createElement("select");
|
||||||
|
dropDown.id = "promptDropdown";
|
||||||
|
dropDown.style.position = "absolute";
|
||||||
|
dropDown.style.top = "15%";
|
||||||
|
dropDown.style.left = "42.5%";
|
||||||
|
dropDown.style.width = "15%";
|
||||||
|
dropDown.title = "prompt";
|
||||||
|
dropDown.style.display = "none";
|
||||||
|
document.getElementById("promptMenu").appendChild(dropDown);
|
||||||
|
|
||||||
|
for(let key of keys){
|
||||||
|
promptMenus[key] = document.getElementById(`prompt${key}`);
|
||||||
|
promptMenus[key].style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
//function prompt
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function showPromptScreen() {
|
||||||
|
if (!promptState) return;
|
||||||
|
closeMenu("prompt");
|
||||||
|
paused = true;
|
||||||
|
checkPause();
|
||||||
|
var promptParent = document.getElementById("promptParent");
|
||||||
|
var menuTitle = document.querySelector("#promptMenu .menuTitle");
|
||||||
|
menuTitle.innerText = promptState.title || "Notice";
|
||||||
|
menuTitle.style.color = promptState.titleColor || "unset";
|
||||||
|
var promptMenuText = document.getElementById("promptMenuText");
|
||||||
|
promptMenuText.innerText = promptState.text || "";
|
||||||
|
if (promptState.html) {
|
||||||
|
promptMenuText.insertAdjacentHTML("beforeend",promptState.html);
|
||||||
|
}
|
||||||
|
let promptOK = document.getElementById("promptOK");
|
||||||
|
let promptCancel = document.getElementById("promptCancel");
|
||||||
|
let promptConfirm = document.getElementById("promptConfirm");
|
||||||
|
let promptInput = document.getElementById("promptInput");
|
||||||
|
let promptChoices = document.getElementById("promptChoices");
|
||||||
|
let promptDirs = document.getElementById("promptDirs");
|
||||||
|
let dropDown = document.getElementById("promptDropdown");
|
||||||
|
for(let key in promptMenus){
|
||||||
|
promptMenus[key].style.display = "none";
|
||||||
|
}
|
||||||
|
promptConfirm.classList.remove("danger");
|
||||||
|
if (promptState.type === "text") {
|
||||||
|
promptOK.style.display = "block";
|
||||||
|
}
|
||||||
|
else if (promptState.type === "confirm") {
|
||||||
|
promptCancel.style.display = "block";
|
||||||
|
promptConfirm.style.display = "block";
|
||||||
|
if (promptState.danger) promptConfirm.classList.add("danger");
|
||||||
|
}
|
||||||
|
else if (promptState.type === "input") {
|
||||||
|
promptInput.value = "";
|
||||||
|
promptInput.style.display = "block";
|
||||||
|
if (promptState.defaultInput !== undefined) {
|
||||||
|
promptInput.value = ""+promptState.defaultInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (promptState.type === "choose" && promptState.choices) {
|
||||||
|
promptChoices.innerHTML = "";
|
||||||
|
for (let i = 0; i < promptState.choices.length; i++) {
|
||||||
|
const choice = promptState.choices[i];
|
||||||
|
let span = document.createElement("span");
|
||||||
|
span.className = "promptChoice";
|
||||||
|
span.onclick = function(){ handlePrompt(choice) };
|
||||||
|
span.innerText = choice;
|
||||||
|
promptChoices.appendChild(span);
|
||||||
|
}
|
||||||
|
promptChoices.style.display = "block";
|
||||||
|
}
|
||||||
|
else if (promptState.type == "dropdown" && promptState.choices != undefined) {
|
||||||
|
dropDown.innerHTML = "";
|
||||||
|
//promptParent.appendChild(promptDropdown);
|
||||||
|
|
||||||
|
for(let choice of promptState.choices){
|
||||||
|
dropDown.innerHTML += `<option value="${choice}">${choice.capitalize()}</option>`;
|
||||||
|
}
|
||||||
|
let span = document.createElement("span");
|
||||||
|
span.className = "promptOK";
|
||||||
|
span.textContent = "Select";
|
||||||
|
span.onclick = ()=>{
|
||||||
|
let c = dropDown.value;
|
||||||
|
console.log(c);
|
||||||
|
handlePrompt(c);
|
||||||
|
document.getElementById("promptMenu").removeChild(span);
|
||||||
|
};
|
||||||
|
document.getElementById("promptMenu").appendChild(span);
|
||||||
|
dropDown.style.display = "block";
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (promptState.type === "dir") {
|
||||||
|
promptDirs.style.display = "block";
|
||||||
|
}
|
||||||
|
promptParent.style.display = "block";
|
||||||
|
showingMenu = "prompt";
|
||||||
|
if (promptState.type === "input") {
|
||||||
|
document.getElementById("promptInput").focus();
|
||||||
|
document.getElementById("promptInput").select();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function promptDropdown(title, choices, handler){
|
||||||
|
let pause = false;
|
||||||
|
if (promptState) { pause = promptState.wasPaused }
|
||||||
|
else if (paused) { pause = true }
|
||||||
|
promptState = {
|
||||||
|
type: "dropdown",
|
||||||
|
text: "",
|
||||||
|
choices: choices,
|
||||||
|
handler: handler,
|
||||||
|
title: title || "Choose",
|
||||||
|
wasPaused: pause
|
||||||
|
}
|
||||||
|
showPromptScreen();
|
||||||
|
}
|
||||||
|
|
||||||
function makeCurve(pos, w, dir, div = 200){
|
function makeCurve(pos, w, dir, div = 200){
|
||||||
let prevX = pos[0], prevY = pos[1];
|
let prevX = pos[0], prevY = pos[1];
|
||||||
let res = [];
|
let res = [];
|
||||||
|
|
@ -325,16 +453,15 @@ elements.SeedGenerate = {
|
||||||
let arr = [];
|
let arr = [];
|
||||||
let txt = shiftDown;
|
let txt = shiftDown;
|
||||||
Object.keys(biomes).forEach(function(b){arr.push(b);});
|
Object.keys(biomes).forEach(function(b){arr.push(b);});
|
||||||
txt = (arr.length >= 7) ? true : txt;
|
|
||||||
promptInput("Leave blank to generate new seed or C to keep current seed. Your current seed is: " + seed, function(i){
|
promptInput("Leave blank to generate new seed or C to keep current seed. Your current seed is: " + seed, function(i){
|
||||||
seed = (i != null && i.toLowerCase() == "c") ? seed : parseFloat(i) || Math.random()*(2**32);
|
seed = (i != null && i.toLowerCase() == "c") ? seed : parseFloat(i) || Math.random()*(2**32);
|
||||||
seed = seed % (2**32);
|
seed = seed % (2**32);
|
||||||
if(!txt){
|
if(!txt){
|
||||||
promptChoose("", arr, (choice)=>{
|
promptDropdown( "Select a biome to generate: ", arr, (choice)=>{
|
||||||
biomes[choice].generate(seed);
|
biomes[choice].generate(seed);
|
||||||
promptText("World generation complete.");
|
promptText("World generation complete.");
|
||||||
selectElement('dirt');
|
selectElement('dirt');
|
||||||
}, "Select a biome to generate: ");
|
});
|
||||||
} else {
|
} else {
|
||||||
let str = "";
|
let str = "";
|
||||||
for(let key in biomes){
|
for(let key in biomes){
|
||||||
|
|
@ -360,7 +487,6 @@ elements.RandomGen = {
|
||||||
let arr = [];
|
let arr = [];
|
||||||
let txt = shiftDown;
|
let txt = shiftDown;
|
||||||
Object.keys(biomes).forEach(function(b){arr.push(b);});
|
Object.keys(biomes).forEach(function(b){arr.push(b);});
|
||||||
txt = (arr.length >= 7) ? true : txt;
|
|
||||||
seed = Math.random()*(2**32);
|
seed = Math.random()*(2**32);
|
||||||
//seed %= 2**32;
|
//seed %= 2**32;
|
||||||
if(txt){
|
if(txt){
|
||||||
|
|
@ -382,13 +508,15 @@ elements.RandomGen = {
|
||||||
}, "Enter Biome Name: ");
|
}, "Enter Biome Name: ");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
promptChoose("", arr, (choice)=>{
|
promptDropdown( "Select a biome to generate: ", arr, (choice)=>{
|
||||||
biomes[choice].generate(seed);
|
biomes[choice].generate(seed);
|
||||||
selectElement("dirt");
|
promptText("World generation complete.");
|
||||||
}, "Biome Selection");
|
selectElement('dirt');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.view_seed = {
|
elements.view_seed = {
|
||||||
category: "edit",
|
category: "edit",
|
||||||
onSelect: function(){
|
onSelect: function(){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue