Merge branch 'R74nCom:main' into main
This commit is contained in:
commit
3f14798b26
|
|
@ -540,5 +540,10 @@
|
||||||
"tsunami": "海嘯",
|
"tsunami": "海嘯",
|
||||||
"blaster": "爆破器",
|
"blaster": "爆破器",
|
||||||
"propane_ice": "丙烷冰",
|
"propane_ice": "丙烷冰",
|
||||||
"molten_caustic_potash": "熔氢氧化鉀"
|
"molten_caustic_potash": "熔氢氧化鉀",
|
||||||
|
"cloth":"布",
|
||||||
|
"freeze_ray":"冷雷",
|
||||||
|
"kelp":"海帶",
|
||||||
|
"mixer":"混合機",
|
||||||
|
"grinder":"混合機"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -322,6 +322,7 @@
|
||||||
<tr><td>rainbow_tests.js</td><td>Adds variants of the rainbow element with different maths</td><td>Alice</td></tr>
|
<tr><td>rainbow_tests.js</td><td>Adds variants of the rainbow element with different maths</td><td>Alice</td></tr>
|
||||||
<tr><td>Shroomboxels.js</td><td>A variant of acid_and_shapes.js that uses a different trigonometric function</td><td>Alice</td></tr>
|
<tr><td>Shroomboxels.js</td><td>A variant of acid_and_shapes.js that uses a different trigonometric function</td><td>Alice</td></tr>
|
||||||
<tr><td>singleColor.js</td><td>Makes all elements pick one color each time they're drawn</td><td>stefanblox</td></tr>
|
<tr><td>singleColor.js</td><td>Makes all elements pick one color each time they're drawn</td><td>stefanblox</td></tr>
|
||||||
|
<tr><td>lightmap.js</td><td>Makes light sources glow</td><td>RedBirdly</td></tr>
|
||||||
|
|
||||||
<!----><tr><td class="modCat" colspan="3">Compilations</td></tr><!---->
|
<!----><tr><td class="modCat" colspan="3">Compilations</td></tr><!---->
|
||||||
<tr><td>a_mod_by_alice.js</td><td>A mod combining most of Alice’s mods, and some other things</td><td>Alice</td></tr>
|
<tr><td>a_mod_by_alice.js</td><td>A mod combining most of Alice’s mods, and some other things</td><td>Alice</td></tr>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
elements.water.behavior = [
|
||||||
|
"XX|XX|XX",
|
||||||
|
"M2%5|XX|M2 AND BO",
|
||||||
|
"XX|M1|M2",
|
||||||
|
];
|
||||||
|
elements.water.flippableX = true;
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
// Redbirdly's Mod that adds a better light system
|
// Redbirdly's Mod that adds a better light system
|
||||||
// this is the faster version of lightmap.js (although lower quality)
|
// this is the faster version of lightmap.js (although lower quality)
|
||||||
|
|
||||||
let lightmap = [];
|
var lightmap = [];
|
||||||
let nextLightmap = [];
|
var nextLightmap = [];
|
||||||
let lightmapWidth, lightmapHeight;
|
var lightmapWidth, lightmapHeight;
|
||||||
let pixelSizeQuarter = pixelSizeHalf / 2;
|
var lightmapScale = 3;
|
||||||
let lightmapScale = 3;
|
var pixelSizeQuarter = pixelSizeHalf / 2;
|
||||||
|
|
||||||
// Define RGB colors
|
// Define RGB colors
|
||||||
let lightColor = [255, 223, 186];
|
var fireColor = [255, 69, 0];
|
||||||
let sunColor = [255*8, 210*8, 26*8];
|
var coldFireColor = [0, 191, 255];
|
||||||
let lampColor = [255*4, 223*4, 186*4];
|
var fireflyColor = [240, 255, 70];
|
||||||
let laserColor = [255, 0, 0];
|
var radColor = [75, 100, 30];
|
||||||
let ledRColor = [255, 0, 0];
|
var strangeMatterColor = [220 * 0.3, 255 * 0.3, 210 * 0.3];
|
||||||
let ledGColor = [0, 255, 0];
|
var sparkColors = [[255, 210, 120], [255, 140, 10]];
|
||||||
let ledBColor = [0, 0, 255];
|
|
||||||
let fireColor = [255, 69, 0];
|
function getRandomElement(arr) {
|
||||||
let plasmaColor = [160, 69, 255];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
let coldFireColor = [0, 191, 255];
|
}
|
||||||
let magmaColor = [255, 140, 0];
|
|
||||||
let fireFlyColors = [[180, 255, 70], scaleList([180, 255, 70], 0.75), scaleList([180, 255, 70], 0.5), scaleList([180, 255, 70], 0.25)];
|
function rgbToArray(rgbString) {
|
||||||
let radColor = [75, 100, 30];
|
return rgbString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
||||||
let neonColor = [255*2, 60*2, 10*2];
|
}
|
||||||
|
|
||||||
function scaleList(numbers, scale) {
|
function scaleList(numbers, scale) {
|
||||||
return numbers.map(number => number * scale);
|
return numbers.map(number => number * scale);
|
||||||
|
|
@ -30,11 +30,11 @@ function scaleList(numbers, scale) {
|
||||||
function initializeLightmap(width, height) {
|
function initializeLightmap(width, height) {
|
||||||
lightmapWidth = Math.ceil(width / lightmapScale);
|
lightmapWidth = Math.ceil(width / lightmapScale);
|
||||||
lightmapHeight = Math.ceil(height / lightmapScale);
|
lightmapHeight = Math.ceil(height / lightmapScale);
|
||||||
|
|
||||||
for (let y = 0; y < lightmapHeight; y++) {
|
for (var y = 0; y < lightmapHeight; y++) {
|
||||||
lightmap[y] = [];
|
lightmap[y] = [];
|
||||||
nextLightmap[y] = [];
|
nextLightmap[y] = [];
|
||||||
for (let x = 0; x < lightmapWidth; x++) {
|
for (var x = 0; x < lightmapWidth; x++) {
|
||||||
lightmap[y][x] = { color: [0, 0, 0] };
|
lightmap[y][x] = { color: [0, 0, 0] };
|
||||||
nextLightmap[y][x] = { color: [0, 0, 0] };
|
nextLightmap[y][x] = { color: [0, 0, 0] };
|
||||||
}
|
}
|
||||||
|
|
@ -42,33 +42,35 @@ function initializeLightmap(width, height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function deepCopy(source, target) {
|
function deepCopy(source, target) {
|
||||||
for (let y = 0; y < source.length; y++) {
|
for (var y = 0; y < source.length; y++) {
|
||||||
target[y] = [];
|
target[y] = [];
|
||||||
for (let x = 0; x < source[y].length; x++) {
|
for (var x = 0; x < source[y].length; x++) {
|
||||||
target[y][x] = { ...source[y][x] };
|
target[y][x] = { ...source[y][x] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function propagateLightmap() {
|
function propagateLightmap() {
|
||||||
if (!lightmap || !lightmap[0]) { return; }
|
if (!lightmap || !lightmap[0]) return;
|
||||||
let width = lightmap[0].length;
|
|
||||||
let height = lightmap.length;
|
|
||||||
|
|
||||||
let neighbors = [
|
var width = lightmap[0].length;
|
||||||
|
var height = lightmap.length;
|
||||||
|
|
||||||
|
var neighbors = [
|
||||||
{ dx: 1, dy: 0 },
|
{ dx: 1, dy: 0 },
|
||||||
{ dx: -1, dy: 0 },
|
{ dx: -1, dy: 0 },
|
||||||
{ dx: 0, dy: 1 },
|
{ dx: 0, dy: 1 },
|
||||||
{ dx: 0, dy: -1 },
|
{ dx: 0, dy: -1 },
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let y = 0; y < height; y++) {
|
for (var y = 0; y < height; y++) {
|
||||||
for (let x = 0; x < width; x++) {
|
for (var x = 0; x < width; x++) {
|
||||||
let totalColor = [0, 0, 0];
|
var totalColor = [0, 0, 0];
|
||||||
let neighborCount = 0;
|
var neighborCount = 0;
|
||||||
|
|
||||||
neighbors.forEach(({ dx, dy }) => {
|
neighbors.forEach(({ dx, dy }) => {
|
||||||
let nx = x + dx;
|
var nx = x + dx;
|
||||||
let ny = y + dy;
|
var ny = y + dy;
|
||||||
if (nx >= 0 && ny >= 0 && nx < width && ny < height) {
|
if (nx >= 0 && ny >= 0 && nx < width && ny < height) {
|
||||||
totalColor[0] += lightmap[ny][nx].color[0];
|
totalColor[0] += lightmap[ny][nx].color[0];
|
||||||
totalColor[1] += lightmap[ny][nx].color[1];
|
totalColor[1] += lightmap[ny][nx].color[1];
|
||||||
|
|
@ -76,11 +78,12 @@ function propagateLightmap() {
|
||||||
neighborCount++;
|
neighborCount++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
nextLightmap[y][x] = {
|
nextLightmap[y][x] = {
|
||||||
color: [
|
color: [
|
||||||
Math.min(Math.max(0, totalColor[0] / neighborCount * 0.8), 255*8),
|
Math.min(Math.max(0, totalColor[0] / neighborCount * 0.8), 255 * 8),
|
||||||
Math.min(Math.max(0, totalColor[1] / neighborCount * 0.8), 255*8),
|
Math.min(Math.max(0, totalColor[1] / neighborCount * 0.8), 255 * 8),
|
||||||
Math.min(Math.max(0, totalColor[2] / neighborCount * 0.8), 255*8)
|
Math.min(Math.max(0, totalColor[2] / neighborCount * 0.8), 255 * 8)
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -90,11 +93,11 @@ function propagateLightmap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function rgbToHsv(r, g, b) {
|
function rgbToHsv(r, g, b) {
|
||||||
r /= 255, g /= 255, b /= 255;
|
r /= 255; g /= 255; b /= 255;
|
||||||
let max = Math.max(r, g, b), min = Math.min(r, g, b);
|
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
||||||
let h, s, v = max;
|
var h, s, v = max;
|
||||||
|
|
||||||
let d = max - min;
|
var d = max - min;
|
||||||
s = max === 0 ? 0 : d / max;
|
s = max === 0 ? 0 : d / max;
|
||||||
|
|
||||||
if (max === min) {
|
if (max === min) {
|
||||||
|
|
@ -112,54 +115,57 @@ function rgbToHsv(r, g, b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function hsvToRgb(h, s, v) {
|
function hsvToRgb(h, s, v) {
|
||||||
let r, g, b;
|
var r, g, b;
|
||||||
|
|
||||||
let i = Math.floor(h * 6);
|
var i = Math.floor(h * 6);
|
||||||
let f = h * 6 - i;
|
var f = h * 6 - i;
|
||||||
let p = v * (1 - s);
|
var p = v * (1 - s);
|
||||||
let q = v * (1 - f * s);
|
var q = v * (1 - f * s);
|
||||||
let t = v * (1 - (1 - f) * s);
|
var t = v * (1 - (1 - f) * s);
|
||||||
|
|
||||||
switch (i % 6) {
|
switch (i % 6) {
|
||||||
case 0: r = v, g = t, b = p; break;
|
case 0: r = v; g = t; b = p; break;
|
||||||
case 1: r = q, g = v, b = p; break;
|
case 1: r = q; g = v; b = p; break;
|
||||||
case 2: r = p, g = v, b = t; break;
|
case 2: r = p; g = v; b = t; break;
|
||||||
case 3: r = p, g = q, b = v; break;
|
case 3: r = p; g = q; b = v; break;
|
||||||
case 4: r = t, g = p, b = v; break;
|
case 4: r = t; g = p; b = v; break;
|
||||||
case 5: r = v, g = p, b = q; break;
|
case 5: r = v; g = p; b = q; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderLightmap() {
|
function renderLightmap() {
|
||||||
if (!canvas) { return; }
|
if (!canvas) return;
|
||||||
if (!lightmap || !lightmap[0]) { return; }
|
if (!lightmap || !lightmap[0]) return;
|
||||||
let context = canvas.getContext('2d');
|
|
||||||
let width = lightmap[0].length;
|
var context = canvas.getContext('2d');
|
||||||
let height = lightmap.length;
|
var width = lightmap[0].length;
|
||||||
|
var height = lightmap.length;
|
||||||
|
|
||||||
|
for (var y = 0; y < height; y++) {
|
||||||
|
for (var x = 0; x < width; x++) {
|
||||||
|
var { color } = lightmap[y][x];
|
||||||
|
var [r, g, b] = color;
|
||||||
|
|
||||||
for (let y = 0; y < height; y++) {
|
|
||||||
for (let x = 0; x < width; x++) {
|
|
||||||
let { color } = lightmap[y][x];
|
|
||||||
let [r, g, b] = color;
|
|
||||||
if (r > 0 || g > 0 || b > 0) {
|
if (r > 0 || g > 0 || b > 0) {
|
||||||
let [h, s, v] = rgbToHsv(r, g, b);
|
var [h, s, v] = rgbToHsv(r, g, b);
|
||||||
let newColor = hsvToRgb(h, s, 1);
|
var newColor = hsvToRgb(h, s, 1);
|
||||||
let alpha = v;
|
var alpha = v;
|
||||||
|
|
||||||
context.fillStyle = `rgba(${newColor[0]}, ${newColor[1]}, ${newColor[2]}, ${alpha*0.4})`;
|
context.fillStyle = `rgba(${newColor[0]}, ${newColor[1]}, ${newColor[2]}, ${alpha * 0.4})`;
|
||||||
context.fillRect(
|
context.fillRect(
|
||||||
x * pixelSize * lightmapScale,
|
x * pixelSize * lightmapScale,
|
||||||
y * pixelSize * lightmapScale,
|
y * pixelSize * lightmapScale,
|
||||||
pixelSize * lightmapScale,
|
pixelSize * lightmapScale,
|
||||||
pixelSize * lightmapScale
|
pixelSize * lightmapScale
|
||||||
);
|
);
|
||||||
|
|
||||||
context.fillStyle = `rgba(${newColor[0]}, ${newColor[1]}, ${newColor[2]}, ${alpha * 0.25})`;
|
context.fillStyle = `rgba(${newColor[0]}, ${newColor[1]}, ${newColor[2]}, ${alpha * 0.25})`;
|
||||||
context.fillRect(
|
context.fillRect(
|
||||||
(x * pixelSize - pixelSizeHalf) * lightmapScale,
|
(x * pixelSize - pixelSizeHalf) * lightmapScale,
|
||||||
(y * pixelSize - pixelSizeHalf) * lightmapScale,
|
(y * pixelSize - pixelSizeHalf) * lightmapScale,
|
||||||
pixelSize * lightmapScale * 2,
|
pixelSize * lightmapScale * 2,
|
||||||
pixelSize * lightmapScale * 2
|
pixelSize * lightmapScale * 2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -167,190 +173,148 @@ function renderLightmap() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.sun.tick = function(pixel) {
|
function glowItsOwnColor(pixel) {
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
if (!pixel.color) {return;}
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
lightmap[y][x] = { color: sunColor };
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
|
lightmap[y][x] = { color: rgbToArray(pixel.color) };
|
||||||
|
}
|
||||||
|
|
||||||
|
function glowItsOwnColorIfPowered(pixel) {
|
||||||
|
if (!pixel.charge || pixel.charge <= 0) {return;}
|
||||||
|
if (!pixel.color) return;
|
||||||
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
|
lightmap[y][x] = { color: rgbToArray(pixel.color) };
|
||||||
|
}
|
||||||
|
|
||||||
|
function glowColor(pixel, color) {
|
||||||
|
if (!color) {return;}
|
||||||
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
|
lightmap[y][x] = { color: color };
|
||||||
|
}
|
||||||
|
|
||||||
|
function glowRadiationColor(pixel) {
|
||||||
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
|
lightmap[y][x] = { color: radColor };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Define element tick functions
|
||||||
|
var originalStrangeMatterTick = elements.strange_matter.tick;
|
||||||
|
elements.strange_matter.tick = function(pixel) {
|
||||||
|
originalStrangeMatterTick(pixel);
|
||||||
|
glowColor(pixel, strangeMatterColor);
|
||||||
};
|
};
|
||||||
|
|
||||||
let originalLightTick = elements.light.tick;
|
var originalLightTick = elements.light.tick;
|
||||||
elements.light.tick = function(pixel) {
|
elements.light.tick = function(pixel) {
|
||||||
originalLightTick(pixel);
|
originalLightTick(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
glowItsOwnColor(pixel);
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: lightColor };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let originalLiquidLightTick = elements.liquid_light.tick;
|
var originalLiquidLightTick = elements.liquid_light.tick;
|
||||||
elements.liquid_light.tick = function(pixel) {
|
elements.liquid_light.tick = function(pixel) {
|
||||||
originalLiquidLightTick(pixel);
|
originalLiquidLightTick(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
glowItsOwnColor(pixel);
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: lightColor };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.magma.tick = function(pixel) {
|
var originalLaserTick = elements.laser.tick;
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: fireColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.neon.tick = function(pixel) {
|
|
||||||
if (!pixel.charge || pixel.charge <= 0) {return;}
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: neonColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.light_bulb.behaviorOn = null
|
|
||||||
elements.light_bulb.tick = function(pixel) {
|
|
||||||
if (pixel.charge > 0) {pixel.lightIntensity = 10;}
|
|
||||||
if (pixel.lightIntensity > 0) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: lampColor };
|
|
||||||
}
|
|
||||||
pixel.lightIntensity -= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.led_r.tick = function(pixel) {
|
|
||||||
if (pixel.charge > 0) {pixel.lightIntensity = 4;}
|
|
||||||
if (pixel.lightIntensity > 0) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: ledRColor };
|
|
||||||
}
|
|
||||||
pixel.lightIntensity -= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.led_g.tick = function(pixel) {
|
|
||||||
if (pixel.charge > 0) {pixel.lightIntensity = 4;}
|
|
||||||
if (pixel.lightIntensity > 0) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: ledGColor };
|
|
||||||
}
|
|
||||||
pixel.lightIntensity -= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.led_b.tick = function(pixel) {
|
|
||||||
if (pixel.charge > 0) {pixel.lightIntensity = 4;}
|
|
||||||
if (pixel.lightIntensity > 0) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: ledBColor };
|
|
||||||
}
|
|
||||||
pixel.lightIntensity -= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
let originalLaserTick = elements.laser.tick;
|
|
||||||
elements.laser.tick = function(pixel) {
|
elements.laser.tick = function(pixel) {
|
||||||
originalLaserTick(pixel);
|
originalLaserTick(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
glowColor(pixel, scaleList(rgbToArray(pixel.color), 0.5));
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: laserColor };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let originalFireTick2 = elements.fire.tick;
|
var originalFireTick2 = elements.fire.tick;
|
||||||
elements.fire.tick = function(pixel) {
|
elements.fire.tick = function(pixel) {
|
||||||
originalFireTick2(pixel);
|
originalFireTick2(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
glowColor(pixel, fireColor);
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: fireColor };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.cold_fire.tick = function(pixel) {
|
var originalFlashTick = elements.flash.tick;
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
elements.flash.tick = function(pixel) {
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
originalFlashTick(pixel);
|
||||||
lightmap[y][x] = { color: coldFireColor };
|
glowItsOwnColor(pixel);
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.plasma.tick = function(pixel) {
|
var originalRainbowTick = elements.rainbow.tick;
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
elements.rainbow.tick = function(pixel) {
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
originalRainbowTick(pixel);
|
||||||
lightmap[y][x] = { color: plasmaColor };
|
glowItsOwnColor(pixel);
|
||||||
};
|
};
|
||||||
|
|
||||||
let originalFireflyTick = elements.firefly.tick;
|
var originalFireflyTick = elements.firefly.tick;
|
||||||
elements.firefly.tick = function(pixel) {
|
elements.firefly.tick = function(pixel) {
|
||||||
originalFireflyTick(pixel);
|
originalFireflyTick(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
|
|
||||||
let col = undefined;
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
if (pixelTicks % pixel.fff <= 5) { col = fireFlyColors[3]; }
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
if (pixelTicks % pixel.fff <= 4) { col = fireFlyColors[2]; }
|
|
||||||
if (pixelTicks % pixel.fff <= 3) { col = fireFlyColors[1]; }
|
var tickMod = pixelTicks % pixel.fff;
|
||||||
if (pixelTicks % pixel.fff <= 2) { col = fireFlyColors[0]; }
|
var num;
|
||||||
if (col) {
|
|
||||||
lightmap[y][x] = { color: col };
|
if (tickMod <= 2) num = 1;
|
||||||
}
|
else if (tickMod <= 3) num = 0.75;
|
||||||
|
else if (tickMod <= 4) num = 0.5;
|
||||||
|
else if (tickMod <= 5) num = 0.25;
|
||||||
|
else return;
|
||||||
|
|
||||||
|
lightmap[y][x] = { color: scaleList(fireflyColor, num) };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
elements.electric.tick = pixel => glowColor(pixel, scaleList(getRandomElement(sparkColors), 0.5));
|
||||||
|
|
||||||
|
elements.neon.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.led_r.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.led_g.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.led_b.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.light_bulb.behaviorOn = null;
|
||||||
|
elements.light_bulb.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.sun.tick = glowItsOwnColor;
|
||||||
|
elements.magma.tick = glowItsOwnColor;
|
||||||
|
elements.plasma.tick = glowItsOwnColor;
|
||||||
|
elements.fw_ember.tick = glowItsOwnColor;
|
||||||
|
|
||||||
|
elements.cold_fire.tick = pixel => glowColor(pixel, coldFireColor);
|
||||||
|
|
||||||
// Radioactive elements
|
// Radioactive elements
|
||||||
elements.uranium.tick = function(pixel) {
|
var radioactiveElements = [
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
"uranium", "radiation", "rad_glass", "fallout",
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
"molten_uranium", "rad_shard", "rad_cloud", "rad_steam"
|
||||||
lightmap[y][x] = { color: radColor };
|
];
|
||||||
};
|
radioactiveElements.forEach(element => {
|
||||||
|
elements[element].tick = glowRadiationColor;
|
||||||
elements.radiation.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.rad_glass.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.fallout.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.molten_uranium.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.rad_shard.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.rad_cloud.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.rad_steam.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('load', function() {
|
|
||||||
initializeLightmap(width, height);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add code to functions instead of replacing them
|
window.addEventListener('load', () => initializeLightmap(width, height));
|
||||||
let originalTick = tick;
|
|
||||||
|
var originalTick = tick;
|
||||||
tick = function() {
|
tick = function() {
|
||||||
originalTick();
|
originalTick();
|
||||||
if (!paused) {propagateLightmap();}
|
if (!paused) propagateLightmap();
|
||||||
};
|
};
|
||||||
// Even after updating tick(), setInterval still uses the old tick(), reset setInterval
|
|
||||||
resetInterval(tps);
|
resetInterval(tps);
|
||||||
|
|
||||||
let originalDrawPixels = drawPixels;
|
var originalDoFrame = doFrame;
|
||||||
drawPixels = function(forceTick = false) {
|
doFrame = function() {
|
||||||
originalDrawPixels(forceTick);
|
originalDoFrame();
|
||||||
renderLightmap();
|
propagateLightmap();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (enabledMods.includes("mods/velocity.js")) {
|
||||||
|
runAfterAutogen(() => {
|
||||||
|
var originalDrawPixels = drawPixels;
|
||||||
|
drawPixels = function(forceTick = false) {
|
||||||
|
originalDrawPixels(forceTick);
|
||||||
|
renderLightmap();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var originalDrawPixels = drawPixels;
|
||||||
|
drawPixels = function(forceTick = false) {
|
||||||
|
originalDrawPixels(forceTick);
|
||||||
|
renderLightmap();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
410
mods/lightmap.js
410
mods/lightmap.js
|
|
@ -1,27 +1,27 @@
|
||||||
// Redbirdly's Mod that adds a better light system
|
// Redbirdly's Mod that adds a better light system
|
||||||
// if the mod is too laggy, use fast_lightmap.js
|
// if the mod is too laggy, use fast_lightmap.js
|
||||||
|
|
||||||
let lightmap = [];
|
var lightmap = [];
|
||||||
let nextLightmap = [];
|
var nextLightmap = [];
|
||||||
let lightmapWidth, lightmapHeight;
|
var lightmapWidth, lightmapHeight;
|
||||||
let pixelSizeQuarter = pixelSizeHalf / 2;
|
var lightmapScale = 2;
|
||||||
let lightmapScale = 2;
|
var pixelSizeQuarter = pixelSizeHalf / 2;
|
||||||
|
|
||||||
// Define RGB colors
|
// Define RGB colors
|
||||||
let lightColor = [255, 223, 186];
|
var fireColor = [255, 69, 0];
|
||||||
let sunColor = [255*8, 210*8, 26*8];
|
var coldFireColor = [0, 191, 255];
|
||||||
let lampColor = [255*4, 223*4, 186*4];
|
var fireflyColor = [240, 255, 70];
|
||||||
let laserColor = [255, 0, 0];
|
var radColor = [75, 100, 30];
|
||||||
let ledRColor = [255, 0, 0];
|
var strangeMatterColor = [220 * 0.3, 255 * 0.3, 210 * 0.3];
|
||||||
let ledGColor = [0, 255, 0];
|
var sparkColors = [[255, 210, 120], [255, 140, 10]];
|
||||||
let ledBColor = [0, 0, 255];
|
|
||||||
let fireColor = [255, 69, 0];
|
function getRandomElement(arr) {
|
||||||
let plasmaColor = [160, 69, 255];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
let coldFireColor = [0, 191, 255];
|
}
|
||||||
let magmaColor = [255, 140, 0];
|
|
||||||
let fireFlyColors = [[180, 255, 70], scaleList([180, 255, 70], 0.75), scaleList([180, 255, 70], 0.5), scaleList([180, 255, 70], 0.25)];
|
function rgbToArray(rgbString) {
|
||||||
let radColor = [75, 100, 30];
|
return rgbString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
||||||
let neonColor = [255*2, 60*2, 10*2];
|
}
|
||||||
|
|
||||||
function scaleList(numbers, scale) {
|
function scaleList(numbers, scale) {
|
||||||
return numbers.map(number => number * scale);
|
return numbers.map(number => number * scale);
|
||||||
|
|
@ -30,11 +30,11 @@ function scaleList(numbers, scale) {
|
||||||
function initializeLightmap(width, height) {
|
function initializeLightmap(width, height) {
|
||||||
lightmapWidth = Math.ceil(width / lightmapScale);
|
lightmapWidth = Math.ceil(width / lightmapScale);
|
||||||
lightmapHeight = Math.ceil(height / lightmapScale);
|
lightmapHeight = Math.ceil(height / lightmapScale);
|
||||||
|
|
||||||
for (let y = 0; y < lightmapHeight; y++) {
|
for (var y = 0; y < lightmapHeight; y++) {
|
||||||
lightmap[y] = [];
|
lightmap[y] = [];
|
||||||
nextLightmap[y] = [];
|
nextLightmap[y] = [];
|
||||||
for (let x = 0; x < lightmapWidth; x++) {
|
for (var x = 0; x < lightmapWidth; x++) {
|
||||||
lightmap[y][x] = { color: [0, 0, 0] };
|
lightmap[y][x] = { color: [0, 0, 0] };
|
||||||
nextLightmap[y][x] = { color: [0, 0, 0] };
|
nextLightmap[y][x] = { color: [0, 0, 0] };
|
||||||
}
|
}
|
||||||
|
|
@ -42,33 +42,35 @@ function initializeLightmap(width, height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function deepCopy(source, target) {
|
function deepCopy(source, target) {
|
||||||
for (let y = 0; y < source.length; y++) {
|
for (var y = 0; y < source.length; y++) {
|
||||||
target[y] = [];
|
target[y] = [];
|
||||||
for (let x = 0; x < source[y].length; x++) {
|
for (var x = 0; x < source[y].length; x++) {
|
||||||
target[y][x] = { ...source[y][x] };
|
target[y][x] = { ...source[y][x] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function propagateLightmap() {
|
function propagateLightmap() {
|
||||||
if (!lightmap || !lightmap[0]) { return; }
|
if (!lightmap || !lightmap[0]) return;
|
||||||
let width = lightmap[0].length;
|
|
||||||
let height = lightmap.length;
|
|
||||||
|
|
||||||
let neighbors = [
|
var width = lightmap[0].length;
|
||||||
|
var height = lightmap.length;
|
||||||
|
|
||||||
|
var neighbors = [
|
||||||
{ dx: 1, dy: 0 },
|
{ dx: 1, dy: 0 },
|
||||||
{ dx: -1, dy: 0 },
|
{ dx: -1, dy: 0 },
|
||||||
{ dx: 0, dy: 1 },
|
{ dx: 0, dy: 1 },
|
||||||
{ dx: 0, dy: -1 },
|
{ dx: 0, dy: -1 },
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let y = 0; y < height; y++) {
|
for (var y = 0; y < height; y++) {
|
||||||
for (let x = 0; x < width; x++) {
|
for (var x = 0; x < width; x++) {
|
||||||
let totalColor = [0, 0, 0];
|
var totalColor = [0, 0, 0];
|
||||||
let neighborCount = 0;
|
var neighborCount = 0;
|
||||||
|
|
||||||
neighbors.forEach(({ dx, dy }) => {
|
neighbors.forEach(({ dx, dy }) => {
|
||||||
let nx = x + dx;
|
var nx = x + dx;
|
||||||
let ny = y + dy;
|
var ny = y + dy;
|
||||||
if (nx >= 0 && ny >= 0 && nx < width && ny < height) {
|
if (nx >= 0 && ny >= 0 && nx < width && ny < height) {
|
||||||
totalColor[0] += lightmap[ny][nx].color[0];
|
totalColor[0] += lightmap[ny][nx].color[0];
|
||||||
totalColor[1] += lightmap[ny][nx].color[1];
|
totalColor[1] += lightmap[ny][nx].color[1];
|
||||||
|
|
@ -76,11 +78,12 @@ function propagateLightmap() {
|
||||||
neighborCount++;
|
neighborCount++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
nextLightmap[y][x] = {
|
nextLightmap[y][x] = {
|
||||||
color: [
|
color: [
|
||||||
Math.min(Math.max(0, totalColor[0] / neighborCount * 0.8), 255*8),
|
Math.min(Math.max(0, totalColor[0] / neighborCount * 0.8), 255 * 8),
|
||||||
Math.min(Math.max(0, totalColor[1] / neighborCount * 0.8), 255*8),
|
Math.min(Math.max(0, totalColor[1] / neighborCount * 0.8), 255 * 8),
|
||||||
Math.min(Math.max(0, totalColor[2] / neighborCount * 0.8), 255*8)
|
Math.min(Math.max(0, totalColor[2] / neighborCount * 0.8), 255 * 8)
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -90,11 +93,11 @@ function propagateLightmap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function rgbToHsv(r, g, b) {
|
function rgbToHsv(r, g, b) {
|
||||||
r /= 255, g /= 255, b /= 255;
|
r /= 255; g /= 255; b /= 255;
|
||||||
let max = Math.max(r, g, b), min = Math.min(r, g, b);
|
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
||||||
let h, s, v = max;
|
var h, s, v = max;
|
||||||
|
|
||||||
let d = max - min;
|
var d = max - min;
|
||||||
s = max === 0 ? 0 : d / max;
|
s = max === 0 ? 0 : d / max;
|
||||||
|
|
||||||
if (max === min) {
|
if (max === min) {
|
||||||
|
|
@ -112,54 +115,57 @@ function rgbToHsv(r, g, b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function hsvToRgb(h, s, v) {
|
function hsvToRgb(h, s, v) {
|
||||||
let r, g, b;
|
var r, g, b;
|
||||||
|
|
||||||
let i = Math.floor(h * 6);
|
var i = Math.floor(h * 6);
|
||||||
let f = h * 6 - i;
|
var f = h * 6 - i;
|
||||||
let p = v * (1 - s);
|
var p = v * (1 - s);
|
||||||
let q = v * (1 - f * s);
|
var q = v * (1 - f * s);
|
||||||
let t = v * (1 - (1 - f) * s);
|
var t = v * (1 - (1 - f) * s);
|
||||||
|
|
||||||
switch (i % 6) {
|
switch (i % 6) {
|
||||||
case 0: r = v, g = t, b = p; break;
|
case 0: r = v; g = t; b = p; break;
|
||||||
case 1: r = q, g = v, b = p; break;
|
case 1: r = q; g = v; b = p; break;
|
||||||
case 2: r = p, g = v, b = t; break;
|
case 2: r = p; g = v; b = t; break;
|
||||||
case 3: r = p, g = q, b = v; break;
|
case 3: r = p; g = q; b = v; break;
|
||||||
case 4: r = t, g = p, b = v; break;
|
case 4: r = t; g = p; b = v; break;
|
||||||
case 5: r = v, g = p, b = q; break;
|
case 5: r = v; g = p; b = q; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderLightmap() {
|
function renderLightmap() {
|
||||||
if (!canvas) { return; }
|
if (!canvas) return;
|
||||||
if (!lightmap || !lightmap[0]) { return; }
|
if (!lightmap || !lightmap[0]) return;
|
||||||
let context = canvas.getContext('2d');
|
|
||||||
let width = lightmap[0].length;
|
var context = canvas.getContext('2d');
|
||||||
let height = lightmap.length;
|
var width = lightmap[0].length;
|
||||||
|
var height = lightmap.length;
|
||||||
|
|
||||||
|
for (var y = 0; y < height; y++) {
|
||||||
|
for (var x = 0; x < width; x++) {
|
||||||
|
var { color } = lightmap[y][x];
|
||||||
|
var [r, g, b] = color;
|
||||||
|
|
||||||
for (let y = 0; y < height; y++) {
|
|
||||||
for (let x = 0; x < width; x++) {
|
|
||||||
let { color } = lightmap[y][x];
|
|
||||||
let [r, g, b] = color;
|
|
||||||
if (r > 0 || g > 0 || b > 0) {
|
if (r > 0 || g > 0 || b > 0) {
|
||||||
let [h, s, v] = rgbToHsv(r, g, b);
|
var [h, s, v] = rgbToHsv(r, g, b);
|
||||||
let newColor = hsvToRgb(h, s, 1);
|
var newColor = hsvToRgb(h, s, 1);
|
||||||
let alpha = v;
|
var alpha = v;
|
||||||
|
|
||||||
context.fillStyle = `rgba(${newColor[0]}, ${newColor[1]}, ${newColor[2]}, ${alpha*0.4})`;
|
context.fillStyle = `rgba(${newColor[0]}, ${newColor[1]}, ${newColor[2]}, ${alpha * 0.4})`;
|
||||||
context.fillRect(
|
context.fillRect(
|
||||||
x * pixelSize * lightmapScale,
|
x * pixelSize * lightmapScale,
|
||||||
y * pixelSize * lightmapScale,
|
y * pixelSize * lightmapScale,
|
||||||
pixelSize * lightmapScale,
|
pixelSize * lightmapScale,
|
||||||
pixelSize * lightmapScale
|
pixelSize * lightmapScale
|
||||||
);
|
);
|
||||||
|
|
||||||
context.fillStyle = `rgba(${newColor[0]}, ${newColor[1]}, ${newColor[2]}, ${alpha * 0.25})`;
|
context.fillStyle = `rgba(${newColor[0]}, ${newColor[1]}, ${newColor[2]}, ${alpha * 0.25})`;
|
||||||
context.fillRect(
|
context.fillRect(
|
||||||
(x * pixelSize - pixelSizeHalf) * lightmapScale,
|
(x * pixelSize - pixelSizeHalf) * lightmapScale,
|
||||||
(y * pixelSize - pixelSizeHalf) * lightmapScale,
|
(y * pixelSize - pixelSizeHalf) * lightmapScale,
|
||||||
pixelSize * lightmapScale * 2,
|
pixelSize * lightmapScale * 2,
|
||||||
pixelSize * lightmapScale * 2
|
pixelSize * lightmapScale * 2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -167,190 +173,148 @@ function renderLightmap() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.sun.tick = function(pixel) {
|
function glowItsOwnColor(pixel) {
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
if (!pixel.color) {return;}
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
lightmap[y][x] = { color: sunColor };
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
|
lightmap[y][x] = { color: rgbToArray(pixel.color) };
|
||||||
|
}
|
||||||
|
|
||||||
|
function glowItsOwnColorIfPowered(pixel) {
|
||||||
|
if (!pixel.charge || pixel.charge <= 0) {return;}
|
||||||
|
if (!pixel.color) return;
|
||||||
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
|
lightmap[y][x] = { color: rgbToArray(pixel.color) };
|
||||||
|
}
|
||||||
|
|
||||||
|
function glowColor(pixel, color) {
|
||||||
|
if (!color) {return;}
|
||||||
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
|
lightmap[y][x] = { color: color };
|
||||||
|
}
|
||||||
|
|
||||||
|
function glowRadiationColor(pixel) {
|
||||||
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
|
lightmap[y][x] = { color: radColor };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Define element tick functions
|
||||||
|
var originalStrangeMatterTick = elements.strange_matter.tick;
|
||||||
|
elements.strange_matter.tick = function(pixel) {
|
||||||
|
originalStrangeMatterTick(pixel);
|
||||||
|
glowColor(pixel, strangeMatterColor);
|
||||||
};
|
};
|
||||||
|
|
||||||
let originalLightTick = elements.light.tick;
|
var originalLightTick = elements.light.tick;
|
||||||
elements.light.tick = function(pixel) {
|
elements.light.tick = function(pixel) {
|
||||||
originalLightTick(pixel);
|
originalLightTick(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
glowItsOwnColor(pixel);
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: lightColor };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let originalLiquidLightTick = elements.liquid_light.tick;
|
var originalLiquidLightTick = elements.liquid_light.tick;
|
||||||
elements.liquid_light.tick = function(pixel) {
|
elements.liquid_light.tick = function(pixel) {
|
||||||
originalLiquidLightTick(pixel);
|
originalLiquidLightTick(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
glowItsOwnColor(pixel);
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: lightColor };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.magma.tick = function(pixel) {
|
var originalLaserTick = elements.laser.tick;
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: fireColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.neon.tick = function(pixel) {
|
|
||||||
if (!pixel.charge || pixel.charge <= 0) {return;}
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: neonColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.light_bulb.behaviorOn = null
|
|
||||||
elements.light_bulb.tick = function(pixel) {
|
|
||||||
if (pixel.charge > 0) {pixel.lightIntensity = 10;}
|
|
||||||
if (pixel.lightIntensity > 0) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: lampColor };
|
|
||||||
}
|
|
||||||
pixel.lightIntensity -= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.led_r.tick = function(pixel) {
|
|
||||||
if (pixel.charge > 0) {pixel.lightIntensity = 4;}
|
|
||||||
if (pixel.lightIntensity > 0) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: ledRColor };
|
|
||||||
}
|
|
||||||
pixel.lightIntensity -= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.led_g.tick = function(pixel) {
|
|
||||||
if (pixel.charge > 0) {pixel.lightIntensity = 4;}
|
|
||||||
if (pixel.lightIntensity > 0) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: ledGColor };
|
|
||||||
}
|
|
||||||
pixel.lightIntensity -= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.led_b.tick = function(pixel) {
|
|
||||||
if (pixel.charge > 0) {pixel.lightIntensity = 4;}
|
|
||||||
if (pixel.lightIntensity > 0) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: ledBColor };
|
|
||||||
}
|
|
||||||
pixel.lightIntensity -= 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
let originalLaserTick = elements.laser.tick;
|
|
||||||
elements.laser.tick = function(pixel) {
|
elements.laser.tick = function(pixel) {
|
||||||
originalLaserTick(pixel);
|
originalLaserTick(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
glowColor(pixel, scaleList(rgbToArray(pixel.color), 0.5));
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: laserColor };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let originalFireTick2 = elements.fire.tick;
|
var originalFireTick2 = elements.fire.tick;
|
||||||
elements.fire.tick = function(pixel) {
|
elements.fire.tick = function(pixel) {
|
||||||
originalFireTick2(pixel);
|
originalFireTick2(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
glowColor(pixel, fireColor);
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: fireColor };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.cold_fire.tick = function(pixel) {
|
var originalFlashTick = elements.flash.tick;
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
elements.flash.tick = function(pixel) {
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
originalFlashTick(pixel);
|
||||||
lightmap[y][x] = { color: coldFireColor };
|
glowItsOwnColor(pixel);
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.plasma.tick = function(pixel) {
|
var originalRainbowTick = elements.rainbow.tick;
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
elements.rainbow.tick = function(pixel) {
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
originalRainbowTick(pixel);
|
||||||
lightmap[y][x] = { color: plasmaColor };
|
glowItsOwnColor(pixel);
|
||||||
};
|
};
|
||||||
|
|
||||||
let originalFireflyTick = elements.firefly.tick;
|
var originalFireflyTick = elements.firefly.tick;
|
||||||
elements.firefly.tick = function(pixel) {
|
elements.firefly.tick = function(pixel) {
|
||||||
originalFireflyTick(pixel);
|
originalFireflyTick(pixel);
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
|
|
||||||
let col = undefined;
|
var x = Math.floor(pixel.x / lightmapScale);
|
||||||
if (pixelTicks % pixel.fff <= 5) { col = fireFlyColors[3]; }
|
var y = Math.floor(pixel.y / lightmapScale);
|
||||||
if (pixelTicks % pixel.fff <= 4) { col = fireFlyColors[2]; }
|
|
||||||
if (pixelTicks % pixel.fff <= 3) { col = fireFlyColors[1]; }
|
var tickMod = pixelTicks % pixel.fff;
|
||||||
if (pixelTicks % pixel.fff <= 2) { col = fireFlyColors[0]; }
|
var num;
|
||||||
if (col) {
|
|
||||||
lightmap[y][x] = { color: col };
|
if (tickMod <= 2) num = 1;
|
||||||
}
|
else if (tickMod <= 3) num = 0.75;
|
||||||
|
else if (tickMod <= 4) num = 0.5;
|
||||||
|
else if (tickMod <= 5) num = 0.25;
|
||||||
|
else return;
|
||||||
|
|
||||||
|
lightmap[y][x] = { color: scaleList(fireflyColor, num) };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
elements.electric.tick = pixel => glowColor(pixel, scaleList(getRandomElement(sparkColors), 0.5));
|
||||||
|
|
||||||
|
elements.neon.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.led_r.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.led_g.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.led_b.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.light_bulb.behaviorOn = null;
|
||||||
|
elements.light_bulb.tick = glowItsOwnColorIfPowered;
|
||||||
|
elements.sun.tick = glowItsOwnColor;
|
||||||
|
elements.magma.tick = glowItsOwnColor;
|
||||||
|
elements.plasma.tick = glowItsOwnColor;
|
||||||
|
elements.fw_ember.tick = glowItsOwnColor;
|
||||||
|
|
||||||
|
elements.cold_fire.tick = pixel => glowColor(pixel, coldFireColor);
|
||||||
|
|
||||||
// Radioactive elements
|
// Radioactive elements
|
||||||
elements.uranium.tick = function(pixel) {
|
var radioactiveElements = [
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
"uranium", "radiation", "rad_glass", "fallout",
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
"molten_uranium", "rad_shard", "rad_cloud", "rad_steam"
|
||||||
lightmap[y][x] = { color: radColor };
|
];
|
||||||
};
|
radioactiveElements.forEach(element => {
|
||||||
|
elements[element].tick = glowRadiationColor;
|
||||||
elements.radiation.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.rad_glass.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.fallout.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.molten_uranium.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.rad_shard.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.rad_cloud.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
elements.rad_steam.tick = function(pixel) {
|
|
||||||
let x = Math.floor(pixel.x / lightmapScale);
|
|
||||||
let y = Math.floor(pixel.y / lightmapScale);
|
|
||||||
lightmap[y][x] = { color: radColor };
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('load', function() {
|
|
||||||
initializeLightmap(width, height);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add code to functions instead of replacing them
|
window.addEventListener('load', () => initializeLightmap(width, height));
|
||||||
let originalTick = tick;
|
|
||||||
|
var originalTick = tick;
|
||||||
tick = function() {
|
tick = function() {
|
||||||
originalTick();
|
originalTick();
|
||||||
if (!paused) {propagateLightmap();}
|
if (!paused) propagateLightmap();
|
||||||
};
|
};
|
||||||
// Even after updating tick(), setInterval still uses the old tick(), reset setInterval
|
|
||||||
resetInterval(tps);
|
resetInterval(tps);
|
||||||
|
|
||||||
let originalDrawPixels = drawPixels;
|
var originalDoFrame = doFrame;
|
||||||
drawPixels = function(forceTick = false) {
|
doFrame = function() {
|
||||||
originalDrawPixels(forceTick);
|
originalDoFrame();
|
||||||
renderLightmap();
|
propagateLightmap();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (enabledMods.includes("mods/velocity.js")) {
|
||||||
|
runAfterAutogen(() => {
|
||||||
|
var originalDrawPixels = drawPixels;
|
||||||
|
drawPixels = function(forceTick = false) {
|
||||||
|
originalDrawPixels(forceTick);
|
||||||
|
renderLightmap();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var originalDrawPixels = drawPixels;
|
||||||
|
drawPixels = function(forceTick = false) {
|
||||||
|
originalDrawPixels(forceTick);
|
||||||
|
renderLightmap();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue