mobs/spouts-style generation
This commit is contained in:
parent
e01df3ce43
commit
e300acde02
|
|
@ -1,5 +1,10 @@
|
|||
if(enabledMods.includes("mods/fey_and_more.js")) {
|
||||
var modName = "mods/more_fairies.js";
|
||||
var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js";
|
||||
var libraryMod = "mods/code_library.js";
|
||||
var feyAndMoreMod = "mods/fey_and_more.js";
|
||||
|
||||
if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(libraryMod) && enabledMods.includes(feyAndMoreMod)) {
|
||||
//keep old fairies
|
||||
elements.acid_fairy = {
|
||||
name: "acid fairy",
|
||||
color: ["#e2f777","#d1ff94","#d8f7c1"],
|
||||
|
|
@ -11,6 +16,7 @@ if(enabledMods.includes("mods/fey_and_more.js")) {
|
|||
state: "solid",
|
||||
category: "fey",
|
||||
}
|
||||
eLists.FAIRY.push("acid_fairy");
|
||||
|
||||
elements.oil_fairy = {
|
||||
name: "oil fairy",
|
||||
|
|
@ -23,6 +29,7 @@ if(enabledMods.includes("mods/fey_and_more.js")) {
|
|||
state: "solid",
|
||||
category: "fey",
|
||||
}
|
||||
eLists.FAIRY.push("oil_fairy");
|
||||
|
||||
elements.honey_fairy = {
|
||||
name: "honey fairy",
|
||||
|
|
@ -35,68 +42,256 @@ if(enabledMods.includes("mods/fey_and_more.js")) {
|
|||
state: "solid",
|
||||
category: "fey",
|
||||
}
|
||||
eLists.FAIRY.push("honey_fairy");
|
||||
|
||||
}
|
||||
excludedFairyElements = [];
|
||||
|
||||
if(urlParams.get('fairyIncludeRandom') !== null) { //if the variable exists at all
|
||||
fairyIncludeRandom = true
|
||||
} else { //if it doesn't (and it returns null)
|
||||
fairyIncludeRandom = false
|
||||
}
|
||||
|
||||
elements.acid.ignore.push("fairy")
|
||||
elements.acid.ignore.push("fairy_dust")
|
||||
elements.acid.ignore.push("acid_fairy")
|
||||
//Generator function
|
||||
|
||||
runAfterLoad(function() {
|
||||
if(enabledMods.includes("mods/fey_and_more.js")) {
|
||||
//eList rebuilding {
|
||||
eLists.FAIRY.push("acid_fairy");
|
||||
eLists.FAIRY.push("oil_fairy");
|
||||
eLists.FAIRY.push("honey_fairy");
|
||||
|
||||
elements.iron.behavior = [
|
||||
"XX|DL:"+eLists.FAIRY+"|XX",
|
||||
"DL:"+eLists.FAIRY+"|XX|DL:"+eLists.FAIRY+"",
|
||||
"XX|DL:"+eLists.FAIRY+"|XX"
|
||||
];
|
||||
elements.silver.behavior = [
|
||||
"XX|DL:"+eLists.FAIRY+"|XX",
|
||||
"DL:"+eLists.FAIRY+"|XX|DL:"+eLists.FAIRY+"",
|
||||
"XX|DL:"+eLists.FAIRY+"|XX"
|
||||
];
|
||||
//}
|
||||
elements.fairy.reactions.acid = { "elem1": "acid_fairy", "elem2": null }
|
||||
elements.fairy.reactions.oil = { "elem1": "oil_fairy", "elem2": null }
|
||||
elements.fairy.reactions.honey = { "elem1": "honey_fairy", "elem2": null }
|
||||
function tryJoin(stringOrArray,joiner) {
|
||||
//console.log(`tryJoin: ${stringOrArray}`);
|
||||
if(typeof(stringOrArray) === "string") {
|
||||
//console.log("tryJoin: String");
|
||||
return stringOrArray;
|
||||
} else if(Array.isArray(stringOrArray)) {
|
||||
//console.log("tryJoin: Array");
|
||||
return stringOrArray.join(joiner);
|
||||
} else {
|
||||
throw new TypeError(`Unexpected type: ${typeof(stringOrArray)}`);
|
||||
};
|
||||
};
|
||||
if(enabledMods.includes("mods/fey_and_more.js") && enabledMods.includes("mods/randomness.js")) {
|
||||
elements.warp_fairy = {
|
||||
name: "warp fairy",
|
||||
color: ["#332f33","#3b3b3b","#413f4a"],
|
||||
behavior: [
|
||||
"XX|M1|M1",
|
||||
"XX|FX%5|XX",
|
||||
"XX|CR:warp%0.4 AND CR:fairy_dust%0.005 AND M1|M1",
|
||||
],
|
||||
state: "solid",
|
||||
category: "fey",
|
||||
|
||||
//Standalone generator
|
||||
function generateFairy(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),
|
||||
then isAfterScriptLoading should be true or you might also get TypeErrors (this latter case was a bit inconsistent when I tested it, but
|
||||
the former case wasn't. **isAfterScriptLoading must be false when this function is run from a JS mod file**.*/
|
||||
if(typeof(fairyElements) === "string") { //it should be an array, so string check
|
||||
//console.log("String detected");
|
||||
if(fairyElements.includes(",")) { //comma-separated string?
|
||||
//console.log("Splitting string to array");
|
||||
fairyElements = fairyElements.split(","); //,SS to array
|
||||
} else {
|
||||
//console.log("Wrapping string in array");
|
||||
fairyElements = [fairyElements]; //single string to array
|
||||
};
|
||||
};
|
||||
for(aaf = 0; aaf < fairyElements.length; aaf++) {
|
||||
var elementOfFairy = fairyElements[aaf];
|
||||
var startColor;
|
||||
var randomExcl = 0;
|
||||
//console.log("randomExcl set")
|
||||
//console.log(elementOfFairy);
|
||||
|
||||
var fairyName;
|
||||
|
||||
if(typeof(elementOfFairy === "string")) { //comma separated string check
|
||||
if(elementOfFairy.includes(",")) { //if it is
|
||||
elementOfFairy = elementOfFairy.split(","); //to array
|
||||
elementOfFairy = elementOfFairy.filter(function(e) { //strip nonexistent elements
|
||||
return typeof(elements[e]) === "object";
|
||||
});
|
||||
};
|
||||
};
|
||||
if(Array.isArray(elementOfFairy)) {
|
||||
fairyName = `${elementOfFairy.join("_")}_fairy`; //auto placer element name
|
||||
|
||||
//array case color concatenator and excludeRandom handler
|
||||
startColor = [];
|
||||
//console.log(elementOfFairy);
|
||||
for(ll = 0; ll < elementOfFairy.length; ll++) {
|
||||
if(typeof(elements[elementOfFairy[ll]].excludeRandom !== "undefined")) { //if excludeRandom exists (prevent TypeError)
|
||||
if(elements[elementOfFairy[ll]].excludeRandom) { //it it's true
|
||||
randomExcl = 1; //the whole array fairy is excluded
|
||||
//console.log("array nyet" + elementOfFairy);
|
||||
};
|
||||
};
|
||||
//console.log(elementOfFairy[ll]);
|
||||
startColor = startColor.concat(elements[elementOfFairy[ll]].color);
|
||||
};
|
||||
} else { //they should all be strings, so here
|
||||
fairyName = `${elementOfFairy}_fairy`; //auto placer element name
|
||||
startColor = elements[elementOfFairy].color;
|
||||
if(typeof(elements[elementOfFairy].excludeRandom !== "undefined")) { //if excludeRandom exists (prevent TypeError)
|
||||
if(elements[elementOfFairy].excludeRandom) { //it it's true
|
||||
//console.log("nyet " + elementOfFairy);
|
||||
randomExcl = 1; //the fairy is excluded
|
||||
} else {
|
||||
//console.log("allow " + elementOfFairy);
|
||||
randomExcl = 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
//Color gen
|
||||
if(Array.isArray(startColor)) { //Average arrays, make colors rgb()
|
||||
startColor = averageRgbPrefixedColorArray(startColor);
|
||||
} else {
|
||||
startColor = rgbHexCatcher(startColor);
|
||||
};
|
||||
|
||||
//console.log(`rgbStringToObject(${startColor}) from more_fairies.js`)
|
||||
var newColorObjectArray = [];
|
||||
var newColorArray = [];
|
||||
|
||||
for(i = 0; i < elements.fairy.color.length; i++) {
|
||||
var newFairyColorlet = elements.fairy.color[i];
|
||||
var newColor = multiplyColors(startColor,newFairyColorlet);
|
||||
var newColorJSON = multiplyColors(startColor,newFairyColorlet,"json");
|
||||
newColorArray.push(newColor);
|
||||
newColorObjectArray.push(newColorJSON);
|
||||
};
|
||||
|
||||
//End color gen
|
||||
|
||||
//The fairy
|
||||
|
||||
//console.log(elementOfFairy);
|
||||
var firstInfo, firstTemp;
|
||||
if(Array.isArray(elementOfFairy)) {
|
||||
firstInfo = elements[elementOfFairy[0]];
|
||||
firstTemp = airTemp;
|
||||
if(typeof(firstInfo.temp) !== "undefined") {
|
||||
firstTemp = firstInfo.temp;
|
||||
};
|
||||
} else {
|
||||
firstInfo = elements[elementOfFairy];
|
||||
firstTemp = airTemp;
|
||||
if(typeof(firstInfo.temp) !== "undefined") {
|
||||
firstTemp = firstInfo.temp;
|
||||
};
|
||||
};
|
||||
|
||||
elementOfFairy = tryJoin(elementOfFairy,",");
|
||||
|
||||
//console.log(elementOfFairy);
|
||||
|
||||
if(!elementExists(fairyName)) {
|
||||
elements[fairyName] = {
|
||||
color: newColorArray,
|
||||
insulate: true,
|
||||
colorObject: newColorObjectArray,
|
||||
behavior: [
|
||||
["XX","M1","M1"],
|
||||
["XX","FX%5","XX"],
|
||||
["XX",`CR:${elementOfFairy}%0.5 AND CR:fairy_dust%0.005 AND M1`,"M1"]
|
||||
],
|
||||
category: "auto_fey",
|
||||
temp: firstTemp,
|
||||
hardness: 1,
|
||||
};
|
||||
if(typeof(eLists) === "undefined") {
|
||||
eLists = {};
|
||||
};
|
||||
if(typeof(eLists.FAIRY) === "undefined") {
|
||||
eLists.FAIRY = [];
|
||||
};
|
||||
eLists.FAIRY.push(fairyName);
|
||||
if(!randomExcl) {
|
||||
if(typeof(fairyChoices) === "undefined") {
|
||||
fairyChoices = []
|
||||
};
|
||||
if(!fairyChoices.includes(fairyName)) {
|
||||
fairyChoices.push(fairyName);
|
||||
};
|
||||
}
|
||||
if(fairyIncludeRandom) {
|
||||
randomExcl ? elements[fairyName].excludeRandom = true : elements[fairyName].excludeRandom = false;
|
||||
} else {
|
||||
elements[fairyName].excludeRandom = true;
|
||||
};
|
||||
if(isAfterScriptLoading) {
|
||||
elementCount++; //increment for new fairy element
|
||||
createElementButton(fairyName);
|
||||
elements[fairyName].id = nextid++;
|
||||
document.getElementById("extraInfo").innerHTML = "<small><p>There are " + elementCount + " elements, including " + hiddenCount + " hidden ones.</p><p>©2021-" + new Date().getFullYear() + ". All Rights Reserved. <a href='https://r74n.com'>R74n</a></p></small>"; //update extra info counts (and the copyright year, due to the method used)
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
runAfterAutogen(function() {
|
||||
fairyArray = Object.keys(elements).filter(function(e) { //same criteria as spouts
|
||||
return (elements[e].state == "liquid" || elements[e].state == "gas" || elements[e].movable) && !excludedFairyElements.includes(elements[e]);
|
||||
});
|
||||
generateFairy(fairyArray,false);
|
||||
});
|
||||
|
||||
elements.spawn_random_fairy = {
|
||||
color: ["#3e5f8a","#a334ec","#ea96f9","#a6ecf6","#70ebc8","#d9286b","#7eed91","#a18b30"],
|
||||
behavior: behaviors.WALL,
|
||||
category: "special",
|
||||
excludeRandom: true,
|
||||
tick: function(pixel) {
|
||||
changePixel(pixel,fairyChoices[Math.floor(Math.random() * fairyChoices.length)])
|
||||
},
|
||||
};
|
||||
|
||||
//Post-generation tasks
|
||||
//Revamp fairykill
|
||||
behaviors.FAIRYKILL_OLD = behaviors.FAIRYKILL;
|
||||
behaviors.FAIRYKILL = function(pixel) {
|
||||
if (pixel.start === pixelTicks) {return}
|
||||
if (pixel.charge && elements[pixel.element].behaviorOn) {
|
||||
pixelTick(pixel)
|
||||
}
|
||||
elements.fairy.reactions.warp = { "elem1": "warp_fairy", "elem2": null }
|
||||
eLists.FAIRY.push("warp_fairy");
|
||||
elements.iron.behavior = [
|
||||
"XX|DL:"+eLists.FAIRY+"|XX",
|
||||
"DL:"+eLists.FAIRY+"|XX|DL:"+eLists.FAIRY+"",
|
||||
"XX|DL:"+eLists.FAIRY+"|XX"
|
||||
];
|
||||
elements.silver.behavior = [
|
||||
"XX|DL:"+eLists.FAIRY+"|XX",
|
||||
"DL:"+eLists.FAIRY+"|XX|DL:"+eLists.FAIRY+"",
|
||||
"XX|DL:"+eLists.FAIRY+"|XX"
|
||||
];
|
||||
elements.tungstensteel.behavior = [
|
||||
"XX|DL:"+eLists.FAIRY+"|XX",
|
||||
"DL:"+eLists.FAIRY+"|XX|DL:"+eLists.FAIRY+"",
|
||||
"XX|DL:"+eLists.FAIRY+"|XX",
|
||||
],
|
||||
elements.molten_tungstensteel.behavior = [
|
||||
"XX|DL:"+eLists.FAIRY+" AND CR:fire%2.5|XX",
|
||||
"DL:"+eLists.FAIRY+" AND M2|XX|DL:"+eLists.FAIRY+" AND M2",
|
||||
"M1|DL:"+eLists.FAIRY+"|M1",
|
||||
]
|
||||
var ignore = [];
|
||||
if(typeof(elements[pixel.element].ignore) !== "undefined") {
|
||||
ignore = elements[pixel.element].ignore;
|
||||
};
|
||||
for(i = 0; i < adjacentCoords.length; i++) {
|
||||
var coord = adjacentCoords[i];
|
||||
var offsetX = coord[0];
|
||||
var offsetY = coord[1];
|
||||
var newX = pixel.x+offsetX;
|
||||
var newY = pixel.y+offsetY;
|
||||
if(!isEmpty(newX,newY,true)) {
|
||||
var newPixel = pixelMap[newX][newY];
|
||||
var newElement = newPixel.element;
|
||||
var isIgnored = (newElement === ignore || ignore.includes(newElement))
|
||||
if(eLists.FAIRY.includes(newElement) && !isIgnored) {
|
||||
deletePixel(newX,newY);
|
||||
};
|
||||
};
|
||||
};
|
||||
doDefaults(pixel);
|
||||
};
|
||||
});
|
||||
|
||||
//Add ignores
|
||||
var ignoreArray = ["acid", "iron", "silver", "steel", "tungstensteel", "void", "liquid_void", "chute", "vute", "drute", "drolute", "volute", "alkahest", "acid_gas"];
|
||||
for(l = 0; l < ignoreArray.length; l++) {
|
||||
var name = ignoreArray[l];
|
||||
var fairyName = `${ignoreArray[l]}_fairy`;
|
||||
if(elementExists(name) && elementExists(fairyName)) {
|
||||
var baseInfo = elements[name];
|
||||
if(typeof(baseInfo.ignore) === "undefined") {
|
||||
baseInfo.ignore = [];
|
||||
} else if(typeof(baseInfo.ignore) === "string") {
|
||||
baseInfo.ignore = [baseInfo.ignore];
|
||||
};
|
||||
baseInfo.ignore.push(fairyName);
|
||||
};
|
||||
};
|
||||
|
||||
//Add updated fairykills
|
||||
var fairykillElements = ["iron", "silver", "steel", "tungstensteel"];
|
||||
for(q = 0; q < fairykillElements.length; q++) {
|
||||
var name = fairykillElements[q];
|
||||
if(elementExists(name)) {
|
||||
elements[name].behavior = behaviors.FAIRYKILL;
|
||||
};
|
||||
};
|
||||
} else {
|
||||
if(!enabledMods.includes(runAfterAutogenMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,runAfterAutogenMod) };
|
||||
if(!enabledMods.includes(libraryMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod) };
|
||||
if(!enabledMods.includes(feyAndMoreMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,feyAndMoreMod) };
|
||||
alert(`The "${runAfterAutogenMod}", "${libraryMod}", and "${feyAndMoreMod}" mods are required; any missing mods in this list have been automatically inserted (reload for this to take effect).`)
|
||||
localStorage.setItem("enabledMods", JSON.stringify(enabledMods));
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue