WOW_Collection_System/SM_CollectionSystem.lua

90 lines
3.1 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--[[
配置系统 - SM_Collections.Config 控制数据源切换
数据提供者接口 - 抽象基类定义统一接口
本地数据提供者 - 封装现有硬编码数据
服务端数据提供者 - 预留服务端通信接口
数据管理器 - 统一管理数据获取逻辑
当您准备好与 AzerothCore 服务端通信时,只需要:
SM_Collections.Config.UseServerData 默认 true 读取服务端数据
如需切换回本地数据,将 UseServerData 设为 false
在 ServerDataProvider:SendServerRequest 中实现实际的服务端通信逻辑
所有UI代码无需修改,插件可以正常测试UI功能同时为未来的服务端集成做好了准备
--]]
-- 这里将拆分为多个文件,主入口只保留加载和初始化逻辑
SM_Collections = {}
SM_Collections.MainFrame = nil
SM_Collections.CurrentPanel = nil
SM_Collections.CurrentTab = 1
-- 配置系统
SM_Collections.Config = {
UseServerData = true, -- 数据源切换开关,默认使用服务端数据
ServerTimeout = 5000, -- 服务端超时时间
FallbackToLocal = true, -- 服务端失败时回退到本地数据
Debug = true -- 调试模式
}
-- 新获得的收藏项目记录
SM_Collections.NewItems = {
mount = {}, -- 新获得的坐骑ID
companion = {}, -- 新获得的小伙伴ID
card = {}, -- 新获得的卡牌ID
item = {} -- 新获得的物品ID
}
-- 添加ADDON_LOADED事件处理以初始化数据库
local InitFrame = CreateFrame("Frame")
InitFrame:RegisterEvent("ADDON_LOADED")
InitFrame:SetScript("OnEvent", function(self, event, addonName)
if addonName == "SM_CollectionSystem" then
-- 确保SM_CollectionsDB存在
if not SM_CollectionsDB then
SM_CollectionsDB = {
mountCache = { mounts = {} },
companionCache = { companions = {} },
cardCache = { cards = {} },
itemCache = { items = {} }
}
end
-- 确保缓存子表存在
if not SM_CollectionsDB.mountCache then
SM_CollectionsDB.mountCache = { mounts = {} }
end
if not SM_CollectionsDB.companionCache then
SM_CollectionsDB.companionCache = { companions = {} }
end
if not SM_CollectionsDB.cardCache then
SM_CollectionsDB.cardCache = { cards = {} }
end
if not SM_CollectionsDB.itemCache then
SM_CollectionsDB.itemCache = { items = {} }
end
-- 确保items子表存在
if not SM_CollectionsDB.itemCache.items then
SM_CollectionsDB.itemCache.items = {}
end
-- 设置清理数据库的函数,在每次登录时调用
self:RegisterEvent("PLAYER_LOGIN")
elseif event == "PLAYER_LOGIN" then
-- 在登录时清理过期的缓存条目
SM_Collections.CleanupExpiredCacheEntries()
end
end)
-- 清理过期的缓存条目
function SM_Collections.CleanupExpiredCacheEntries()
-- 这里可以添加逻辑来删除很久未更新的缓存条目
-- 或者根据服务器版本检测不再有效的条目
end