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

Method Load

src/game/editor/auto_map.cpp:50–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50void CAutoMapper::Load(const char *pTileName)
51{
52 char aPath[IO_MAX_PATH_LENGTH];
53 str_format(aPath, sizeof(aPath), "editor/automap/%s.rules", pTileName);
54 if(!Storage()->FileExists(aPath, IStorage::TYPE_ALL))
55 {
56 return; // Avoid error message if no rules exist
57 }
58
59 CLineReader LineReader;
60 if(!LineReader.OpenFile(Storage()->OpenFile(aPath, IOFLAG_READ, IStorage::TYPE_ALL)))
61 {
62 log_error("editor/automap", "Failed to load rules from '%s'", aPath);
63 return;
64 }
65
66 CConfiguration *pCurrentConf = nullptr;
67 CRun *pCurrentRun = nullptr;
68 CIndexRule *pCurrentIndex = nullptr;
69
70 // read each line
71 while(const char *pLine = LineReader.Get())
72 {
73 // skip blank/empty lines as well as comments
74 if(str_length(pLine) > 0 && pLine[0] != '#' && pLine[0] != '\n' && pLine[0] != '\r' && pLine[0] != '\t' && pLine[0] != '\v' && pLine[0] != ' ')
75 {
76 if(pLine[0] == '[')
77 {
78 // new configuration, get the name
79 pLine++;
80 CConfiguration NewConf;
81 NewConf.m_aName[0] = '\0';
82 NewConf.m_StartX = 0;
83 NewConf.m_StartY = 0;
84 NewConf.m_EndX = 0;
85 NewConf.m_EndY = 0;
86 m_vConfigs.push_back(NewConf);
87 int ConfigurationId = m_vConfigs.size() - 1;
88 pCurrentConf = &m_vConfigs[ConfigurationId];
89 str_copy(pCurrentConf->m_aName, pLine, minimum<int>(sizeof(pCurrentConf->m_aName), str_length(pLine)));
90
91 // add start run
92 CRun NewRun;
93 NewRun.m_AutomapCopy = true;
94 pCurrentConf->m_vRuns.push_back(NewRun);
95 int RunId = pCurrentConf->m_vRuns.size() - 1;
96 pCurrentRun = &pCurrentConf->m_vRuns[RunId];
97 }
98 else if(str_startswith(pLine, "NewRun") && pCurrentConf)
99 {
100 // add new run
101 CRun NewRun;
102 NewRun.m_AutomapCopy = true;
103 pCurrentConf->m_vRuns.push_back(NewRun);
104 int RunId = pCurrentConf->m_vRuns.size() - 1;
105 pCurrentRun = &pCurrentConf->m_vRuns[RunId];
106 }
107 else if(str_startswith(pLine, "Index") && pCurrentRun)

Callers

nothing calls this directly

Calls 12

str_formatFunction · 0.85
StorageFunction · 0.85
str_lengthFunction · 0.85
str_startswithFunction · 0.85
str_compFunction · 0.85
str_trim_wordsFunction · 0.85
maximumFunction · 0.85
FileExistsMethod · 0.80
str_copyFunction · 0.50
minimumFunction · 0.50
OpenFileMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected