-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCore.lua
More file actions
122 lines (101 loc) · 2.74 KB
/
Core.lua
File metadata and controls
122 lines (101 loc) · 2.74 KB
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
local _, Core = ...
FS = LibStub("AceAddon-3.0"):NewAddon(Core, "FS")
FS.Util = {}
FS.PTR = GetBuildInfo() == "7.1.0"
LibStub("AceEvent-3.0"):Embed(FS)
LibStub("AceConsole-3.0"):Embed(FS)
FS:SetDefaultModuleLibraries("AceEvent-3.0", "AceConsole-3.0")
local LSM = LibStub("LibSharedMedia-3.0")
LSM:Register("font", "Fira Mono Medium", "Interface\\Addons\\FS_Core\\media\\FiraMono-Medium.ttf")
-- Version
do
local version_str = "@project-version@"
local dev_version = "@project" .. "-version@"
FS.version = version_str == dev_version and "dev" or version_str
end
function Core:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("FSDB", nil, true)
if not self.db.global.PLAYER_KEY then
self.db.global.PLAYER_KEY = "PK:" .. FS:UUID() .. ":" .. time()
end
end
function Core:OnEnable()
self:RegisterEvent("ENCOUNTER_START")
self:RegisterEvent("ENCOUNTER_END")
self:RegisterEvent("GUILD_ROSTER_UPDATE")
self:Printf("Core Loaded [%s]", FS.version)
end
function Core:RegisterModule(name, ...)
local mod = self:NewModule(name, ...)
self[name] = mod
return mod
end
-- Encounter tracking
do
function Core:ENCOUNTER_START(id, name, difficulty, size)
self.encounter = { id = id, name = name, difficulty = difficulty, size = size }
end
function Core:ENCOUNTER_END()
self.encounter = nil
end
function Core:EncounterInProgress()
return self.encounter
end
end
-- Players tracking
do
function Core:NormalizeName(name)
if not name then return name end
return name:match("([^\\-]+)") or name
end
local guild_members = {}
function Core:GUILD_ROSTER_UPDATE()
if self:EncounterInProgress() then return end
wipe(guild_members)
for i = 1, GetNumGuildMembers() do
local name = self:NormalizeName(GetGuildRosterInfo(i))
if name then guild_members[name] = true end
end
end
function Core:UnitIsInGuild(unit)
return guild_members[UnitName(unit) or unit] or false
end
function Core:UnitIsTrusted(unit)
return UnitIsUnit("player", unit)
or UnitIsGroupLeader(unit)
or UnitIsGroupAssistant(unit)
end
end
-- UUID
do
local chars = {}
for i = 48, 57 do chars[#chars + 1] = string.char(i) end
for i = 65, 90 do chars[#chars + 1] = string.char(i) end
for i = 97, 122 do chars[#chars + 1] = string.char(i) end
local floor, random = math.floor, math.random
function Core:UUID(length)
if not length then length = 64 end
local uuid = ""
for i = 1, length do
uuid = uuid .. chars[floor(random() * #chars + 1)]
end
return uuid
end
end
-- PlayerKey
function Core:PlayerKey()
if not self.db then return end
return self.db.global.PLAYER_KEY
end
-- Deep cloning helper
function Core:Clone(source)
local clone = {}
for k, v in pairs(source) do
if type(v) == "table" then
clone[k] = Core:Clone(v)
else
clone[k] = v
end
end
return clone
end