vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --------------------- |
2 | -- Helper Function -- |
||
3 | --------------------- |
||
4 | |||
5 | -- ReagentData_Flatten(table) |
||
6 | -- |
||
7 | -- This function takes a two-dimensional table and flattens it. This is |
||
8 | -- necessary due to the way profession tables are built (to assist in |
||
9 | -- maintainability). If necessary, this function can be extended to an |
||
10 | -- n-dimensional table by way of recursion, though this requires a minor |
||
11 | -- logic change and will not be done unless necessary. |
||
12 | |||
13 | function ReagentData_Flatten(table) |
||
14 | if (type(table) ~= "table") then |
||
15 | return; |
||
16 | end |
||
17 | |||
18 | local returnTable = {}; |
||
19 | |||
20 | for key,value in table do |
||
21 | if (type(value) == "table") then |
||
22 | for subKey, subValue in value do |
||
23 | tinsert(returnTable, subValue); |
||
24 | end |
||
25 | else |
||
26 | tinsert(returnTable, value); |
||
27 | end |
||
28 | end |
||
29 | |||
30 | return returnTable; |
||
31 | end |
||
32 | |||
33 | ReagentData = {}; |
||
34 | ReagentData['crafted'] = {}; |
||
35 | |||
36 | -- Reagent Data: Version |
||
37 | ReagentData['version'] = "2.4.0c"; |
||
38 | |||
39 | -- Now perform localizations if needed |
||
40 | if (GetLocale() == "deDE") then |
||
41 | ReagentData_LoadGerman(); |
||
42 | elseif (GetLocale() == "frFR") then |
||
43 | ReagentData_LoadFrench(); |
||
44 | elseif (GetLocale() == "zhCN") then |
||
45 | ReagentData_LoadChinese(); |
||
46 | else |
||
47 | ReagentData_LoadEnglish(); |
||
48 | end |
||
49 | |||
50 | --------------- |
||
51 | -- Functions -- |
||
52 | --------------- |
||
53 | |||
54 | ------------------------ |
||
55 | -- EXTERNAL FUNCTIONS -- |
||
56 | ------------------------ |
||
57 | |||
58 | -- ReagentData_ClassSpellReagent(item) |
||
59 | -- |
||
60 | -- This function takes an item name (such as "Fish Oil") and returns |
||
61 | -- an array of classes that use the reagent {"Shaman"}. It returns the |
||
62 | -- translated text version of the name. |
||
63 | |||
64 | function ReagentData_ClassSpellReagent(item) |
||
65 | if (item == nil or ReagentData['spellreagents'] == nil) then |
||
66 | return; |
||
67 | end |
||
68 | |||
69 | local returnArray = {}; |
||
70 | |||
71 | for class, subtable in ReagentData['spellreagents'] do |
||
72 | for key, value in subtable do |
||
73 | if (value == item) then |
||
74 | tinsert(returnArray, class); |
||
75 | end |
||
76 | end |
||
77 | end |
||
78 | |||
79 | return returnArray; |
||
80 | end |
||
81 | |||
82 | -- ReagentData_GatheredBy(item) |
||
83 | -- |
||
84 | -- This function takes an item name (such as "Light Leather") and returns |
||
85 | -- an array of gather skills that are used to gather the item. For example, |
||
86 | -- calling ReagentData_GatheredBy("Light Leather") on an English client |
||
87 | -- will return {"Skinning"}. Results are not sorted, so be sure to run them |
||
88 | -- through table.sort if you want them in alphabetical order. |
||
89 | -- |
||
90 | -- I can't think of any items that are gathered by more than one skill, but |
||
91 | -- this way the function behaves the same as other API calls and is flexible |
||
92 | -- in case we can one day skin herbs or something. |
||
93 | |||
94 | function ReagentData_GatheredBy(item) |
||
95 | if (item == nil) then |
||
96 | return; |
||
97 | end |
||
98 | |||
99 | local returnArray = {}; |
||
100 | |||
101 | for profession in ReagentData['gathering'] do |
||
102 | if (ReagentData[profession] ~= nil) then |
||
103 | for key, value in ReagentData[profession] do |
||
104 | if (value == item) then |
||
105 | tinsert(returnArray, ReagentData['gathering'][profession]); |
||
106 | break; |
||
107 | end |
||
108 | end |
||
109 | end |
||
110 | end |
||
111 | |||
112 | return returnArray; |
||
113 | end |
||
114 | |||
115 | -- ReagentData_GetItemClass(class) |
||
116 | -- |
||
117 | -- Returns the data array for the requested item class. This is the |
||
118 | -- Reagent Data name for the item, NOT the translated name. This means |
||
119 | -- you'll need to run it through ReagentData['reverseprofessions'] or |
||
120 | -- ReagentData['reversegatherskills'] first. This function does NOT |
||
121 | -- flatten the returned function either, so keep that in mind when loading |
||
122 | -- professions; it doesn't apply to base classes such as ReagentData['bar']. |
||
123 | -- |
||
124 | -- Most authors will simply want to access the ReagentData tables directly |
||
125 | -- instead of using this function, but it's provided anyway. |
||
126 | |||
127 | function ReagentData_GetItemClass(class) |
||
128 | if (class == nil or ReagentData[class] == nil) then |
||
129 | return; |
||
130 | end |
||
131 | |||
132 | return ReagentData[class]; |
||
133 | end |
||
134 | |||
135 | -- ReagentData_GetProfessions(item) |
||
136 | -- |
||
137 | -- Returns a table that contains a translated list of all professions |
||
138 | -- that use the specified item. For example, calling |
||
139 | -- ReagentData_GetProfessions("Light Leather") on an English client |
||
140 | -- will return {"Blacksmithing", "Engineering", "Leatherworking", "Tailoring"}. |
||
141 | -- Results are not sorted, so be sure to run them through table.sort if you |
||
142 | -- want them in alphabetical order. |
||
143 | |||
144 | function ReagentData_GetProfessions(item) |
||
145 | if (item == nil) then |
||
146 | return; |
||
147 | end |
||
148 | |||
149 | local returnArray = {}; |
||
150 | |||
151 | for profession in ReagentData['professions'] do |
||
152 | if (ReagentData[profession] ~= nil) then |
||
153 | for key, value in ReagentData[profession] do |
||
154 | if (value == item) then |
||
155 | tinsert(returnArray, ReagentData['professions'][profession]); |
||
156 | break; |
||
157 | end |
||
158 | end |
||
159 | end |
||
160 | end |
||
161 | |||
162 | return returnArray; |
||
163 | end |
||
164 | |||
165 | -- ReagentData_GetSpellReagents(class) |
||
166 | -- |
||
167 | -- Returns a table that contains all spell reagents used by the specified |
||
168 | -- class. For example, calling ReagentData_GetSpellReagents("shaman"} |
||
169 | -- will return {"Ankh", "Fish Oil", "Shiny Fish Scales"}. If class |
||
170 | -- is omitted or specified as "all", all classes and spell reagents will |
||
171 | -- be returned in a multi-dimensional array. |
||
172 | |||
173 | function ReagentData_GetSpellReagents(class) |
||
174 | if (class == nil) then |
||
175 | class = "all"; |
||
176 | end |
||
177 | |||
178 | if (class == "all") then |
||
179 | return ReagentData['spellreagents']; |
||
180 | end |
||
181 | |||
182 | for key, value in ReagentData['spellreagents'] do |
||
183 | if (key == class) then |
||
184 | return value; |
||
185 | end |
||
186 | end |
||
187 | |||
188 | return nil; |
||
189 | end |
||
190 | |||
191 | -- ReagentData_IsMonsterDrop(item) |
||
192 | -- |
||
193 | -- A Boolean function that indicates if the specified item is primarily |
||
194 | -- obtained from monster drops. Item is expected to be a localized string |
||
195 | -- such as "Tiger Meat". |
||
196 | |||
197 | function ReagentData_IsMonsterDrop(item) |
||
198 | if (item == nil or ReagentData['monsterdrops'] == nil) then |
||
199 | return false; |
||
200 | end |
||
201 | |||
202 | for key, value in ReagentData['monsterdrops'] do |
||
203 | if (value == item) then |
||
204 | return true; |
||
205 | end |
||
206 | end |
||
207 | |||
208 | return false; |
||
209 | end |
||
210 | |||
211 | -- ReagentData_IsUsedByProfession(item, profession) |
||
212 | -- |
||
213 | -- A Boolean function that indicates if the specified profession |
||
214 | -- uses the specified item. Both profession and item are expected |
||
215 | -- to be the localized text version of the name (such as |
||
216 | -- "Copper Bar" and "Blacksmithing"). |
||
217 | |||
218 | function ReagentData_IsUsedByProfession(item, profession) |
||
219 | -- If we have nil arguments, just return false. |
||
220 | if (item == nil or profession == nil) then |
||
221 | return false; |
||
222 | end |
||
223 | |||
224 | -- Now make sure we were passed a valid profession |
||
225 | if (ReagentData['reverseprofessions'] == nil or ReagentData['reverseprofessions'][profession] == nil) then |
||
226 | return false; |
||
227 | end |
||
228 | |||
229 | -- Check to see if the requested item is in the array. If so, return true. |
||
230 | for key, value in ReagentData[ReagentData['reverseprofessions'][profession]] do |
||
231 | if (value == item) then |
||
232 | return true; |
||
233 | end |
||
234 | end |
||
235 | |||
236 | -- If we've gotten here, it's not in the requested profession, so return false. |
||
237 | return false; |
||
238 | end |
||
239 | |||
240 | -- ReagentData_IsVendorItem(item) |
||
241 | -- |
||
242 | -- A Boolean function that indicates if the specified item is primarily |
||
243 | -- obtained from vendors. Item is expected to be a localized string such as "Heavy Stock". |
||
244 | |||
245 | function ReagentData_IsVendorItem(item) |
||
246 | if (item == nil or ReagentData['vendor'] == nil) then |
||
247 | return false; |
||
248 | end |
||
249 | |||
250 | for key, value in ReagentData['vendor'] do |
||
251 | if (value == item) then |
||
252 | return true; |
||
253 | end |
||
254 | end |
||
255 | |||
256 | return false; |
||
257 | end |
||
258 | |||
259 | ------------------------ |
||
260 | -- INTERNAL FUNCTIONS -- |
||
261 | ------------------------ |
||
262 | |||
263 | -- Not only do you not need to touch these function, but they're localized |
||
264 | -- to Reagent Data to prevent any confusion. :-) |
||
265 | |||
266 | -- ReagentData_CreateReverseProfessions() |
||
267 | -- |
||
268 | -- Creates the ReagentData['reverseprofessions'] array. |
||
269 | |||
270 | local function ReagentData_CreateReverseProfessions() |
||
271 | if (ReagentData['professions'] == nil) then |
||
272 | return; |
||
273 | end |
||
274 | |||
275 | local returnArray = {}; |
||
276 | |||
277 | for key, profession in ReagentData['professions'] do |
||
278 | returnArray[profession] = key; |
||
279 | end |
||
280 | |||
281 | return returnArray; |
||
282 | end |
||
283 | |||
284 | -- ReagentData_CreateReverseGatherSkills() |
||
285 | -- |
||
286 | -- Creates the ReagentData['reversegathering'] array. |
||
287 | |||
288 | local function ReagentData_CreateReverseGatherSkills() |
||
289 | if (ReagentData['gathering'] == nil) then |
||
290 | return; |
||
291 | end |
||
292 | |||
293 | local returnArray = {}; |
||
294 | |||
295 | for key, profession in ReagentData['gathering'] do |
||
296 | returnArray[profession] = key; |
||
297 | end |
||
298 | |||
299 | return returnArray; |
||
300 | end |
||
301 | |||
302 | --------------------- |
||
303 | -- Execution Block -- |
||
304 | --------------------- |
||
305 | |||
306 | -- ReagentData['reverseprofessions'] |
||
307 | -- |
||
308 | -- This array allows you to translated the localized text version of a profession |
||
309 | -- into the index used by Reagent Data. This is useful if your addon has the localized |
||
310 | -- version ("Blacksmithing") and would like to access the associated data array. You |
||
311 | -- could do this via ReagentData[ReagentData['reverseprofessions']["Blacksmithing"]]. |
||
312 | |||
313 | ReagentData['reverseprofessions'] = ReagentData_CreateReverseProfessions(); |
||
314 | |||
315 | -- ReagentData['reversegathering'] |
||
316 | -- |
||
317 | -- This array allows you to translated the localized text version of a gather skill |
||
318 | -- into the index used by Reagent Data. This is useful if your addon has the localized |
||
319 | -- version ("Mining") and would like to access the associated data array. You |
||
320 | -- could do this via ReagentData[ReagentData['reversegathering']["Mining"]]. |
||
321 | |||
322 | ReagentData['reversegathering'] = ReagentData_CreateReverseGatherSkills(); |