Skip to content

Commit d3c0d25

Browse files
committed
Change bounds format
1 parent d1e5405 commit d3c0d25

File tree

4 files changed

+19
-35
lines changed

4 files changed

+19
-35
lines changed

src/from-minimap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ const parseMarkerData = (buffer) => {
127127
const drawMapSection = async (mapContext, fileName) => {
128128
const id = path.basename(fileName, '.png').replace(/^Minimap_Color_/, '');
129129
const coordinates = minimapIdToAbsoluteXyz(id);
130-
const xOffset = coordinates.x - GLOBALS.bounds.xMin * 256;
131-
const yOffset = coordinates.y - GLOBALS.bounds.yMin * 256;
130+
const xOffset = coordinates.x - GLOBALS.bounds.xMin;
131+
const yOffset = coordinates.y - GLOBALS.bounds.yMin;
132132
const buffer = await fsp.readFile(fileName);
133133
const image = new Image();
134134
image.src = buffer;
@@ -138,8 +138,8 @@ const drawMapSection = async (mapContext, fileName) => {
138138
const drawPathSection = async (pathContext, fileName) => {
139139
const id = path.basename(fileName, '.png').replace(/^Minimap_WaypointCost_/, '');
140140
const coordinates = minimapIdToAbsoluteXyz(id);
141-
const xOffset = coordinates.x - GLOBALS.bounds.xMin * 256;
142-
const yOffset = coordinates.y - GLOBALS.bounds.yMin * 256;
141+
const xOffset = coordinates.x - GLOBALS.bounds.xMin;
142+
const yOffset = coordinates.y - GLOBALS.bounds.yMin;
143143
const buffer = await fsp.readFile(fileName);
144144
const image = new Image();
145145
image.src = buffer;

src/generate-bounds-from-minimap.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ const minimapIdToAbsoluteXyz = require('./minimap-id-to-absolute-xyz.js');
1010
const generateBoundsFromMinimap = async (mapsDirectory, dataDirectory) => {
1111
const files = await glob(`${mapsDirectory}/*.png`);
1212
const bounds = {
13-
'xMin': +Infinity,
14-
'xMax': -Infinity,
15-
'yMin': +Infinity,
16-
'yMax': -Infinity,
17-
'zMin': +Infinity,
18-
'zMax': -Infinity,
13+
xMin: +Infinity,
14+
xMax: -Infinity,
15+
yMin: +Infinity,
16+
yMax: -Infinity,
17+
zMin: +Infinity,
18+
zMax: -Infinity,
1919
};
2020
const floorIDs = [];
2121
for (const file of files) {
2222
const id = path.basename(file, '.png').replace(/^Minimap_(?:Color|WaypointCost)_/, '');
2323
const coordinates = minimapIdToAbsoluteXyz(id);
24-
const x = Math.floor(coordinates.x / 256);
25-
const y = Math.floor(coordinates.y / 256);
26-
const z = coordinates.z;
24+
const { x, y, z } = coordinates;
2725
if (bounds.xMin > x) {
2826
bounds.xMin = x;
2927
}
@@ -47,8 +45,8 @@ const generateBoundsFromMinimap = async (mapsDirectory, dataDirectory) => {
4745
floorIDs.push(floorID);
4846
}
4947
}
50-
bounds.width = (1 + bounds.xMax - bounds.xMin) * 256;
51-
bounds.height = (1 + bounds.yMax - bounds.yMin) * 256;
48+
bounds.width = 256 + bounds.xMax - bounds.xMin;
49+
bounds.height = 256 + bounds.yMax - bounds.yMin;
5250
bounds.floorIDs = floorIDs.sort();
5351
writeJson(`${dataDirectory}/bounds.json`, bounds);
5452
return bounds;

src/id-to-xyz.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/to-minimap.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const handleParallel = require('./handle-parallel.js');
1111

1212
const arrayToMinimapMarkerBuffer = require('./array-to-minimap-marker.js');
1313
const colors = require('./colors.js');
14-
const idToXyz = require('./id-to-xyz.js');
1514
const pixelDataToMapBuffer = require('./pixel-data-to-map.js');
1615
const pixelDataToPathBuffer = require('./pixel-data-to-path.js');
1716

@@ -42,22 +41,21 @@ const writeBuffer = (fileName, buffer) => {
4241

4342
const forEachTile = (context, map, callback, name, floorID) => {
4443
const isGroundFloor = floorID == '07';
44+
const z = Number(floorID);
4545
const bounds = GLOBALS.bounds;
4646
const image = new Image();
4747
image.src = map;
4848
context.drawImage(image, 0, 0, bounds.width, bounds.height);
4949
// Extract each 256×256px tile.
5050
let yOffset = 0;
5151
while (yOffset < bounds.height) {
52-
const y = bounds.yMin + (yOffset / 256);
53-
const yID = String(y).padStart(3, '0');
52+
const y = bounds.yMin + yOffset;
5453
let xOffset = 0;
5554
while (xOffset < bounds.width) {
56-
const x = bounds.xMin + (xOffset / 256);
57-
const xID = String(x).padStart(3, '0');
55+
const x = bounds.xMin + xOffset;
5856
const pixels = context.getImageData(xOffset, yOffset, 256, 256);
5957
const buffer = callback(pixels, isGroundFloor);
60-
const id = `${xID}${yID}${floorID}`;
58+
const id = `${x}_${y}_${z}`;
6159
if (buffer) {
6260
addResult(id, name, buffer);
6361
}
@@ -127,14 +125,12 @@ const convertToMinimap = async (dataDirectory, outputPath, includeMarkers, overl
127125
data.pathBuffer = EMPTY_PATH_BUFFER;
128126
}
129127
// Generate the Tibia 11-compatible minimap PNGs.
130-
const coords = idToXyz(id);
131-
const minimapId = `${ coords.x * 256 }_${ coords.y * 256 }_${ coords.z }`;
132128
writeBuffer(
133-
`${outputPath}/Minimap_Color_${minimapId}.png`,
129+
`${outputPath}/Minimap_Color_${id}.png`,
134130
wrapColorData(data.mapBuffer, { overlayGrid })
135131
);
136132
writeBuffer(
137-
`${outputPath}/Minimap_WaypointCost_${minimapId}.png`,
133+
`${outputPath}/Minimap_WaypointCost_${id}.png`,
138134
wrapWaypointData(data.pathBuffer)
139135
);
140136
}

0 commit comments

Comments
 (0)