MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / determineCommand

Method determineCommand

src/logic/Console.cpp:187–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187std::list<Logic::Console::Command>::iterator Console::determineCommand(const std::vector<std::string>& tokens)
188{
189 bool worldAvailable = m_BaseEngine.getMainWorld().isValid();
190 std::vector<std::size_t> numMatchingTokens(m_Commands.size(), 0);
191 size_t commandIndex = 0;
192 for (auto it = m_Commands.begin(); it != m_Commands.end(); ++it, ++commandIndex)
193 {
194 const auto& command = *it;
195 if (!worldAvailable && command.requiresWorld)
196 continue;
197 if (command.numFixTokens > tokens.size())
198 continue;
199 bool allStagesMatched = true;
200 for (std::size_t tokenID = 0; tokenID < command.numFixTokens; tokenID++)
201 {
202 auto suggestion = findSuggestion(command.generators.at(tokenID)(), tokens.at(tokenID));
203 if (suggestion == nullptr)
204 allStagesMatched = false;
205 }
206 if (allStagesMatched)
207 {
208 numMatchingTokens[commandIndex] = command.numFixTokens;
209 }
210 }
211 auto itMaxelement = std::max_element(numMatchingTokens.begin(), numMatchingTokens.end());
212 if (itMaxelement != numMatchingTokens.end() && *itMaxelement != 0)
213 {
214 // case: at least one command matched with command.numFixTokens
215 auto commandIndex = itMaxelement - numMatchingTokens.begin();
216 return std::next(m_Commands.begin(), commandIndex);
217 }
218 return m_Commands.end();
219}
220
221void Console::generateSuggestions(const std::string& input, bool limitToFixed)
222{

Callers

nothing calls this directly

Calls 6

atMethod · 0.80
isValidMethod · 0.45
getMainWorldMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected