Skip to content

Commit

Permalink
use acedb for meta and item dbs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukme committed Nov 20, 2022
1 parent 71417ed commit 4126bd1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 42 deletions.
18 changes: 12 additions & 6 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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")
Expand Down Expand Up @@ -108,7 +114,7 @@ function IE:OnDisable()
WIN:Hide()
end

function IE:ResetTooltipHookFlags()
function IE:ResetPOSTFlags()
IE.dbInitialized = false;
IE.tooltipsHooked = false;
end
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions InspectEquip.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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@
Expand Down
91 changes: 57 additions & 34 deletions LocalDatabase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -178,7 +207,6 @@ local function EndUpdate()
EnableEJ()
coUpdate = nil
IE:UnregisterEvent("EJ_LOOT_DATA_RECIEVED")
IE.dbInitialized = true;
end

local function UpdateTick()
Expand Down Expand Up @@ -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
Expand All @@ -305,7 +333,7 @@ local function SaveToDB(tempDB, entryType)

end

InspectEquipLocalDB.Items[itemID] = str
IE.itemDB.global.Items[itemID] = str
end
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -668,4 +689,6 @@ function IE:CreateLocalDatabase()
message("[InspectEquip] Could not update database: " .. msg)
end

IE.dbInitialized = true;

end
1 change: 1 addition & 0 deletions Tooltips.lua
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ function IE:AddToTooltip(tip, itemLink)
if IE.configDB.global.tooltips == false then
return
end

addItemData(tip, itemLink, 0)
end

Expand Down

0 comments on commit 4126bd1

Please sign in to comment.