Skip to content

Commit a7da481

Browse files
committed
Simplify to-minimap
1 parent d3c0d25 commit a7da481

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

src/to-minimap.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ const EMPTY_PATH_BUFFER = Buffer.alloc(0x10000, colors.unexploredPathByte);
1919

2020
const GLOBALS = {};
2121

22-
const RESULTS = new Map();
23-
const addResult = (id, type, result) => {
24-
if (!RESULTS.has(id)) {
25-
RESULTS.set(id, {});
26-
}
27-
const reference = RESULTS.get(id);
28-
reference[type] = result;
29-
};
30-
3122
const writeBuffer = (fileName, buffer) => {
3223
if (buffer == null) {
3324
console.log('Undefined buffer; skipping creating `' + fileName + '`');
@@ -57,7 +48,17 @@ const forEachTile = (context, map, callback, name, floorID) => {
5748
const buffer = callback(pixels, isGroundFloor);
5849
const id = `${x}_${y}_${z}`;
5950
if (buffer) {
60-
addResult(id, name, buffer);
51+
if (name === 'mapBuffer') {
52+
writeBuffer(
53+
`${GLOBALS.outputPath}/Minimap_Color_${id}.png`,
54+
wrapColorData(buffer, { overlayGrid: GLOBALS.overlayGrid })
55+
);
56+
} else if (name === 'pathBuffer') {
57+
writeBuffer(
58+
`${GLOBALS.outputPath}/Minimap_WaypointCost_${id}.png`,
59+
wrapWaypointData(buffer)
60+
);
61+
}
6162
}
6263
xOffset += 256;
6364
}
@@ -103,6 +104,8 @@ const convertToMinimap = async (dataDirectory, outputPath, includeMarkers, overl
103104
outputPath = 'minimap-new';
104105
}
105106
GLOBALS.dataDirectory = dataDirectory;
107+
GLOBALS.outputPath = outputPath;
108+
GLOBALS.overlayGrid = overlayGrid;
106109
const bounds = JSON.parse(fs.readFileSync(`${dataDirectory}/bounds.json`));
107110
GLOBALS.bounds = bounds;
108111
GLOBALS.canvas = Canvas.createCanvas(bounds.width, bounds.height);
@@ -117,23 +120,10 @@ const convertToMinimap = async (dataDirectory, outputPath, includeMarkers, overl
117120
promises.push(handleParallel(floorIDs, createBinaryMarkers));
118121
}
119122
await Promise.all(promises);
120-
for (const [id, data] of RESULTS) {
121-
if (!data.mapBuffer) {
122-
data.mapBuffer = EMPTY_MAP_BUFFER;
123-
}
124-
if (!data.pathBuffer) {
125-
data.pathBuffer = EMPTY_PATH_BUFFER;
126-
}
127-
// Generate the Tibia 11-compatible minimap PNGs.
128-
writeBuffer(
129-
`${outputPath}/Minimap_Color_${id}.png`,
130-
wrapColorData(data.mapBuffer, { overlayGrid })
131-
);
132-
writeBuffer(
133-
`${outputPath}/Minimap_WaypointCost_${id}.png`,
134-
wrapWaypointData(data.pathBuffer)
135-
);
136-
}
123+
// TODO: We *could* keep track of all the files that have been written, and
124+
// if any `Color` files don’t have a corresponding `WaypointCost` file or
125+
// vice versa, we could then create it using `EMPTY_PATH_BUFFER` or
126+
// `EMPTY_MAP_BUFFER`. Not sure if this is worth the hassle, though.
137127
if (includeMarkers && MINIMAP_MARKERS.length) {
138128
// The Tibia 11 installer doesn’t create the file if no markers are set.
139129
writeBuffer(`${outputPath}/minimapmarkers.bin`, MINIMAP_MARKERS);
-1.33 KB
Binary file not shown.
-1.33 KB
Binary file not shown.
-1.33 KB
Binary file not shown.
-1.33 KB
Binary file not shown.

0 commit comments

Comments
 (0)