diff --git a/js/core.js b/js/core.js index 66304e8..aa3578c 100644 --- a/js/core.js +++ b/js/core.js @@ -31,6 +31,11 @@ function Canvas(width, height, upscale) { that.clicked = true; }); + this.elem.addEventListener('touchmove', function (e) { + that.pageX = e.touches[0].pageX; + that.pageY = e.touches[0].pageY; + }) + this.elem.addEventListener('mousemove', function (e) { that.pageX = e.pageX; that.pageY = e.pageY; @@ -79,10 +84,10 @@ Canvas.prototype.setBlock = function (x, y, block, doTemp) { Canvas.prototype.resize = function () { this.elem.style.width = this.width * this.upscale + 'px'; this.elem.style.height = this.height * this.upscale + 'px'; - + this.elem.width = this.width; this.elem.height = this.height; - + this.render(); } @@ -92,36 +97,36 @@ Canvas.prototype.render = function () { let imgData = this.ctx.getImageData(0, 0, this.width, this.height); let pixels = imgData.data; - let int = Math.ceil(this.width * this.height/8); + let int = Math.ceil(this.width * this.height / 8); for (let j = 0; j < 8; j++) { let that = this; - (async function() { - for (let i = j*int; i < (j+1)*int; i++) { + (async function () { + for (let i = j * int; i < (j + 1) * int; i++) { if (i > that.width * that.height) break; let x = Math.floor(i / that.height); let y = i % that.height; - - let i2 = x + y*that.width; - + + let i2 = x + y * that.width; + let block = mainTiles.tiles[that.blocks[i]]; - + let temp = that.temp[i]; - + if (block.color[0] != -1) { - - let val = (temp + 310)/310; + + let val = (temp + 310) / 310; if (val < -2.861) val = -2.861; - - pixels[i2*4] = (block.color[0] - temp / 1e28) * val ; - pixels[i2*4+1] = (block.color[1] - temp / 1e28) * (val * 0.259 + 0.741); - pixels[i2*4+2] = (block.color[2] - temp / 1e28) * (val * 0.023 + 0.977); - pixels[i2*4+3] = block.color[3] * 255 + Math.abs(val-1) * 100 || 255; + + pixels[i2 * 4] = (block.color[0] - temp / 1e28) * val; + pixels[i2 * 4 + 1] = (block.color[1] - temp / 1e28) * (val * 0.259 + 0.741); + pixels[i2 * 4 + 2] = (block.color[2] - temp / 1e28) * (val * 0.023 + 0.977); + pixels[i2 * 4 + 3] = block.color[3] * 255 + Math.abs(val - 1) * 100 || 255; } else { let lg = Math.log(temp); - pixels[i2*4] = ((handler.ticks*69 ) % (lg*0.6969)) * 255 / (lg*0.6969); - pixels[i2*4+1] = ((handler.ticks*69) % (lg*0.420420)) * 255 /(lg*0.420420); - pixels[i2*4+2] = ((handler.ticks*69) % (lg*0.13371337)) * 255 / (lg*0.13371337); - pixels[i2*4+3] = 255; + pixels[i2 * 4] = ((handler.ticks * 69) % (lg * 0.6969)) * 255 / (lg * 0.6969); + pixels[i2 * 4 + 1] = ((handler.ticks * 69) % (lg * 0.420420)) * 255 / (lg * 0.420420); + pixels[i2 * 4 + 2] = ((handler.ticks * 69) % (lg * 0.13371337)) * 255 / (lg * 0.13371337); + pixels[i2 * 4 + 3] = 255; } } })() @@ -129,7 +134,7 @@ Canvas.prototype.render = function () { /* TODO: clean up */ - this.ctx.putImageData(imgData,0,0,0,0,this.width,this.height) + this.ctx.putImageData(imgData, 0, 0, 0, 0, this.width, this.height) if (window.loc2 && loc2.get('only') == 'true') { this.stopNow = true; @@ -137,37 +142,37 @@ Canvas.prototype.render = function () { document.querySelector('body').id = 'no-overflow'; return; } - - if(this.forceShowTilePlacement == true) { + + if (this.forceShowTilePlacement == true) { var x = (this.width / 2 - this.radius) * this.upscale; var y = (this.height / 2 - this.radius) * this.upscale; } else { var x = (this.pageX - this.elem.getBoundingClientRect().x - scrollX + this.x) - 0.5 - this.radius * this.upscale; var y = (this.pageY - this.elem.getBoundingClientRect().y - scrollY + this.y) - 0.5 - this.radius * this.upscale; } - + this.ctx.globalAlpha = 1; this.ctx.strokeStyle = 'rgb(255,255,255)'; this.ctx.lineWidth = 2; - if(this.isMouseOver || this.forceShowTilePlacement) - this.ctx.strokeRect(x / this.upscale, y / this.upscale, this.radius * 2 + 2, this.radius * 2 + 2); + if (this.isMouseOver || this.forceShowTilePlacement) + this.ctx.strokeRect(x / this.upscale, y / this.upscale, this.radius * 2 + 2, this.radius * 2 + 2); - let theX = Math.floor(x/this.upscale + this.radius + 1); - let theY = Math.floor(y/this.upscale + this.radius + 1); + let theX = Math.floor(x / this.upscale + this.radius + 1); + let theY = Math.floor(y / this.upscale + this.radius + 1); let blok = mainTiles.tiles[this.getBlock(theX, theY)]; - let temp = this.getBlock(theX,theY, true); + let temp = this.getBlock(theX, theY, true); if (blok && this.isMouseOver) { document.querySelector('.info').textContent = ` - Looking at ${blok.id} from ${blok.namespace}. Temperature at tile: ${Math.round(temp+23)}deg Celsius` + Looking at ${blok.id} from ${blok.namespace}. Temperature at tile: ${Math.round(temp + 23)}deg Celsius` } else { document.querySelector('.info').textContent = `` } - + } /* TODO: cleanup again */ @@ -220,7 +225,7 @@ var handler = new TickHandler(canvas); setInterval(() => { if (canvas.stopNow) return; - handler.tick(); + handler.tick(); }, 1000 / 60);