11/* (c) DDNet developers. See licence.txt in the root of the distribution for more information. */
22/* If you are missing that file, acquire a complete release at teeworlds.com. */
33
4- #include < base/dbg.h>
54#include < base/fs.h>
65#include < base/io.h>
76#include < base/logger.h>
1716
1817#include < utility>
1918
20- /*
21- Usage: map_convert_07 <source map filepath> <dest map filepath>
22- */
19+ static constexpr const char *const TOOL_NAME = " map_convert_07" ;
2320
2421static CDataFileReader g_DataReader;
2522static CDataFileWriter g_DataWriter;
@@ -59,7 +56,7 @@ static bool CheckImageDimensions(void *pLayerItem, int LayerType, const char *pF
5956 IntsToStr (pTMap->m_aName , std::size (pTMap->m_aName ), aTileLayerName, std::size (aTileLayerName));
6057
6158 const char *pName = g_DataReader.GetDataString (pImgItem->m_ImageName );
62- dbg_msg ( " map_convert_07 " , " %s: Tile layer \" %s\" uses image \" %s\" with width %d, height %d, which is not divisible by 16. This is not supported in Teeworlds 0.7. Please scale the image and replace it manually." , pFilename, aTileLayerName, pName == nullptr ? " (error)" : pName, pImgItem->m_Width , pImgItem->m_Height );
59+ log_error ( TOOL_NAME , " %s: Tile layer \" %s\" uses image \" %s\" with width %d, height %d, which is not divisible by 16. This is not supported in Teeworlds 0.7. Please scale the image and replace it manually." , pFilename, aTileLayerName, pName == nullptr ? " (error)" : pName, pImgItem->m_Width , pImgItem->m_Height );
6360 return false ;
6461}
6562
@@ -71,11 +68,11 @@ static void *ReplaceImageItem(int Index, CMapItemImage *pImgItem, CMapItemImage
7168 const char *pName = g_DataReader.GetDataString (pImgItem->m_ImageName );
7269 if (pName == nullptr || pName[0 ] == ' \0 ' )
7370 {
74- dbg_msg ( " map_convert_07 " , " failed to load name of image %d" , Index);
71+ log_error ( TOOL_NAME , " failed to load name of image %d" , Index);
7572 return pImgItem;
7673 }
7774
78- dbg_msg ( " map_convert_07 " , " embedding image '%s'" , pName);
75+ log_info ( TOOL_NAME , " embedding image '%s'" , pName);
7976
8077 char aStr[IO_MAX_PATH_LENGTH ];
8178 str_format (aStr, sizeof (aStr), " data/mapres/%s.png" , pName);
@@ -88,7 +85,7 @@ static void *ReplaceImageItem(int Index, CMapItemImage *pImgItem, CMapItemImage
8885 const size_t MaxImageDimension = 1 << 13 ;
8986 if (ImgInfo.m_Format != CImageInfo::FORMAT_RGBA || ImgInfo.m_Width > MaxImageDimension || ImgInfo.m_Height > MaxImageDimension)
9087 {
91- dbg_msg ( " map_convert_07 " , " ERROR: only RGBA PNG images with maximum width/height %" PRIzu " are supported" , MaxImageDimension);
88+ log_error ( TOOL_NAME , " only RGBA PNG images with maximum width/height %" PRIzu " are supported" , MaxImageDimension);
9289 ImgInfo.Free ();
9390 return pImgItem;
9491 }
@@ -113,15 +110,15 @@ int main(int argc, const char **argv)
113110
114111 if (argc < 2 || argc > 3 )
115112 {
116- dbg_msg ( " map_convert_07 " , " Invalid arguments" );
117- dbg_msg ( " map_convert_07 " , " Usage: map_convert_07 <source map filepath> [<dest map filepath>]" );
113+ log_error ( TOOL_NAME , " Invalid arguments" );
114+ log_error ( TOOL_NAME , " Usage: %s <source map filepath> [<dest map filepath>]" , argc > 0 ? argv[ 0 ] : TOOL_NAME );
118115 return -1 ;
119116 }
120117
121118 std::unique_ptr<IStorage> pStorage = std::unique_ptr<IStorage>(CreateStorage (IStorage::EInitializationType::BASIC , argc, argv));
122119 if (!pStorage)
123120 {
124- log_error (" map_convert_07 " , " Error creating basic storage" );
121+ log_error (TOOL_NAME , " Error creating basic storage" );
125122 return -1 ;
126123 }
127124
@@ -139,26 +136,26 @@ int main(int argc, const char **argv)
139136 str_format (aDestFilename, sizeof (aDestFilename), " data/maps7/%s.map" , aBuf);
140137 if (fs_makedir (" data" ) != 0 )
141138 {
142- dbg_msg ( " map_convert_07 " , " failed to create data directory" );
139+ log_error ( TOOL_NAME , " failed to create data directory" );
143140 return -1 ;
144141 }
145142
146143 if (fs_makedir (" data/maps7" ) != 0 )
147144 {
148- dbg_msg ( " map_convert_07 " , " failed to create data/maps7 directory" );
145+ log_error ( TOOL_NAME , " failed to create data/maps7 directory" );
149146 return -1 ;
150147 }
151148 }
152149
153150 if (!g_DataReader.Open (pStorage.get (), pSourceFilename, IStorage::TYPE_ABSOLUTE ))
154151 {
155- dbg_msg ( " map_convert_07 " , " failed to open source map. filename='%s'" , pSourceFilename);
152+ log_error ( TOOL_NAME , " failed to open source map. filename='%s'" , pSourceFilename);
156153 return -1 ;
157154 }
158155
159156 if (!g_DataWriter.Open (pStorage.get (), aDestFilename, IStorage::TYPE_ABSOLUTE ))
160157 {
161- dbg_msg ( " map_convert_07 " , " failed to open destination map. filename='%s'" , aDestFilename);
158+ log_error ( TOOL_NAME , " failed to open destination map. filename='%s'" , aDestFilename);
162159 return -1 ;
163160 }
164161
@@ -173,7 +170,7 @@ int main(int argc, const char **argv)
173170 {
174171 if (i >= MAX_MAPIMAGES )
175172 {
176- dbg_msg ( " map_convert_07 " , " map uses more images than the client maximum of %" PRIzu " . filename='%s'" , MAX_MAPIMAGES , pSourceFilename);
173+ log_warn ( TOOL_NAME , " map uses more images than the client maximum of %" PRIzu " . filename='%s'" , MAX_MAPIMAGES , pSourceFilename);
177174 break ;
178175 }
179176 g_aImageIds[i] = Index;
0 commit comments