vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 
2 --[[
3  
4 A module can optionally have
5  
6 1) .myevents - a list of strings, the events to register
7 2) .onload - to be called on startup
8 3) .onloadcomplete to be called after all other modules have been loaded.
9 3) .onevent - will do your onevent. Currently sends all events to you, we should fix it to send only your events!
10 4) .onupdate - you can guess this one!
11 5) .isenabled - whether to receive onload, onevent, onupdate commands. Must be <false> to not be called
12  
13  
14 Managing your Variables / Methods
15  
16 --> Initialise static data anywhere in your code file
17 --> Initialise variables that depend on other module's static data in your onload() method
18 --> Initialise variables that depend on other module's variables in your onloadcomplete() method
19  
20  
21 Each module has a key / branch in the master table. The following keys have been taken:
22  
23 ]]
24  
25 -- table setup
26 local mod = thismod
27 local me = { }
28 mod.core = me
29  
30 me.frame = nil -- set at runtime
31  
32 -- Mod Version
33 me.release = 3
34 me.revision = 1
35 me.build = 4
36  
37 --[[
38 Release Build
39 1
40 ]]
41  
42  
43 me.events = { } --[[
44 Remember which module wants which events.
45 It will look like
46 {
47 ["combat"] =
48 {
49 ["CHAT_MSG_SPELL_SELF_BUFF"] = true,
50 },
51 }
52 if the combat module has registered CHAT_MSG_SPELL_SELF_BUFF
53 ]]
54  
55  
56 me.isloaded = false -- true when .onload has been called for all sub-modules
57 me.isenabled = true -- iif false, onupdate and onevent will not be called
58  
59 -- onload
60 mod.onload = function()
61  
62 -- find frame
63 me.frame = getglobal(mod.string.get("print", "core", "frame"))
64  
65 -- initialise all submodules
66 for key, subtable in mod do
67 if type(subtable) == "table" and subtable.onload and subtable.isenabled ~= "false" then
68 subtable.onload()
69 end
70 end
71  
72 me.isloaded = true
73  
74 -- register events. Strictly after all modules have been loaded.
75 for key, subtable in mod do
76 if type(subtable) == "table" and subtable.myevents then
77  
78 me.events[key] = { }
79  
80 for _, event in subtable.myevents do
81 me.frame:RegisterEvent(event)
82 me.events[key][event] = true
83 end
84 end
85 end
86  
87 -- onloadcomplete
88 for key, subtable in mod do
89 if type(subtable) == "table" and subtable.onloadcomplete and subtable.isenabled ~= "false" then
90 subtable.onloadcomplete()
91 end
92 end
93  
94 -- Print load message
95 mod.out.print(string.format(mod.string.get("print", "core", "startupmessage"), me.release, me.revision), nil, true)
96 end
97  
98 -- OnUpdate
99 mod.onupdate = function()
100  
101 -- only call when everything has been loaded
102 if me.isloaded ~= true then
103 return
104 end
105  
106 -- don't call if the entire addon is disabled
107 if me.isenabled == false then
108 return
109 end
110  
111 for key, subtable in mod do
112 if type(subtable) == "table" and subtable.onupdate and subtable.isenabled ~= "false" then
113 subtable.onupdate()
114 end
115 end
116  
117 end
118  
119 -- OnEvent
120 mod.onevent = function()
121  
122 -- don't call if the entire addon is disabled
123 if me.isenabled == false then
124 return
125 end
126  
127 for key, subtable in mod do
128 -- 1) The subtable is a valid module - is a table and has a .onevent property.
129 -- 2) The subtable is not disabled
130 -- 3) The subtable has registered the event
131 if type(subtable) == "table" and subtable.onevent and subtable.isenabled ~= "false" and me.events[key][event] then
132  
133 subtable.onevent()
134 end
135 end
136  
137 end