mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Move/rename variable declarations in map_extract tool
This commit is contained in:
parent
4bc1aeeb7a
commit
fbfbc78be4
|
@ -9,40 +9,39 @@
|
|||
|
||||
bool Process(IStorage *pStorage, const char *pMapName, const char *pPathSave)
|
||||
{
|
||||
CDataFileReader Map;
|
||||
|
||||
if(!Map.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE))
|
||||
CDataFileReader Reader;
|
||||
if(!Reader.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE))
|
||||
{
|
||||
dbg_msg("map_extract", "error opening map '%s'", pMapName);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check version
|
||||
CMapItemVersion *pVersion = (CMapItemVersion *)Map.FindItem(MAPITEMTYPE_VERSION, 0);
|
||||
CMapItemVersion *pVersion = (CMapItemVersion *)Reader.FindItem(MAPITEMTYPE_VERSION, 0);
|
||||
if(pVersion && pVersion->m_Version != 1)
|
||||
return false;
|
||||
|
||||
dbg_msg("map_extract", "Make sure you have the permission to use these images and sounds in your own maps");
|
||||
|
||||
CMapItemInfo *pInfo = (CMapItemInfo *)Map.FindItem(MAPITEMTYPE_INFO, 0);
|
||||
CMapItemInfo *pInfo = (CMapItemInfo *)Reader.FindItem(MAPITEMTYPE_INFO, 0);
|
||||
|
||||
if(pInfo)
|
||||
{
|
||||
dbg_msg("map_extract", "author: %s", (char *)Map.GetData(pInfo->m_Author));
|
||||
dbg_msg("map_extract", "version: %s", (char *)Map.GetData(pInfo->m_MapVersion));
|
||||
dbg_msg("map_extract", "credits: %s", (char *)Map.GetData(pInfo->m_Credits));
|
||||
dbg_msg("map_extract", "license: %s", (char *)Map.GetData(pInfo->m_License));
|
||||
dbg_msg("map_extract", "author: %s", (char *)Reader.GetData(pInfo->m_Author));
|
||||
dbg_msg("map_extract", "version: %s", (char *)Reader.GetData(pInfo->m_MapVersion));
|
||||
dbg_msg("map_extract", "credits: %s", (char *)Reader.GetData(pInfo->m_Credits));
|
||||
dbg_msg("map_extract", "license: %s", (char *)Reader.GetData(pInfo->m_License));
|
||||
}
|
||||
|
||||
int Start, Num;
|
||||
|
||||
// load images
|
||||
Map.GetType(MAPITEMTYPE_IMAGE, &Start, &Num);
|
||||
Reader.GetType(MAPITEMTYPE_IMAGE, &Start, &Num);
|
||||
|
||||
for(int i = 0; i < Num; i++)
|
||||
{
|
||||
CMapItemImage *pItem = (CMapItemImage *)Map.GetItem(Start + i, 0, 0);
|
||||
char *pName = (char *)Map.GetData(pItem->m_ImageName);
|
||||
CMapItemImage *pItem = (CMapItemImage *)Reader.GetItem(Start + i, nullptr, nullptr);
|
||||
char *pName = (char *)Reader.GetData(pItem->m_ImageName);
|
||||
|
||||
if(pItem->m_External)
|
||||
continue;
|
||||
|
@ -66,18 +65,18 @@ bool Process(IStorage *pStorage, const char *pMapName, const char *pPathSave)
|
|||
}
|
||||
else
|
||||
{
|
||||
png_set_data(&Png, pItem->m_Width, pItem->m_Height, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)Map.GetData(pItem->m_ImageData));
|
||||
png_set_data(&Png, pItem->m_Width, pItem->m_Height, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)Reader.GetData(pItem->m_ImageData));
|
||||
}
|
||||
io_close(File);
|
||||
}
|
||||
|
||||
// load sounds
|
||||
Map.GetType(MAPITEMTYPE_SOUND, &Start, &Num);
|
||||
Reader.GetType(MAPITEMTYPE_SOUND, &Start, &Num);
|
||||
|
||||
for(int i = 0; i < Num; i++)
|
||||
{
|
||||
CMapItemSound *pItem = (CMapItemSound *)Map.GetItem(Start + i, 0, 0);
|
||||
char *pName = (char *)Map.GetData(pItem->m_SoundName);
|
||||
CMapItemSound *pItem = (CMapItemSound *)Reader.GetItem(Start + i, nullptr, nullptr);
|
||||
char *pName = (char *)Reader.GetData(pItem->m_SoundName);
|
||||
|
||||
if(pItem->m_External)
|
||||
continue;
|
||||
|
@ -87,11 +86,11 @@ bool Process(IStorage *pStorage, const char *pMapName, const char *pPathSave)
|
|||
dbg_msg("map_extract", "writing sound: %s (%d B)", aBuf, pItem->m_SoundDataSize);
|
||||
|
||||
IOHANDLE Opus = io_open(aBuf, IOFLAG_WRITE);
|
||||
io_write(Opus, (unsigned char *)Map.GetData(pItem->m_SoundData), pItem->m_SoundDataSize);
|
||||
io_write(Opus, (unsigned char *)Reader.GetData(pItem->m_SoundData), pItem->m_SoundDataSize);
|
||||
io_close(Opus);
|
||||
}
|
||||
|
||||
return Map.Close();
|
||||
return Reader.Close();
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
|
@ -99,20 +98,18 @@ int main(int argc, const char *argv[])
|
|||
cmdline_fix(&argc, &argv);
|
||||
log_set_global_logger_default();
|
||||
|
||||
char aMap[512];
|
||||
char aDir[512];
|
||||
|
||||
IStorage *pStorage = CreateLocalStorage();
|
||||
if(!pStorage)
|
||||
return -1;
|
||||
|
||||
const char *pDir;
|
||||
if(argc == 2)
|
||||
{
|
||||
str_copy(aMap, argv[1], sizeof(aMap));
|
||||
str_copy(aDir, ".", sizeof(aMap));
|
||||
pDir = ".";
|
||||
}
|
||||
else if(argc == 3)
|
||||
{
|
||||
str_copy(aMap, argv[1], sizeof(aMap));
|
||||
str_copy(aDir, argv[2], sizeof(aDir));
|
||||
pDir = argv[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -120,15 +117,15 @@ int main(int argc, const char *argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(!fs_is_dir(aDir))
|
||||
if(!fs_is_dir(pDir))
|
||||
{
|
||||
dbg_msg("usage", "directory '%s' does not exist", aDir);
|
||||
dbg_msg("usage", "directory '%s' does not exist", pDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
png_init(0, 0);
|
||||
|
||||
int Result = Process(pStorage, aMap, aDir) ? 0 : 1;
|
||||
int Result = Process(pStorage, argv[1], pDir) ? 0 : 1;
|
||||
cmdline_free(argc, argv);
|
||||
return Result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue