diff --git a/Core.lua b/Core.lua index fbd69da..553f92e 100644 --- a/Core.lua +++ b/Core.lua @@ -55,6 +55,12 @@ function IE:OnInitialize() -- Register Config Values self:RegisterConfigs() + -- Register Metas + self:RegisterMetas() + + -- Register Items + self:RegisterItems() + -- Register Option Menus self:RegisterMenus() @@ -67,7 +73,7 @@ function IE:OnInitialize() WIN:Hide() TITLE:SetText("InspectEquip") - self:ResetTooltipHookFlags() + self:ResetPOSTFlags() self:RegisterEvent("PLAYER_ENTERING_WORLD") self:RegisterEvent("ADDON_LOADED") @@ -108,7 +114,7 @@ function IE:OnDisable() WIN:Hide() end -function IE:ResetTooltipHookFlags() +function IE:ResetPOSTFlags() IE.dbInitialized = false; IE.tooltipsHooked = false; end @@ -117,8 +123,8 @@ local entered = false function IE:PLAYER_ENTERING_WORLD() entered = true + self:DatabasePOST() self:ScheduleTooltipHook() - self:InitLocalDatabase() self:UnregisterEvent("PLAYER_ENTERING_WORLD") end @@ -636,7 +642,7 @@ function IE:GetItemData(item) if id then local isSrc = IS.Items[id] - local locSrc = InspectEquipLocalDB.Items[id] + local locSrc = self.itemDB.global.Items[id] if isSrc and locSrc then -- combine results return locSrc .. ";" .. isSrc @@ -651,11 +657,11 @@ function IE:GetItemData(item) end function IE:GetZoneName(id) - return IS.Zones[id] or InspectEquipLocalDB.Zones[id] + return IS.Zones[id] or self.itemDB.global.Zones[id] end function IE:GetBossName(id) - return IS.Bosses[id] or InspectEquipLocalDB.Bosses[id] + return IS.Bosses[id] or self.itemDB.global.Bosses[id] end function IE:FixWindowSize() diff --git a/InspectEquip.toc b/InspectEquip.toc index 8b27421..4442df2 100644 --- a/InspectEquip.toc +++ b/InspectEquip.toc @@ -3,13 +3,13 @@ ## Notes: Shows where the equipment of inspected users or yourself is from. ## Notes-deDE: Zeigt an, wo die Ausrüstung betrachteter Spieler (oder deine eigene) her ist. ## Notes-zhCN: 显示被观察者或自己装备的出处。 -## Version: 10.0.2.2 +## Version: 10.0.2.3 ## Author: emelio ## X-Maintainer: Nukme ## X-Repository: https://github.com/Nukme/InspectEquip ## X-NGA_Feedback: https://bbs.nga.cn/read.php?tid=8749947 ## OptionalDeps: Ace3, LibBabble-SubZone-3.0, LibBabble-Boss-3.0, LibItemUpgradeInfo-1.0, Examiner, Outfitter, Links, LinkWrangler, AtlasLoot -## SavedVariables: InspectEquipConfigDB, InspectEquipLocalDB +## SavedVariables: InspectEquipConfigDB, InspectEquipMetaDB, InspectEquipItemDB #@no-lib-strip@ diff --git a/LocalDatabase.lua b/LocalDatabase.lua index 4d0876c..8ae6409 100644 --- a/LocalDatabase.lua +++ b/LocalDatabase.lua @@ -15,9 +15,6 @@ local max = math.max -- check for 5.0+ client, because EJ api was changed local _retail_ = select(4, GetBuildInfo()) >= 70000 --- Database -InspectEquipLocalDB = {} -local ieVersion -- Max wait cycles for database update local MAX_WC = 1 -- 5 @@ -31,32 +28,64 @@ local bar, barText local coUpdate local bar2 -function IE:InitLocalDatabase() - if IE.dbInitialized then - return +local defaults_meta = { + global = { + ClientBuild = nil, + IEVersion = nil, + Locale = nil, + Expansion = nil + } +} + +local defaults_item = { + global = { + Zones = {}, + Bosses = {}, + Items = {} + } +} + +function IE:RegisterMetas() + -- InspectEquip Meta Infomation DBObj + self.metaDB = LibStub("AceDB-3.0"):New("InspectEquipMetaDB", defaults_meta, true) +end + +function IE:AreMetasMatching(clientbuild, ieversion, locale, expansion) + if self.metaDB.global.ClientBuild == clientbuild and self.metaDB.global.IEVersion == ieversion and + self.metaDB.global.Locale == locale and self.metaDB.global.Expansion == expansion then + return true + else + return false end +end - if not InspectEquipLocalDB then - InspectEquipLocalDB = {} +function IE:UpdateMetas(clientbuild, ieversion, locale, expansion) + self.metaDB.global.ClientBuild = clientbuild + self.metaDB.global.IEVersion = ieversion + self.metaDB.global.Locale = locale + self.metaDB.global.Expansion = expansion +end + +function IE:RegisterItems() + -- InspectEquip Item Information DBObj + self.itemDB = LibStub("AceDB-3.0"):New("InspectEquipItemDB", defaults_item, true) +end + +function IE:DatabasePOST() + if IE.dbInitialized then + return end - setmetatable(InspectEquipLocalDB, { - __index = { - Zones = {}, - Bosses = {}, - Items = {} - } - }) - local _, currentBuild = GetBuildInfo() - ieVersion = GetAddOnMetadata("InspectEquip", "Version") + local _, clientbuild = GetBuildInfo() + local ieversion = GetAddOnMetadata("InspectEquip", "Version") + local locale = GetLocale() + local expansion = GetExpansionLevel() - -- create database if not present or outdated (or wrong locale) - if (InspectEquipLocalDB.ClientBuild ~= currentBuild) or (InspectEquipLocalDB.Locale ~= GetLocale()) or - (InspectEquipLocalDB.IEVersion ~= ieVersion) or (InspectEquipLocalDB.Expansion ~= GetExpansionLevel()) then - -- self:CreateLocalDatabase() - self:ScheduleTimer("CreateLocalDatabase", 5) - else + if self:AreMetasMatching(clientbuild, ieversion, locale, expansion) then IE.dbInitialized = true + else + self:ScheduleTimer("CreateLocalDatabase", 5) + self:UpdateMetas(clientbuild, ieversion, locale, expansion) end end @@ -178,7 +207,6 @@ local function EndUpdate() EnableEJ() coUpdate = nil IE:UnregisterEvent("EJ_LOOT_DATA_RECIEVED") - IE.dbInitialized = true; end local function UpdateTick() @@ -287,7 +315,7 @@ end local function SaveToDB(tempDB, entryType) local itemID, sources, entry for itemID, sources in pairs(tempDB) do - local str = InspectEquipLocalDB.Items[itemID] + local str = IE.itemDB.global.Items[itemID] local isEntry = IS.Items[itemID] -- loop through sources we found @@ -305,7 +333,7 @@ local function SaveToDB(tempDB, entryType) end - InspectEquipLocalDB.Items[itemID] = str + IE.itemDB.global.Items[itemID] = str end end @@ -386,12 +414,10 @@ local function UpdateFunction(recursive) IE:RegisterEvent("EJ_LOOT_DATA_RECIEVED") -- init/reset database - local db = InspectEquipLocalDB + local db = IE.itemDB.global db.Zones = {} db.Bosses = {} db.Items = {} - db.NextZoneID = 1000 - db.NextBossID = 1000 -- count total number of instances local insCount = 0 @@ -608,11 +634,6 @@ local function UpdateFunction(recursive) SaveToDB(tempDungeonDB, "d") SaveToDB(tempRaidDB, "r") - local _, currentBuild = GetBuildInfo() - db.ClientBuild = currentBuild - db.Locale = GetLocale() - db.IEVersion = ieVersion - db.Expansion = GetExpansionLevel() UpdateBar() @@ -668,4 +689,6 @@ function IE:CreateLocalDatabase() message("[InspectEquip] Could not update database: " .. msg) end + IE.dbInitialized = true; + end diff --git a/Tooltips.lua b/Tooltips.lua index 1bebb11..4a6a941 100644 --- a/Tooltips.lua +++ b/Tooltips.lua @@ -414,6 +414,7 @@ function IE:AddToTooltip(tip, itemLink) if IE.configDB.global.tooltips == false then return end + addItemData(tip, itemLink, 0) end