MCPcopy Create free account
hub / github.com/ddnet/ddnet / main

Function main

src/tools/map_replace_image.cpp:69–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69int main(int argc, const char **argv)
70{
71 CCmdlineFix CmdlineFix(&argc, &argv);
72 log_set_global_logger_default();
73
74 if(argc != 5)
75 {
76 dbg_msg("map_replace_image", "Invalid arguments");
77 dbg_msg("map_replace_image", "Usage: map_replace_image <source map filepath> <dest map filepath> <current image name> <new image filepath>");
78 dbg_msg("map_replace_image", "Notes: map filepath must be relative to user default teeworlds folder");
79 dbg_msg("map_replace_image", " new image filepath must be absolute or relative to the current position");
80 return -1;
81 }
82
83 std::unique_ptr<IStorage> pStorage = std::unique_ptr<IStorage>(CreateStorage(IStorage::EInitializationType::BASIC, argc, argv));
84 if(!pStorage)
85 {
86 log_error("map_replace_image", "Error creating basic storage");
87 return -1;
88 }
89
90 const char *pSourceFilename = argv[1];
91 const char *pDestFilename = argv[2];
92 const char *pImageName = argv[3];
93 const char *pImageFile = argv[4];
94
95 if(!g_DataReader.Open(pStorage.get(), pSourceFilename, IStorage::TYPE_ALL))
96 {
97 dbg_msg("map_replace_image", "failed to open source map. filename='%s'", pSourceFilename);
98 return -1;
99 }
100
101 CDataFileWriter Writer;
102 if(!Writer.Open(pStorage.get(), pDestFilename))
103 {
104 dbg_msg("map_replace_image", "failed to open destination map. filename='%s'", pDestFilename);
105 return -1;
106 }
107
108 // add all items
109 for(int Index = 0; Index < g_DataReader.NumItems(); Index++)
110 {
111 int Type, Id;
112 CUuid Uuid;
113 void *pItem = g_DataReader.GetItem(Index, &Type, &Id, &Uuid);
114
115 // Filter ITEMTYPE_EX items, they will be automatically added again.
116 if(Type == ITEMTYPE_EX)
117 {
118 continue;
119 }
120
121 int Size = g_DataReader.GetItemSize(Index);
122
123 CMapItemImage NewImageItem;
124 if(Type == MAPITEMTYPE_IMAGE)
125 {
126 pItem = ReplaceImageItem(Index, (CMapItemImage *)pItem, pImageName, pImageFile, &NewImageItem);

Callers

nothing calls this directly

Calls 15

dbg_msgFunction · 0.85
CreateStorageFunction · 0.85
str_lengthFunction · 0.85
getMethod · 0.80
AddItemMethod · 0.80
AddDataMethod · 0.80
ReplaceImageItemFunction · 0.70
OpenMethod · 0.45
NumItemsMethod · 0.45
GetItemMethod · 0.45
GetItemSizeMethod · 0.45

Tested by

no test coverage detected