Mercurial > wow > cyborg-mmo7
comparison WowObjects.lua @ 39:ce4ddefb68c2
Fail early when a wow object cannot be created. Default to empty slots rather than empty wow objects.
| author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
|---|---|
| date | Thu, 25 Apr 2013 18:16:03 +0000 |
| parents | d12a5a7d2be5 |
| children | 1a29be548897 |
comparison
equal
deleted
inserted
replaced
| 38:d12a5a7d2be5 | 39:ce4ddefb68c2 |
|---|---|
| 108 | 108 |
| 109 local WowItem_methods = setmetatable({}, {__index=WowObject_methods}) | 109 local WowItem_methods = setmetatable({}, {__index=WowObject_methods}) |
| 110 local WowItem_mt = {__index=WowItem_methods} | 110 local WowItem_mt = {__index=WowItem_methods} |
| 111 | 111 |
| 112 local function WowItem(itemID) | 112 local function WowItem(itemID) |
| 113 local texture = select(10, GetItemInfo(itemID)) -- :FIXME: this may fail too early in the session (like when loading saved data) | |
| 114 if not texture then | |
| 115 return nil | |
| 116 end | |
| 117 | |
| 113 local self = WowObject("item", itemID) | 118 local self = WowObject("item", itemID) |
| 114 | 119 |
| 115 self.itemID = itemID | 120 self.itemID = itemID |
| 116 self.texture = select(10, GetItemInfo(itemID)) -- :FIXME: this may fail too early in the session (like when loading saved data) | 121 self.texture = texture |
| 117 | 122 |
| 118 setmetatable(self, WowItem_mt) | 123 setmetatable(self, WowItem_mt) |
| 119 | 124 |
| 120 return self | 125 return self |
| 121 end | 126 end |
| 136 | 141 |
| 137 local WowSpell_methods = setmetatable({}, {__index=WowObject_methods}) | 142 local WowSpell_methods = setmetatable({}, {__index=WowObject_methods}) |
| 138 local WowSpell_mt = {__index=WowSpell_methods} | 143 local WowSpell_mt = {__index=WowSpell_methods} |
| 139 | 144 |
| 140 local function WowSpell(spellID) | 145 local function WowSpell(spellID) |
| 146 local texture = GetSpellTexture(spellID) | |
| 147 if not texture then | |
| 148 return nil | |
| 149 end | |
| 150 | |
| 141 local self = WowObject("spell", spellID) | 151 local self = WowObject("spell", spellID) |
| 142 | 152 |
| 143 self.spellID = spellID | 153 self.spellID = spellID |
| 144 self.texture = GetSpellTexture(spellID) | 154 self.texture = texture |
| 145 | 155 |
| 146 setmetatable(self, WowSpell_mt) | 156 setmetatable(self, WowSpell_mt) |
| 147 | 157 |
| 148 return self | 158 return self |
| 149 end | 159 end |
| 171 | 181 |
| 172 local WowMacro_methods = setmetatable({}, {__index=WowObject_methods}) | 182 local WowMacro_methods = setmetatable({}, {__index=WowObject_methods}) |
| 173 local WowMacro_mt = {__index=WowMacro_methods} | 183 local WowMacro_mt = {__index=WowMacro_methods} |
| 174 | 184 |
| 175 local function WowMacro(name) | 185 local function WowMacro(name) |
| 186 local texture = select(2, GetMacroInfo(name)) | |
| 187 if not texture then | |
| 188 return nil | |
| 189 end | |
| 190 | |
| 176 local self = WowObject("macro", name) | 191 local self = WowObject("macro", name) |
| 177 | 192 |
| 178 self.name = name | 193 self.name = name |
| 179 self.texture = select(2, GetMacroInfo(name)) | 194 self.texture = texture |
| 180 | 195 |
| 181 setmetatable(self, WowMacro_mt) | 196 setmetatable(self, WowMacro_mt) |
| 182 | 197 |
| 183 return self | 198 return self |
| 184 end | 199 end |
| 202 | 217 |
| 203 local WowCompanion_methods = setmetatable({}, {__index=WowObject_methods}) | 218 local WowCompanion_methods = setmetatable({}, {__index=WowObject_methods}) |
| 204 local WowCompanion_mt = {__index=WowCompanion_methods} | 219 local WowCompanion_mt = {__index=WowCompanion_methods} |
| 205 | 220 |
| 206 local function WowCompanion(spellID) | 221 local function WowCompanion(spellID) |
| 222 local texture = select(3, GetSpellInfo(spellID)) | |
| 223 if not texture then | |
| 224 return nil | |
| 225 end | |
| 226 | |
| 207 local self = WowObject("companion", spellID) | 227 local self = WowObject("companion", spellID) |
| 208 CyborgMMO_DPrint("creating companion binding:", type, spellID) | 228 CyborgMMO_DPrint("creating companion binding:", type, spellID) |
| 209 | 229 |
| 210 self.spellID = spellID | 230 self.spellID = spellID |
| 211 self.texture = select(3, GetSpellInfo(spellID)) | 231 self.texture = texture |
| 212 | 232 |
| 213 setmetatable(self, WowCompanion_mt) | 233 setmetatable(self, WowCompanion_mt) |
| 214 | 234 |
| 215 return self | 235 return self |
| 216 end | 236 end |
| 253 | 273 |
| 254 local WowEquipmentSet_methods = setmetatable({}, {__index=WowObject_methods}) | 274 local WowEquipmentSet_methods = setmetatable({}, {__index=WowObject_methods}) |
| 255 local WowEquipmentSet_mt = {__index=WowEquipmentSet_methods} | 275 local WowEquipmentSet_mt = {__index=WowEquipmentSet_methods} |
| 256 | 276 |
| 257 local function WowEquipmentSet(name) | 277 local function WowEquipmentSet(name) |
| 278 local texture = GetEquipmentSetInfoByName(name) | |
| 279 if not texture then | |
| 280 return nil | |
| 281 end | |
| 282 | |
| 258 local self = WowObject("equipmentset", name) | 283 local self = WowObject("equipmentset", name) |
| 259 | 284 |
| 260 self.name = name | 285 self.name = name |
| 261 local texture = GetEquipmentSetInfoByName(name) | |
| 262 self.texture = "Interface\\Icons\\"..texture | 286 self.texture = "Interface\\Icons\\"..texture |
| 263 | 287 |
| 264 setmetatable(self, WowEquipmentSet_mt) | 288 setmetatable(self, WowEquipmentSet_mt) |
| 265 | 289 |
| 266 return self | 290 return self |
| 286 | 310 |
| 287 local WowBattlePet_methods = setmetatable({}, {__index=WowObject_methods}) | 311 local WowBattlePet_methods = setmetatable({}, {__index=WowObject_methods}) |
| 288 local WowBattlePet_mt = {__index=WowBattlePet_methods} | 312 local WowBattlePet_mt = {__index=WowBattlePet_methods} |
| 289 | 313 |
| 290 local function WowBattlePet(petID) | 314 local function WowBattlePet(petID) |
| 315 local texture = select(9, C_PetJournal.GetPetInfoByPetID(petID)) -- :FIXME: this may fail too early in the session (like when loading saved data) | |
| 316 if not texture then | |
| 317 return nil | |
| 318 end | |
| 319 | |
| 291 local self = WowObject("battlepet", petID) | 320 local self = WowObject("battlepet", petID) |
| 292 CyborgMMO_DPrint("creating battle pet binding:", petID) | 321 CyborgMMO_DPrint("creating battle pet binding:", petID) |
| 293 | 322 |
| 294 self.petID = petID | 323 self.petID = petID |
| 295 self.texture = select(9, C_PetJournal.GetPetInfoByPetID(petID)) -- :FIXME: this may fail too early in the session (like when loading saved data) | 324 self.texture = texture |
| 296 | 325 |
| 297 setmetatable(self, WowBattlePet_mt) | 326 setmetatable(self, WowBattlePet_mt) |
| 298 | 327 |
| 299 return self | 328 return self |
| 300 end | 329 end |
| 371 } | 400 } |
| 372 | 401 |
| 373 ------------------------------------------------------------------------------ | 402 ------------------------------------------------------------------------------ |
| 374 | 403 |
| 375 function CyborgMMO_CreateWowObject(type, ...) | 404 function CyborgMMO_CreateWowObject(type, ...) |
| 376 local object | 405 local object,unsupported |
| 377 | 406 |
| 378 if type == "item" then | 407 if type == "item" then |
| 379 -- :KLUDGE: if the item is not in the cache, return an empty WowObject | 408 object = WowItem(...) |
| 380 local id = ... | |
| 381 if not GetItemInfo(id) then | |
| 382 object = WowObject() | |
| 383 else | |
| 384 object = WowItem(...) | |
| 385 end | |
| 386 elseif type == "macro" then | 409 elseif type == "macro" then |
| 387 object = WowMacro(...) | 410 object = WowMacro(...) |
| 388 elseif type == "spell" then | 411 elseif type == "spell" then |
| 389 object = WowSpell(...) | 412 object = WowSpell(...) |
| 390 elseif type == "companion" then | 413 elseif type == "companion" then |
| 394 elseif type == "battlepet" then | 417 elseif type == "battlepet" then |
| 395 object = WowBattlePet(...) | 418 object = WowBattlePet(...) |
| 396 elseif type == "callback" then | 419 elseif type == "callback" then |
| 397 object = WowCallback(...) | 420 object = WowCallback(...) |
| 398 else | 421 else |
| 399 object = WowObject(type, ...) | 422 CyborgMMO_DPrint("unsupported wow object:", type, ...) |
| 423 unsupported = true | |
| 424 end | |
| 425 if not object and not unsupported then | |
| 426 CyborgMMO_DPrint("creating "..tostring(type).." object failed:", type, ...) | |
| 400 end | 427 end |
| 401 | 428 |
| 402 return object | 429 return object |
| 403 end | 430 end |
| 404 | 431 |
