-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary.lua
82 lines (73 loc) · 2.48 KB
/
Library.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
------------------------------------------------------
-- ____ _ _ _____ ____
-- / __ \ | | (_) | __ \| _ \
-- | | | |_ _ ___ ___| |_ _ ___| | | | |_) |
-- | | | | | | |/ _ \/ __| __| |/ _ \ | | | _ <
-- | |__| | |_| | __/\__ \ |_| | __/ |__| | |_) |
-- \___\_\\__,_|\___||___/\__|_|\___|_____/|____/
------------------------------------------------------
--* This file is the main file for the QuestieDB library.
--* It contains the main functions for the library.
--
-- The library is split into two namespaces, Public and Private.
--* The Public namespace is the one that is returned when you call LibQuestieDB()
-- The Private namespace is the one that is used internally in the library.
--- The main public namespace for QuestieDB
---@class QuestieDB
---@field public Quest QuestFunctions
---@field public Item ItemFunctions
---@field public Npc NpcFunctions
---@field public Object ObjectFunctions
---@field public ChangeLocale fun(locale: string)
local PublicLibQuestieDB = {
Quest = {},
Item = {},
Npc = {},
Object = {},
}
---Get LibQuestieDB
---@return QuestieDB
function LibQuestieDB()
---@type QuestieDB
return setmetatable(PublicLibQuestieDB, {
__newindex = function(_, _, _)
error("Attempt to write to a read-only table")
end,
})
end
---- Private namespace -----
-- The main namespace class for the QuestieDB library.
---@class LibQuestieDB
local PrivateLibQuestieDB = select(2, ...)
-- Set a metatable to create a new table when a key is accessed
---@private
function PrivateLibQuestieDB:initNamespace()
self = setmetatable(self, {
---@generic T
---@param key `T`
---@return T
__index = function(s, key)
print("Creating Module", key)
s[key] = {}
return s[key]
end,
-- __newindex = function(_, _, _)
-- error("Attempt to write to a read-only table")
-- end
})
end
-- Set the metatable to the namespace
PrivateLibQuestieDB:initNamespace()
PrivateLibQuestieDB.initNamespace = nil -- Remove it, no one should be able to change it
PrivateLibQuestieDB.PublicLibQuestieDB = PublicLibQuestieDB
do
local savedFunction = LibQuestieDB
local checkFunction = function()
if LibQuestieDB ~= savedFunction then
PrivateLibQuestieDB.ColorizePrint("red", "LibQuestieDB was replaced by another addon!")
LibQuestieDB = savedFunction
PrivateLibQuestieDB.ColorizePrint("green", "LibQuestieDB was restored!")
end
end
C_Timer.NewTicker(1, checkFunction)
end