@@ -7,6 +7,7 @@ local ipairs = ipairs
77local pairs = pairs
88local select = select
99local t_insert = table.insert
10+ local t_remove = table.remove
1011local m_floor = math.floor
1112local m_min = math.min
1213local m_max = math.max
@@ -64,6 +65,45 @@ function ModDBClass:ReplaceModInternal(mod)
6465 return false
6566end
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+
67107function ModDBClass :AddList (modList )
68108 local mods = self .mods
69109 for i , mod in ipairs (modList ) do
0 commit comments