Game Development Reference
In-Depth Information
else
{
auto color = m_textBox->GetForegroundColor();
AddItem(it->Name() + L" " + it->Value(), color);
AddItem(it->Description(), color * 0.75f);
}
break;
}
}
}
The goal of the console is to take a string of text and translate it into parameters we can
apply on a runtime variable or find a function to execute. When we call Execute we pass
the input text into a helper class called console_parser . This helper class does some pre-
liminary parsing of the input text, it will split the string of text into separate string objects
by space.
console_parser(const wchar_t* text)
: m_source(text)
{
helper::stringutils::SplitW(text, ' ', m_split);
}
Having split the input text into separate strings in a vector, we will implement a function
that allows us to get any individual parameter by index GetString , and a function to get all
theparametersstartingfromsomeindex, GetParametersFromIndex weusethisfunctionto
pass only the parameters to the runtime variable, to allow it to parse them and apply them
if they are valid.
const std::wstring GetParametersFromIndex(size_t argIndex)
{
size_t index = m_source.find_first_of(L' ');
if ( index != std::wstring::npos )
{
return m_source.c_str() + index + 1;
}
return std::wstring();
}
const std::wstring& GetString(size_t argIndex)
{
if ( m_split.size() > argIndex )
{
return m_split[argIndex];
}
throw new std::out_of_range("index argument is out of range");
}
The first step is to query the database's trie and verify if the variable name exists in the
database, this allows us to exit the function early in case it does not exist. Knowing that
Search WWH ::




Custom Search