Skip to content

Commit

Permalink
More annotation and grouploot stuff.
Browse files Browse the repository at this point in the history
Print binary status every potential roll
  • Loading branch information
evil-morfar committed Sep 5, 2024
1 parent d679ecb commit 7f54b18
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 71 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@
"require",
"tInsertUnique",
"CLOSE",
"LOOT_ITEM"
"LOOT_ITEM",
"ToggleDropDownMenu",
"UIDropDownMenu_HandleGlobalMouseEvent",
"CloseMenus",
"ColorPickerFrame",
"VIDEO_QUALITY_LABEL6",
"DEFAULT_CHAT_FRAME"
],
"Lua.diagnostics.disable": [
"undefined-doc-name",
Expand Down
39 changes: 20 additions & 19 deletions Classes/Lib/RxLua/Observer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,46 @@ local util = addon.Require("rx.Util")
-- @description Observers are simple objects that receive values from Observables.
local Observer = addon.Init("rx.Observer")
Observer.__index = Observer
Observer.__tostring = util.constant('Observer')
Observer.__tostring = util.constant("Observer")

--- Creates a new Observer.
-- @arg {function=} onNext - Called when the Observable produces a value.
-- @arg {function=} onError - Called when the Observable terminates due to an error.
-- @arg {function=} onCompleted - Called when the Observable completes normally.
-- @returns {Observer}
function Observer.create(onNext, onError, onCompleted)
local self = {
_onNext = onNext or util.noop,
_onError = onError or error,
_onCompleted = onCompleted or util.noop,
stopped = false
}
---@class rx.Observer
local self = {
_onNext = onNext or util.noop,
_onError = onError or error,
_onCompleted = onCompleted or util.noop,
stopped = false,
}

return setmetatable(self, Observer)
return setmetatable(self, Observer)
end

--- Pushes zero or more values to the Observer.
-- @arg {*...} values
function Observer:onNext(...)
if not self.stopped then
self._onNext(...)
end
if not self.stopped then
self._onNext(...)
end
end

--- Notify the Observer that an error has occurred.
-- @arg {string=} message - A string describing what went wrong.
function Observer:onError(message)
if not self.stopped then
self.stopped = true
self._onError(message)
end
if not self.stopped then
self.stopped = true
self._onError(message)
end
end

--- Notify the Observer that the sequence has completed and will produce no more values.
function Observer:onCompleted()
if not self.stopped then
self.stopped = true
self._onCompleted()
end
if not self.stopped then
self.stopped = true
self._onCompleted()
end
end
91 changes: 45 additions & 46 deletions Classes/Lib/RxLua/Subjects/Subject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,75 @@ local util = addon.Require("rx.Util")
-- be broadcasted to any subscribed Observers.
local Subject = setmetatable(addon.Init("rx.Subject"), Observable)
Subject.__index = Subject
Subject.__tostring = util.constant('Subject')
Subject.__tostring = util.constant("Subject")

--- Creates a new Subject.
-- @returns {Subject}
function Subject.create()
local self = {
observers = {},
stopped = false
}

return setmetatable(self, Subject)
---@class rx.Subject
local self = {
observers = {},
stopped = false,
}
return setmetatable(self, Subject)
end

--- Creates a new Observer and attaches it to the Subject.
-- @arg {function|table} onNext|observer - A function called when the Subject produces a value or
-- an existing Observer to attach to the Subject.
-- @arg {function} onError - Called when the Subject terminates due to an error.
-- @arg {function} onCompleted - Called when the Subject completes normally.
--- @param onNext function|rx.Observer A function called when the Subject produces a value or
--- an existing Observer to attach to the Subject.
--- @param onError function Called when the Subject terminates due to an error.
--- @param onCompleted function Called when the Subject completes normally.
function Subject:subscribe(onNext, onError, onCompleted)
local observer
local observer

if util.isa(onNext, Observer) then
observer = onNext
else
observer = Observer.create(onNext, onError, onCompleted)
end
if util.isa(onNext, Observer) then
observer = onNext
else
observer = Observer.create(onNext, onError, onCompleted)
end

table.insert(self.observers, observer)
table.insert(self.observers, observer)

return Subscription.create(function()
for i = 1, #self.observers do
if self.observers[i] == observer then
table.remove(self.observers, i)
return
end
end
end)
return Subscription.create(function()
for i = 1, #self.observers do
if self.observers[i] == observer then
table.remove(self.observers, i)
return
end
end
end)
end

--- Pushes zero or more values to the Subject. They will be broadcasted to all Observers.
-- @arg {*...} values
--- @param ... any values
function Subject:onNext(...)
if not self.stopped then
for i = #self.observers, 1, -1 do
self.observers[i]:onNext(...)
end
end
if not self.stopped then
for i = #self.observers, 1, -1 do
self.observers[i]:onNext(...)
end
end
end

--- Signal to all Observers that an error has occurred.
-- @arg {string=} message - A string describing what went wrong.
--- @param message string? A string describing what went wrong.
function Subject:onError(message)
if not self.stopped then
for i = #self.observers, 1, -1 do
self.observers[i]:onError(message)
end
if not self.stopped then
for i = #self.observers, 1, -1 do
self.observers[i]:onError(message)
end

self.stopped = true
end
self.stopped = true
end
end

--- Signal to all Observers that the Subject will not produce any more values.
function Subject:onCompleted()
if not self.stopped then
for i = #self.observers, 1, -1 do
self.observers[i]:onCompleted()
end
if not self.stopped then
for i = #self.observers, 1, -1 do
self.observers[i]:onCompleted()
end

self.stopped = true
end
self.stopped = true
end
end

Subject.__call = Subject.onNext
Expand Down
1 change: 1 addition & 0 deletions Classes/Lib/RxLua/Util.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--- @type RCLootCouncil
local addon = select(2, ...)
---@class rx.Util
local util = addon.Init("rx.Util")

util.pack = table.pack or function(...) return { n = select('#', ...), ... } end
Expand Down
8 changes: 4 additions & 4 deletions Classes/Utils/GroupLoot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local ItemUtils = addon.Require "Utils.Item"
--- @class OnLootRoll
--- Called everytime we're auto rolling for loot.
--- Subscriber functions are called with args: `itemLink` ,`rollID`, `rollType`
--- @field subscribe fun(onNext: fun(link:ItemLink, rollID:integer, rollType:RollType), onError:fun(message:string), onComplete:fun()): rx.Subscription
--- @field subscribe fun(self:OnLootRoll, onNext: fun(link:ItemLink, rollID:integer, rollType:RollType), onError:fun(message:string), onComplete:fun()): rx.Subscription
GroupLoot.OnLootRoll = Subject.create()

--- @type table<integer, boolean>
Expand Down Expand Up @@ -48,9 +48,9 @@ function GroupLoot:OnStartLootRoll(_, rollID)
self.Log:d(link, "is ignored, bailing.")
return
end
local binStatus = self:GetStatusBinary()
self.Log:D("Status:", self:GetStatusBinary())
if self:ShouldPassOnLoot() then
self.Log:d("Passing on loot", link, binStatus)
self.Log:d("Passing on loot", link)
self:RollOnLoot(rollID, 0)
self.OnLootRoll(link, rollID, 0)
elseif self:ShouldRollOnLoot() then
Expand All @@ -63,7 +63,7 @@ function GroupLoot:OnStartLootRoll(_, rollID)
else
roll = 2
end
self.Log:d("Rolling on loot", link, roll, binStatus)
self.Log:d("Rolling on loot", link, roll)
self:RollOnLoot(rollID, roll)
self.OnLootRoll(link, rollID, roll)
end
Expand Down
2 changes: 1 addition & 1 deletion core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ end
--- Returns the active module if found or fails silently.
--- Always use this when calling functions in another module.
--- @param module DefaultModules|UserModules Index in self.defaultModules.
--- @return AceAddon? #The module object of the active module or nil if not found. Prioritises userModules if set.
--- @return AceModule? #The module object of the active module or nil if not found. Prioritises userModules if set.
function RCLootCouncil:GetActiveModule(module)
return self:GetModule(userModules[module] or defaultModules[module], false)
end
Expand Down

0 comments on commit 7f54b18

Please sign in to comment.