Skip to content

Commit

Permalink
Merge pull request #39 from powerof3/36-merge-levspell-into-spell-entry
Browse files Browse the repository at this point in the history
36 merge LevSpell into Spell entry
  • Loading branch information
adya authored Apr 7, 2024
2 parents 3dbc218 + 85afb05 commit 2f8bc13
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
24 changes: 23 additions & 1 deletion SPID/src/LinkedDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,32 @@ namespace LinkedDistribution

void Manager::LookupLinkedForms(RE::TESDataHandler* dataHandler, INI::LinkedFormsConfig& rawLinkedForms)
{
ForEachLinkedForms([&]<typename Form>(LinkedForms<Form>& forms) {
ForEachLinkedForms([&]<class Form>(LinkedForms<Form>& forms) {
// If it's spells distributable we want to manually lookup forms to pick LevSpells that are added into the list.
if constexpr (std::is_same_v<Form, RE::SpellItem>) {
return;
}
forms.LookupForms(dataHandler, rawLinkedForms[forms.GetType()]);
});

// Sort out Spells and Leveled Spells into two separate lists.
auto& rawSpells = rawLinkedForms[RECORD::kSpell];

for (auto& rawSpell : rawSpells) {
if (auto form = detail::LookupLinkedForm(dataHandler, rawSpell); form) {
auto& [formID, scope, parentFormIDs, idxOrCount, chance, path] = rawSpell;
FormVec parentForms{};
if (!Forms::detail::formID_to_form(dataHandler, parentFormIDs.MATCH, parentForms, path, false, false)) {
continue;
}
if (const auto spell = form->As<RE::SpellItem>(); spell) {
spells.Link(spell, scope, parentForms, idxOrCount, chance, path);
} else if (const auto levSpell = form->As<RE::TESLevSpell>(); levSpell) {
levSpells.Link(levSpell, scope, parentForms, idxOrCount, chance, path);
}
}
}

auto& genericForms = rawLinkedForms[RECORD::kForm];
for (auto& rawForm : genericForms) {
if (auto form = detail::LookupLinkedForm(dataHandler, rawForm); form) {
Expand Down
19 changes: 18 additions & 1 deletion SPID/src/LookupForms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,29 @@ bool LookupDistributables(RE::TESDataHandler* const dataHandler)
{
using namespace Forms;

ForEachDistributable([&]<typename Form>(Distributables<Form>& a_distributable) {
ForEachDistributable([&]<class Form>(Distributables<Form>& a_distributable) {
// If it's spells distributable we want to manually lookup forms to pick LevSpells that are added into the list.
if constexpr (std::is_same_v<Form, RE::SpellItem>) {
return;
}
const auto& recordName = RECORD::GetTypeName(a_distributable.GetType());

a_distributable.LookupForms(dataHandler, recordName, INI::configs[a_distributable.GetType()]);
});

// Sort out Spells and Leveled Spells into two separate lists.
auto& rawSpells = INI::configs[RECORD::kSpell];

for (auto& rawSpell : rawSpells) {
LookupGenericForm<RE::TESForm>(dataHandler, rawSpell, [&](bool isValid, auto form, const auto& idxOrCount, const auto& filters, const auto& path) {
if (const auto spell = form->As<RE::SpellItem>(); spell) {
spells.EmplaceForm(isValid, spell, idxOrCount, filters, path);
} else if (const auto levSpell = form->As<RE::TESLevSpell>(); levSpell) {
levSpells.EmplaceForm(isValid, levSpell, idxOrCount, filters, path);
}
});
}

auto& genericForms = INI::configs[RECORD::kForm];

for (auto& rawForm : genericForms) {
Expand Down

0 comments on commit 2f8bc13

Please sign in to comment.