mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 12:15:36 +00:00
Combine initializer_lists
This commit is contained in:
parent
d3bc79e9b2
commit
8d2b5ed8ee
1 changed files with 19 additions and 31 deletions
|
@ -5,7 +5,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <variant>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
|
@ -47,27 +46,19 @@ namespace
|
||||||
{ "actionuse", "#{sUse}" },
|
{ "actionuse", "#{sUse}" },
|
||||||
{ "actionrun", "#{sRun}" },
|
{ "actionrun", "#{sRun}" },
|
||||||
};
|
};
|
||||||
template <class T>
|
using ContextMethod = std::string_view (Interpreter::Context::*)() const;
|
||||||
using ContextMethod = T (Interpreter::Context::*)() const;
|
const std::initializer_list<std::tuple<std::string_view, std::pair<ContextMethod, ContextMethod>>> sContextMethods{
|
||||||
const std::initializer_list<
|
|
||||||
std::tuple<std::string_view, std::variant<ContextMethod<int>, ContextMethod<std::string_view>>>>
|
|
||||||
sContextMethods{
|
|
||||||
{ "pccrimelevel", &Interpreter::Context::getPCBounty },
|
|
||||||
{ "pcclass", &Interpreter::Context::getPCClass },
|
|
||||||
{ "pcrace", &Interpreter::Context::getPCRace },
|
|
||||||
{ "pcname", &Interpreter::Context::getPCName },
|
|
||||||
{ "cell", &Interpreter::Context::getCurrentCellName },
|
|
||||||
};
|
|
||||||
const std::initializer_list<
|
|
||||||
std::tuple<std::string_view, std::pair<ContextMethod<std::string_view>, ContextMethod<std::string_view>>>>
|
|
||||||
sVariableContextMethods{
|
|
||||||
{ "faction", { &Interpreter::Context::getNPCFaction, nullptr } },
|
|
||||||
{ "nextpcrank", { &Interpreter::Context::getPCNextRank, nullptr } },
|
{ "nextpcrank", { &Interpreter::Context::getPCNextRank, nullptr } },
|
||||||
{ "pcnextrank", { &Interpreter::Context::getPCNextRank, nullptr } },
|
{ "pcnextrank", { &Interpreter::Context::getPCNextRank, nullptr } },
|
||||||
|
{ "faction", { &Interpreter::Context::getNPCFaction, nullptr } },
|
||||||
|
{ "pcclass", { &Interpreter::Context::getPCClass, &Interpreter::Context::getPCClass } },
|
||||||
|
{ "pcname", { &Interpreter::Context::getPCName, &Interpreter::Context::getPCName } },
|
||||||
|
{ "pcrace", { &Interpreter::Context::getPCRace, &Interpreter::Context::getPCRace } },
|
||||||
{ "pcrank", { &Interpreter::Context::getPCRank, nullptr } },
|
{ "pcrank", { &Interpreter::Context::getPCRank, nullptr } },
|
||||||
{ "rank", { &Interpreter::Context::getNPCRank, nullptr } },
|
|
||||||
{ "class", { &Interpreter::Context::getNPCClass, &Interpreter::Context::getPCClass } },
|
{ "class", { &Interpreter::Context::getNPCClass, &Interpreter::Context::getPCClass } },
|
||||||
|
{ "cell", { &Interpreter::Context::getCurrentCellName, &Interpreter::Context::getCurrentCellName } },
|
||||||
{ "race", { &Interpreter::Context::getNPCRace, &Interpreter::Context::getPCRace } },
|
{ "race", { &Interpreter::Context::getNPCRace, &Interpreter::Context::getPCRace } },
|
||||||
|
{ "rank", { &Interpreter::Context::getNPCRank, nullptr } },
|
||||||
{ "name", { &Interpreter::Context::getActorName, &Interpreter::Context::getPCName } },
|
{ "name", { &Interpreter::Context::getActorName, &Interpreter::Context::getPCName } },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,15 +78,12 @@ namespace
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto& [name, variant] : sContextMethods)
|
if (check(temp, "pccrimelevel", i, start))
|
||||||
{
|
{
|
||||||
if (check(temp, name, i, start))
|
retval << context.getPCBounty();
|
||||||
{
|
|
||||||
std::visit([&](auto&& method) { retval << (context.*method)(); }, variant);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
for (const auto& [name, methods] : sContextMethods)
|
||||||
for (const auto& [name, methods] : sVariableContextMethods)
|
|
||||||
{
|
{
|
||||||
const auto& method = dialogue ? methods.first : methods.second;
|
const auto& method = dialogue ? methods.first : methods.second;
|
||||||
if (check(temp, name, i, start))
|
if (check(temp, name, i, start))
|
||||||
|
|
Loading…
Reference in a new issue