@@ -19,15 +19,6 @@ const EMPTY_PATH_BUFFER = Buffer.alloc(0x10000, colors.unexploredPathByte);
19
19
20
20
const GLOBALS = { } ;
21
21
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
-
31
22
const writeBuffer = ( fileName , buffer ) => {
32
23
if ( buffer == null ) {
33
24
console . log ( 'Undefined buffer; skipping creating `' + fileName + '`' ) ;
@@ -57,7 +48,17 @@ const forEachTile = (context, map, callback, name, floorID) => {
57
48
const buffer = callback ( pixels , isGroundFloor ) ;
58
49
const id = `${ x } _${ y } _${ z } ` ;
59
50
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
+ }
61
62
}
62
63
xOffset += 256 ;
63
64
}
@@ -103,6 +104,8 @@ const convertToMinimap = async (dataDirectory, outputPath, includeMarkers, overl
103
104
outputPath = 'minimap-new' ;
104
105
}
105
106
GLOBALS . dataDirectory = dataDirectory ;
107
+ GLOBALS . outputPath = outputPath ;
108
+ GLOBALS . overlayGrid = overlayGrid ;
106
109
const bounds = JSON . parse ( fs . readFileSync ( `${ dataDirectory } /bounds.json` ) ) ;
107
110
GLOBALS . bounds = bounds ;
108
111
GLOBALS . canvas = Canvas . createCanvas ( bounds . width , bounds . height ) ;
@@ -117,23 +120,10 @@ const convertToMinimap = async (dataDirectory, outputPath, includeMarkers, overl
117
120
promises . push ( handleParallel ( floorIDs , createBinaryMarkers ) ) ;
118
121
}
119
122
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.
137
127
if ( includeMarkers && MINIMAP_MARKERS . length ) {
138
128
// The Tibia 11 installer doesn’t create the file if no markers are set.
139
129
writeBuffer ( `${ outputPath } /minimapmarkers.bin` , MINIMAP_MARKERS ) ;
0 commit comments