Phase 2: prefer live ClassicAPI vendor prices

This commit is contained in:
2026-08-24 08:20:32 +02:00
parent 13a5843bba
commit 36979d2da8
+32
View File
@@ -0,0 +1,32 @@
local API = ShaguTweaks.API
-- Keep the original static database as an immediate compatibility fallback.
-- ClassicAPI's live item cache is authoritative when it has the item record,
-- which also covers Turtle/custom items and server-side price changes.
if not API or not API.itemprice or not ShaguTweaks.SellValueDB then return end
local legacy = ShaguTweaks.SellValueDB
local live = {}
setmetatable(live, {
__index = function(tab, itemID)
if type(itemID) ~= "number" then
return legacy[itemID]
end
local price = API.GetItemSellPriceByID(itemID)
if price ~= nil then
-- Vendor values don't change during a session. Cache successful reads so
-- the tooltip's repeated lookups stay pure Lua after the first hit.
rawset(tab, itemID, price)
return price
end
-- An uncached item is warmed by ClassicAPI in the background. Use the old
-- database now; a later tooltip lookup will transparently pick up live data.
return legacy[itemID]
end
})
ShaguTweaks.SellValueLegacyDB = legacy
ShaguTweaks.SellValueDB = live