From: The Grand Dog Date: Thu, 4 Jun 2020 00:00:29 +0000 (-0400) Subject: commit the part that makes the map work X-Git-Url: http://git.osdn.net/view?p=automap%2Fautomap.git;a=commitdiff_plain;h=ad682e7cf674fd298acefd562fd3787dbaa1f07d commit the part that makes the map work --- diff --git a/Automap/MapSRC/build.js b/Automap/MapSRC/build.js index c5e0fb2..9c60009 100755 --- a/Automap/MapSRC/build.js +++ b/Automap/MapSRC/build.js @@ -8,15 +8,15 @@ fs.readFile(__dirname + '/src/Automap.html', 'utf8', (err, d) => { if (err) console.log(err); let outD = d.replace(//g, (match, name, offset, string) => { return ''; }) .replace(/'; - }) - .replace(/[\t\n]/g, ''); + }); + // .replace(/[\t\n]/g, ''); fs.writeFile(__dirname + '/../assets/automap/config/automap.html', outD, err => { if (err) console.log(err); }); diff --git a/Automap/MapSRC/src/ViewFrame.js b/Automap/MapSRC/src/ViewFrame.js index 663a50f..2e286b9 100644 --- a/Automap/MapSRC/src/ViewFrame.js +++ b/Automap/MapSRC/src/ViewFrame.js @@ -40,7 +40,7 @@ function ViewFrame() { this.x = -1; this.y = -1; // can be fractional - this.zoom = 32; // pixels wide the images are to be + this.zoom = 32; // pixels wide the shards are to be this.updateEdges(); } // prototypes, some less... notable? methods are @@ -107,7 +107,7 @@ ViewFrame.prototype.render = function () { const img = new Image(32, 32); const name = round.value.join('_'); - img.src = name + '.png'; + img.src = 'Chunks/' + name + '.png'; decode(img, loadedImage => { this.place(img, round.value[0], round.value[1]); diff --git a/Automap/MapSRC/src/ViewFrameUtils.js b/Automap/MapSRC/src/ViewFrameUtils.js index dc35335..7693516 100644 --- a/Automap/MapSRC/src/ViewFrameUtils.js +++ b/Automap/MapSRC/src/ViewFrameUtils.js @@ -1,5 +1,5 @@ ViewFrame.initInfobox = function (ibox, iboxSlots) { - + // TODO: make faster ViewFrame.chunks .chunkMetadataNames.forEach((item, i) => { const slot = document.createElement('tr'); @@ -34,16 +34,31 @@ ViewFrame.prototype.updateEdges = function () { this.southChunk = Math.floor(this.south); }; +/** +* dx and dy are the distances in chunks +*/ ViewFrame.prototype.moveCenter = function (dx, dy) { // to pan when we click on the map! this.x += (dx - this.width / 2) / this.zoom; this.y += (dy - this.height / 2) / this.zoom; }; + +/** +* x and y are positions in chunks +*/ ViewFrame.prototype.setCenter = function (x, y) { this.x = x; this.y = y; }; +/** +* x and y are positions in BLOCKS!!!! +*/ +ViewFrame.prototype.setBlockwiseCenter = function (x, y) { + this.x = x / this.zoom; + this.y = y / this.zoom; +}; + ViewFrame.prototype.clear = function () { this.loadedChunksByName.clear(); this.loadedChunksByCoords.clear(); diff --git a/Automap/MapSRC/src/index.js b/Automap/MapSRC/src/index.js index 5b8dc9e..55abc93 100644 --- a/Automap/MapSRC/src/index.js +++ b/Automap/MapSRC/src/index.js @@ -25,7 +25,6 @@ vf.reloadChunkList(); }); }()); - // #### CONTROLS #### // hovering (function () { @@ -49,10 +48,17 @@ vf.reloadChunkList(); var id; vf.map.canvas.addEventListener('wheel', event => { clearTimeout(id); - vf.zoom += -Math.sign(event.deltaY)*2; id = setTimeout(() => { vf.render(); }, 250); + // this makes it so zooming out is faster + let dir = -Math.sign(event.deltaY); + if (vf.zoom < 16) // arbitrary value + vf.zoom += dir; + else + vf.zoom += dir * 4; + if (vf.zoom <= 0) + vf.zoom += 1; // make sure it doesnt go to negative values }); }()); diff --git a/Automap/assets/automap/config/automap.html b/Automap/assets/automap/config/automap.html index ad5ec0b..03f3d26 100644 --- a/Automap/assets/automap/config/automap.html +++ b/Automap/assets/automap/config/automap.html @@ -4,140 +4,342 @@ Automap - + -
-

Chunk Info

-
-
- + +}; + +ViewFrame.prototype.updateEdges = function () { + if (this.width != window.innerWidth || this.height != window.innerHeight) { + this.width = window.innerWidth; + this.map.canvas.width = this.width; + this.height = window.innerHeight; + this.map.canvas.height = this.height; + this.map.imageSmoothingEnabled = false; + } + const chunksWide = Math.ceil(this.width / this.zoom); + const chunksHigh = Math.ceil(this.height / this.zoom); + + this.east = this.x + chunksWide / 2; // this is fractional and is used to keep track of the edges of the window + this.eastChunk = Math.ceil(this.east); // this is not and is used to track the chunks that need to load + this.west = this.x - chunksWide / 2; + this.westChunk = Math.floor(this.west); + this.north = this.y + chunksHigh / 2; + this.northChunk = Math.ceil(this.north); + this.south = this.y - chunksHigh / 2; + this.southChunk = Math.floor(this.south); +}; + +/** +* dx and dy are the distances in chunks +*/ +ViewFrame.prototype.moveCenter = function (dx, dy) { + // to pan when we click on the map! + this.x += (dx - this.width / 2) / this.zoom; + this.y += (dy - this.height / 2) / this.zoom; +}; + +/** +* x and y are positions in chunks +*/ +ViewFrame.prototype.setCenter = function (x, y) { + this.x = x; + this.y = y; +}; + +/** +* x and y are positions in BLOCKS!!!! +*/ +ViewFrame.prototype.setBlockwiseCenter = function (x, y) { + this.x = x / this.zoom; + this.y = y / this.zoom; +}; + +ViewFrame.prototype.clear = function () { + this.loadedChunksByName.clear(); + this.loadedChunksByCoords.clear(); + if (this.chunkScript) this.chunkScript.remove(); + delete this.chunkScript; + delete ViewFrame.chunks; + this.map.clearRect(0, 0, window.innerWidth, window.innerHeight); +}; + +function decode(img, cb) { + img.decode() + .then(() => { + cb(img); + }) + .catch(() => {}); // so images arent added on error +} +
+

Chunk Info

+ +
+
+ + \ No newline at end of file