Skip to content

Commit 7bc6645

Browse files
github-actions[bot]EtherealCarnivoreLocalIdentity
authored
Add support for ConvertModInternal (#1777)
* Apply changes from PathOfBuildingCommunity/PathOfBuilding#9517 * Remove unneeded files --------- Co-authored-by: EtherealCarnivore <EtherealCarnivore@users.noreply.github.com> Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent a27925b commit 7bc6645

4 files changed

Lines changed: 76 additions & 0 deletions

File tree

src/Classes/ModDB.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local ipairs = ipairs
77
local pairs = pairs
88
local select = select
99
local t_insert = table.insert
10+
local t_remove = table.remove
1011
local m_floor = math.floor
1112
local m_min = math.min
1213
local m_max = math.max
@@ -64,6 +65,45 @@ function ModDBClass:ReplaceModInternal(mod)
6465
return false
6566
end
6667

68+
---ConvertModInternal
69+
--- Converts an existing mod with oldName to a new mod with a different name.
70+
--- Moves the mod from the old name's bucket to the new name's bucket.
71+
--- If no matching mod exists, then the function returns false
72+
---@param oldName string @The name of the existing mod to find
73+
---@param mod table @The new mod to replace it with
74+
---@return boolean @Whether any mod was converted
75+
function ModDBClass:ConvertModInternal(oldName, mod)
76+
if not self.mods[oldName] then
77+
if self.parent then
78+
return self.parent:ConvertModInternal(oldName, mod)
79+
end
80+
return false
81+
end
82+
83+
local oldList = self.mods[oldName]
84+
for i = 1, #oldList do
85+
local curMod = oldList[i]
86+
if oldName == curMod.name and mod.type == curMod.type and mod.flags == curMod.flags and mod.keywordFlags == curMod.keywordFlags and mod.source == curMod.source and not curMod.converted then
87+
-- Remove from old name's bucket
88+
t_remove(oldList, i)
89+
-- Add to new name's bucket
90+
local newName = mod.name
91+
if not self.mods[newName] then
92+
self.mods[newName] = { }
93+
end
94+
mod.converted = true
95+
t_insert(self.mods[newName], mod)
96+
return true
97+
end
98+
end
99+
100+
if self.parent then
101+
return self.parent:ConvertModInternal(oldName, mod)
102+
end
103+
104+
return false
105+
end
106+
67107
function ModDBClass:AddList(modList)
68108
local mods = self.mods
69109
for i, mod in ipairs(modList) do

src/Classes/ModList.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ function ModListClass:ReplaceModInternal(mod)
4545
return false
4646
end
4747

48+
---ConvertModInternal
49+
--- Converts an existing mod with oldName to a new mod with a different name.
50+
--- If no matching mod exists, then the function returns false
51+
---@param oldName string @The name of the existing mod to find
52+
---@param mod table @The new mod to replace it with
53+
---@return boolean @Whether any mod was converted
54+
function ModListClass:ConvertModInternal(oldName, mod)
55+
for i, curMod in ipairs(self) do
56+
if oldName == curMod.name and mod.type == curMod.type and mod.flags == curMod.flags and mod.keywordFlags == curMod.keywordFlags and mod.source == curMod.source then
57+
self[i] = mod
58+
return true
59+
end
60+
end
61+
62+
if self.parent then
63+
return self.parent:ConvertModInternal(oldName, mod)
64+
end
65+
66+
return false
67+
end
68+
4869
function ModListClass:MergeMod(mod, skipNonAdditive)
4970
if mod.type == "BASE" or mod.type == "INC" or mod.type == "MORE" then
5071
for i = 1, #self do

src/Classes/ModStore.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ function ModStoreClass:ReplaceMod(...)
118118
end
119119
end
120120

121+
---ConvertMod
122+
--- Converts an existing mod to a new name, replacing it in the store.
123+
--- Finds a mod matching oldName with the same type, flags, keywordFlags, and source as the new mod.
124+
--- If no matching mod exists, the new mod is added instead.
125+
---@param oldName string @The name of the existing mod to convert
126+
---@param ... any @Parameters to be passed along to the modLib.createMod function (new name, type, value, source, ...)
127+
function ModStoreClass:ConvertMod(oldName, ...)
128+
local mod = mod_createMod(...)
129+
if not self:ConvertModInternal(oldName, mod) then
130+
self:AddMod(mod)
131+
end
132+
end
133+
121134
function ModStoreClass:Combine(modType, cfg, ...)
122135
if modType == "MORE" then
123136
return self:More(cfg, ...)

src/Modules/CalcPerform.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ local function doActorAttribsConditions(env, actor)
376376
condList["StrHighestAttribute"] = output.Str >= output.Dex and output.Str >= output.Int
377377
condList["IntHighestAttribute"] = output.Int >= output.Str and output.Int >= output.Dex
378378
condList["DexHighestAttribute"] = output.Dex >= output.Str and output.Dex >= output.Int
379+
condList["IntSingleHighestAttribute"] = output.Int > output.Str and output.Int > output.Dex
380+
condList["DexSingleHighestAttribute"] = output.Dex > output.Str and output.Dex > output.Int
379381
end
380382
end
381383

0 commit comments

Comments
 (0)