Skip to content

Commit a5dc118

Browse files
authored
Implement buff icon sync capability (#6838)
1 parent 5b99dab commit a5dc118

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- (#6838) Implement the previously non-functional `BlueprintBuff.Icon` field which syncs the buff name to the UI when it affects a unit.

lua/SimSync.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ end
2020

2121
---@class UnitSyncData
2222
---@field WepPriority? UnitSyncWepPriority
23+
---@field Buffs? BuffName[] # Buffs affecting this unit
2324

2425
-- UnitData that has been synced. We keep a separate copy of this so when we change
2526
-- focus army we can resync the data.

lua/sim/Buff.lua

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,13 @@ function RemoveBuff(unit, buffName, removeAllCounts, instigator)
623623
def:OnBuffRemove(unit, instigator)
624624
end
625625

626-
-- FIXME: This doesn't work because the magic sync table doesn't detect
627-
-- the change. Need to give all child tables magic meta tables too.
628626
if def.Icon then
629627
-- If the user layer was displaying an icon, remove it from the sync table
630-
local newTable = unit.Sync.Buffs
631-
table.removeByValue(newTable, buffName)
632-
unit.Sync.Buffs = table.copy(newTable)
628+
local oldTable = unit.Sync.Buffs
629+
if oldTable then
630+
table.removeByValue(oldTable, buffName)
631+
unit.Sync.Buffs = oldTable
632+
end
633633
end
634634

635635
BuffAffectUnit(unit, buffName, unit, true)
@@ -810,6 +810,16 @@ function ApplyBuff(unit, buffName, instigator)
810810
def:OnApplyBuff(unit, instigator)
811811
end
812812

813+
if def.Icon then
814+
local currentBuffs = unit.Sync.Buffs
815+
if currentBuffs then
816+
table.insert(currentBuffs, buffName)
817+
unit.Sync.Buffs = currentBuffs
818+
else
819+
unit.Sync.Buffs = { buffName }
820+
end
821+
end
822+
813823
BuffAffectUnit(unit, buffName, instigator, false)
814824
end
815825

lua/system/BuffBlueprints.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Buffs = {}
113113
--- table of VFX (not the how the buff affects units)
114114
---@field Effects? FileName[]
115115
---@field EffectsScale? number
116+
---@field Icon? boolean # Syncs the buff name to UnitData when it affects a unit so that the UI can display an icon
116117
BuffDefMeta = {}
117118
BuffDefMeta.__index = BuffDefMeta
118119
BuffDefMeta.__call = function(...)

0 commit comments

Comments
 (0)