sandboxels/mods/10kelements.js

69 lines
3.5 KiB
JavaScript
Raw Normal View History

2024-04-06 18:44:46 -04:00
elements.change_count = {
color: "#34eb86",
canPlace: false,
behavior: behaviors.SELFDELETE,
onSelect: function() {
var cans = prompt("Please input how many elements you would like to be generared each time.", 10000);
if (!cans) { return }
2024-04-06 19:04:28 -04:00
if (cans > 2000000){alert("You have put too big of a number! This would surely crash your browser or eat up all your RAM! Element count will remain unchanged."); return}
if (cans < 1){alert("You have either put a decimal, zero, or a negative number. Why? Element count will remain unchanged."); return}
2024-04-06 19:10:01 -04:00
if (isNaN(parseInt(cans))){alert("Apparently your input isnt even a number. Try again. Element count will remain unchanged."); return}
2024-04-06 18:44:46 -04:00
settings.randomcount = parseInt(cans)
saveSettings()
},
category: "random"
}
if (!settings.randomcount){settings.randomcount = 10000; saveSettings()}
2024-04-03 18:34:17 -04:00
var color = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e","f"]
var states = ["solid", "liquid", "gas"]
var total = 0
2024-04-03 21:30:44 -04:00
var dangerouselements = ["supernova", "n_explosion", "pn_explosion", "armageddon", "nuke", "h_bomb"]
2024-04-03 18:34:17 -04:00
var elementslist = []
for (elementi in elements){
elementslist.push(elementi)
}
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}
var randomProperty = function (obj) {
var keys = Object.keys(obj);
return obj[keys[ keys.length* Math.random() << 0]];
};
2024-04-06 18:44:46 -04:00
for (var i = 1; i <= settings.randomcount; i++){
2024-04-03 18:34:17 -04:00
var f = Math.random() < 0.2
var co = Math.random() < 0.2
elements["element_"+i] = {
color: "#" + color[Math.floor(Math.random()*color.length)] + color[Math.floor(Math.random()*color.length)] + color[Math.floor(Math.random()*color.length)] + color[Math.floor(Math.random()*color.length)] + color[Math.floor(Math.random()*color.length)] + color[Math.floor(Math.random()*color.length)],
category: "random",
behavior: randomProperty(behaviors),
state: states[Math.floor(Math.random()*states.length)],
reactions: {},
density: randomIntFromInterval(1, 10000)
}
total = i
if (f){
elements["element_"+i].tempHigh = 20 + randomIntFromInterval(10, 6000)
elements["element_"+i].stateHigh = elementslist[Math.floor(Math.random()*elementslist.length)]
}
if (co){
elements["element_"+i].tempLow = 20 - randomIntFromInterval(10, 270)
elements["element_"+i].stateLow = elementslist[Math.floor(Math.random()*elementslist.length)]
}
for (r = 0; r < 10; r++){
elements["element_"+i].reactions[elementslist[Math.floor(Math.random()*elementslist.length)]] = { elem1: elementslist[Math.floor(Math.random()*elementslist.length)], elem2: elementslist[Math.floor(Math.random()*elementslist.length)]}
}
// console.log(i + " is done!")
2024-04-03 18:49:51 -04:00
// console.log(i)
// console.log(elements["element_"+i].behavior)
if (elements["element_" + i].density == i){
2024-04-03 19:40:02 -04:00
console.log(i + "is unique because its density is the same as its id!")
}
for (var reaction in elements["element_" + i].reactions){
2024-04-03 21:30:44 -04:00
if (dangerouselements.includes(elements["element_" + i].reactions[reaction].elem1)|| dangerouselements.includes(elements["element_" + i].reactions[reaction].elem2)){
2024-04-03 19:40:02 -04:00
console.log(i + " is scary due to its reaction with " + reaction)
2024-04-03 21:30:44 -04:00
if (!elements["element_"+i].desc){
2024-04-03 19:40:02 -04:00
elements["element_" + i].desc = "This is scary! Don't let it touch " + reaction
2024-04-03 21:30:44 -04:00
}else(elements["element_"+i].desc += (" or " + reaction))
2024-04-03 19:40:02 -04:00
}
2024-04-03 18:49:51 -04:00
}
2024-04-03 18:34:17 -04:00
}