Use namespaces to differentiate between different categories of scripts.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-02-16 14:38:05 +01:00
parent bb06026587
commit 321afbebe4
10 changed files with 41 additions and 78 deletions

View File

@@ -96,8 +96,23 @@ void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param)
type = "INFO";
printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
}
static constexpr const char* GetCategoryNamespace(AngelScripResolver::ScriptCategory category){
switch (category){
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack: return "Moves";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Talent: return "Abilities";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Status: return "Status";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Creature: return "Pokemon";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Battle: return "Battle";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Side: return "Side";
default: throw CreatureException("Unknown script category");
}
}
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const std::string& scriptName) {
auto typeInfo = GetTypeInfo(scriptName);
std::stringstream decl;
decl << GetCategoryNamespace(category) << "::" << scriptName;
auto typeInfo = GetTypeInfo(decl.str());
if (typeInfo == nullptr)
return nullptr;
auto ctx = _contextPool->RequestContext();
@@ -110,10 +125,6 @@ void AngelScripResolver::FinalizeModule() {
if (r < 0)
throw CreatureException("Building Script Module failed.");
}
void AngelScripResolver::CreateScript(ScriptCategory category, const char* scriptName) {
auto scriptString = _loadFunc(category, scriptName);
_mainModule->AddScriptSection(scriptName, scriptString);
}
void AngelScripResolver::CreateScript(const char* name, const char* script) {
_mainModule->AddScriptSection(name, script);
}

View File

@@ -15,7 +15,6 @@ private:
asIScriptEngine* _engine = nullptr;
asIScriptModule* _mainModule = nullptr;
ContextPool* _contextPool = nullptr;
const char* (*_loadFunc)(ScriptCategory category, const char*) = nullptr;
std::unordered_map<std::string, AngelScriptTypeInfo*> _types;
static void MessageCallback(const asSMessageInfo* msg, void* param);
@@ -35,12 +34,6 @@ public:
}
void Initialize(CreatureLib::Battling::BattleLibrary* library) override;
void SetCreateFunction(const char* (*loadFunc)(ScriptCategory category, const char* scriptName)) {
_loadFunc = loadFunc;
}
void CreateScript(ScriptCategory category, const char* scriptName);
void CreateScript(const char* name, const char* script);
void FinalizeModule();