Mercurial > wow > dependencyloader
comparison DependencyLoader_Core/Addon.lua @ 0:9852fcd5e59e
initial import
| author | mckenziemc |
|---|---|
| date | Tue, 30 Nov 2010 16:13:04 -0800 |
| parents | |
| children | 930871e163bc |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9852fcd5e59e |
|---|---|
| 1 -- Addon | |
| 2 -- Represents individual addon modules | |
| 3 | |
| 4 | |
| 5 local addonName, addonTable = ... | |
| 6 | |
| 7 print("running Addon.lua") | |
| 8 | |
| 9 -- NOTE: I assume that the API addon functions are | |
| 10 -- slightly quicker with an index than with a number. | |
| 11 | |
| 12 -- TODO: modify the dependency stuff to use the Errata module if available | |
| 13 | |
| 14 local Addon, addon = addonTable:NewClass("Addon") | |
| 15 | |
| 16 function Addon:New(id) | |
| 17 assert(type(id) == "number" or type(id) == "string") | |
| 18 | |
| 19 local instance = {} | |
| 20 | |
| 21 setmetatable(instance, self.instanceMetatable) | |
| 22 | |
| 23 if type(id) == "number" then | |
| 24 -- TODO: make sure it's in range | |
| 25 instance.index = id | |
| 26 instance.name = GetAddOnInfo(id) | |
| 27 else | |
| 28 -- FIXME: allow blizzard addons? | |
| 29 local index | |
| 30 | |
| 31 for i=1,GetNumAddOns() do | |
| 32 if GetAddOnInfo(i) == id then | |
| 33 index = i | |
| 34 break | |
| 35 end | |
| 36 end | |
| 37 | |
| 38 if index then | |
| 39 instance.name = GetAddOnInfo(id) | |
| 40 instance.index = index | |
| 41 else | |
| 42 error("Addon not found") | |
| 43 end | |
| 44 end | |
| 45 | |
| 46 return instance | |
| 47 end | |
| 48 | |
| 49 | |
| 50 -- Checks if an addon exists with the specified name. | |
| 51 -- @param addon Name of the addon. | |
| 52 -- @return True if the addon is present, false otherwise. | |
| 53 function Addon:Exists(addon) | |
| 54 if type(addon) == "number" then | |
| 55 if addon >= 1 and addon <= GetNumAddOns() then | |
| 56 return true | |
| 57 else | |
| 58 return false | |
| 59 end | |
| 60 elseif type(addon) == "string" then | |
| 61 local status = select(6, GetAddOnInfo(addon)) | |
| 62 | |
| 63 if status == "MISSING" then | |
| 64 return false | |
| 65 else | |
| 66 return true | |
| 67 end | |
| 68 else | |
| 69 error() | |
| 70 end | |
| 71 end | |
| 72 | |
| 73 | |
| 74 function addon:GetName() | |
| 75 return self.name | |
| 76 end | |
| 77 | |
| 78 | |
| 79 function addon:GetIndex() | |
| 80 return self.index | |
| 81 end | |
| 82 | |
| 83 | |
| 84 function addon:IsEnabled() | |
| 85 -- FIXME: written while tired; review later | |
| 86 local status = select(6, GetAddOnInfo(self.index)) | |
| 87 | |
| 88 if status == "DISABLED" then | |
| 89 return false | |
| 90 else | |
| 91 return true | |
| 92 end | |
| 93 end | |
| 94 | |
| 95 -- FIXME: an addon may be present but unloadable if loading out of date addons is disabled. | |
| 96 -- NOTE: CanForceLoad and CanLoD don't check the status of dependencies | |
| 97 | |
| 98 function addon:CanForceLoad() | |
| 99 return true -- TODO: check if there's any reason addons can't be forceloaded | |
| 100 end | |
| 101 | |
| 102 function addon:CanLoD() | |
| 103 -- FIXME: what will the client say about addons using LoadManagers if the LM was force-loaded? | |
| 104 if IsAddOnLoadOnDemand(self.name) then | |
| 105 return true | |
| 106 else | |
| 107 return false | |
| 108 end | |
| 109 end | |
| 110 | |
| 111 -- NOTE: only call for LoD, not force-loading | |
| 112 function addon:Load() | |
| 113 assert(self:CanLoD()) | |
| 114 | |
| 115 EnableAddOn(self.name) | |
| 116 LoadAddOn(self.name) | |
| 117 end | |
| 118 | |
| 119 function addon:ForceLoad() | |
| 120 assert(self:CanForceLoad()) | |
| 121 -- TODO: make sure force-loading is available at this time | |
| 122 | |
| 123 EnableAddOn(self.name) -- This should cause the game to also load this addon | |
| 124 end | |
| 125 | |
| 126 | |
| 127 function addon:GetDependencies() | |
| 128 return GetAddOnDependencies(self.index) | |
| 129 end | |
| 130 | |
| 131 | |
| 132 function addon:GetEmbeds() | |
| 133 local embeds = {} | |
| 134 | |
| 135 local embedString = GetAddOnMetadata(self.name, "X-Embeds") | |
| 136 | |
| 137 if embedString then | |
| 138 for match in string.gmatch(embedString, "[^,%s]+") do | |
| 139 table.insert(embeds, match) | |
| 140 end | |
| 141 end | |
| 142 | |
| 143 return unpack(embeds) | |
| 144 end | |
| 145 | |
| 146 function addon:IsLoaded() | |
| 147 if IsAddOnLoaded(self.index) then | |
| 148 return true | |
| 149 else | |
| 150 return false | |
| 151 end | |
| 152 end |
