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

Method Save

src/game/editor/mapitems/map_io.cpp:66–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66bool CEditorMap::Save(const char *pFilename, const FErrorHandler &ErrorHandler)
67{
68 char aFilenameTmp[IO_MAX_PATH_LENGTH];
69 IStorage::FormatTmpPath(aFilenameTmp, sizeof(aFilenameTmp), pFilename);
70
71 log_info("editor/save", "Saving map to '%s'...", aFilenameTmp);
72
73 if(!PerformPreSaveSanityChecks(ErrorHandler))
74 {
75 return false;
76 }
77
78 CDataFileWriter Writer;
79 if(!Writer.Open(m_pEditor->Storage(), aFilenameTmp))
80 {
81 char aBuf[IO_MAX_PATH_LENGTH + 64];
82 str_format(aBuf, sizeof(aBuf), "Error: Failed to open file '%s' for writing.", aFilenameTmp);
83 ErrorHandler(aBuf);
84 return false;
85 }
86
87 // save version
88 {
89 CMapItemVersion Item;
90 Item.m_Version = 1;
91 Writer.AddItem(MAPITEMTYPE_VERSION, 0, sizeof(Item), &Item);
92 }
93
94 // save map info
95 {
96 CMapItemInfoSettings Item;
97 Item.m_Version = 1;
98 Item.m_Author = Writer.AddDataString(m_MapInfo.m_aAuthor);
99 Item.m_MapVersion = Writer.AddDataString(m_MapInfo.m_aVersion);
100 Item.m_Credits = Writer.AddDataString(m_MapInfo.m_aCredits);
101 Item.m_License = Writer.AddDataString(m_MapInfo.m_aLicense);
102
103 Item.m_Settings = -1;
104 if(!m_vSettings.empty())
105 {
106 int Size = 0;
107 for(const auto &Setting : m_vSettings)
108 {
109 Size += str_length(Setting.m_aCommand) + 1;
110 }
111
112 char *pSettings = (char *)malloc(maximum(Size, 1));
113 char *pNext = pSettings;
114 for(const auto &Setting : m_vSettings)
115 {
116 int Length = str_length(Setting.m_aCommand) + 1;
117 mem_copy(pNext, Setting.m_aCommand, Length);
118 pNext += Length;
119 }
120 Item.m_Settings = Writer.AddData(Size, pSettings);
121 free(pSettings);
122 }
123

Callers

nothing calls this directly

Calls 15

str_formatFunction · 0.85
str_lengthFunction · 0.85
maximumFunction · 0.85
mem_copyFunction · 0.85
StrToIntsFunction · 0.85
mem_zeroFunction · 0.85
AddItemMethod · 0.80
AddDataStringMethod · 0.80
AddDataMethod · 0.80
AnalyseTileFlagsMethod · 0.80
PrepareForSaveMethod · 0.80
AddDataSwappedMethod · 0.80

Tested by

no test coverage detected