simplify code
This commit is contained in:
parent
25684ef889
commit
cbff198583
|
|
@ -23,36 +23,19 @@ if(enabledMods.includes(libraryMod)) {
|
||||||
//doBurning
|
//doBurning
|
||||||
function doBurning(pixel) {
|
function doBurning(pixel) {
|
||||||
if (pixel.burning) { // Burning
|
if (pixel.burning) { // Burning
|
||||||
|
pixel.burnStart ??= pixelTicks;
|
||||||
var info = elements[pixel.element];
|
var info = elements[pixel.element];
|
||||||
var burnTempChange = info.burnTempChange
|
var burnTempChange = info.burnTempChange ?? 1;
|
||||||
if (burnTempChange == undefined) {
|
|
||||||
burnTempChange = 1;
|
|
||||||
};
|
|
||||||
//move fire ahead so that cold burners don't light hot burners
|
|
||||||
var fireIsCold;
|
var fireIsCold;
|
||||||
//Fire getter block
|
var fire = info.fireElement === undefined ? "fire" : info.fireElement; //allow null but disallow undefined
|
||||||
var fire = info.fireElement;
|
//console.log(info.fireElement,fire);
|
||||||
if (fire == undefined) {
|
while(fire instanceof Array) {
|
||||||
fire = 'fire';
|
|
||||||
}
|
|
||||||
else if(fire instanceof Array) {
|
|
||||||
fire = fire[Math.floor(Math.random()*fire.length)];
|
fire = fire[Math.floor(Math.random()*fire.length)];
|
||||||
}
|
|
||||||
//End fire getter block
|
|
||||||
//Fire temp getter block
|
|
||||||
var fireTemp = info.fireSpawnTemp;
|
|
||||||
if (fireTemp == undefined) {
|
|
||||||
fireTemp = pixel.temp;
|
|
||||||
};
|
};
|
||||||
//End fire temp getter block
|
var fireTemp = info.fireSpawnTemp ?? pixel.temp;
|
||||||
//Fire chance getter block
|
var fireChance = info.fireSpawnChance ?? 10;
|
||||||
var fireChance = info.fireSpawnChance;
|
|
||||||
if (fireChance == undefined) {
|
|
||||||
fireChance = 10;
|
|
||||||
};
|
|
||||||
//End fire chance getter block
|
|
||||||
var fireIsCold = (fire === "cold_fire");
|
var fireIsCold = (fire === "cold_fire");
|
||||||
var fireInfo = elements[fire];
|
//var fireInfo = fire === null ? null : elements[fire];
|
||||||
|
|
||||||
pixel.temp += burnTempChange;
|
pixel.temp += burnTempChange;
|
||||||
pixelTempCheck(pixel);
|
pixelTempCheck(pixel);
|
||||||
|
|
@ -64,17 +47,11 @@ if(enabledMods.includes(libraryMod)) {
|
||||||
var newPixel = pixelMap[x][y];
|
var newPixel = pixelMap[x][y];
|
||||||
var newInfo = elements[newPixel.element];
|
var newInfo = elements[newPixel.element];
|
||||||
var newFireIsCold;
|
var newFireIsCold;
|
||||||
//Fire getter block
|
var newFire = newInfo.fireElement == undefined ? "fire" : newInfo.fireElement;
|
||||||
var newFire = newInfo.fireElement;
|
while(newFire instanceof Array) {
|
||||||
if (newFire == undefined) {
|
|
||||||
newFire = 'fire';
|
|
||||||
}
|
|
||||||
else if(newFire instanceof Array) {
|
|
||||||
newFire = newFire[Math.floor(Math.random()*newFire.length)];
|
newFire = newFire[Math.floor(Math.random()*newFire.length)];
|
||||||
}
|
};
|
||||||
//End fire getter block
|
|
||||||
newFireIsCold = (newFire === "cold_fire");
|
newFireIsCold = (newFire === "cold_fire");
|
||||||
|
|
||||||
//console.log(`burning pixel ${pixel.element}: ${fire} (${fireIsCold}) / burned element ${newPixel.element}: ${newFire} (${newFireIsCold})`);
|
//console.log(`burning pixel ${pixel.element}: ${fire} (${fireIsCold}) / burned element ${newPixel.element}: ${newFire} (${newFireIsCold})`);
|
||||||
if((!fireIsCold && !newFireIsCold) || (fireIsCold && newFireIsCold)) {
|
if((!fireIsCold && !newFireIsCold) || (fireIsCold && newFireIsCold)) {
|
||||||
if (elements[newPixel.element].burn && !newPixel.burning) {
|
if (elements[newPixel.element].burn && !newPixel.burning) {
|
||||||
|
|
@ -88,14 +65,13 @@ if(enabledMods.includes(libraryMod)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pixelTicks - pixel.burnStart > (info.burnTime || 200)) && Math.floor(Math.random()*100)<(info.burn || 10)) {
|
if ((pixelTicks - pixel.burnStart > (info.burnTime || 200)) && Math.floor(Math.random()*100)<(info.burn || 10)) {
|
||||||
var burnInto = info.burnInto;
|
var burnInto = info.burnInto ?? "fire";
|
||||||
if (burnInto == undefined) {
|
while(burnInto instanceof Array) {
|
||||||
burnInto = 'fire';
|
|
||||||
}
|
|
||||||
else if (burnInto instanceof Array) {
|
|
||||||
burnInto = burnInto[Math.floor(Math.random()*burnInto.length)];
|
burnInto = burnInto[Math.floor(Math.random()*burnInto.length)];
|
||||||
}
|
};
|
||||||
changePixel(pixel,burnInto,(burnInto !== "smoke"));
|
changePixel(pixel,burnInto,burnInto !== "smoke");
|
||||||
|
//console.log("ass");
|
||||||
|
pixel.temp = fireTemp;
|
||||||
if (info.fireColor != undefined && burnInto == "fire") {
|
if (info.fireColor != undefined && burnInto == "fire") {
|
||||||
pixel.color = pixelColorPick(pixel,info.fireColor);
|
pixel.color = pixelColorPick(pixel,info.fireColor);
|
||||||
}
|
}
|
||||||
|
|
@ -104,20 +80,25 @@ if(enabledMods.includes(libraryMod)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Math.floor(Math.random()*100)<fireChance && !fireSpawnBlacklist.includes(pixel.element)) { // Spawn fire
|
else if (Math.floor(Math.random()*100)<fireChance && !fireSpawnBlacklist.includes(pixel.element)) { // Spawn fire
|
||||||
|
//console.log(fire);
|
||||||
if (isEmpty(pixel.x,pixel.y-1)) {
|
if (isEmpty(pixel.x,pixel.y-1)) {
|
||||||
|
if(fire !== null) {
|
||||||
createPixel(fire,pixel.x,pixel.y-1);
|
createPixel(fire,pixel.x,pixel.y-1);
|
||||||
pixelMap[pixel.x][pixel.y-1].temp = fireTemp;
|
pixelMap[pixel.x][pixel.y-1].temp = fireTemp;
|
||||||
if (info.fireColor != undefined) {
|
if (info.fireColor != undefined) {
|
||||||
pixelMap[pixel.x][pixel.y-1].color = pixelColorPick(pixelMap[pixel.x][pixel.y-1],info.fireColor);
|
pixelMap[pixel.x][pixel.y-1].color = pixelColorPick(pixelMap[pixel.x][pixel.y-1],info.fireColor);
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// same for below if top is blocked
|
// same for below if top is blocked
|
||||||
else if (isEmpty(pixel.x,pixel.y+1)) {
|
else if (isEmpty(pixel.x,pixel.y+1)) {
|
||||||
|
if(fire !== null) {
|
||||||
createPixel(fire,pixel.x,pixel.y+1);
|
createPixel(fire,pixel.x,pixel.y+1);
|
||||||
pixelMap[pixel.x][pixel.y+1].temp = fireTemp;
|
pixelMap[pixel.x][pixel.y+1].temp = fireTemp;
|
||||||
if (info.fireColor != undefined) {
|
if (info.fireColor != undefined) {
|
||||||
pixelMap[pixel.x][pixel.y+1].color = pixelColorPick(pixelMap[pixel.x][pixel.y+1],info.fireColor);
|
pixelMap[pixel.x][pixel.y+1].color = pixelColorPick(pixelMap[pixel.x][pixel.y+1],info.fireColor);
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -366,7 +347,7 @@ if(enabledMods.includes(libraryMod)) {
|
||||||
state: "liquid",
|
state: "liquid",
|
||||||
viscosity: 1000,
|
viscosity: 1000,
|
||||||
density: 1200, //google was f***ing useless and i'm not searching that again, so arbitrary 1.2 it is
|
density: 1200, //google was f***ing useless and i'm not searching that again, so arbitrary 1.2 it is
|
||||||
burnTempChange: 2,
|
burnTempChange: 3,
|
||||||
burn: 300,
|
burn: 300,
|
||||||
burnTime: 500,
|
burnTime: 500,
|
||||||
temp: airTemp,
|
temp: airTemp,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue