move code out
This commit is contained in:
parent
6d2d608bc7
commit
af8c1205ba
100
mods/fire_mod.js
100
mods/fire_mod.js
|
|
@ -1,3 +1,7 @@
|
||||||
|
var modName = "mods/random_rocks.js";
|
||||||
|
var libraryMod = "mods/code_library.js";
|
||||||
|
|
||||||
|
if(enabledMods.includes(libraryMod)) {
|
||||||
/* elements.iron.reactions.radiation =
|
/* elements.iron.reactions.radiation =
|
||||||
{elem1: 'dirty_water', elem2: null}
|
{elem1: 'dirty_water', elem2: null}
|
||||||
when radiation touches iron,
|
when radiation touches iron,
|
||||||
|
|
@ -119,97 +123,6 @@ function doBurning(pixel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Use other pixels' reactions as if they were meant for the calling pixel
|
|
||||||
function reactionStealer(pixel,newPixel,reactionTarget) {
|
|
||||||
if(!elements[reactionTarget]) {
|
|
||||||
throw new Error(`No such element ${reactionTarget}!`);
|
|
||||||
};
|
|
||||||
if(typeof(newPixel) === "undefined") { //timing issue?
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
var newElement = newPixel.element;
|
|
||||||
var newInfo = elements[newElement];
|
|
||||||
if(typeof(newInfo.reactions) === "undefined") {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
if(typeof(newInfo.reactions[reactionTarget]) === "undefined") {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
var pixel2 = pixel;
|
|
||||||
var pixel1 = newPixel;
|
|
||||||
var r = newInfo.reactions[reactionTarget];
|
|
||||||
|
|
||||||
if (r.setting && settings[r.setting]===0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// r has the attribute "y" which is a range between two y values
|
|
||||||
// r.y example: [10,30]
|
|
||||||
// return false if y is defined and pixel1's y is not in the range
|
|
||||||
if (r.tempMin !== undefined && pixel1.temp < r.tempMin) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (r.tempMax !== undefined && pixel1.temp > r.tempMax) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (r.charged && !pixel.charge) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (r.chance !== undefined && Math.random() > r.chance) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (r.y !== undefined && (pixel1.y < r.y[0] || pixel1.y > r.y[1])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (r.elem1 !== undefined) {
|
|
||||||
// if r.elem1 is an array, set elem1 to a random element from the array, otherwise set it to r.elem1
|
|
||||||
if (Array.isArray(r.elem1)) {
|
|
||||||
var elem1 = r.elem1[Math.floor(Math.random() * r.elem1.length)];
|
|
||||||
} else { var elem1 = r.elem1; }
|
|
||||||
|
|
||||||
if (elem1 == null) {
|
|
||||||
deletePixel(pixel1.x,pixel1.y);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
changePixel(pixel1,elem1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (r.charge1) { pixel1.charge = r.charge1; }
|
|
||||||
if (r.temp1) { pixel1.temp += r.temp1; pixelTempCheck(pixel1); }
|
|
||||||
if (r.color1) { // if it's a list, use a random color from the list, else use the color1 attribute
|
|
||||||
pixel1.color = pixelColorPick(pixel1, Array.isArray(r.color1) ? r.color1[Math.floor(Math.random() * r.color1.length)] : r.color1);
|
|
||||||
}
|
|
||||||
if (r.attr1) { // add each attribute to pixel1
|
|
||||||
for (var key in r.attr1) {
|
|
||||||
pixel1[key] = r.attr1[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (r.elem2 !== undefined) {
|
|
||||||
// if r.elem2 is an array, set elem2 to a random element from the array, otherwise set it to r.elem2
|
|
||||||
if (Array.isArray(r.elem2)) {
|
|
||||||
var elem2 = r.elem2[Math.floor(Math.random() * r.elem2.length)];
|
|
||||||
} else { var elem2 = r.elem2; }
|
|
||||||
|
|
||||||
if (elem2 == null) {
|
|
||||||
deletePixel(pixel2.x,pixel2.y);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
changePixel(pixel2,elem2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (r.charge2) { pixel2.charge = r.charge2; }
|
|
||||||
if (r.temp2) { pixel2.temp += r.temp2; pixelTempCheck(pixel2); }
|
|
||||||
if (r.color2) { // if it's a list, use a random color from the list, else use the color2 attribute
|
|
||||||
pixel2.color = pixelColorPick(pixel2, Array.isArray(r.color2) ? r.color2[Math.floor(Math.random() * r.color2.length)] : r.color2);
|
|
||||||
}
|
|
||||||
if (r.attr2) { // add each attribute to pixel2
|
|
||||||
for (var key in r.attr2) {
|
|
||||||
pixel2[key] = r.attr2[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (r.func) { r.func(pixel1,pixel2); }
|
|
||||||
return r.elem1!==undefined || r.elem2!==undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
//New elements
|
//New elements
|
||||||
|
|
||||||
elements.cold_fire.burning = true;
|
elements.cold_fire.burning = true;
|
||||||
|
|
@ -664,3 +577,8 @@ runAfterLoad(function() {
|
||||||
elements.burning_unnamed_powder.fireElement = "plasma";
|
elements.burning_unnamed_powder.fireElement = "plasma";
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
alert(`The ${libraryMod} mod is required and has been automatically inserted (reload for this to take effect).`)
|
||||||
|
enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod)
|
||||||
|
localStorage.setItem("enabledMods", JSON.stringify(enabledMods));
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue