mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Fixing spaces and globals
This commit is contained in:
parent
2c748ebf70
commit
7cd95f63cf
|
@ -10,13 +10,13 @@
|
||||||
#include <game/mapitems.h>
|
#include <game/mapitems.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Usage: map_replace_image <source map filepath> <dest map filepath> <current image name> <new image filepath>
|
Usage: map_replace_image <source map filepath> <dest map filepath> <current image name> <new image filepath>
|
||||||
Notes: map filepath must be relative to user default teeworlds folder
|
Notes: map filepath must be relative to user default teeworlds folder
|
||||||
new image filepath must be absolute or relative to the current position
|
new image filepath must be absolute or relative to the current position
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CDataFileReader DataReader;
|
CDataFileReader g_DataReader;
|
||||||
CDataFileWriter DataWriter;
|
CDataFileWriter g_DataWriter;
|
||||||
|
|
||||||
// global new image data (set by ReplaceImageItem)
|
// global new image data (set by ReplaceImageItem)
|
||||||
int g_NewNameID = -1;
|
int g_NewNameID = -1;
|
||||||
|
@ -27,37 +27,37 @@ void *g_pNewData = 0;
|
||||||
|
|
||||||
int LoadPNG(CImageInfo *pImg, const char *pFilename)
|
int LoadPNG(CImageInfo *pImg, const char *pFilename)
|
||||||
{
|
{
|
||||||
unsigned char *pBuffer;
|
unsigned char *pBuffer;
|
||||||
png_t Png;
|
png_t Png;
|
||||||
|
|
||||||
int Error = png_open_file(&Png, pFilename);
|
int Error = png_open_file(&Png, pFilename);
|
||||||
if(Error != PNG_NO_ERROR)
|
if(Error != PNG_NO_ERROR)
|
||||||
{
|
{
|
||||||
dbg_msg("map_replace_image", "failed to open image file. filename='%s'", pFilename);
|
dbg_msg("map_replace_image", "failed to open image file. filename='%s'", pFilename);
|
||||||
if(Error != PNG_FILE_ERROR)
|
if(Error != PNG_FILE_ERROR)
|
||||||
png_close_file(&Png);
|
png_close_file(&Png);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Png.depth != 8 || (Png.color_type != PNG_TRUECOLOR && Png.color_type != PNG_TRUECOLOR_ALPHA) || Png.width > (2<<12) || Png.height > (2<<12))
|
if(Png.depth != 8 || (Png.color_type != PNG_TRUECOLOR && Png.color_type != PNG_TRUECOLOR_ALPHA) || Png.width > (2<<12) || Png.height > (2<<12))
|
||||||
{
|
{
|
||||||
dbg_msg("map_replace_image", "invalid image format. filename='%s'", pFilename);
|
dbg_msg("map_replace_image", "invalid image format. filename='%s'", pFilename);
|
||||||
png_close_file(&Png);
|
png_close_file(&Png);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pBuffer = (unsigned char *)mem_alloc(Png.width * Png.height * Png.bpp, 1);
|
pBuffer = (unsigned char *)mem_alloc(Png.width * Png.height * Png.bpp, 1);
|
||||||
png_get_data(&Png, pBuffer);
|
png_get_data(&Png, pBuffer);
|
||||||
png_close_file(&Png);
|
png_close_file(&Png);
|
||||||
|
|
||||||
pImg->m_Width = Png.width;
|
pImg->m_Width = Png.width;
|
||||||
pImg->m_Height = Png.height;
|
pImg->m_Height = Png.height;
|
||||||
if(Png.color_type == PNG_TRUECOLOR)
|
if(Png.color_type == PNG_TRUECOLOR)
|
||||||
pImg->m_Format = CImageInfo::FORMAT_RGB;
|
pImg->m_Format = CImageInfo::FORMAT_RGB;
|
||||||
else if(Png.color_type == PNG_TRUECOLOR_ALPHA)
|
else if(Png.color_type == PNG_TRUECOLOR_ALPHA)
|
||||||
pImg->m_Format = CImageInfo::FORMAT_RGBA;
|
pImg->m_Format = CImageInfo::FORMAT_RGBA;
|
||||||
pImg->m_pData = pBuffer;
|
pImg->m_pData = pBuffer;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtractName(const char *pFileName, char *pName, int BufferSize)
|
void ExtractName(const char *pFileName, char *pName, int BufferSize)
|
||||||
|
@ -82,7 +82,7 @@ void *ReplaceImageItem(void *pItem, int Type, const char *pImgName, const char *
|
||||||
return pItem;
|
return pItem;
|
||||||
|
|
||||||
CMapItemImage *pImgItem = (CMapItemImage *)pItem;
|
CMapItemImage *pImgItem = (CMapItemImage *)pItem;
|
||||||
char *pName = (char *)DataReader.GetData(pImgItem->m_ImageName);
|
char *pName = (char *)g_DataReader.GetData(pImgItem->m_ImageName);
|
||||||
|
|
||||||
if(str_comp(pImgName, pName) != 0)
|
if(str_comp(pImgName, pName) != 0)
|
||||||
return pItem;
|
return pItem;
|
||||||
|
@ -116,16 +116,16 @@ int main(int argc, const char **argv)
|
||||||
|
|
||||||
if(argc != 5)
|
if(argc != 5)
|
||||||
{
|
{
|
||||||
dbg_msg("map_replace_image", "Invalid arguments");
|
dbg_msg("map_replace_image", "Invalid arguments");
|
||||||
dbg_msg("map_replace_image", "Usage: map_replace_image <source map filepath> <dest map filepath> <current image name> <new image filepath>");
|
dbg_msg("map_replace_image", "Usage: map_replace_image <source map filepath> <dest map filepath> <current image name> <new image filepath>");
|
||||||
dbg_msg("map_replace_image", "Notes: map filepath must be relative to user default teeworlds folder");
|
dbg_msg("map_replace_image", "Notes: map filepath must be relative to user default teeworlds folder");
|
||||||
dbg_msg("map_replace_image", " new image filepath must be absolute or relative to the current position");
|
dbg_msg("map_replace_image", " new image filepath must be absolute or relative to the current position");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pStorage)
|
if (!pStorage)
|
||||||
{
|
{
|
||||||
dbg_msg("map_replace_image", "error loading storage");
|
dbg_msg("map_replace_image", "error loading storage");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,35 +135,35 @@ int main(int argc, const char **argv)
|
||||||
const char *pImageFile = argv[4];
|
const char *pImageFile = argv[4];
|
||||||
|
|
||||||
int ID = 0;
|
int ID = 0;
|
||||||
int Type = 0;
|
int Type = 0;
|
||||||
int Size = 0;
|
int Size = 0;
|
||||||
void *pItem = 0;
|
void *pItem = 0;
|
||||||
void *pData = 0;
|
void *pData = 0;
|
||||||
|
|
||||||
if(!DataReader.Open(pStorage, pSourceFileName, IStorage::TYPE_ALL))
|
if(!g_DataReader.Open(pStorage, pSourceFileName, IStorage::TYPE_ALL))
|
||||||
{
|
{
|
||||||
dbg_msg("map_replace_image", "failed to open source map. filename='%s'", pSourceFileName);
|
dbg_msg("map_replace_image", "failed to open source map. filename='%s'", pSourceFileName);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!DataWriter.Open(pStorage, pDestFileName))
|
if(!g_DataWriter.Open(pStorage, pDestFileName))
|
||||||
{
|
{
|
||||||
dbg_msg("map_replace_image", "failed to open destination map. filename='%s'", pDestFileName);
|
dbg_msg("map_replace_image", "failed to open destination map. filename='%s'", pDestFileName);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_init(0,0);
|
png_init(0,0);
|
||||||
|
|
||||||
// add all items
|
// add all items
|
||||||
for(int Index = 0; Index < DataReader.NumItems(); Index++)
|
for(int Index = 0; Index < g_DataReader.NumItems(); Index++)
|
||||||
{
|
{
|
||||||
CMapItemImage NewImageItem;
|
CMapItemImage NewImageItem;
|
||||||
pItem = DataReader.GetItem(Index, &Type, &ID);
|
pItem = g_DataReader.GetItem(Index, &Type, &ID);
|
||||||
Size = DataReader.GetItemSize(Index);
|
Size = g_DataReader.GetItemSize(Index);
|
||||||
pItem = ReplaceImageItem(pItem, Type, pImageName, pImageFile, &NewImageItem);
|
pItem = ReplaceImageItem(pItem, Type, pImageName, pImageFile, &NewImageItem);
|
||||||
if(!pItem)
|
if(!pItem)
|
||||||
return -1;
|
return -1;
|
||||||
DataWriter.AddItem(Type, ID, Size, pItem);
|
g_DataWriter.AddItem(Type, ID, Size, pItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(g_NewDataID == -1)
|
if(g_NewDataID == -1)
|
||||||
|
@ -173,13 +173,13 @@ int main(int argc, const char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add all data
|
// add all data
|
||||||
for(int Index = 0; Index < DataReader.NumItems(); Index++)
|
for(int Index = 0; Index < g_DataReader.NumItems(); Index++)
|
||||||
{
|
{
|
||||||
if(Index == g_NewDataID)
|
if(Index == g_NewDataID)
|
||||||
{
|
{
|
||||||
pData = g_pNewData;
|
pData = g_pNewData;
|
||||||
Size = g_NewDataSize;
|
Size = g_NewDataSize;
|
||||||
}
|
}
|
||||||
else if (Index == g_NewNameID)
|
else if (Index == g_NewNameID)
|
||||||
{
|
{
|
||||||
pData = (void *)g_aNewName;
|
pData = (void *)g_aNewName;
|
||||||
|
@ -187,15 +187,15 @@ int main(int argc, const char **argv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pData = DataReader.GetData(Index);
|
pData = g_DataReader.GetData(Index);
|
||||||
Size = DataReader.GetUncompressedDataSize(Index);
|
Size = g_DataReader.GetUncompressedDataSize(Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataWriter.AddData(Size, pData);
|
g_DataWriter.AddData(Size, pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataReader.Close();
|
g_DataReader.Close();
|
||||||
DataWriter.Finish();
|
g_DataWriter.Finish();
|
||||||
|
|
||||||
dbg_msg("map_replace_image", "image '%s' replaced", pImageName);
|
dbg_msg("map_replace_image", "image '%s' replaced", pImageName);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue