diff --git a/mods/chem.js b/mods/chem.js index ca91df4b..b6a35ded 100644 --- a/mods/chem.js +++ b/mods/chem.js @@ -1,16 +1,25 @@ -function whenAvailable(name, callback) { +function whenAvailable(names, callback) { var interval = 10; // ms window.setTimeout(function() { - if (window[name]) { + let bool = true; + for(let i = 0; i < names.length; i++) + { + if(!window[names[i]]) + { + bool = false; + } + } + if (bool) { callback(); } else { - whenAvailable(name, callback); + whenAvailable(names, callback); } }, interval); } -var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js"; +var runAfterAutogenMod = "mods/runAfterAutogen2.js"; if(enabledMods.includes(runAfterAutogenMod)){ -whenAvailable("runAfterAutogen", function() { +whenAvailable(["runAfterAutogen"], function() { + elements.fluorine = { color: "#FFFFBF", @@ -411,9 +420,8 @@ trueAcidGases = ["acid_gas", "hydrofluoric_acid_gas"]; if (enabledMods.includes("mods/generative_mods.js")) { - runAfterLoad(function() { - generateCloud("hydrofluoric_acid"); - }); +whenAvailable(["generateCloud"], function() { + generateCloud("hydrofluoric_acid"); elements["hydrofluoric_acid_gas"].reactions["hydrofluoric_acid_gas"]= { "elem1": null, "elem2": "hydrofluoric_acid_cloud", "chance":0.3, "y":[0,12], "setting":"clouds" }; elements["hydrofluoric_acid_gas"].reactions["rain_cloud"]= { "elem1": null, "elem2": "hydrofluoric_acid_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; elements["hydrofluoric_acid_gas"].reactions["cloud"]= { "elem1": null, "elem2": "hydrofluoric_acid_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; @@ -425,6 +433,7 @@ if (enabledMods.includes("mods/generative_mods.js")) { elements["cloud"].reactions["anesthesia"] = { elem1:"nitric_acid_cloud", elem2:null, chance:0.05 }; elements["rain_cloud"].reactions["anesthesia"] = { elem1:"nitric_acid_cloud", elem2:null, chance:0.05 }; +}); } function createAcid(name,reactions, gasReactions, color, category, categoryGas, tempHigh, tempLowGas, tempLow, tempHighGas, density, densityGas) { @@ -471,9 +480,8 @@ function createAcid(name,reactions, gasReactions, color, category, categoryGas, elements.bless.reactions[name] = { elem2: "hydrogen" }; elements.bless.reactions[name+"_gas"] = { elem2: "hydrogen" }; if (enabledMods.includes("mods/generative_mods.js")) { - runAfterLoad(function() { - generateCloud(name); - }); + whenAvailable(["generateCloud"], function() { + generateCloud(name); elements[name+"_gas"].reactions[name+"_gas"]= { "elem1": null, "elem2": name + "_cloud", "chance":0.3, "y":[0,12], "setting":"clouds" }; elements[name+"_gas"].reactions["rain_cloud"]= { "elem1": null, "elem2": name + "_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; elements[name+"_gas"].reactions["cloud"]= { "elem1": null, "elem2": name + "_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; @@ -481,7 +489,8 @@ function createAcid(name,reactions, gasReactions, color, category, categoryGas, elements[name+"_gas"].reactions["hail_cloud"]= { "elem1": null, "elem2": name + "_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; elements[name+"_gas"].reactions["pyrocumulus"]= { "elem1": null, "elem2": name + "_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; elements[name+"_gas"].reactions["fire_cloud"]= { "elem1": null, "elem2": name + "_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; - } + }); + } else { elements[name+"_gas"].reactions[name+"_gas"]= { "elem1": null, "elem2": "acid_cloud", "chance":0.3, "y":[0,12], "setting":"clouds" }; @@ -2278,25 +2287,25 @@ elements.disinfectant = { }; - -elements.bauxite = { - color: ["#915a30","#cc7533"], - behavior: behaviors.POWDER, - category: "land", - density: 2420, - state: "solid", - tempHigh: 300 -}; - -elements.sodium_aluminate = { - color: ["#e6c9b3","#ebc8ad"], - behavior: behaviors.POWDER, - category: "powders", - hidden: true, - density: 1500, - state: "solid", - tempHigh: 1650 -}; + +//elements.bauxite = { +// color: ["#915a30","#cc7533"], +// behavior: behaviors.POWDER, +// category: "land", +// density: 2420, +// state: "solid", +// tempHigh: 300 +//}; +// +//elements.sodium_aluminate = { +// color: ["#e6c9b3","#ebc8ad"], +// behavior: behaviors.POWDER, +// category: "powders", +// hidden: true, +// density: 1500, +// state: "solid", +// tempHigh: 1650 +//}; function acidReact(acid,element,product1,product2) { @@ -2347,13 +2356,14 @@ acidNeutralize("potassium_hydroxide"); acidNeutralize("potassium_hydroxide_gas"); -createAcid("red_mud",structuredClone(defaultBaseReactions),structuredClone(defaultBaseGasReactions),["#ab3d24","#cc5d2d","#a81b1b"],"hidden","hidden",1600,1600,0,Infinity,5200,3); -acidNeutralize("red_mud"); -acidNeutralize("red_mud_gas"); -elements.red_mud.viscosity = 1000000; -elements.red_mud.reactions.water = {"elem2":"dirty_water" }; -elements.red_mud.reactions.salt_water = {"elem2":"dirty_water" }; -elements.red_mud.reactions.sugar_water = {"elem2":"dirty_water" }; +//createAcid("red_mud",structuredClone(defaultBaseReactions),structuredClone(defaultBaseGasReactions),["#ab3d24","#cc5d2d","#a81b1b"],"hidden","hidden",1600,1600,0,Infinity,5200,3); +//acidNeutralize("red_mud"); +//acidNeutralize("red_mud_gas"); +//elements.red_mud.viscosity = 1000000; +//elements.red_mud.reactions.water = {"elem2":"dirty_water" }; +//elements.red_mud.reactions.salt_water = {"elem2":"dirty_water" }; +//elements.red_mud.reactions.sugar_water = {"elem2":"dirty_water" }; + elements.potassium_hydroxide.reactions["fertilizer"] = { elem1: "niter", elem2: "ammonia"}; elements.potassium_hydroxide_gas.reactions["fertilizer"] = { elem1: "niter", elem2: "ammonia"}; @@ -2373,8 +2383,8 @@ elements.potassium_salt_water.reactions["mercury"] = { elem1:["potassium_hydroxi elements.potassium_hydroxide.ignore.push("mercury"); elements.potassium_hydroxide.ignore.push("potassium_salt_water"); -acidReact("sodium_hydroxide","bauxite","sodium_aluminate","red_mud") -elements.red_mud.ignore.push("bauxite","sodium_aluminate"); +//acidReact("sodium_hydroxide","bauxite","sodium_aluminate","red_mud") +//elements.red_mud.ignore.push("bauxite","sodium_aluminate"); elements.bless.reactions["FOOF"] = {elem2: "oxygen"}; elements.bless.reactions["solid_FOOF"] = {elem2: "oxygen"}; @@ -2407,7 +2417,6 @@ elements.bless.reactions["sulfur_dioxide_ice"] = {elem2: "oxygen"}; elements.bless.reactions["hydrogen_sulfide"] = {elem2: "hydrogen"}; elements.bless.reactions["liquid_hydrogen_sulfide"] = {elem2: "hydrogen"}; elements.bless.reactions["rocket_fuel"] = {elem2: null}; -// do something }); } else { if(!enabledMods.includes(runAfterAutogenMod)) { enabledMods.unshift(runAfterAutogenMod) }; diff --git a/mods/generative_mods.js b/mods/generative_mods.js index 1805df2d..e23757ed 100644 --- a/mods/generative_mods.js +++ b/mods/generative_mods.js @@ -1,11 +1,30 @@ +function whenAvailable(names, callback) { + var interval = 10; // ms + window.setTimeout(function() { + let bool = true; + for(let i = 0; i < names.length; i++) + { + if(!window[names[i]]) + { + bool = false; + } + } + if (bool) { + callback(); + } else { + whenAvailable(names, callback); + } + }, interval); +} var modName = "mods/generative_mods.js"; var explodeAtPlusMod = "mods/explodeAtPlus.js"; -var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js"; +var runAfterAutogenMod = "mods/runAfterAutogen2.js"; var libraryMod = "mods/code_library.js"; var feyAndMoreMod = "mods/fey_and_more.js"; var mobsMod = "mods/mobs.js"; if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlusMod) && enabledMods.includes(libraryMod) && enabledMods.includes(feyAndMoreMod) && enabledMods.includes(mobsMod)) { +whenAvailable(["eLists","explodeAtPlus","urlParams","runAfterAutogen","mobsLoaded"], function() { //urlParams reads @@ -1331,7 +1350,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlu //Bombs - function generateBomb(bombElements,isAfterScriptLoading=false,bombNumber=1) {//it can be a single element, though + generateBomb = function(bombElements,isAfterScriptLoading=false,bombNumber=1) {//it can be a single element, though bombNumber = Math.max(0,bombNumber); //To specify an array bomb, have the array be inside another array. @@ -1490,7 +1509,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlu //Clouds - function generateCloud(cloudElements,cloudType=0,isAfterScriptLoading=false) {//it can be a single element, though + generateCloud = function(cloudElements,cloudType=0,isAfterScriptLoading=false) {//it can be a single element, though //To specify an array cloud, have the array be inside another array. /*For reasons related to how element colors are loaded, if this function is being run from a JS mod file, isAfterScriptLoading should be false. Otherwise, you'll get TypeErrors for some reason when trying to place your cloud. If this is being run after the game has loaded (e.g. in the console), @@ -1698,7 +1717,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlu //Creepers - function generateCreeper(creeperElements,isAfterScriptLoading=false) {//it can be a single element, though + generateCreeper = function(creeperElements,isAfterScriptLoading=false) {//it can be a single element, though //To specify an array creeper, have the array be inside another array. /*For reasons related to how element colors are loaded, if this function is being run from a JS mod file, isAfterScriptLoading should be false. Otherwise, you'll get TypeErrors for some reason when trying to place your creeper. If this is being run after the game has loaded (e.g. in the console), @@ -1929,7 +1948,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlu //Fairies - function generateFairy(fairyElements,isAfterScriptLoading=false) {//it can be a single element, though + generateFairy = function(fairyElements,isAfterScriptLoading=false) {//it can be a single element, though //To specify an array fairy, have the array be inside another array. /*For reasons related to how element colors are loaded, if this function is being run from a JS mod file, isAfterScriptLoading should be false. Otherwise, you'll get TypeErrors for some reason when trying to place your fairy. If this is being run after the game has loaded (e.g. in the console), @@ -2118,7 +2137,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlu //Spouts - function generateSpout(spoutElements,isAfterScriptLoading=false) {//it can be a single element, though + generateSpout = function(spoutElements,isAfterScriptLoading=false) {//it can be a single element, though //To specify an array spout, have the array be inside another array. /*For reasons related to how element colors are loaded, if this function is being run from a JS mod file, isAfterScriptLoading should be false. Otherwise, you'll get TypeErrors for some reason when trying to place your spout. If this is being run after the game has loaded (e.g. in the console), @@ -2494,6 +2513,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlu elements[name].behavior = behaviors.FAIRYKILL; }; }; +}); } else { if(!enabledMods.includes(runAfterAutogenMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,runAfterAutogenMod) }; if(!enabledMods.includes(explodeAtPlusMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,explodeAtPlusMod) }; diff --git a/mods/metals.js b/mods/metals.js index 7e67f524..cfe0132c 100644 --- a/mods/metals.js +++ b/mods/metals.js @@ -1,9 +1,29 @@ +function whenAvailable(names, callback) { + var interval = 10; // ms + window.setTimeout(function() { + let bool = true; + for(let i = 0; i < names.length; i++) + { + if(!window[names[i]]) + { + bool = false; + } + } + if (bool) { + callback(); + } else { + whenAvailable(names, callback); + } + }, interval); +} + var modName = "mods/metals.js"; var changeTempMod = "mods/changeTempReactionParameter.js"; -var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js"; +var runAfterAutogenMod = "mods/runAfterAutogen2.js"; var libraryMod = "mods/code_library.js"; var onTryMoveIntoMod = "mods/onTryMoveInto.js"; if(enabledMods.includes(changeTempMod) && enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(libraryMod) && enabledMods.includes(onTryMoveIntoMod)) { + whenAvailable(["runAfterAutogen"], function() { elements.iron.hardness = 0.74 //https://www.engineeringtoolbox.com/bhn-brinell-hardness-number-d_1365.html //https://en.wikipedia.org/wiki/Hardnesses_of_the_elements_(data_page) @@ -761,6 +781,7 @@ if(enabledMods.includes(changeTempMod) && enabledMods.includes(runAfterAutogenMo conduct: 0.35, hardness: 0.7, //idk lol }; +}); } else { if(!enabledMods.includes(changeTempMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,changeTempMod) }; if(!enabledMods.includes(runAfterAutogenMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,runAfterAutogenMod) }; diff --git a/mods/mobs.js b/mods/mobs.js index 7761f24f..f40aca55 100644 --- a/mods/mobs.js +++ b/mods/mobs.js @@ -1,9 +1,28 @@ +function whenAvailable(names, callback) { + var interval = 10; // ms + window.setTimeout(function() { + let bool = true; + for(let i = 0; i < names.length; i++) + { + if(!window[names[i]]) + { + bool = false; + } + } + if (bool) { + callback(); + } else { + whenAvailable(names, callback); + } + }, interval); +} var modName = "mods/mobs.js"; var explodeAtPlusMod = "mods/explodeAtPlus.js"; -var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js"; +var runAfterAutogenMod = "mods/runAfterAutogen2.js"; var libraryMod = "mods/code_library.js"; - +var mobsLoaded = false; if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlusMod) && enabledMods.includes(libraryMod)) { +whenAvailable(["runAfterAutogen","explodeAtPlus"], function() { //Prerequisite Functions and Variables minimumCreeperTries = 3; @@ -5117,6 +5136,8 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlu /* ------------------------- - End skeleton elements - ------------------------- */ + mobsLoaded = true; +}); } else { if(!enabledMods.includes(runAfterAutogenMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,runAfterAutogenMod) }; if(!enabledMods.includes(explodeAtPlusMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,explodeAtPlusMod) }; diff --git a/mods/neutronium_compressor.js b/mods/neutronium_compressor.js index fc59d905..106fb506 100644 --- a/mods/neutronium_compressor.js +++ b/mods/neutronium_compressor.js @@ -1,8 +1,27 @@ +function whenAvailable(names, callback) { + var interval = 10; // ms + window.setTimeout(function() { + let bool = true; + for(let i = 0; i < names.length; i++) + { + if(!window[names[i]]) + { + bool = false; + } + } + if (bool) { + callback(); + } else { + whenAvailable(names, callback); + } + }, interval); +} var modName = "mods/neutronium_compressor.js"; -var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js"; +var runAfterAutogenMod = "mods/runAfterAutogen2.js"; var libraryMod = "mods/code_library.js"; if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(libraryMod)) { + whenAvailable(["urlParams","runAfterAutogen"], function() { var singularityColorTemplate = ["#202020", "#505050", "#b0b0b0", "#c7c7c7"]; singularityNumber = 10000; @@ -388,6 +407,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(libraryMod)) //Post-generation tasks + }); } else { if(!enabledMods.includes(runAfterAutogenMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,runAfterAutogenMod) }; if(!enabledMods.includes(libraryMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod) }; diff --git a/mods/rays.js b/mods/rays.js index 0a7e8ee0..f862df47 100644 --- a/mods/rays.js +++ b/mods/rays.js @@ -1,8 +1,28 @@ +function whenAvailable(names, callback) { + var interval = 10; // ms + window.setTimeout(function() { + let bool = true; + for(let i = 0; i < names.length; i++) + { + if(!window[names[i]]) + { + bool = false; + } + } + if (bool) { + callback(); + } else { + whenAvailable(names, callback); + } + }, interval); +} + var modName = "mods/rays.js"; -var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js"; +var runAfterAutogenMod = "mods/runAfterAutogen2.js"; var libraryMod = "mods/code_library.js"; if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(libraryMod)) { +whenAvailable(["runAfterAutogen","libraryLoaded"], function() { runAfterAutogen(function() { snowAndIceCache = Object.keys(elements).filter(function(name) { return name.endsWith("snow") || name.endsWith("ice") || name == "rime" @@ -435,7 +455,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(libraryMod)) } } }; - +}); } else { if(!enabledMods.includes(libraryMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod) }; if(!enabledMods.includes(runAfterAutogenMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,runAfterAutogenMod) }; diff --git a/mods/runAfterAutogen2.js b/mods/runAfterAutogen2.js new file mode 100644 index 00000000..d7b1f692 --- /dev/null +++ b/mods/runAfterAutogen2.js @@ -0,0 +1,52 @@ +//runs after the elements in "names" are defined + +function runAfterAutogen(callback) { + var interval = 10; // ms + window.setTimeout(function() { + if (window.autoElements) { + callback(); + } else { + runAfterAutogen(callback); + } + }, interval); +} +function createButtonsAndCountElements() { + document.getElementById("categoryControls").innerHTML = ""; + document.getElementById("elementControls").innerHTML = ""; + document.getElementById("extraInfo").innerHTML = ""; + elementCount = 0; + hiddenCount = 0; + categoryList = []; + for (var element in elements) { + elementCount++; + if (settings.cheerful && elements[element].nocheer) { + elements[element].hidden = true; + hiddenCount++; + continue; + } + if (element === "unknown") {continue;} + var category = elements[element].category; + if (category==null) {category="other"} + if (categoryList.indexOf(category) === -1) { + categoryList.push(category); + } + if (elements[element].hidden && (!settings["unhide"] || ( settings["unhide"]===2 && !settings.unlocked[element] ))) { hiddenCount++; continue; } + var categoryDiv = document.getElementById("category-"+category); + if (categoryDiv == null) { + createCategoryDiv(category); + categoryDiv = document.getElementById("category-"+category); + } + createElementButton(element); + } + if (document.getElementById("categoryButton-states")) { + // move it to the end of its parent + document.getElementById("categoryButton-states").parentNode.appendChild(document.getElementById("categoryButton-states")); + } + // Set the first button in categoryControls div to be the current category + document.getElementById("categoryControls").children[0].click() + document.getElementById("extraInfo").insertAdjacentHTML("beforeend", "
v" + currentversion + " • " + elementCount + " elements, including " + hiddenCount + " hidden ones.
©2021-" + new Date().getFullYear() + ". All Rights Reserved. R74n
"); + selectElement(currentElement); + +}; + +runAfterAutogen(createButtonsAndCountElements); \ No newline at end of file diff --git a/mods/the_ground.js b/mods/the_ground.js index ad0c48e3..7a93de6b 100644 --- a/mods/the_ground.js +++ b/mods/the_ground.js @@ -15,7 +15,7 @@ var libHookTickMod = "mods/libhooktick.js"; var propertyLibrary = "mods/special_property_library.js"; //someone retroactively turned off ??= assignment on undeclared variables /hj -if(!urlParams) { urlParams = new URLSearchParams(window.location.search) }; +if(!window["urlParams"] || !urlParams) { urlParams = new URLSearchParams(window.location.search) }; modRequirementsPartOne = (enabledMods.includes(libraryMod) && enabledMods.includes(colorOffsetMod)); if(urlParams.get("radiationSystemEnabled") === null) {