Update to new Arbutils
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-06-26 17:08:23 +02:00
parent f50f76e993
commit 48639eeee5
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
44 changed files with 177 additions and 200 deletions

View File

@ -56,21 +56,21 @@ export BattleParty* const* CreatureLib_Battle_GetParties(const Battle* p) {
} }
export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) { export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) {
return p->GetVolatileScript(ConstString::GetHash(key)).GetRaw(); return p->GetVolatileScript(ArbUt::StringView::CalculateHash(key)).GetRaw();
} }
export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) { export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) {
Try(p->AddVolatileScript(ConstString(key));) Try(p->AddVolatileScript(ArbUt::StringView(key));)
} }
export uint8_t CreatureLib_Battle_AddVolatileScript(Battle* p, Script* script) { Try(p->AddVolatileScript(script);) } export uint8_t CreatureLib_Battle_AddVolatileScript(Battle* p, Script* script) { Try(p->AddVolatileScript(script);) }
export uint8_t CreatureLib_Battle_RemoveVolatileScript(Battle* p, const char* key) { export uint8_t CreatureLib_Battle_RemoveVolatileScript(Battle* p, const char* key) {
Try(p->RemoveVolatileScript(ConstString::GetHash(key));) Try(p->RemoveVolatileScript(ArbUt::StringView::CalculateHash(key));)
} }
export uint8_t CreatureLib_Battle_RemoveVolatileScriptWithScript(Battle* p, Script* script) { export uint8_t CreatureLib_Battle_RemoveVolatileScriptWithScript(Battle* p, Script* script) {
Try(p->RemoveVolatileScript(script);) Try(p->RemoveVolatileScript(script);)
} }
export bool CreatureLib_Battle_HasVolatileScript(Battle* p, const char* key) { export bool CreatureLib_Battle_HasVolatileScript(Battle* p, const char* key) {
return p->HasVolatileScript(ConstString::GetHash(key)); return p->HasVolatileScript(ArbUt::StringView::CalculateHash(key));
} }
export uint8_t CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(const EventData*)) { export uint8_t CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(const EventData*)) {

View File

@ -36,12 +36,12 @@ SIMPLE_GET_FUNC(Creature, GetGender, CreatureLib::Library::Gender);
SIMPLE_GET_FUNC(Creature, GetColoring, uint8_t); SIMPLE_GET_FUNC(Creature, GetColoring, uint8_t);
export bool CreatureLib_Creature_HasHeldItem(const Creature* p, const char* name) { export bool CreatureLib_Creature_HasHeldItem(const Creature* p, const char* name) {
return p->HasHeldItem(ArbUt::CaseInsensitiveConstString(name)); return p->HasHeldItem(ArbUt::StringView(name));
} }
export bool CreatureLib_Creature_HasHeldItemWithHash(const Creature* p, uint32_t hash) { return p->HasHeldItem(hash); } export bool CreatureLib_Creature_HasHeldItemWithHash(const Creature* p, uint32_t hash) { return p->HasHeldItem(hash); }
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetHeldItem, const CreatureLib::Library::Item*); SIMPLE_GET_FUNC_SMART_PTR(Creature, GetHeldItem, const CreatureLib::Library::Item*);
export uint8_t CreatureLib_Creature_SetHeldItem(Creature* p, const char* name) { export uint8_t CreatureLib_Creature_SetHeldItem(Creature* p, const char* name) {
Try(p->SetHeldItem(ArbUt::CaseInsensitiveConstString(name));) Try(p->SetHeldItem(ArbUt::StringView(name));)
} }
export uint8_t CreatureLib_Creature_SetHeldItemWithHash(Creature* p, uint32_t hash) { Try(p->SetHeldItem(hash);) } export uint8_t CreatureLib_Creature_SetHeldItemWithHash(Creature* p, uint32_t hash) { Try(p->SetHeldItem(hash);) }
export void CreatureLib_Creature_SetHeldItemFromItem(Creature* p, const CreatureLib::Library::Item* item) { export void CreatureLib_Creature_SetHeldItemFromItem(Creature* p, const CreatureLib::Library::Item* item) {
@ -51,7 +51,7 @@ SIMPLE_GET_FUNC(Creature, GetCurrentHealth, uint32_t);
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattle, Battle*); SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattle, Battle*);
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattleSide, BattleSide*); SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattleSide, BattleSide*);
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool); SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().c_str(); } export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().data(); }
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); } export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t); SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t);
export uint8_t CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { Try(p->ChangeLevelBy(level);) } export uint8_t CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { Try(p->ChangeLevelBy(level);) }
@ -62,26 +62,26 @@ export uint8_t CreatureLib_Creature_Heal(Creature* p, uint32_t health, bool canR
Try(p->Heal(health, canRevive);) Try(p->Heal(health, canRevive);)
} }
export uint8_t CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) { export uint8_t CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) {
Try(p->OverrideActiveTalent(ArbUt::CaseInsensitiveConstString(talent));) Try(p->OverrideActiveTalent(ArbUt::StringView(talent));)
} }
export uint8_t CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) { export uint8_t CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) {
Try(p->AddExperience(experience);) Try(p->AddExperience(experience);)
} }
export uint8_t CreatureLib_Creature_ClearVolatileScripts(Creature* p) { Try(p->ClearVolatileScripts();) } export uint8_t CreatureLib_Creature_ClearVolatileScripts(Creature* p) { Try(p->ClearVolatileScripts();) }
export uint8_t CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) { export uint8_t CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) {
Try(p->AddVolatileScript(ArbUt::CaseInsensitiveConstString(scriptName));) Try(p->AddVolatileScript(ArbUt::StringView(scriptName));)
} }
export uint8_t CreatureLib_Creature_AddVolatileScript(Creature* p, Script* script) { export uint8_t CreatureLib_Creature_AddVolatileScript(Creature* p, Script* script) {
Try(p->AddVolatileScript(script);) Try(p->AddVolatileScript(script);)
} }
export uint8_t CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) { export uint8_t CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) {
Try(p->RemoveVolatileScript(ArbUt::CaseInsensitiveConstString(scriptName));) Try(p->RemoveVolatileScript(ArbUt::StringView(scriptName));)
} }
export uint8_t CreatureLib_Creature_RemoveVolatileScript(Creature* p, Script* script) { export uint8_t CreatureLib_Creature_RemoveVolatileScript(Creature* p, Script* script) {
Try(p->RemoveVolatileScript(script);) Try(p->RemoveVolatileScript(script);)
} }
export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) { export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) {
return p->HasVolatileScript(ArbUt::CaseInsensitiveConstString(scriptName)); return p->HasVolatileScript(ArbUt::StringView(scriptName));
} }
export size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetAttacks().Count(); } export size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetAttacks().Count(); }
export LearnedAttack* const* CreatureLib_Creature_GetAttack(Creature* p, size_t index) { export LearnedAttack* const* CreatureLib_Creature_GetAttack(Creature* p, size_t index) {

View File

@ -11,8 +11,7 @@ export const char* CreatureLib_Script_GetName(Script* p) { return p->GetName().c
export uint8_t CreatureLib_Script_OnBeforeTurn(Script* p, const BaseTurnChoice* choice) { export uint8_t CreatureLib_Script_OnBeforeTurn(Script* p, const BaseTurnChoice* choice) {
Try(p->OnBeforeTurn(choice)); Try(p->OnBeforeTurn(choice));
} }
export uint8_t CreatureLib_Script_ChangeAttack(Script* p, AttackTurnChoice* choice, export uint8_t CreatureLib_Script_ChangeAttack(Script* p, AttackTurnChoice* choice, ArbUt::StringView* outAttack) {
ArbUt::CaseInsensitiveConstString* outAttack) {
Try(p->ChangeAttack(choice, outAttack)); Try(p->ChangeAttack(choice, outAttack));
} }
export uint8_t CreatureLib_Script_PreventAttack(Script* p, ExecutingAttack* attack, bool* outResult) { export uint8_t CreatureLib_Script_PreventAttack(Script* p, ExecutingAttack* attack, bool* outResult) {

View File

@ -11,5 +11,5 @@ export uint8_t CreatureLib_ScriptResolver_Initialize(ScriptResolver* p, BattleLi
}; };
export uint8_t CreatureLib_ScriptResolver_LoadScript(Script*& out, ScriptResolver* p, ScriptCategory category, export uint8_t CreatureLib_ScriptResolver_LoadScript(Script*& out, ScriptResolver* p, ScriptCategory category,
const char* scriptName) { const char* scriptName) {
Try(out = p->LoadScript(category, ArbUt::CaseInsensitiveConstString(scriptName));) Try(out = p->LoadScript(category, ArbUt::StringView(scriptName));)
}; };

View File

@ -11,18 +11,17 @@ export uint8_t CreatureLib_AttackData_Construct(AttackData*& out, const char* na
Try({ Try({
std::unordered_set<uint32_t> conversedFlags(flagsCount); std::unordered_set<uint32_t> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) { for (size_t i = 0; i < flagsCount; i++) {
conversedFlags.insert(ArbUt::CaseInsensitiveConstString::GetHash(flags[i])); conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i]));
} }
ArbUt::List<EffectParameter*> effectParameterList(effectParameterCount); ArbUt::List<EffectParameter*> effectParameterList(effectParameterCount);
for (size_t i = 0; i < effectParameterCount; i++) { for (size_t i = 0; i < effectParameterCount; i++) {
effectParameterList[i] = effectParameters[i]; effectParameterList[i] = effectParameters[i];
} }
auto effect = auto effect = new SecondaryEffect(effectChance, ArbUt::StringView(effectName), effectParameterList);
new SecondaryEffect(effectChance, ArbUt::CaseInsensitiveConstString(effectName), effectParameterList);
out = new AttackData(ArbUt::CaseInsensitiveConstString(name), type, category, power, accuracy, baseUsage, out = new AttackData(ArbUt::StringView(name), type, category, power, accuracy, baseUsage, target, priority,
target, priority, effect, conversedFlags); effect, conversedFlags);
}) })
}; };
@ -51,7 +50,7 @@ export const char* CreatureLib_AttackData_GetSecondaryEffectName(const AttackDat
} }
export bool CreatureLib_AttackData_HasFlag(const AttackData* p, const char* key) { export bool CreatureLib_AttackData_HasFlag(const AttackData* p, const char* key) {
return p->HasFlag(ArbUt::CaseInsensitiveConstString::GetHash(key)); return p->HasFlag(ArbUt::StringView::CalculateHash(key));
} }
#undef SIMPLE_GET_FUNC #undef SIMPLE_GET_FUNC

View File

@ -2,7 +2,7 @@
#define BASELIBRARY(simpleName, fullname, returnType) \ #define BASELIBRARY(simpleName, fullname, returnType) \
export uint8_t simpleName##_Insert(fullname* p, const char* name, returnType* t) { \ export uint8_t simpleName##_Insert(fullname* p, const char* name, returnType* t) { \
Try(p->Insert(ArbUt::CaseInsensitiveConstString::GetHash(name), t);) \ Try(p->Insert(ArbUt::StringView::CalculateHash(name), t);) \
} \ } \
\ \
export uint8_t simpleName##_InsertWithHash(fullname* p, uint32_t hashedKey, returnType* t) { \ export uint8_t simpleName##_InsertWithHash(fullname* p, uint32_t hashedKey, returnType* t) { \
@ -10,14 +10,14 @@
} \ } \
\ \
export uint8_t simpleName##_Delete(fullname* p, const char* name) { \ export uint8_t simpleName##_Delete(fullname* p, const char* name) { \
Try(p->Delete(ArbUt::CaseInsensitiveConstString::GetHash(name));) \ Try(p->Delete(ArbUt::StringView::CalculateHash(name));) \
} \ } \
\ \
export uint8_t simpleName##_DeleteWithHash(fullname* p, uint32_t hashedKey) { Try(p->Delete(hashedKey);) } \ export uint8_t simpleName##_DeleteWithHash(fullname* p, uint32_t hashedKey) { Try(p->Delete(hashedKey);) } \
\ \
export bool simpleName##_TryGet(fullname* p, const char* name, const returnType*& out) { \ export bool simpleName##_TryGet(fullname* p, const char* name, const returnType*& out) { \
ArbUt::BorrowedPtr<const returnType> o; \ ArbUt::BorrowedPtr<const returnType> o; \
auto v = p->TryGet(ArbUt::CaseInsensitiveConstString::GetHash(name), o); \ auto v = p->TryGet(ArbUt::StringView::CalculateHash(name), o); \
out = o.operator->(); \ out = o.operator->(); \
return v; \ return v; \
} \ } \
@ -30,7 +30,7 @@
} \ } \
\ \
export uint8_t simpleName##_Get(fullname* p, const char* name, const returnType*& out) { \ export uint8_t simpleName##_Get(fullname* p, const char* name, const returnType*& out) { \
Try(out = p->Get(ArbUt::CaseInsensitiveConstString::GetHash(name)).operator->();) \ Try(out = p->Get(ArbUt::StringView::CalculateHash(name)).operator->();) \
} \ } \
\ \
export uint8_t simpleName##_GetWithHash(fullname* p, uint32_t hashedKey, const returnType*& out) { \ export uint8_t simpleName##_GetWithHash(fullname* p, uint32_t hashedKey, const returnType*& out) { \

View File

@ -6,8 +6,8 @@ export uint8_t CreatureLib_CreatureSpecies_Construct(CreatureSpecies*& out, uint
SpeciesVariant* defaultVariant, float genderRatio, SpeciesVariant* defaultVariant, float genderRatio,
const char* growthRate, uint8_t captureRate) { const char* growthRate, uint8_t captureRate) {
Try(out = new CreatureSpecies(id, ArbUt::CaseInsensitiveConstString(name), defaultVariant, genderRatio, Try(out = new CreatureSpecies(id, ArbUt::StringView(name), defaultVariant, genderRatio,
ArbUt::CaseInsensitiveConstString(growthRate), captureRate);) ArbUt::StringView(growthRate), captureRate);)
} }
export void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; } export void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; }
@ -23,7 +23,7 @@ export const char* CreatureLib_CreatureSpecies_GetGrowthRate(const CreatureSpeci
return p->GetGrowthRate().c_str(); return p->GetGrowthRate().c_str();
} }
export bool CreatureLib_CreatureSpecies_HasVariant(const CreatureSpecies* p, const char* name) { export bool CreatureLib_CreatureSpecies_HasVariant(const CreatureSpecies* p, const char* name) {
return p->HasVariant(ArbUt::CaseInsensitiveConstString::GetHash(name)); return p->HasVariant(ArbUt::StringView::CalculateHash(name));
} }
export bool CreatureLib_CreatureSpecies_HasVariantWithHash(const CreatureSpecies* p, uint32_t hash) { export bool CreatureLib_CreatureSpecies_HasVariantWithHash(const CreatureSpecies* p, uint32_t hash) {
return p->HasVariant(hash); return p->HasVariant(hash);
@ -31,7 +31,7 @@ export bool CreatureLib_CreatureSpecies_HasVariantWithHash(const CreatureSpecies
export bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureSpecies* p, const char* name, export bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureSpecies* p, const char* name,
const SpeciesVariant*& out) { const SpeciesVariant*& out) {
ArbUt::BorrowedPtr<const SpeciesVariant> o; ArbUt::BorrowedPtr<const SpeciesVariant> o;
auto res = p->TryGetVariant(ArbUt::CaseInsensitiveConstString::GetHash(name), o); auto res = p->TryGetVariant(ArbUt::StringView::CalculateHash(name), o);
out = o.GetRaw(); out = o.GetRaw();
return res; return res;
} }
@ -45,14 +45,14 @@ export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpec
export uint8_t CreatureLib_CreatureSpecies_GetVariant(const SpeciesVariant*& out, const CreatureSpecies* p, export uint8_t CreatureLib_CreatureSpecies_GetVariant(const SpeciesVariant*& out, const CreatureSpecies* p,
const char* name) { const char* name) {
Try(out = p->GetVariant(ArbUt::CaseInsensitiveConstString::GetHash(name)).GetRaw();) Try(out = p->GetVariant(ArbUt::StringView::CalculateHash(name)).GetRaw();)
} }
export uint8_t CreatureLib_CreatureSpecies_GetVariantWithHash(const SpeciesVariant* out, const CreatureSpecies* p, export uint8_t CreatureLib_CreatureSpecies_GetVariantWithHash(const SpeciesVariant* out, const CreatureSpecies* p,
uint32_t hash) { uint32_t hash) {
Try(out = p->GetVariant(hash).GetRaw();) Try(out = p->GetVariant(hash).GetRaw();)
} }
export uint8_t CreatureLib_CreatureSpecies_SetVariant(CreatureSpecies* p, const char* name, SpeciesVariant* variant) { export uint8_t CreatureLib_CreatureSpecies_SetVariant(CreatureSpecies* p, const char* name, SpeciesVariant* variant) {
Try(p->SetVariant(ArbUt::CaseInsensitiveConstString(name), variant);) Try(p->SetVariant(ArbUt::StringView(name), variant);)
} }
#undef SIMPLE_GET_FUNC #undef SIMPLE_GET_FUNC

View File

@ -6,7 +6,7 @@ export EffectParameter* CreatureLib_EffectParameter_FromBool(bool b) { return ne
export EffectParameter* CreatureLib_EffectParameter_FromInt(int64_t i) { return new EffectParameter(i); } export EffectParameter* CreatureLib_EffectParameter_FromInt(int64_t i) { return new EffectParameter(i); }
export EffectParameter* CreatureLib_EffectParameter_FromFloat(float f) { return new EffectParameter(f); } export EffectParameter* CreatureLib_EffectParameter_FromFloat(float f) { return new EffectParameter(f); }
export EffectParameter* CreatureLib_EffectParameter_FromString(const char* c) { export EffectParameter* CreatureLib_EffectParameter_FromString(const char* c) {
return new EffectParameter(ArbUt::CaseInsensitiveConstString(c)); return new EffectParameter(ArbUt::StringView(c));
} }
export void CreatureLib_EffectParameter_Destruct(const EffectParameter* p) { delete p; } export void CreatureLib_EffectParameter_Destruct(const EffectParameter* p) { delete p; }

View File

@ -10,7 +10,7 @@ export void CreatureLib_GrowthRateLibrary_Destruct(GrowthRateLibrary* p) { delet
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(uint8_t& out, GrowthRateLibrary* library, export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(uint8_t& out, GrowthRateLibrary* library,
const char* growthRate, uint32_t experience) { const char* growthRate, uint32_t experience) {
Try(out = library->CalculateLevel(ArbUt::CaseInsensitiveConstString::GetHash(growthRate), experience);) Try(out = library->CalculateLevel(ArbUt::StringView::CalculateHash(growthRate), experience);)
} }
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(uint8_t& out, GrowthRateLibrary* library, export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(uint8_t& out, GrowthRateLibrary* library,
uint32_t growthRateHash, uint32_t experience) { uint32_t growthRateHash, uint32_t experience) {
@ -19,7 +19,7 @@ export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(uint8_t& out
export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperience(uint32_t& out, GrowthRateLibrary* library, export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperience(uint32_t& out, GrowthRateLibrary* library,
const char* growthRate, uint8_t level) { const char* growthRate, uint8_t level) {
Try(out = library->CalculateExperience(ArbUt::CaseInsensitiveConstString::GetHash(growthRate), level);) Try(out = library->CalculateExperience(ArbUt::StringView::CalculateHash(growthRate), level);)
} }
export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(uint32_t& out, GrowthRateLibrary* library, export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(uint32_t& out, GrowthRateLibrary* library,
@ -28,7 +28,7 @@ export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(uint32_
} }
export uint8_t CreatureLib_GrowthRateLibrary_AddGrowthRate(GrowthRateLibrary* library, const char* growthRateName, export uint8_t CreatureLib_GrowthRateLibrary_AddGrowthRate(GrowthRateLibrary* library, const char* growthRateName,
GrowthRate* growthRate) { GrowthRate* growthRate) {
Try(library->AddGrowthRate(ArbUt::CaseInsensitiveConstString::GetHash(growthRateName), growthRate);) Try(library->AddGrowthRate(ArbUt::StringView::CalculateHash(growthRateName), growthRate);)
} }
export uint8_t CreatureLib_GrowthRateLibrary_AddGrowthRateWithHash(GrowthRateLibrary* library, uint32_t growthRateHash, export uint8_t CreatureLib_GrowthRateLibrary_AddGrowthRateWithHash(GrowthRateLibrary* library, uint32_t growthRateHash,

View File

@ -1,16 +1,15 @@
#include "../../src/Library/Items/Item.hpp" #include "../../src/Library/Items/Item.hpp"
#include "../Core.hpp" #include "../Core.hpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
using ConstString = ArbUt::CaseInsensitiveConstString;
export Item* CreatureLib_Item_Construct(const char* name, ItemCategory category, BattleItemCategory battleCategory, export Item* CreatureLib_Item_Construct(const char* name, ItemCategory category, BattleItemCategory battleCategory,
int32_t price, const char* flags[], size_t flagsCount) { int32_t price, const char* flags[], size_t flagsCount) {
std::unordered_set<uint32_t> conversedFlags(flagsCount); std::unordered_set<uint32_t> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) { for (size_t i = 0; i < flagsCount; i++) {
conversedFlags.insert(ConstString::GetHash(flags[i])); conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i]));
} }
return new Item(ConstString(name), category, battleCategory, price, conversedFlags); return new Item(ArbUt::StringView(name), category, battleCategory, price, conversedFlags);
}; };
export void CreatureLib_Item_Destruct(const Item* p) { delete p; } export void CreatureLib_Item_Destruct(const Item* p) { delete p; }
@ -23,6 +22,8 @@ SIMPLE_GET_FUNC(Item, GetCategory, ItemCategory);
SIMPLE_GET_FUNC(Item, GetBattleCategory, BattleItemCategory); SIMPLE_GET_FUNC(Item, GetBattleCategory, BattleItemCategory);
SIMPLE_GET_FUNC(Item, GetPrice, int32_t); SIMPLE_GET_FUNC(Item, GetPrice, int32_t);
export bool CreatureLib_Item_HasFlag(const Item* p, const char* key) { return p->HasFlag(ConstString::GetHash(key)); } export bool CreatureLib_Item_HasFlag(const Item* p, const char* key) {
return p->HasFlag(ArbUt::StringView::CalculateHash(key));
}
#undef SIMPLE_GET_FUNC #undef SIMPLE_GET_FUNC

View File

@ -9,20 +9,19 @@ export SpeciesVariant* CreatureLib_SpeciesVariant_Construct(
uint16_t baseMagicalDefense, uint16_t baseSpeed, const char* talents[], size_t talentsLength, uint16_t baseMagicalDefense, uint16_t baseSpeed, const char* talents[], size_t talentsLength,
const char* secretTalents[], size_t secretTalentsLength, const LearnableAttacks* attacks) { const char* secretTalents[], size_t secretTalentsLength, const LearnableAttacks* attacks) {
auto talentsWrapped = ArbUt::List<ArbUt::CaseInsensitiveConstString>(talentsLength); auto talentsWrapped = ArbUt::List<ArbUt::StringView>(talentsLength);
for (size_t i = 0; i < talentsLength; i++) { for (size_t i = 0; i < talentsLength; i++) {
talentsWrapped.Append(ArbUt::CaseInsensitiveConstString(talents[i])); talentsWrapped.Append(ArbUt::StringView(talents[i]));
} }
auto secretTalentsWrapped = ArbUt::List<ArbUt::CaseInsensitiveConstString>(secretTalentsLength); auto secretTalentsWrapped = ArbUt::List<ArbUt::StringView>(secretTalentsLength);
for (size_t i = 0; i < secretTalentsLength; i++) { for (size_t i = 0; i < secretTalentsLength; i++) {
secretTalentsWrapped.Append(ArbUt::CaseInsensitiveConstString(secretTalents[i])); secretTalentsWrapped.Append(ArbUt::StringView(secretTalents[i]));
} }
return new SpeciesVariant(ArbUt::CaseInsensitiveConstString(name), height, weight, baseExperience, return new SpeciesVariant(
ArbUt::List<uint8_t>(types, types + typeLength), ArbUt::StringView(name), height, weight, baseExperience, ArbUt::List<uint8_t>(types, types + typeLength),
CreatureLib::Library::StatisticSet<uint16_t>(baseHealth, baseAttack, baseDefense, CreatureLib::Library::StatisticSet<uint16_t>(baseHealth, baseAttack, baseDefense, baseMagicalAttack,
baseMagicalAttack, baseMagicalDefense, baseMagicalDefense, baseSpeed),
baseSpeed),
talentsWrapped, secretTalentsWrapped, attacks); talentsWrapped, secretTalentsWrapped, attacks);
} }

View File

@ -9,14 +9,14 @@ export TypeLibrary* CreatureLib_TypeLibrary_Construct(size_t initialCapacity) {
export void CreatureLib_TypeLibrary_Destruct(const TypeLibrary* p) { delete p; } export void CreatureLib_TypeLibrary_Destruct(const TypeLibrary* p) { delete p; }
export uint8_t CreatureLib_TypeLibrary_GetTypeId(uint8_t& out, const TypeLibrary* p, const char* type) { export uint8_t CreatureLib_TypeLibrary_GetTypeId(uint8_t& out, const TypeLibrary* p, const char* type) {
Try(out = p->GetTypeId(ArbUt::CaseInsensitiveConstString::GetHash(type));) Try(out = p->GetTypeId(ArbUt::StringView::CalculateHash(type));)
} }
export uint8_t CreatureLib_TypeLibrary_GetTypeIdWithHash(uint8_t& out, const TypeLibrary* p, uint32_t type) { export uint8_t CreatureLib_TypeLibrary_GetTypeIdWithHash(uint8_t& out, const TypeLibrary* p, uint32_t type) {
Try(out = p->GetTypeId(type);) Try(out = p->GetTypeId(type);)
} }
export uint8_t CreatureLib_TypeLibrary_RegisterType(uint8_t& out, TypeLibrary* p, const char* type) { export uint8_t CreatureLib_TypeLibrary_RegisterType(uint8_t& out, TypeLibrary* p, const char* type) {
Try(out = p->RegisterType(ArbUt::CaseInsensitiveConstString::GetHash(type));) Try(out = p->RegisterType(ArbUt::StringView::CalculateHash(type));)
} }
export uint8_t CreatureLib_TypeLibrary_RegisterTypeWithHash(uint8_t& out, TypeLibrary* p, uint32_t type) { export uint8_t CreatureLib_TypeLibrary_RegisterTypeWithHash(uint8_t& out, TypeLibrary* p, uint32_t type) {
Try(out = p->RegisterType(type);) Try(out = p->RegisterType(type);)

View File

@ -5,7 +5,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
project(CreatureLib) project(CreatureLib)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

View File

@ -55,12 +55,12 @@ namespace CreatureLib::Battling {
}; };
class DisplayTextEvent : public EventData { class DisplayTextEvent : public EventData {
const std::string _text; const ArbUt::StringView _text;
public: public:
DisplayTextEvent(const std::string& text) noexcept : _text(text) {} DisplayTextEvent(const ArbUt::StringView& text) noexcept : _text(text) {}
EventDataKind GetKind() const noexcept override { return EventDataKind ::DisplayText; } EventDataKind GetKind() const noexcept override { return EventDataKind ::DisplayText; }
const std::string& GetText() const noexcept { return _text; } const ArbUt::StringView& GetText() const noexcept { return _text; }
}; };
} }

View File

@ -1,4 +1,5 @@
#include "BattleLibrary.hpp" #include "BattleLibrary.hpp"
#include <Arbutils/Assert.hpp>
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
@ -43,6 +44,6 @@ 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; }
Script* BattleLibrary::LoadScript(ScriptCategory category, const ArbUt::CaseInsensitiveConstString& scriptName) const { Script* BattleLibrary::LoadScript(ScriptCategory category, const ArbUt::BasicStringView& scriptName) const {
return _scriptResolver->LoadScript(category, scriptName); return _scriptResolver->LoadScript(category, scriptName);
} }

View File

@ -41,8 +41,7 @@ namespace CreatureLib::Battling {
return _experienceLibrary; return _experienceLibrary;
} }
[[nodiscard]] Script* LoadScript(ScriptCategory category, [[nodiscard]] Script* LoadScript(ScriptCategory category, const ArbUt::BasicStringView& scriptName) const;
const ArbUt::CaseInsensitiveConstString& scriptName) const;
}; };
} }

View File

@ -129,7 +129,7 @@ void Battle::ValidateBattleState() {
this->_battleResult = BattleResult::Conclusive(winningSide); this->_battleResult = BattleResult::Conclusive(winningSide);
this->_hasEnded = true; this->_hasEnded = true;
} }
void Battle::AddVolatileScript(const ConstString& key) { void Battle::AddVolatileScript(const ArbUt::BasicStringView& key) {
auto script = _volatile.Get(key); auto script = _volatile.Get(key);
if (script != nullptr) { if (script != nullptr) {
script->Stack(); script->Stack();
@ -145,4 +145,4 @@ void Battle::AddVolatileScript(const ConstString& key) {
} }
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); } void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); } void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
void Battle::DisplayText(const std::string& text) const { TriggerEventListener(new DisplayTextEvent(text)); } void Battle::DisplayText(const ArbUt::StringView& text) const { TriggerEventListener(new DisplayTextEvent(text)); }

View File

@ -83,17 +83,17 @@ namespace CreatureLib::Battling {
const ArbUt::UniquePtrList<BattleParty>& GetParties() const noexcept { return _parties; } const ArbUt::UniquePtrList<BattleParty>& GetParties() const noexcept { return _parties; }
const ArbUt::UniquePtrList<BattleSide>& GetSides() const noexcept { return _sides; } const ArbUt::UniquePtrList<BattleSide>& GetSides() const noexcept { return _sides; }
ArbUt::BorrowedPtr<Script> GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); } ArbUt::BorrowedPtr<Script> GetVolatileScript(const ArbUt::StringView& key) const { return _volatile.Get(key); }
ArbUt::BorrowedPtr<Script> GetVolatileScript(uint32_t keyHash) const noexcept { return _volatile.Get(keyHash); } ArbUt::BorrowedPtr<Script> GetVolatileScript(uint32_t keyHash) const noexcept { return _volatile.Get(keyHash); }
void AddVolatileScript(const ConstString& key); void AddVolatileScript(const ArbUt::BasicStringView& key);
void AddVolatileScript(Script* script); void AddVolatileScript(Script* script);
void RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); } void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
void RemoveVolatileScript(uint32_t keyHash) { _volatile.Remove(keyHash); } void RemoveVolatileScript(uint32_t keyHash) { _volatile.Remove(keyHash); }
void RemoveVolatileScript(Script* script); void RemoveVolatileScript(Script* script);
bool HasVolatileScript(const ConstString& name) const { return _volatile.Has(name); } bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); } bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }
void DisplayText(const std::string& text) const; void DisplayText(const ArbUt::StringView& text) const;
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); } void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
void TriggerEventListener(EventData* data) const { this->_eventHook.TriggerEvent(data); } void TriggerEventListener(EventData* data) const { this->_eventHook.TriggerEvent(data); }
}; };

View File

@ -5,7 +5,7 @@
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
CreateCreature CreateCreature::WithVariant(const ArbUt::CaseInsensitiveConstString& variant) { CreateCreature CreateCreature::WithVariant(const ArbUt::StringView& variant) {
this->_variant = variant; this->_variant = variant;
return *this; return *this;
} }
@ -20,8 +20,7 @@ CreateCreature CreateCreature::WithGender(Library::Gender gender) {
return *this; return *this;
} }
CreateCreature CreateCreature::WithAttack(const ArbUt::CaseInsensitiveConstString& attackName, CreateCreature CreateCreature::WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod) {
AttackLearnMethod learnMethod) {
if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves()) if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves())
throw CreatureException("You have already set the maximum amount of allowed moves."); throw CreatureException("You have already set the maximum amount of allowed moves.");

View File

@ -9,28 +9,27 @@
namespace CreatureLib::Battling { namespace CreatureLib::Battling {
class CreateCreature { class CreateCreature {
ArbUt::BorrowedPtr<const BattleLibrary> _library; ArbUt::BorrowedPtr<const BattleLibrary> _library;
ArbUt::CaseInsensitiveConstString _species; ArbUt::StringView _species;
ArbUt::CaseInsensitiveConstString _variant = "default"_cnc; ArbUt::StringView _variant = "default"_cnc;
uint8_t _level; uint8_t _level;
std::string _nickname = ""; std::string _nickname = "";
ArbUt::CaseInsensitiveConstString _talent = ""_cnc; ArbUt::StringView _talent = ""_cnc;
Library::Gender _gender = static_cast<Library::Gender>(-1); Library::Gender _gender = static_cast<Library::Gender>(-1);
uint8_t _coloring = 0; uint8_t _coloring = 0;
ArbUt::CaseInsensitiveConstString _heldItem = ""_cnc; ArbUt::StringView _heldItem = ""_cnc;
uint32_t _identifier = 0; uint32_t _identifier = 0;
ArbUt::List<std::tuple<ArbUt::BorrowedPtr<const Library::AttackData>, AttackLearnMethod>> _attacks; ArbUt::List<std::tuple<ArbUt::BorrowedPtr<const Library::AttackData>, AttackLearnMethod>> _attacks;
public: public:
CreateCreature(ArbUt::BorrowedPtr<const BattleLibrary> library, CreateCreature(ArbUt::BorrowedPtr<const BattleLibrary> library, const ArbUt::StringView& species, uint8_t level)
const ArbUt::CaseInsensitiveConstString& species, uint8_t level)
: _library(library), _species(species), _level(level), _attacks(library->GetSettings()->GetMaximalMoves()) { : _library(library), _species(species), _level(level), _attacks(library->GetSettings()->GetMaximalMoves()) {
} }
CreateCreature WithVariant(const ArbUt::CaseInsensitiveConstString& variant); CreateCreature WithVariant(const ArbUt::StringView& variant);
CreateCreature WithNickname(std::string nickname); CreateCreature WithNickname(std::string nickname);
CreateCreature WithGender(Library::Gender gender); CreateCreature WithGender(Library::Gender gender);
CreateCreature WithAttack(const ArbUt::CaseInsensitiveConstString& attackName, AttackLearnMethod learnMethod); CreateCreature WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod);
Creature* Create(); Creature* Create();
}; };

View File

@ -10,7 +10,7 @@ Battling::Creature::Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species, const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level, const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level,
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring, uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
const ArbUt::BorrowedPtr<const Library::Item> heldItem, std::string nickname, const ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string_view& nickname,
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks, const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
bool allowedExperienceGain) bool allowedExperienceGain)
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience), : _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
@ -68,7 +68,7 @@ void Battling::Creature::ChangeLevelBy(int8_t amount) {
RecalculateFlatStats(); RecalculateFlatStats();
} }
const ConstString& Battling::Creature::GetActiveTalent() const { const ArbUt::StringView& Battling::Creature::GetActiveTalent() const {
if (_hasOverridenTalent) { if (_hasOverridenTalent) {
return _overridenTalentName; return _overridenTalentName;
} }
@ -169,7 +169,7 @@ void Battling::Creature::Heal(uint32_t amount, bool canRevive) {
_currentHealth = newHealth; _currentHealth = newHealth;
} }
void Battling::Creature::OverrideActiveTalent(const ConstString& talent) { void Battling::Creature::OverrideActiveTalent(const ArbUt::StringView& talent) {
_hasOverridenTalent = true; _hasOverridenTalent = true;
_activeTalent->OnRemove(); _activeTalent->OnRemove();
_overridenTalentName = talent; _overridenTalentName = talent;
@ -224,7 +224,7 @@ ArbUt::BorrowedPtr<const Library::SpeciesVariant> Battling::Creature::GetDisplay
variant = _variant; variant = _variant;
return variant; return variant;
} }
void Battling::Creature::SetHeldItem(const ConstString& itemName) { void Battling::Creature::SetHeldItem(const ArbUt::BasicStringView& itemName) {
ArbUt::BorrowedPtr<const Library::Item> item; ArbUt::BorrowedPtr<const Library::Item> item;
if (!_library->GetItemLibrary()->TryGet(itemName.GetHash(), item)) { if (!_library->GetItemLibrary()->TryGet(itemName.GetHash(), item)) {
throw CreatureException("Item not found."); throw CreatureException("Item not found.");
@ -239,7 +239,7 @@ void Battling::Creature::SetHeldItem(uint32_t itemNameHash) {
_heldItem = item; _heldItem = item;
} }
void Battling::Creature::AddVolatileScript(const ConstString& name) { void Battling::Creature::AddVolatileScript(const ArbUt::BasicStringView& name) {
auto script = _volatile.Get(name); auto script = _volatile.Get(name);
if (script != nullptr) { if (script != nullptr) {
script->Stack(); script->Stack();
@ -255,6 +255,6 @@ void Battling::Creature::AddVolatileScript(const ConstString& name) {
} }
void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); } void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); }
void Battling::Creature::RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); } void Battling::Creature::RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); } void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); }
bool Battling::Creature::HasVolatileScript(const ConstString& name) const { return _volatile.Has(name); } bool Battling::Creature::HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }

View File

@ -45,12 +45,12 @@ namespace CreatureLib::Battling {
ArbUt::BorrowedPtr<BattleSide> _side = nullptr; ArbUt::BorrowedPtr<BattleSide> _side = nullptr;
bool _onBattleField = false; bool _onBattleField = false;
std::string _nickname = ""; std::string_view _nickname = "";
CreatureLib::Library::TalentIndex _talentIndex; CreatureLib::Library::TalentIndex _talentIndex;
std::unique_ptr<Script> _activeTalent = nullptr; std::unique_ptr<Script> _activeTalent = nullptr;
bool _hasOverridenTalent; bool _hasOverridenTalent;
ArbUt::CaseInsensitiveConstString _overridenTalentName = ""_cnc; ArbUt::StringView _overridenTalentName = ""_cnc;
std::unordered_set<ArbUt::BorrowedPtr<Creature>> _seenOpponents; std::unordered_set<ArbUt::BorrowedPtr<Creature>> _seenOpponents;
ArbUt::UniquePtrList<LearnedAttack> _attacks; ArbUt::UniquePtrList<LearnedAttack> _attacks;
@ -69,7 +69,7 @@ namespace CreatureLib::Battling {
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species, const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level, uint32_t experience, const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level, uint32_t experience,
uint32_t uid, Library::Gender gender, uint8_t coloring, uint32_t uid, Library::Gender gender, uint8_t coloring,
const ArbUt::BorrowedPtr<const Library::Item> heldItem, std::string nickname, const ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string_view& nickname,
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks, const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
bool allowedExperienceGain = true); bool allowedExperienceGain = true);
@ -89,14 +89,14 @@ namespace CreatureLib::Battling {
inline uint32_t GetExperience() const noexcept { return _experience; } inline uint32_t GetExperience() const noexcept { return _experience; }
inline Library::Gender GetGender() const noexcept { return _gender; } inline Library::Gender GetGender() const noexcept { return _gender; }
inline uint8_t GetColoring() const noexcept { return _coloring; } inline uint8_t GetColoring() const noexcept { return _coloring; }
inline bool HasHeldItem(const ArbUt::CaseInsensitiveConstString& name) const noexcept { inline bool HasHeldItem(const ArbUt::BasicStringView& name) const noexcept {
return _heldItem != nullptr && _heldItem->GetName() == name; return _heldItem != nullptr && _heldItem->GetName() == name;
} }
inline bool HasHeldItem(uint32_t nameHash) const noexcept { inline bool HasHeldItem(uint32_t nameHash) const noexcept {
return _heldItem != nullptr && _heldItem->GetName() == nameHash; return _heldItem != nullptr && _heldItem->GetName() == nameHash;
} }
inline const ArbUt::BorrowedPtr<const Library::Item>& GetHeldItem() const noexcept { return _heldItem; } inline const ArbUt::BorrowedPtr<const Library::Item>& GetHeldItem() const noexcept { return _heldItem; }
void SetHeldItem(const ArbUt::CaseInsensitiveConstString& itemName); void SetHeldItem(const ArbUt::BasicStringView& itemName);
void SetHeldItem(uint32_t itemNameHash); void SetHeldItem(uint32_t itemNameHash);
inline void SetHeldItem(const ArbUt::BorrowedPtr<const Library::Item>& item) noexcept { _heldItem = item; }; inline void SetHeldItem(const ArbUt::BorrowedPtr<const Library::Item>& item) noexcept { _heldItem = item; };
@ -108,8 +108,8 @@ namespace CreatureLib::Battling {
inline void SetOnBattleField(bool value) { _onBattleField = value; } inline void SetOnBattleField(bool value) { _onBattleField = value; }
inline bool IsOnBattleField() const { return _onBattleField; } inline bool IsOnBattleField() const { return _onBattleField; }
inline const std::string& GetNickname() const noexcept { return _nickname; } inline const std::string_view& GetNickname() const noexcept { return _nickname; }
const ArbUt::CaseInsensitiveConstString& GetActiveTalent() const; const ArbUt::StringView& GetActiveTalent() const;
[[nodiscard]] bool IsFainted() const noexcept; [[nodiscard]] bool IsFainted() const noexcept;
[[nodiscard]] const std::unordered_set<uint8_t>& GetTypes() const noexcept; [[nodiscard]] const std::unordered_set<uint8_t>& GetTypes() const noexcept;
@ -119,7 +119,7 @@ namespace CreatureLib::Battling {
void ChangeLevelBy(int8_t amount); void ChangeLevelBy(int8_t amount);
void Damage(uint32_t damage, DamageSource source); void Damage(uint32_t damage, DamageSource source);
void Heal(uint32_t amount, bool canRevive = false); void Heal(uint32_t amount, bool canRevive = false);
void OverrideActiveTalent(const ArbUt::CaseInsensitiveConstString& talent); void OverrideActiveTalent(const ArbUt::StringView& talent);
void AddExperience(uint32_t amount); void AddExperience(uint32_t amount);
void MarkOpponentAsSeen(ArbUt::BorrowedPtr<Creature> creature) { _seenOpponents.insert(creature); } void MarkOpponentAsSeen(ArbUt::BorrowedPtr<Creature> creature) { _seenOpponents.insert(creature); }
@ -128,11 +128,11 @@ namespace CreatureLib::Battling {
size_t ScriptCount() const override; size_t ScriptCount() const override;
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override; void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
void ClearVolatileScripts(); void ClearVolatileScripts();
void AddVolatileScript(const ArbUt::CaseInsensitiveConstString& name); void AddVolatileScript(const ArbUt::BasicStringView& name);
void AddVolatileScript(Script* script); void AddVolatileScript(Script* script);
void RemoveVolatileScript(const ArbUt::CaseInsensitiveConstString& name); void RemoveVolatileScript(const ArbUt::BasicStringView& name);
void RemoveVolatileScript(Script* script); void RemoveVolatileScript(Script* script);
bool HasVolatileScript(const ArbUt::CaseInsensitiveConstString& name) const; bool HasVolatileScript(const ArbUt::BasicStringView& name) const;
const ArbUt::UniquePtrList<LearnedAttack>& GetAttacks() noexcept { return _attacks; } const ArbUt::UniquePtrList<LearnedAttack>& GetAttacks() noexcept { return _attacks; }

View File

@ -2,7 +2,7 @@
#define CREATURELIB_SCRIPT_HPP #define CREATURELIB_SCRIPT_HPP
#include <Arbutils/Collections/List.hpp> #include <Arbutils/Collections/List.hpp>
#include <Arbutils/ConstString.hpp> #include <Arbutils/StringView.hpp>
#include "../../Library/EffectParameter.hpp" #include "../../Library/EffectParameter.hpp"
namespace CreatureLib::Battling { namespace CreatureLib::Battling {
@ -19,13 +19,13 @@ namespace CreatureLib::Battling {
virtual void Stack(){}; virtual void Stack(){};
virtual void OnRemove(){}; virtual void OnRemove(){};
virtual const ArbUt::CaseInsensitiveConstString& GetName() const noexcept = 0; virtual const ArbUt::StringView& GetName() const noexcept = 0;
virtual void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){}; virtual void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
virtual void OnBeforeTurn(const BaseTurnChoice* choice){}; virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
virtual void ChangePriority(AttackTurnChoice* choice, int8_t* priority){}; virtual void ChangePriority(AttackTurnChoice* choice, int8_t* priority){};
virtual void ChangeAttack(AttackTurnChoice* choice, ArbUt::CaseInsensitiveConstString* outAttack){}; virtual void ChangeAttack(AttackTurnChoice* choice, ArbUt::StringView* outAttack){};
virtual void PreventAttack(ExecutingAttack* attack, bool* outResult){}; virtual void PreventAttack(ExecutingAttack* attack, bool* outResult){};
virtual void FailAttack(ExecutingAttack* attack, bool* outFailed){}; virtual void FailAttack(ExecutingAttack* attack, bool* outFailed){};
virtual void StopBeforeAttack(ExecutingAttack* attack, bool* outResult){}; virtual void StopBeforeAttack(ExecutingAttack* attack, bool* outResult){};

View File

@ -14,7 +14,7 @@ namespace CreatureLib::Battling {
virtual ~ScriptResolver() = default; virtual ~ScriptResolver() = default;
virtual void Initialize(BattleLibrary* library){}; virtual void Initialize(BattleLibrary* library){};
virtual Script* LoadScript(ScriptCategory category, const ArbUt::CaseInsensitiveConstString& scriptName) { virtual Script* LoadScript(ScriptCategory category, const ArbUt::BasicStringView& scriptName) {
return nullptr; return nullptr;
}; };
}; };

View File

@ -29,9 +29,7 @@ namespace CreatureLib::Battling {
_lookup.Insert(script->GetName(), _scripts.Count() - 1); _lookup.Insert(script->GetName(), _scripts.Count() - 1);
} }
ArbUt::BorrowedPtr<Script> Get(const ArbUt::CaseInsensitiveConstString& key) const { ArbUt::BorrowedPtr<Script> Get(const ArbUt::BasicStringView& key) const { return Get(key.GetHash()); }
return Get(key.GetHash());
}
ArbUt::BorrowedPtr<Script> Get(uint32_t keyHash) const noexcept { ArbUt::BorrowedPtr<Script> Get(uint32_t keyHash) const noexcept {
size_t v; size_t v;
@ -41,7 +39,7 @@ namespace CreatureLib::Battling {
return nullptr; return nullptr;
} }
void Remove(const ArbUt::CaseInsensitiveConstString& key) { Remove(key.GetHash()); } void Remove(const ArbUt::BasicStringView& key) { Remove(key.GetHash()); }
void Remove(uint32_t keyHash) { void Remove(uint32_t keyHash) {
size_t v; size_t v;
@ -62,7 +60,7 @@ namespace CreatureLib::Battling {
_lookup.Clear(); _lookup.Clear();
} }
bool Has(const ArbUt::CaseInsensitiveConstString& key) const { return _lookup.Has(key); } bool Has(const ArbUt::BasicStringView& key) const { return _lookup.Has(key); }
bool Has(uint32_t keyHash) const { return _lookup.Has(keyHash); } bool Has(uint32_t keyHash) const { return _lookup.Has(keyHash); }

View File

@ -1,7 +1,7 @@
#include "AttackData.hpp" #include "AttackData.hpp"
#include <utility> #include <utility>
CreatureLib::Library::AttackData::AttackData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type, CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, uint8_t type,
CreatureLib::Library::AttackCategory category, uint8_t power, CreatureLib::Library::AttackCategory category, uint8_t power,
uint8_t accuracy, uint8_t baseUsage, uint8_t accuracy, uint8_t baseUsage,
CreatureLib::Library::AttackTarget target, int8_t priority, CreatureLib::Library::AttackTarget target, int8_t priority,

View File

@ -1,7 +1,7 @@
#ifndef CREATURELIB_ATTACKDATA_HPP #ifndef CREATURELIB_ATTACKDATA_HPP
#define CREATURELIB_ATTACKDATA_HPP #define CREATURELIB_ATTACKDATA_HPP
#include <Arbutils/ConstString.hpp> #include <Arbutils/StringView.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
@ -12,7 +12,7 @@
namespace CreatureLib::Library { namespace CreatureLib::Library {
class AttackData { class AttackData {
protected: protected:
ArbUt::CaseInsensitiveConstString _name; ArbUt::StringView _name;
uint8_t _type; uint8_t _type;
AttackCategory _category; AttackCategory _category;
uint8_t _basePower; uint8_t _basePower;
@ -24,12 +24,12 @@ namespace CreatureLib::Library {
std::unordered_set<uint32_t> _flags; std::unordered_set<uint32_t> _flags;
public: public:
AttackData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type, AttackCategory category, uint8_t power, AttackData(const ArbUt::StringView& name, uint8_t type, AttackCategory category, uint8_t power,
uint8_t accuracy, uint8_t baseUsage, AttackTarget target, int8_t priority, uint8_t accuracy, uint8_t baseUsage, AttackTarget target, int8_t priority,
const SecondaryEffect* effect, std::unordered_set<uint32_t> flags); const SecondaryEffect* effect, std::unordered_set<uint32_t> flags);
virtual ~AttackData() = default; virtual ~AttackData() = default;
inline const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; } inline const ArbUt::StringView& GetName() const noexcept { return _name; }
inline const uint8_t GetType() const noexcept { return _type; } inline const uint8_t GetType() const noexcept { return _type; }
inline AttackCategory GetCategory() const noexcept { return _category; } inline AttackCategory GetCategory() const noexcept { return _category; }
inline uint8_t GetBasePower() const noexcept { return _basePower; } inline uint8_t GetBasePower() const noexcept { return _basePower; }
@ -42,7 +42,7 @@ namespace CreatureLib::Library {
} }
inline const std::unique_ptr<const SecondaryEffect>& GetSecondaryEffect() const noexcept { return _effect; } inline const std::unique_ptr<const SecondaryEffect>& GetSecondaryEffect() const noexcept { return _effect; }
inline bool HasFlag(const ArbUt::CaseInsensitiveConstString& key) const noexcept { inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
return this->_flags.find(key) != this->_flags.end(); return this->_flags.find(key) != this->_flags.end();
} }
inline bool HasFlag(uint32_t keyHash) const noexcept { inline bool HasFlag(uint32_t keyHash) const noexcept {

View File

@ -2,7 +2,7 @@
#define CREATURELIB_SECONDARYEFFECT_HPP #define CREATURELIB_SECONDARYEFFECT_HPP
#include <Arbutils/Collections/List.hpp> #include <Arbutils/Collections/List.hpp>
#include <Arbutils/ConstString.hpp> #include <Arbutils/StringView.hpp>
#include <any> #include <any>
#include "../EffectParameter.hpp" #include "../EffectParameter.hpp"
@ -10,12 +10,12 @@ namespace CreatureLib::Library {
class SecondaryEffect { class SecondaryEffect {
private: private:
float _chance; float _chance;
ArbUt::CaseInsensitiveConstString _effectName; ArbUt::StringView _effectName;
ArbUt::List<EffectParameter*> _parameters; ArbUt::List<EffectParameter*> _parameters;
public: public:
SecondaryEffect() noexcept : _chance(0), _effectName() {} SecondaryEffect() noexcept : _chance(0), _effectName() {}
SecondaryEffect(float chance, const ArbUt::CaseInsensitiveConstString& effectName, SecondaryEffect(float chance, const ArbUt::StringView& effectName,
const ArbUt::List<EffectParameter*>& parameters) noexcept const ArbUt::List<EffectParameter*>& parameters) noexcept
: _chance(chance), _effectName(effectName), _parameters(parameters) {} : _chance(chance), _effectName(effectName), _parameters(parameters) {}
@ -26,7 +26,7 @@ namespace CreatureLib::Library {
} }
constexpr inline float GetChance() const noexcept { return _chance; } constexpr inline float GetChance() const noexcept { return _chance; }
constexpr inline const ArbUt::CaseInsensitiveConstString& GetEffectName() const noexcept { return _effectName; } constexpr inline const ArbUt::StringView& GetEffectName() const noexcept { return _effectName; }
const inline ArbUt::List<EffectParameter*>& GetParameters() const noexcept { return _parameters; } const inline ArbUt::List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
}; };
} }

View File

@ -4,9 +4,9 @@
#include <Arbutils/Assert.hpp> #include <Arbutils/Assert.hpp>
#include <Arbutils/Collections/Dictionary.hpp> #include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/Collections/List.hpp> #include <Arbutils/Collections/List.hpp>
#include <Arbutils/ConstString.hpp>
#include <Arbutils/Memory/BorrowedPtr.hpp> #include <Arbutils/Memory/BorrowedPtr.hpp>
#include <Arbutils/Random.hpp> #include <Arbutils/Random.hpp>
#include <Arbutils/StringView.hpp>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <string> #include <string>
@ -22,7 +22,7 @@ namespace CreatureLib::Library {
virtual ~BaseLibrary() noexcept { _values.Clear(); } virtual ~BaseLibrary() noexcept { _values.Clear(); }
inline void Insert(const ArbUt::CaseInsensitiveConstString& key, const T* value) { inline void Insert(const ArbUt::StringView& key, const T* value) {
AssertNotNull(value) AssertNotNull(value)
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)}); _values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
_listValues.Append(key); _listValues.Append(key);
@ -33,7 +33,7 @@ namespace CreatureLib::Library {
_listValues.Append(hashedKey); _listValues.Append(hashedKey);
} }
inline void Delete(const ArbUt::CaseInsensitiveConstString& key) noexcept { inline void Delete(const ArbUt::StringView& key) noexcept {
_values.erase(key.GetHash()); _values.erase(key.GetHash());
auto k = _listValues.IndexOf(key); auto k = _listValues.IndexOf(key);
_listValues.Remove(k); _listValues.Remove(k);
@ -44,7 +44,7 @@ namespace CreatureLib::Library {
_listValues.Remove(k); _listValues.Remove(k);
} }
bool TryGet(const ArbUt::CaseInsensitiveConstString& name, ArbUt::BorrowedPtr<const T>& out) const noexcept { bool TryGet(const ArbUt::BasicStringView& name, ArbUt::BorrowedPtr<const T>& out) const noexcept {
return TryGet(name.GetHash(), out); return TryGet(name.GetHash(), out);
} }
bool TryGet(uint32_t hashedKey, ArbUt::BorrowedPtr<const T>& out) const noexcept { bool TryGet(uint32_t hashedKey, ArbUt::BorrowedPtr<const T>& out) const noexcept {
@ -55,15 +55,14 @@ namespace CreatureLib::Library {
return true; return true;
} }
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(const ArbUt::CaseInsensitiveConstString& name) const { [[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(const ArbUt::BasicStringView& name) const {
return _values.Get(name.GetHash()); return _values.Get(name.GetHash());
} }
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(uint32_t hashedKey) const { [[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(uint32_t hashedKey) const {
return _values.Get(hashedKey); return _values.Get(hashedKey);
} }
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> [[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](const ArbUt::BasicStringView& name) const {
operator[](const ArbUt::CaseInsensitiveConstString& name) const {
return Get(name); return Get(name);
} }
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](uint32_t hashedKey) const { return Get(hashedKey); } [[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](uint32_t hashedKey) const { return Get(hashedKey); }

View File

@ -3,18 +3,13 @@
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name, CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
const SpeciesVariant* defaultVariant, float genderRatio, float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate)
const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate)
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate), _variants(1) { : _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate), _variants(1) {
AssertNotNull(defaultVariant) AssertNotNull(defaultVariant)
SetVariant("default"_cnc, defaultVariant); SetVariant("default"_cnc, defaultVariant);
} }
bool CreatureSpecies::TryGetVariant(const ArbUt::CaseInsensitiveConstString& name,
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept {
return TryGetVariant(name.GetHash(), out);
}
bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept { bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept {
auto find = _variants.GetStdMap().find(hash); auto find = _variants.GetStdMap().find(hash);
if (find == _variants.end()) if (find == _variants.end())
@ -23,7 +18,7 @@ bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const Spec
return true; return true;
} }
void CreatureSpecies::SetVariant(const ArbUt::CaseInsensitiveConstString& name, const SpeciesVariant* variant) { void CreatureSpecies::SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
_variants.GetStdMap().insert({name, std::unique_ptr<const SpeciesVariant>(variant)}); _variants.GetStdMap().insert({name, std::unique_ptr<const SpeciesVariant>(variant)});
} }

View File

@ -2,8 +2,8 @@
#define CREATURELIB_CREATURESPECIES_HPP #define CREATURELIB_CREATURESPECIES_HPP
#include <Arbutils/Collections/Dictionary.hpp> #include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/ConstString.hpp>
#include <Arbutils/Memory/BorrowedPtr.hpp> #include <Arbutils/Memory/BorrowedPtr.hpp>
#include <Arbutils/StringView.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@ -16,43 +16,44 @@ namespace CreatureLib::Library {
creatures with. creatures with.
*/ */
class CreatureSpecies { class CreatureSpecies {
const ArbUt::CaseInsensitiveConstString _name; const ArbUt::StringView _name;
uint16_t _id; uint16_t _id;
float _genderRate; float _genderRate;
const ArbUt::CaseInsensitiveConstString _growthRate; const ArbUt::StringView _growthRate;
uint8_t _captureRate; uint8_t _captureRate;
ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>> _variants; ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>> _variants;
public: public:
CreatureSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name, CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
const SpeciesVariant* defaultVariant, float genderRatio, float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate);
const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate);
virtual ~CreatureSpecies() noexcept { _variants.Clear(); } virtual ~CreatureSpecies() noexcept { _variants.Clear(); }
inline uint16_t GetId() const noexcept { return _id; } inline uint16_t GetId() const noexcept { return _id; }
inline float GetGenderRate() const noexcept { return _genderRate; } inline float GetGenderRate() const noexcept { return _genderRate; }
inline const ArbUt::CaseInsensitiveConstString& GetGrowthRate() const noexcept { return _growthRate; } inline const ArbUt::StringView& GetGrowthRate() const noexcept { return _growthRate; }
inline uint8_t GetCaptureRate() const noexcept { return _captureRate; } inline uint8_t GetCaptureRate() const noexcept { return _captureRate; }
[[nodiscard]] inline bool HasVariant(const ArbUt::CaseInsensitiveConstString& key) const noexcept { [[nodiscard]] inline bool HasVariant(const ArbUt::BasicStringView& key) const noexcept {
return _variants.Has(key); return _variants.Has(key);
} }
[[nodiscard]] inline bool HasVariant(uint32_t hash) const noexcept { return _variants.Has(hash); } [[nodiscard]] inline bool HasVariant(uint32_t hash) const noexcept { return _variants.Has(hash); }
[[nodiscard]] bool TryGetVariant(const ArbUt::CaseInsensitiveConstString& name, [[nodiscard]] inline bool TryGetVariant(const ArbUt::BasicStringView& name,
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept; ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept {
return TryGetVariant(name.GetHash(), out);
}
[[nodiscard]] bool TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept; [[nodiscard]] bool TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept;
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> [[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant>
GetVariant(const ArbUt::CaseInsensitiveConstString& key) const { GetVariant(const ArbUt::BasicStringView& key) const {
return _variants.Get(key); return _variants.Get(key);
} }
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const { [[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const {
return _variants.Get(key); return _variants.Get(key);
} }
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const noexcept; [[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const noexcept;
[[nodiscard]] inline const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; } [[nodiscard]] inline const ArbUt::StringView& GetName() const { return _name; }
void SetVariant(const ArbUt::CaseInsensitiveConstString& name, const SpeciesVariant* variant); void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant);
inline const ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>>& GetVariantsIterator() const { inline const ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>>& GetVariantsIterator() const {
return _variants; return _variants;

View File

@ -2,7 +2,7 @@
#include <algorithm> #include <algorithm>
const CreatureLib::Library::TalentIndex const CreatureLib::Library::TalentIndex
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::CaseInsensitiveConstString& talent) const { CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::StringView& talent) const {
for (size_t i = 0; i < _talents.Count(); i++) { for (size_t i = 0; i < _talents.Count(); i++) {
if (_talents.At(i) == talent) { if (_talents.At(i) == talent) {
return TalentIndex(false, i); return TalentIndex(false, i);

View File

@ -16,7 +16,7 @@ namespace CreatureLib::Library {
*/ */
class SpeciesVariant { class SpeciesVariant {
protected: protected:
ArbUt::CaseInsensitiveConstString _name; ArbUt::StringView _name;
float _height; float _height;
float _weight; float _weight;
uint32_t _baseExperience; uint32_t _baseExperience;
@ -24,22 +24,20 @@ namespace CreatureLib::Library {
private: private:
ArbUt::List<uint8_t> _types; ArbUt::List<uint8_t> _types;
Library::StatisticSet<uint16_t> _baseStatistics; Library::StatisticSet<uint16_t> _baseStatistics;
ArbUt::List<ArbUt::CaseInsensitiveConstString> _talents; ArbUt::List<ArbUt::StringView> _talents;
ArbUt::List<ArbUt::CaseInsensitiveConstString> _secretTalents; ArbUt::List<ArbUt::StringView> _secretTalents;
std::unique_ptr<const LearnableAttacks> _attacks; std::unique_ptr<const LearnableAttacks> _attacks;
public: public:
SpeciesVariant(const ArbUt::CaseInsensitiveConstString& name, float height, float weight, SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
uint32_t baseExperience, const ArbUt::List<uint8_t>& types, const ArbUt::List<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
Library::StatisticSet<uint16_t> baseStats, const ArbUt::List<ArbUt::StringView>& talents,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& talents, const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks)
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& secretTalents,
const LearnableAttacks* attacks)
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)), : _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)),
_baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks){}; _baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks){};
virtual ~SpeciesVariant() = default; virtual ~SpeciesVariant() = default;
inline const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; } inline const ArbUt::StringView& GetName() const { return _name; }
inline float GetHeight() const { return _height; } inline float GetHeight() const { return _height; }
inline float GetWeight() const { return _weight; } inline float GetWeight() const { return _weight; }
inline uint32_t GetBaseExperience() const { return _baseExperience; } inline uint32_t GetBaseExperience() const { return _baseExperience; }
@ -52,7 +50,7 @@ namespace CreatureLib::Library {
} }
[[nodiscard]] inline const size_t GetTalentCount() const noexcept { return _talents.Count(); } [[nodiscard]] inline const size_t GetTalentCount() const noexcept { return _talents.Count(); }
[[nodiscard]] inline const size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); } [[nodiscard]] inline const size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
[[nodiscard]] const ArbUt::CaseInsensitiveConstString& GetTalent(const TalentIndex& index) const { [[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const {
if (index.IsSecret() && _secretTalents.Count() > 0) { if (index.IsSecret() && _secretTalents.Count() > 0) {
auto i = index.GetIndex(); auto i = index.GetIndex();
if (i > _secretTalents.Count()) if (i > _secretTalents.Count())
@ -64,7 +62,7 @@ namespace CreatureLib::Library {
i = _talents.Count(); i = _talents.Count();
return _talents.At(i); return _talents.At(i);
} }
[[nodiscard]] const TalentIndex GetTalentIndex(const ArbUt::CaseInsensitiveConstString& talent) const; [[nodiscard]] const TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const;
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::LearnableAttacks> [[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::LearnableAttacks>
GetLearnableAttacks() const { GetLearnableAttacks() const {
@ -73,12 +71,8 @@ namespace CreatureLib::Library {
[[nodiscard]] inline TalentIndex GetRandomTalent(ArbUt::Random* rand) const noexcept { [[nodiscard]] inline TalentIndex GetRandomTalent(ArbUt::Random* rand) const noexcept {
return TalentIndex(false, rand->Get(_talents.Count())); return TalentIndex(false, rand->Get(_talents.Count()));
} }
[[nodiscard]] inline const ArbUt::List<ArbUt::CaseInsensitiveConstString>& GetTalents() const { [[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetTalents() const { return _talents; }
return _talents; [[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const { return _secretTalents; }
}
[[nodiscard]] inline const ArbUt::List<ArbUt::CaseInsensitiveConstString>& GetSecretTalents() const {
return _secretTalents;
}
}; };
} }

View File

@ -1,7 +1,7 @@
#ifndef CREATURELIB_EFFECTPARAMETER_HPP #ifndef CREATURELIB_EFFECTPARAMETER_HPP
#define CREATURELIB_EFFECTPARAMETER_HPP #define CREATURELIB_EFFECTPARAMETER_HPP
#include <Arbutils/ConstString.hpp>
#include <Arbutils/Enum.hpp> #include <Arbutils/Enum.hpp>
#include <Arbutils/StringView.hpp>
#include <variant> #include <variant>
#include "Exceptions/CreatureException.hpp" #include "Exceptions/CreatureException.hpp"
@ -11,15 +11,14 @@ namespace CreatureLib::Library {
class EffectParameter { class EffectParameter {
private: private:
EffectParameterType _type = EffectParameterType::None; EffectParameterType _type = EffectParameterType::None;
std::variant<bool, int64_t, float, ArbUt::CaseInsensitiveConstString> _value; std::variant<bool, int64_t, float, ArbUt::StringView> _value;
public: public:
inline EffectParameter() : _type(EffectParameterType::None){}; inline EffectParameter() : _type(EffectParameterType::None){};
inline explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _value(b){}; inline explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _value(b){};
inline explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _value(i){}; inline explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _value(i){};
inline explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){}; inline explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){};
inline explicit EffectParameter(const ArbUt::CaseInsensitiveConstString& s) inline explicit EffectParameter(const ArbUt::StringView& s) : _type(EffectParameterType::String), _value(s){};
: _type(EffectParameterType::String), _value(s){};
EffectParameter(const EffectParameter& other) = delete; EffectParameter(const EffectParameter& other) = delete;
EffectParameter& operator=(const EffectParameter& other) = delete; EffectParameter& operator=(const EffectParameter& other) = delete;
@ -54,13 +53,13 @@ namespace CreatureLib::Library {
} }
return std::get<float>(_value); return std::get<float>(_value);
} }
const ArbUt::CaseInsensitiveConstString& AsString() const { const ArbUt::StringView& AsString() const {
if (_type != EffectParameterType::String) { if (_type != EffectParameterType::String) {
std::stringstream ss; std::stringstream ss;
ss << "Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type); ss << "Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type);
throw CreatureException(ss.str()); throw CreatureException(ss.str());
} }
return std::get<ArbUt::CaseInsensitiveConstString>(_value); return std::get<ArbUt::StringView>(_value);
} }
}; };
} }

View File

@ -1,7 +1,7 @@
#include "GrowthRateLibrary.hpp" #include "GrowthRateLibrary.hpp"
#include "../Exceptions/CreatureException.hpp" #include "../Exceptions/CreatureException.hpp"
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ConstString& growthRate, uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::BasicStringView& growthRate,
uint32_t experience) const { uint32_t experience) const {
auto find = _growthRates.find(growthRate); auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) { if (find == _growthRates.end()) {
@ -18,7 +18,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, u
return find->second->CalculateLevel(experience); return find->second->CalculateLevel(experience);
} }
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ConstString& growthRate, uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
uint8_t level) const { uint8_t level) const {
auto find = _growthRates.find(growthRate); auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) { if (find == _growthRates.end()) {
@ -35,7 +35,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t h
return find->second->CalculateExperience(level); return find->second->CalculateExperience(level);
} }
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ConstString& name, void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ArbUt::StringView& name,
CreatureLib::Library::GrowthRate* rate) { CreatureLib::Library::GrowthRate* rate) {
_growthRates.insert({name, std::unique_ptr<const GrowthRate>(rate)}); _growthRates.insert({name, std::unique_ptr<const GrowthRate>(rate)});
} }

View File

@ -1,15 +1,13 @@
#ifndef CREATURELIB_GROWTHRATELIBRARY_HPP #ifndef CREATURELIB_GROWTHRATELIBRARY_HPP
#define CREATURELIB_GROWTHRATELIBRARY_HPP #define CREATURELIB_GROWTHRATELIBRARY_HPP
#include <Arbutils/ConstString.hpp> #include <Arbutils/StringView.hpp>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include "GrowthRate.hpp" #include "GrowthRate.hpp"
using ConstString = ArbUt::CaseInsensitiveConstString;
namespace CreatureLib::Library { namespace CreatureLib::Library {
class GrowthRateLibrary { class GrowthRateLibrary {
private: private:
@ -21,13 +19,13 @@ namespace CreatureLib::Library {
virtual ~GrowthRateLibrary() = default; virtual ~GrowthRateLibrary() = default;
[[nodiscard]] uint8_t CalculateLevel(const ConstString& growthRate, uint32_t experience) const; [[nodiscard]] uint8_t CalculateLevel(const ArbUt::BasicStringView& growthRate, uint32_t experience) const;
[[nodiscard]] uint8_t CalculateLevel(uint32_t hash, uint32_t experience) const; [[nodiscard]] uint8_t CalculateLevel(uint32_t hash, uint32_t experience) const;
[[nodiscard]] uint32_t CalculateExperience(const ConstString& growthRate, uint8_t level) const; [[nodiscard]] uint32_t CalculateExperience(const ArbUt::BasicStringView& growthRate, uint8_t level) const;
[[nodiscard]] uint32_t CalculateExperience(uint32_t hash, uint8_t level) const; [[nodiscard]] uint32_t CalculateExperience(uint32_t hash, uint8_t level) const;
void AddGrowthRate(uint32_t hash, GrowthRate* rate); void AddGrowthRate(uint32_t hash, GrowthRate* rate);
void AddGrowthRate(const ConstString& name, GrowthRate* rate); void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* rate);
}; };
} }

View File

@ -1,7 +1,7 @@
#ifndef CREATURELIB_ITEM_HPP #ifndef CREATURELIB_ITEM_HPP
#define CREATURELIB_ITEM_HPP #define CREATURELIB_ITEM_HPP
#include <Arbutils/ConstString.hpp> #include <Arbutils/StringView.hpp>
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
#include "BattleItemCategory.hpp" #include "BattleItemCategory.hpp"
@ -10,27 +10,24 @@
namespace CreatureLib::Library { namespace CreatureLib::Library {
class Item { class Item {
protected: protected:
ArbUt::CaseInsensitiveConstString _name; ArbUt::StringView _name;
ItemCategory _category; ItemCategory _category;
BattleItemCategory _battleCategory; BattleItemCategory _battleCategory;
int32_t _price; int32_t _price;
std::unordered_set<uint32_t> _flags; std::unordered_set<uint32_t> _flags;
public: public:
inline Item(const ArbUt::CaseInsensitiveConstString& name, ItemCategory category, inline Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory,
BattleItemCategory battleCategory, int32_t price, int32_t price, const std::unordered_set<uint32_t>& flags) noexcept
const std::unordered_set<uint32_t>& flags) noexcept
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {} : _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
inline const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; } inline const ArbUt::StringView& GetName() const noexcept { return _name; }
inline ItemCategory GetCategory() const noexcept { return _category; } inline ItemCategory GetCategory() const noexcept { return _category; }
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; } inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
inline const int32_t GetPrice() const noexcept { return _price; } inline const int32_t GetPrice() const noexcept { return _price; }
bool HasFlag(const ArbUt::CaseInsensitiveConstString& flag) const noexcept { bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); }
return this->_flags.find(flag) != this->_flags.end(); bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); }
}
bool HasFlag(uint32_t flag) const noexcept { return this->_flags.find(flag) != this->_flags.end(); }
}; };
} }

View File

@ -3,7 +3,7 @@
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
uint8_t TypeLibrary::RegisterType(const ArbUt::CaseInsensitiveConstString& key) { uint8_t TypeLibrary::RegisterType(const ArbUt::StringView& key) {
_types.Insert(key, _types.Count()); _types.Insert(key, _types.Count());
_effectiveness.Resize(_types.Count()); _effectiveness.Resize(_types.Count());
for (auto& eff : _effectiveness) { for (auto& eff : _effectiveness) {

View File

@ -3,7 +3,7 @@
#include <Arbutils/Collections/Dictionary.hpp> #include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/Collections/List.hpp> #include <Arbutils/Collections/List.hpp>
#include <Arbutils/ConstString.hpp> #include <Arbutils/StringView.hpp>
#include <numeric> #include <numeric>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
@ -16,7 +16,7 @@ namespace CreatureLib::Library {
public: public:
TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::Dictionary<uint32_t, uint8_t>(initialCapacity)) {} TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::Dictionary<uint32_t, uint8_t>(initialCapacity)) {}
inline uint8_t GetTypeId(const ArbUt::CaseInsensitiveConstString& key) const { return _types.Get(key); } inline uint8_t GetTypeId(const ArbUt::BasicStringView& key) const { return _types.Get(key); }
inline uint8_t GetTypeId(uint32_t s) const { return _types.Get(s); } inline uint8_t GetTypeId(uint32_t s) const { return _types.Get(s); }
[[nodiscard]] inline float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const { [[nodiscard]] inline float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
return _effectiveness[attacking][defensive]; return _effectiveness[attacking][defensive];
@ -29,7 +29,7 @@ namespace CreatureLib::Library {
}); });
} }
uint8_t RegisterType(const ArbUt::CaseInsensitiveConstString& typeName); uint8_t RegisterType(const ArbUt::StringView& typeName);
uint8_t RegisterType(uint32_t typeHash); uint8_t RegisterType(uint32_t typeHash);
void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness); void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness);
}; };

View File

@ -9,11 +9,11 @@ using namespace CreatureLib::Battling;
class TestScript : public Script { class TestScript : public Script {
private: private:
ArbUt::CaseInsensitiveConstString _name; ArbUt::StringView _name;
public: public:
explicit TestScript(std::string name) : _name(std::move(name)){}; explicit TestScript(std::string name) : _name(std::move(name)){};
const ArbUt::CaseInsensitiveConstString& GetName() const noexcept override { return _name; } const ArbUt::StringView& GetName() const noexcept override { return _name; }
void TestMethod(int& runCount) { runCount++; } void TestMethod(int& runCount) { runCount++; }
}; };

View File

@ -9,11 +9,11 @@ using namespace CreatureLib::Battling;
class TestScript : public Script { class TestScript : public Script {
private: private:
ArbUt::CaseInsensitiveConstString _name; ArbUt::StringView _name;
public: public:
explicit TestScript(std::string name) : _name(std::move(name)){}; explicit TestScript(std::string name) : _name(std::move(name)){};
const ArbUt::CaseInsensitiveConstString& GetName() const noexcept override { return _name; } const ArbUt::StringView& GetName() const noexcept override { return _name; }
}; };
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") { TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {

View File

@ -10,11 +10,11 @@ using namespace CreatureLib::Battling;
class TestScript : public Script { class TestScript : public Script {
private: private:
ArbUt::CaseInsensitiveConstString _name; ArbUt::StringView _name;
public: public:
explicit TestScript(std::string name) : _name(std::move(name)){}; explicit TestScript(std::string name) : _name(std::move(name)){};
const ArbUt::CaseInsensitiveConstString& GetName() const noexcept override { return _name; } const ArbUt::StringView& GetName() const noexcept override { return _name; }
void TestMethod(int& runCount) { runCount++; } void TestMethod(int& runCount) { runCount++; }
}; };

View File

@ -232,23 +232,23 @@ TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integratio
auto seen = c3->GetSeenOpponents(); auto seen = c3->GetSeenOpponents();
REQUIRE(seen.size() == 1); REQUIRE(seen.size() == 1);
REQUIRE(seen.find(c1) != seen.end()); REQUIRE(seen.contains(c1));
battle.TrySetChoice(new SwitchTurnChoice(c1, c2)); battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
battle.TrySetChoice(new PassTurnChoice(c3)); battle.TrySetChoice(new PassTurnChoice(c3));
seen = c3->GetSeenOpponents(); seen = c3->GetSeenOpponents();
REQUIRE(seen.size() == 2); REQUIRE(seen.size() == 2);
REQUIRE(seen.find(c1) != seen.end()); REQUIRE(seen.contains(c1));
REQUIRE(seen.find(c2) != seen.end()); REQUIRE(seen.contains(c2));
battle.TrySetChoice(new SwitchTurnChoice(c2, c1)); battle.TrySetChoice(new SwitchTurnChoice(c2, c1));
battle.TrySetChoice(new PassTurnChoice(c3)); battle.TrySetChoice(new PassTurnChoice(c3));
seen = c3->GetSeenOpponents(); seen = c3->GetSeenOpponents();
REQUIRE(seen.size() == 2); REQUIRE(seen.size() == 2);
REQUIRE(seen.find(c1) != seen.end()); REQUIRE(seen.contains(c1));
REQUIRE(seen.find(c2) != seen.end()); REQUIRE(seen.contains(c2));
} }
TEST_CASE("Flee Battle", "[Integrations]") { TEST_CASE("Flee Battle", "[Integrations]") {

View File

@ -17,7 +17,7 @@ TEST_CASE("Int EffectParameter", "[Library]") {
} }
TEST_CASE("String EffectParameter", "[Library]") { TEST_CASE("String EffectParameter", "[Library]") {
auto p = EffectParameter((ArbUt::CaseInsensitiveConstString) "foobar"_cnc); auto p = EffectParameter((ArbUt::StringView) "foobar"_cnc);
REQUIRE(p.AsString() == "foobar"); REQUIRE(p.AsString() == "foobar");
} }