vanilla-wow-addons – Blame information for rev 1
?pathlinks?
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 | out |
||
23 | alert |
||
24 | console |
||
25 | string |
||
26 | combat |
||
27 | data |
||
28 | my |
||
29 | table |
||
30 | net, netin |
||
31 | gui, guiopt, guiraid, some other gui |
||
32 | boss |
||
33 | diag |
||
34 | ]] |
||
35 | |||
36 | -- table setup |
||
37 | klhtm = { } |
||
38 | local me = klhtm |
||
39 | me.frame = nil -- set at runtime |
||
40 | |||
41 | -- Mod Version |
||
42 | me.release = 17 |
||
43 | me.revision = 12 |
||
44 | me.build = 203 |
||
45 | |||
46 | --[[ |
||
47 | Release Build |
||
48 | 1 6 |
||
49 | 2 11 |
||
50 | 3 30 |
||
51 | 4 32 |
||
52 | 5 44 |
||
53 | 6 54 |
||
54 | 7 73 |
||
55 | 8 80 |
||
56 | 9 92 |
||
57 | 10 103 |
||
58 | 11 116 |
||
59 | 12 124 |
||
60 | 13 141 |
||
61 | 14 156 |
||
62 | 15 177 |
||
63 | 16 189 |
||
64 | 16b 192 |
||
65 | ]] |
||
66 | |||
67 | |||
68 | me.events = { } --[[ |
||
69 | Remember which module wants which events. |
||
70 | It will look like |
||
71 | { |
||
72 | ["combat"] = |
||
73 | { |
||
74 | ["CHAT_MSG_SPELL_SELF_BUFF"] = true, |
||
75 | }, |
||
76 | } |
||
77 | if the combat module has registered CHAT_MSG_SPELL_SELF_BUFF |
||
78 | ]] |
||
79 | |||
80 | -- This checks whether you are on the 0.12 PTR or 1.12+ live (vs 1.11 live) |
||
81 | if SendAddonMessage then |
||
82 | me.isnewwowversion = true |
||
83 | end |
||
84 | |||
85 | me.isloaded = false -- true when .onload has been called for all sub-modules |
||
86 | me.isenabled = true -- iif false, onupdate and onevent will not be called |
||
87 | |||
88 | -- onload |
||
89 | me.onload = function() |
||
90 | |||
91 | -- find frame |
||
92 | me.frame = KLHTM_OnUpdateFrame |
||
93 | |||
94 | -- initialise all submodules |
||
95 | for key, subtable in me do |
||
96 | if type(subtable) == "table" and subtable.onload and subtable.isenabled ~= "false" then |
||
97 | subtable.onload() |
||
98 | end |
||
99 | end |
||
100 | |||
101 | me.isloaded = true |
||
102 | |||
103 | -- register events. Strictly after all modules have been loaded. |
||
104 | for key, subtable in me do |
||
105 | if type(subtable) == "table" and subtable.myevents then |
||
106 | |||
107 | me.events[key] = { } |
||
108 | |||
109 | for _, event in subtable.myevents do |
||
110 | me.frame:RegisterEvent(event) |
||
111 | me.events[key][event] = true |
||
112 | end |
||
113 | end |
||
114 | end |
||
115 | |||
116 | -- onloadcomplete |
||
117 | for key, subtable in me do |
||
118 | if type(subtable) == "table" and subtable.onloadcomplete and subtable.isenabled ~= "false" then |
||
119 | subtable.onloadcomplete() |
||
120 | end |
||
121 | end |
||
122 | |||
123 | -- Print load message |
||
124 | me.out.print(string.format(me.string.get("print", "main", "startupmessage"), me.release, me.revision), nil, true) |
||
125 | |||
126 | -- notify of 1.12 override |
||
127 | if me.isnewwowversion then |
||
128 | me.out.print("The WoW version is 0.12 or 1.12 or higher, so the mod is using multiplicative threat and no longer using a chat channel for communication.") |
||
129 | end |
||
130 | |||
131 | end |
||
132 | |||
133 | -- OnUpdate |
||
134 | me.onupdate = function() |
||
135 | |||
136 | -- only call when everything has been loaded |
||
137 | if me.isloaded ~= true then |
||
138 | return |
||
139 | end |
||
140 | |||
141 | -- don't call if the entire addon is disabled |
||
142 | if me.isenabled == false then |
||
143 | return |
||
144 | end |
||
145 | |||
146 | for key, subtable in me do |
||
147 | if type(subtable) == "table" and subtable.onupdate and subtable.isenabled ~= "false" then |
||
148 | me.diag.logmethodcall(key, "onupdate") |
||
149 | end |
||
150 | end |
||
151 | |||
152 | end |
||
153 | |||
154 | -- OnEvent |
||
155 | me.onevent = function() |
||
156 | |||
157 | -- don't call if the entire addon is disabled |
||
158 | if me.isenabled == false then |
||
159 | return |
||
160 | end |
||
161 | |||
162 | for key, subtable in me do |
||
163 | -- 1) The subtable is a valid module - is a table and has a .onevent property. |
||
164 | -- 2) The subtable is not disabled |
||
165 | -- 3) The subtable has registered the event |
||
166 | if type(subtable) == "table" and subtable.onevent and subtable.isenabled ~= "false" and me.events[key][event] then |
||
167 | |||
168 | me.diag.logmethodcall(key, "onevent") |
||
169 | end |
||
170 | end |
||
171 | |||
172 | end |
||
173 | |||
174 | --[[ |
||
175 | klhtm.emergencystop() |
||
176 | Stops all processing of events and onupdates. Just in case! This is unlocalised and raw to make sure it works even if there are errors elsewhere in the program. |
||
177 | ]] |
||
178 | me.emergencystop = function() |
||
179 | |||
180 | me.isenabled = false |
||
181 | |||
182 | ChatFrame1:AddMessage("KLHThreatMeter emergency stop! |cffffff00/ktm|r e to resume.") |
||
183 | |||
184 | end |