Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve merge bp compatibility with removing fields #6637

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions changelog/snippets/fix.6637.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6637) Improve merge blueprint compatibility with removal of enhancements, enhancement presets, and weapon Buffs.
8 changes: 6 additions & 2 deletions lua/sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3207,12 +3207,16 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni
end;

---@param self Unit
---@param enh Enhancement
---@param enh Enhancement | false
---@return boolean
CreateEnhancement = function(self, enh)
-- enh == false due to a merge blueprint
if not enh then
return false
end
local bp = self.Blueprint.Enhancements[enh]
if not bp then
error('*ERROR: Got CreateEnhancement call with an enhancement that doesnt exist in the blueprint.', 2)
WARN(string.format('Got `CreateEnhancement` call with enhancement "%s" that does not exist in the blueprint.\n%s', tostring(enh), debug.traceback()))
return false
end

Expand Down
12 changes: 5 additions & 7 deletions lua/sim/weapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ Weapon = ClassWeapon(WeaponMethods, DebugWeaponComponent) {

-- Add buff
damageTable.Buffs = {}
if weaponBlueprint.Buffs ~= nil then
if weaponBlueprint.Buffs then
for k, v in weaponBlueprint.Buffs do
if not self.DisabledBuffs[v.BuffType] then
damageTable.Buffs[k] = v
Expand Down Expand Up @@ -684,23 +684,21 @@ Weapon = ClassWeapon(WeaponMethods, DebugWeaponComponent) {
DisableBuff = function(self, buffname)
if buffname then
self.DisabledBuffs[buffname] = true
self.damageTableCache = false
else
-- Error
error('ERROR: DisableBuff in weapon.lua does not have a buffname')
error('DisableBuff in weapon.lua does not have a buffname')
end
self.damageTableCache = false
end,

---@param self Weapon
---@param buffname string
ReEnableBuff = function(self, buffname)
if buffname then
self.DisabledBuffs[buffname] = nil
self.damageTableCache = false
else
-- Error
error('ERROR: ReEnableBuff in weapon.lua does not have a buffname')
error('ReEnableBuff in weapon.lua does not have a buffname')
end
self.damageTableCache = false
end,

--- Method to mark weapon when parent unit gets loaded on to a transport unit
Expand Down
3 changes: 3 additions & 0 deletions lua/system/Blueprints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ function HandleUnitWithBuildPresets(bps, all_bps)

for _, bp in bps do
for name, preset in bp.EnhancementPresets do
-- allow removing presets using merge bp
if not preset then continue end

-- start with clean copy of the original unit BP
tempBp = table.deepcopy(bp)

Expand Down
2 changes: 1 addition & 1 deletion lua/ui/dialogs/createunit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ function CreateDialog()

local mouseover = false
local function SetUnitImage(bitmap, id, smol)
local icon = __blueprints[id].Source and (__blueprints[id].Source):gsub('/units/.*', '')..'/textures/ui/common/icons/units/'..id..'_icon.dds'
local icon = UIUtil.UIFile('/textures/ui/common/icons/units/' .. id .. '_icon.dds', true)
local lods = __blueprints[id].Display.Mesh.LODs
local albedo = lods[smol and lods and table.getn(lods) or 1].AlbedoName

Expand Down
5 changes: 4 additions & 1 deletion lua/ui/game/unitviewDetail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ function WrapAndPlaceText(bp, builder, descID, control)
if builder and bp.EnhancementPresetAssigned then
table.insert(lines, LOC('<LOC uvd_upgrades>')..':')
for _, v in bp.EnhancementPresetAssigned.Enhancements do
table.insert(lines, ' '..LOC(bp.Enhancements[v].Name))
local bpEnh = bp.Enhancements[v]
if bpEnh then
table.insert(lines, ' ' .. LOC(bpEnh.Name))
end
end
table.insert(blocks, {color = 'FFB0FFB0', lines = lines})
elseif bp then
Expand Down
4 changes: 2 additions & 2 deletions lua/ui/lobby/UnitsAnalyzer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,8 @@ local function CacheUnit(bp)

-- Extract and cache enhancements so they can be restricted individually
for name, enh in bp.Enhancements or {} do
-- Skip slots or 'removable' enhancements
if name ~= 'Slots' and not string.find(name, 'Remove') then
-- Skip slots, 'Remove' enhancements, and enhancements removed by merging `false`
if enh and name ~= 'Slots' and not string.find(name, 'Remove') then
-- Some enhancements are shared between factions, e.g. Teleporter
-- and other enhancements have different stats and icons
-- depending on faction or whether they are for ACU or SCU
Expand Down
Loading