-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.lua
executable file
·186 lines (142 loc) · 4.7 KB
/
Main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Scorpio "SmallBuff" "0.1"
import "System.Reactive"
import "Scorpio.Secure"
local _Cache = {}
local function GetSpellFromCache(id)
if not _Cache[id] then
local name, _, icon = GetSpellInfo(id)
_Cache[id] = { name = name, icon = icon }
end
return _Cache[id]
end
interface "ICooldownLike"(function(_ENV)
local sharedcd = { start = 0, duration = 0 }
__Abstract__()
property "Cooldown" { type = Number, get = "GetCooldown" }
__Abstract__()
function GetCooldown(self)
sharedcd.start = self.Start
sharedcd.duration = self.Duration
return sharedcd
end
__Abstract__()
property "ID" { type = Number }
__Abstract__()
property "Name" { type = String }
__Abstract__()
property "Icon" { type = String + Number }
__Abstract__()
property "Enabled" { default = true }
__Abstract__()
property "Count" { default = 1 }
end)
class "Cooldown" (function(_ENV)
extend "ICooldownLike"
property "Name" { get = function(self) return GetSpellFromCache(self.ID).name end }
property "Icon" { get = function(self) return GetSpellFromCache(self.ID).icon end }
property "Start" { type = Number }
property "Duration" { type = Number }
property "ExpirationTime" { get = function(self) return self.Start + self.Duration end }
end)
class "Aura"(function(_ENV)
extend "ICooldownLike"
property "Start" { get = function(self) return self.ExpirationTime - self.Duration end }
property "Duration" { type = Number }
property "ExpirationTime" { type = Number }
end)
local cacheSubject = Subject()
local BUFFS_CACHE = { }
local DEBUFFS_CACHE = { }
local function RebuildCache(cache, auraFn, unit)
return function()
wipe(cache)
for i = 1, 40 do
local name, icon, count, buffType, duration, expirationTime, source, _, _, id = auraFn(unit, i)
if not name then break end
-- TODO if unit == target and source != player
if cache[id] then
cache[id].count = cache[id].count + (count or 1)
else
cache[id] = Aura { ID = id, Name = name, Icon = icon, Duration = duration, ExpirationTime = expirationTime, Count = count }
end
end
cacheSubject:OnNext()
end
end
local shareCooldown = Cooldown()
local function CooldownData(id)
local start, duration, enabled = GetSpellCooldown(id)
shareCooldown.ID = id
shareCooldown.Start = start
shareCooldown.Duration = duration
shareCooldown.Enabled = enabled
shareCooldown.Count = GetSpellCharges(id) or 0
return shareCooldown
end
function OnLoad()
local BUILD_PLAYER_CACHE = RebuildCache(BUFFS_CACHE, UnitBuff, "player")
local BUILD_TARGET_CACHE = RebuildCache(DEBUFFS_CACHE, UnitDebuff, "target")
Wow.FromEvent("UNIT_AURA"):MatchUnit("player"):Next():Subscribe(BUILD_PLAYER_CACHE)
Wow.FromEvent("UNIT_AURA"):MatchUnit("target"):Next():Subscribe(BUILD_TARGET_CACHE)
Wow.FromEvent("PLAYER_TARGET_CHANGED"):Subscribe(BUILD_TARGET_CACHE)
-- TODO ACTIONBAR_UPDATE_USABLE? SPELL_UPDATE_USABLE? UPDATE_SHAPESHIFT_COOLDOWN?
Wow.FromEvent(
"ACTIONBAR_UPDATE_COOLDOWN",
"ACTIONBAR_UPDATE_STATE",
"BAG_UPDATE_COOLDOWN",
"PET_BAR_UPDATE_COOLDOWN",
"SPELL_UPDATE_COOLDOWN"
):Next():Subscribe(cacheSubject)
BUILD_PLAYER_CACHE()
BUILD_TARGET_CACHE()
end
class "MixedElementPanelIcon" { Scorpio.Secure.UnitFrame.AuraPanelIcon }
class "MixedElementPanel"(function(_ENV)
inherit "ElementPanel"
__Observable__()
__Indexer__()
property "Data" { set = Toolset.fakefunc, type = ICooldownLike }
local function DataFor(id)
return BUFFS_CACHE[id] or DEBUFFS_CACHE[id] or CooldownData(id)
end
function Refresh(self)
local count = 0
for i, data in self.IDs:Map(DataFor):GetIterator() do
self.Data[i] = data
count = i
end
self.Count = count
end
property "IDs" { default = function () return List[Number]() end, handler = Refresh }
function __ctor(self)
cacheSubject:Subscribe(function () self:Refresh() end)
end
end)
Style.UpdateSkin("Default", {
[MixedElementPanel] = {
elementType = MixedElementPanelIcon,
elementWidth = 20,
elementHeight = 20,
location = { Anchor("CENTER") },
},
[MixedElementPanelIcon] = {
IconTexture = {
setAllPoints = true,
file = Wow.FromPanelProperty("Data"):Map("x=>x.Icon"),
},
Cooldown = {
setAllPoints = true,
enableMouse = false,
cooldown = Wow.FromPanelProperty("Data"):Map("x=>x.Cooldown")
},
Label = {
location = { Anchor("BOTTOM", 0, -12) },
text = Wow.FromPanelProperty("Data"):Map("x=>x.Count"):Map("x=>x > 1 and x or ''")
}
}
})
SMALLBUFF_PANEL = MixedElementPanel("SmallBuffMain")
__SlashCmd__ "sb" "add"
function AddBuff(id) -- TODO from param
SMALLBUFF_PANEL.IDs = List[Number]{ 8143, 5394, 108271, 974 }
end