Implements functionality for loading scripts.

This commit is contained in:
Deukhoofd 2019-11-18 08:29:17 +01:00
parent 86f8a1e37b
commit 4d796204f8
5 changed files with 55 additions and 12 deletions

View File

@ -3,9 +3,10 @@
CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib, CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib,
CreatureLib::Battling::BattleStatCalculator *statCalculator, CreatureLib::Battling::BattleStatCalculator *statCalculator,
DamageLibrary* damageLibrary, DamageLibrary* damageLibrary,
CriticalLibrary* criticalLibrary) CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver)
: _staticLib(staticLib), _statCalculator(statCalculator), : _staticLib(staticLib), _statCalculator(statCalculator),
_damageLibrary(damageLibrary), _criticalLibrary(criticalLibrary) _damageLibrary(damageLibrary), _criticalLibrary(criticalLibrary),
_scriptResolver(scriptResolver)
{} {}
CreatureLib::Battling::BattleLibrary::~BattleLibrary() { CreatureLib::Battling::BattleLibrary::~BattleLibrary() {
@ -47,3 +48,9 @@ const CreatureLib::Battling::CriticalLibrary *CreatureLib::Battling::BattleLibra
return _criticalLibrary; return _criticalLibrary;
} }
CreatureLib::Battling::Script *
CreatureLib::Battling::BattleLibrary::LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory category,
const std::string &scriptName) {
return _scriptResolver->LoadScript(category, scriptName);
}

View File

@ -5,6 +5,7 @@
#include "../../Library/DataLibrary.hpp" #include "../../Library/DataLibrary.hpp"
#include "DamageLibrary.hpp" #include "DamageLibrary.hpp"
#include "CriticalLibrary.hpp" #include "CriticalLibrary.hpp"
#include "../ScriptHandling/ScriptResolver.hpp"
namespace CreatureLib::Battling { namespace CreatureLib::Battling {
class BattleLibrary { class BattleLibrary {
@ -12,20 +13,23 @@ namespace CreatureLib::Battling {
BattleStatCalculator* _statCalculator; BattleStatCalculator* _statCalculator;
DamageLibrary* _damageLibrary; DamageLibrary* _damageLibrary;
CriticalLibrary* _criticalLibrary; CriticalLibrary* _criticalLibrary;
ScriptResolver* _scriptResolver;
public: public:
BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator, DamageLibrary* damageLibrary, BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator, DamageLibrary* damageLibrary,
CriticalLibrary* criticalLibrary); CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver);
~BattleLibrary(); ~BattleLibrary();
const Library::LibrarySettings& GetSettings() const; [[nodiscard]] const Library::LibrarySettings& GetSettings() const;
const Library::SpeciesLibrary* GetSpeciesLibrary() const; [[nodiscard]] const Library::SpeciesLibrary* GetSpeciesLibrary() const;
const Library::ItemLibrary* GetItemLibrary() const; [[nodiscard]] const Library::ItemLibrary* GetItemLibrary() const;
const Library::AttackLibrary* GetAttackLibrary() const; [[nodiscard]] const Library::AttackLibrary* GetAttackLibrary() const;
const Library::TypeLibrary* GetTypeLibrary() const; [[nodiscard]] const Library::TypeLibrary* GetTypeLibrary() const;
const BattleStatCalculator* GetStatCalculator() const; [[nodiscard]] const BattleStatCalculator* GetStatCalculator() const;
const DamageLibrary* GetDamageLibrary() const; [[nodiscard]] const DamageLibrary* GetDamageLibrary() const;
const CriticalLibrary* GetCriticalLibrary() const; [[nodiscard]] const CriticalLibrary* GetCriticalLibrary() const;
[[nodiscard]] Script* LoadScript(ScriptResolver::ScriptCategory category, const std::string& scriptName);
}; };
} }

View File

@ -0,0 +1,3 @@
#include "ScriptResolver.hpp"

View File

@ -0,0 +1,29 @@
#ifndef CREATURELIB_SCRIPTRESOLVER_HPP
#define CREATURELIB_SCRIPTRESOLVER_HPP
#include <string>
#include "Script.hpp"
namespace CreatureLib::Battling{
class ScriptResolver {
public:
virtual ~ScriptResolver() = default;
enum class ScriptCategory{
Attack,
Talent,
Status,
Creature,
Battle,
Side,
};
virtual Script* LoadScript(ScriptCategory category, const std::string& scriptName){
return nullptr;
};
};
}
#endif //CREATURELIB_SCRIPTRESOLVER_HPP

View File

@ -53,7 +53,7 @@ static BattleLibrary* BuildLibrary(){
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(), auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary()); BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
auto battleLib = new BattleLibrary(l, new BattleStatCalculator(), new DamageLibrary(), auto battleLib = new BattleLibrary(l, new BattleStatCalculator(), new DamageLibrary(),
new CriticalLibrary()); new CriticalLibrary(), new ScriptResolver());
return battleLib; return battleLib;
} }