More work on setting owner of a script.
continuous-integration/drone/push Build is failing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-10-29 21:40:10 +02:00
parent 949fc67831
commit be7a5fe6bd
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
8 changed files with 21 additions and 15 deletions

View File

@ -9,9 +9,9 @@ export void CreatureLib_ScriptResolver_Destruct(const ScriptResolver* p) { delet
export uint8_t CreatureLib_ScriptResolver_Initialize(ScriptResolver* p, BattleLibrary* library) { export uint8_t CreatureLib_ScriptResolver_Initialize(ScriptResolver* p, BattleLibrary* library) {
Try(p->Initialize(library);) Try(p->Initialize(library);)
}; };
export uint8_t CreatureLib_ScriptResolver_LoadScript(BattleScript*& out, ScriptResolver* p, ScriptCategory category, export uint8_t CreatureLib_ScriptResolver_LoadScript(BattleScript*& out, ScriptResolver* p, void* owner,
const char* scriptName) { ScriptCategory category, const char* scriptName) {
Try(out = p->LoadScript(category, ArbUt::StringView(scriptName));) Try(out = p->LoadScript(owner, category, ArbUt::StringView(scriptName));)
}; };
export uint8_t CreatureLib_ScriptResolver_LoadItemScript(ItemUseScript*& out, ScriptResolver* p, export uint8_t CreatureLib_ScriptResolver_LoadItemScript(ItemUseScript*& out, ScriptResolver* p,

View File

@ -43,6 +43,7 @@ const std::unique_ptr<const DamageLibrary>& BattleLibrary::GetDamageLibrary() co
const std::unique_ptr<const MiscLibrary>& BattleLibrary::GetMiscLibrary() const noexcept { return _miscLibrary; } const std::unique_ptr<const MiscLibrary>& BattleLibrary::GetMiscLibrary() const noexcept { return _miscLibrary; }
BattleScript* BattleLibrary::LoadScript(ScriptCategory category, const ArbUt::StringView& scriptName) const { BattleScript* BattleLibrary::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
return _scriptResolver->LoadScript(category, scriptName); const ArbUt::StringView& scriptName) const {
return _scriptResolver->LoadScript(owner, category, scriptName);
} }

View File

@ -44,7 +44,8 @@ namespace CreatureLib::Battling {
return _scriptResolver; return _scriptResolver;
} }
[[nodiscard]] BattleScript* LoadScript(ScriptCategory category, const ArbUt::StringView& scriptName) const; [[nodiscard]] BattleScript* LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
const ArbUt::StringView& scriptName) const;
}; };
} }

View File

@ -167,7 +167,7 @@ BattleScript* Battle::AddVolatileScript(const ArbUt::StringView& key) {
script.GetValue()->Stack(); script.GetValue()->Stack();
return script.GetValue(); return script.GetValue();
} }
script = _library->LoadScript(ScriptCategory::Battle, key); script = _library->LoadScript(this, ScriptCategory::Battle, key);
if (!script.HasValue()) { if (!script.HasValue()) {
THROW("Invalid volatile script requested for battle: '" << key.c_str() << "'."); THROW("Invalid volatile script requested for battle: '" << key.c_str() << "'.");
} }

View File

@ -142,7 +142,7 @@ BattleScript* BattleSide::AddVolatileScript(const ArbUt::StringView& key) {
script.GetValue()->Stack(); script.GetValue()->Stack();
return script.GetValue(); return script.GetValue();
} }
script = _battle->GetLibrary()->LoadScript(ScriptCategory::Side, key); script = _battle->GetLibrary()->LoadScript(this, ScriptCategory::Side, key);
if (!script.HasValue()) { if (!script.HasValue()) {
THROW("Invalid volatile script requested for battleside: '" << key.c_str() << "'."); THROW("Invalid volatile script requested for battleside: '" << key.c_str() << "'.");
} }

View File

@ -19,7 +19,8 @@ namespace CreatureLib::Battling {
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem),
_nickname(std::move(nickname)), _talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks), _nickname(std::move(nickname)), _talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks),
_allowedExperienceGain(allowedExperienceGain) { _allowedExperienceGain(allowedExperienceGain) {
_activeTalent = std::unique_ptr<BattleScript>(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent())); _activeTalent =
std::unique_ptr<BattleScript>(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()));
for (auto t : _variant->GetTypes()) { for (auto t : _variant->GetTypes()) {
_types.push_back(t); _types.push_back(t);
} }
@ -60,7 +61,8 @@ namespace CreatureLib::Battling {
} }
// Grab the new active talent. // Grab the new active talent.
_activeTalent = std::unique_ptr<BattleScript>(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent())); _activeTalent =
std::unique_ptr<BattleScript>(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()));
// We modify the health of the creature by the change in its max health. // We modify the health of the creature by the change in its max health.
auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health); auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health);
@ -214,7 +216,7 @@ namespace CreatureLib::Battling {
_hasOverridenTalent = true; _hasOverridenTalent = true;
if (_activeTalent != nullptr) { if (_activeTalent != nullptr) {
_activeTalent->OnRemove(); _activeTalent->OnRemove();
_activeTalent.reset(this->_library->LoadScript(ScriptCategory::Talent, talent)); _activeTalent.reset(this->_library->LoadScript(this, ScriptCategory::Talent, talent));
} }
_overridenTalentName = talent; _overridenTalentName = talent;
} }
@ -295,7 +297,7 @@ namespace CreatureLib::Battling {
script.GetValue()->Stack(); script.GetValue()->Stack();
return script.GetValue(); return script.GetValue();
} }
script = this->_library->LoadScript(ScriptCategory::Creature, name); script = this->_library->LoadScript(this, ScriptCategory::Creature, name);
if (!script.HasValue()) { if (!script.HasValue()) {
THROW("Invalid volatile script requested for creature: '" << name.c_str() << "'."); THROW("Invalid volatile script requested for creature: '" << name.c_str() << "'.");
} }
@ -384,7 +386,8 @@ void CreatureLib::Battling::Creature::SetStatus(const ArbUt::StringView& name) {
if (_status != nullptr) { if (_status != nullptr) {
_status->OnRemove(); _status->OnRemove();
} }
_status = std::unique_ptr<CreatureLib::Battling::BattleScript>(_library->LoadScript(ScriptCategory::Status, name)); _status =
std::unique_ptr<CreatureLib::Battling::BattleScript>(_library->LoadScript(this, ScriptCategory::Status, name));
if (_battleData.Battle.HasValue()) { if (_battleData.Battle.HasValue()) {
_battleData.Battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, name); _battleData.Battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, name);
} }

View File

@ -17,7 +17,8 @@ namespace CreatureLib::Battling {
virtual ~ScriptResolver() = default; virtual ~ScriptResolver() = default;
virtual void Initialize([[maybe_unused]] BattleLibrary* library){}; virtual void Initialize([[maybe_unused]] BattleLibrary* library){};
virtual BattleScript* LoadScript([[maybe_unused]] ScriptCategory category, virtual BattleScript* LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr<void>& owner,
[[maybe_unused]] ScriptCategory category,
[[maybe_unused]] const ArbUt::StringView& scriptName) { [[maybe_unused]] const ArbUt::StringView& scriptName) {
return nullptr; return nullptr;
}; };

View File

@ -25,7 +25,7 @@ namespace CreatureLib::Battling {
auto library = battle.GetValue()->GetLibrary(); auto library = battle.GetValue()->GetLibrary();
auto& effect = attack->GetSecondaryEffect(); auto& effect = attack->GetSecondaryEffect();
_attackScript = std::unique_ptr<BattleScript>( _attackScript = std::unique_ptr<BattleScript>(
library->LoadScript(ScriptCategory::Attack, effect->GetEffectName())); library->LoadScript(this, ScriptCategory::Attack, effect->GetEffectName()));
if (_attackScript != nullptr) { if (_attackScript != nullptr) {
_attackScript->OnInitialize(effect->GetParameters()); _attackScript->OnInitialize(effect->GetParameters());
} }