-
Notifications
You must be signed in to change notification settings - Fork 1
/
Startup.lua
158 lines (135 loc) · 5.74 KB
/
Startup.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
local ADDON_NAME = "FarmingParty"
local FPSettings
local listContainer
local highscoreWindowIsHidden = true
FarmingParty = ZO_Object:Subclass()
FarmingParty.Modules = {}
FarmingParty.DataTypes = {
MEMBER = 1,
MEMBER_ITEM = 2
}
FarmingParty.SaveData = {}
FarmingParty.Settings = {}
local DIGIT_GROUP_REPLACER = ","
local DIGIT_GROUP_DECIMAL_REPLACER = "."
local DIGIT_GROUP_REPLACER_THRESHOLD = zo_pow(10, GetDigitGroupingSize())
-- Because the ZOS function doesn't handle strings and I don't want to reparse the string later to require 2 decimal places.
-- Maybe I can use the ZOS function with some finagling, but I don't feel like doing that right now.
function FP_LocalizeDecimalNumber(amount)
-- Guards against negative 0 as a displayed numeric value
if amount == 0 then
amount = "0"
end
local amountNumber = tonumber(amount)
if amountNumber >= DIGIT_GROUP_REPLACER_THRESHOLD then
-- We have a number like 10000.5, so localize the non-decimal digit group separators (e.g., 10000 becomes 10,000)
local decimalSeparatorIndex = zo_strfind(amount, "%" .. DIGIT_GROUP_DECIMAL_REPLACER) -- Look for the literal separator
local decimalPartString = decimalSeparatorIndex and zo_strsub(amount, decimalSeparatorIndex) or ""
local wholePartString = zo_strsub(amount, 1, decimalSeparatorIndex and decimalSeparatorIndex - 1)
amount = ZO_CommaDelimitNumber(tonumber(wholePartString)) .. decimalPartString
end
return amount
end
function FarmingParty.FormatNumber(num)
return FP_LocalizeDecimalNumber(string.format("%0." .. (FarmingParty.Settings:ValueDecimals() or 2) .. "f", num))
end
local function OnPlayerDeactivated(eventCode)
FarmingParty:Finalize()
end
function FarmingParty:OnAddOnLoaded(event, addonName)
if (addonName ~= ADDON_NAME) then
return
end
ZO_CreateStringId("SI_BINDING_NAME_TOGGLE_SCOREBOARD", "Toggle Scoreboard")
EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_PLAYER_DEACTIVATED, OnPlayerDeactivated)
EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED)
FarmingParty.Settings = FarmingPartySettings:New()
self:Initialize()
end
function FarmingParty:Finalize()
for moduleName, moduleObject in pairs(self.Modules) do
moduleObject:Finalize()
end
if (self.Settings:ResetStatusOnLogout()) then
self.Settings:ToggleStatusValue(FarmingParty.Settings.TRACKING_STATUS.DISABLED)
end
end
function FarmingParty:Initialize()
self.Modules.MemberList = FarmingPartyMemberList:New()
self.Modules.Logger = FarmingPartyLogger:New()
self.Modules.MemberItems = FarmingPartyMemberItems:New()
self.Modules.Loot = FarmingPartyLoot:New()
FarmingParty:ConsoleCommands()
end
function FarmingParty:Prune()
self.Modules.MemberList:PruneMissingMembers()
d("[Farming Party]: Members have been pruned")
end
function FarmingParty:UpdateMembers()
self.Modules.MemberList:PruneMissingMembers()
self.Modules.MemberList:AddAllGroupMembers()
d("[Farming Party]: Members have been updated")
end
function FarmingParty:Reset()
self.Modules.MemberList:Reset()
d("[Farming Party]: Tracking data has been reset")
end
function FarmingParty:ConsoleCommands()
-- Print all available commands to chat
SLASH_COMMANDS["/fphelp"] = function()
d("-- Farming Party commands --")
d("/fp Show or hide the highscore window.")
d("/fp prune Removes members no longer in group. (Useful when tracking is off and you want to remove members who have left.)")
d("/fp reset Resets all loot data.")
d("/fp [start||stop] Start or stop loot tracking.")
d("/fp [status] Show loot tracking status.")
d("/fp update Adds or removes members to match current group. (Useful when tracking is off and you want to update the members.)")
d("/fpc Puts high score output into the chat box.")
end
SLASH_COMMANDS["/fp"] = function(param)
local trimmedParam = string.gsub(param, "%s$", ""):lower()
if(trimmedParam == "") then
self.Modules.MemberList:ToggleMembersWindow()
elseif (trimmedParam == 'prune') then
self:Prune()
elseif (trimmedParam == 'reset') then
self:Reset()
elseif (trimmedParam == 'start') then
if (FarmingParty.Settings:Status() == FarmingParty.Settings.TRACKING_STATUS.DISABLED) then
self.Modules.MemberList:AddEventHandlers()
self.Modules.Loot:AddEventHandlers()
end
d("[Farming Party]: Tracking is on")
elseif (trimmedParam == 'stop' or trimmedParam == 'pause') then
self.Modules.MemberList:RemoveEventHandlers()
self.Modules.Loot:RemoveEventHandlers()
d("[Farming Party]: Tracking is off")
elseif (trimmedParam == 'status') then
if (FarmingParty.Settings:Status() == FarmingParty.Settings.TRACKING_STATUS.ENABLED) then
d("[Farming Party]: Tracking is on")
else
d("[Farming Party]: Tracking is off")
end
elseif (trimmedParam == 'update') then
self:UpdateMembers()
elseif (trimmedParam == 'help') then
SLASH_COMMANDS["/fphelp"]()
else
d(string.format('Invalid parameter %s.', trimmedParam))
SLASH_COMMANDS["/fphelp"]()
end
end
SLASH_COMMANDS["/fpc"] = function()
self.Modules.MemberList:PrintScoresToChat()
end
SLASH_COMMANDS["/fpm"] = function()
FarmingPartyMemberItems:ToggleWindow()
end
end
EVENT_MANAGER:RegisterForEvent(
ADDON_NAME,
EVENT_ADD_ON_LOADED,
function(...)
FarmingParty:OnAddOnLoaded(...)
end
)