first commit

This commit is contained in:
Salikh Gurgenidze
2025-11-16 04:47:49 +04:00
commit aec33e3652
22 changed files with 3752 additions and 0 deletions
+101
View File
@@ -0,0 +1,101 @@
-- Guda Bag Scanner
-- Scans and stores bag contents
local addon = Guda
local BagScanner = {}
addon.Modules.BagScanner = BagScanner
-- Scan all bags and return data
function BagScanner:ScanBags()
local bagData = {}
for _, bagID in ipairs(addon.Constants.BAGS) do
bagData[bagID] = self:ScanBag(bagID)
end
return bagData
end
-- Scan a single bag
function BagScanner:ScanBag(bagID)
local bag = {
slots = {},
numSlots = addon.Modules.Utils:GetBagSlotCount(bagID),
freeSlots = 0,
}
if not addon.Modules.Utils:IsBagValid(bagID) then
return bag
end
for slot = 1, bag.numSlots do
local itemData = self:ScanSlot(bagID, slot)
bag.slots[slot] = itemData
if not itemData then
bag.freeSlots = bag.freeSlots + 1
end
end
return bag
end
-- Scan a single slot
function BagScanner:ScanSlot(bagID, slot)
local texture, itemCount, locked, quality, readable, lootable = GetContainerItemInfo(bagID, slot)
if not texture then
return nil
end
-- In 1.12.1, must use GetContainerItemLink separately!
local itemLink = GetContainerItemLink(bagID, slot)
-- Get item info
local name, link, itemQuality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, iconTexture
if itemLink then
name, link, itemQuality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, iconTexture = addon.Modules.Utils:GetItemInfo(itemLink)
end
return {
link = itemLink,
texture = texture,
count = itemCount or 1,
quality = quality or itemQuality or 0,
name = name,
iLevel = iLevel,
class = class,
subclass = subclass,
equipSlot = equipSlot,
locked = locked,
}
end
-- Save current bags to database
function BagScanner:SaveToDatabase()
local bagData = self:ScanBags()
addon.Modules.DB:SaveBags(bagData)
end
-- Auto-scan on bag updates
function BagScanner:Initialize()
addon.Modules.Events:OnBagUpdate(function()
BagScanner:SaveToDatabase()
end, "BagScanner")
-- Initial scan on login
addon.Modules.Events:OnPlayerLogin(function()
-- Delay to ensure bags are loaded
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 1 then
frame:SetScript("OnUpdate", nil)
BagScanner:SaveToDatabase()
addon:Debug("Initial bag scan complete")
end
end)
end, "BagScanner")
end
+98
View File
@@ -0,0 +1,98 @@
-- Guda Bank Scanner
-- Scans and stores bank contents
local addon = Guda
local BankScanner = {}
addon.Modules.BankScanner = BankScanner
local bankOpen = false
-- Scan all bank bags and return data
function BankScanner:ScanBank()
if not bankOpen then
addon:Debug("Cannot scan bank - not open")
return {}
end
local bankData = {}
for _, bagID in ipairs(addon.Constants.BANK_BAGS) do
bankData[bagID] = self:ScanBankBag(bagID)
end
return bankData
end
-- Scan a single bank bag
function BankScanner:ScanBankBag(bagID)
local bag = {
slots = {},
numSlots = addon.Modules.Utils:GetBagSlotCount(bagID),
freeSlots = 0,
}
if not addon.Modules.Utils:IsBagValid(bagID) then
return bag
end
for slot = 1, bag.numSlots do
local itemData = addon.Modules.BagScanner:ScanSlot(bagID, slot)
bag.slots[slot] = itemData
if not itemData then
bag.freeSlots = bag.freeSlots + 1
end
end
return bag
end
-- Save current bank to database
function BankScanner:SaveToDatabase()
if not bankOpen then
return
end
local bankData = self:ScanBank()
addon.Modules.DB:SaveBank(bankData)
addon:Debug("Bank data saved")
end
-- Initialize bank scanner
function BankScanner:Initialize()
-- Bank opened
addon.Modules.Events:OnBankOpen(function()
bankOpen = true
addon:Debug("Bank opened")
-- Delay scan to ensure bank is fully loaded
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 0.5 then
frame:SetScript("OnUpdate", nil)
BankScanner:SaveToDatabase()
end
end)
end, "BankScanner")
-- Bank closed
addon.Modules.Events:OnBankClose(function()
bankOpen = false
addon:Debug("Bank closed")
end, "BankScanner")
-- Update on bag changes while bank is open
addon.Modules.Events:OnBagUpdate(function()
if bankOpen then
BankScanner:SaveToDatabase()
end
end, "BankScanner")
end
-- Check if bank is currently open
function BankScanner:IsBankOpen()
return bankOpen
end
+56
View File
@@ -0,0 +1,56 @@
-- Guda Money Tracker
-- Tracks player money and saves to database
local addon = Guda
local MoneyTracker = {}
addon.Modules.MoneyTracker = MoneyTracker
local lastMoney = 0
-- Update money in database
function MoneyTracker:Update()
local currentMoney = GetMoney()
if currentMoney ~= lastMoney then
addon.Modules.DB:SaveMoney(currentMoney)
lastMoney = currentMoney
addon:Debug("Money updated: %s", addon.Modules.Utils:FormatMoney(currentMoney))
end
end
-- Get current money
function MoneyTracker:GetCurrentMoney()
return GetMoney()
end
-- Get total money across all characters
function MoneyTracker:GetTotalMoney(sameFactionOnly)
return addon.Modules.DB:GetTotalMoney(sameFactionOnly)
end
-- Initialize money tracker
function MoneyTracker:Initialize()
-- Track money changes
addon.Modules.Events:OnMoneyChanged(function()
MoneyTracker:Update()
end, "MoneyTracker")
-- Initial update on login
addon.Modules.Events:OnPlayerLogin(function()
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 1 then
frame:SetScript("OnUpdate", nil)
MoneyTracker:Update()
end
end)
end, "MoneyTracker")
-- Save on logout
addon.Modules.Events:OnPlayerLogout(function()
MoneyTracker:Update()
end, "MoneyTracker")
end