Version 0.5.0
- add replacements via options UI - restructure debug functionsmaster 0.5.0
parent
cc26683328
commit
ecd6e5c340
@ -0,0 +1,122 @@
|
||||
-- read namespace from global env
|
||||
local _G = _G
|
||||
local Grichelde = _G.Grichelde
|
||||
|
||||
local pairs, ipairs, tInsert, tSort, unpack, join, toString
|
||||
= Grichelde.functions.pairs, Grichelde.functions.ipairs, Grichelde.functions.tInsert, Grichelde.functions.tSort, Grichelde.functions.unpack, Grichelde.functions.join, Grichelde.functions.toString
|
||||
|
||||
local defaultConfig = {
|
||||
global = {},
|
||||
profile = {
|
||||
enabled = true,
|
||||
channels = {
|
||||
["*"] = false,
|
||||
say = true,
|
||||
emote = false,
|
||||
yell = true,
|
||||
party = true,
|
||||
guild = true,
|
||||
officer = true,
|
||||
},
|
||||
replacements = {
|
||||
["**"] = {
|
||||
order = 9999,
|
||||
searchText = "",
|
||||
replaceText = "",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
},
|
||||
replacement_0 = {
|
||||
order = 5,
|
||||
searchText = "s",
|
||||
replaceText = "ch",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
},
|
||||
replacement_1 = {
|
||||
order = 9,
|
||||
searchText = "t",
|
||||
replaceText = "ck",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Grichelde:LoadDatabase()
|
||||
local db = LibStub("AceDB-3.0"):New(self.name .."DB", defaultConfig, true)
|
||||
|
||||
db.RegisterCallback(self, "OnNewProfile", "RefreshOptions")
|
||||
db.RegisterCallback(self, "OnProfileChanged", "RefreshOptions")
|
||||
db.RegisterCallback(self, "OnProfileDeleted", "RefreshOptions")
|
||||
db.RegisterCallback(self, "OnProfileCopied", "RefreshOptions")
|
||||
db.RegisterCallback(self, "OnProfileReset", "RefreshOptions")
|
||||
|
||||
return db
|
||||
end
|
||||
|
||||
function Grichelde:SyncToDatabase(info, val)
|
||||
local option = self.db.profile
|
||||
local path = 1
|
||||
while (path < #info) do
|
||||
option = option[info[path]] -- or nil
|
||||
path = path + 1
|
||||
end
|
||||
local optionPath = join(".", unpack(info, 1, #info))
|
||||
self:DebugPrint("change option \"%s\" from %s to %s", optionPath, toString(option[info[path]]), toString(val))
|
||||
option[info[path]] = val
|
||||
end
|
||||
|
||||
function Grichelde:ReadFromDatabase(info)
|
||||
local option = self.db.profile
|
||||
local path = 1
|
||||
while (path <= #info) do
|
||||
option = option[info[path]] -- or nil
|
||||
path = path + 1
|
||||
end
|
||||
local optionPath = join(".", unpack(info, 1, #info))
|
||||
self:DebugPrint("read option \"%s\": %s", optionPath, toString(option))
|
||||
return option
|
||||
end
|
||||
|
||||
--- Sorts a replacements table by order sub-field.
|
||||
--- Usually called with with self.db.profile.replacements
|
||||
-- @param replacementsTable table
|
||||
-- @return table
|
||||
function Grichelde:ReorderReplacements(replacementsTable)
|
||||
local replacements = replacementsTable or {}
|
||||
local sortedByOrder = {}
|
||||
for replName, _ in pairs(replacements) do
|
||||
tInsert(sortedByOrder, replName)
|
||||
end
|
||||
|
||||
tSort(sortedByOrder) -- lexicographical order will do for non-nil values
|
||||
--[[tSort(sortedByOrder, function(a, b)
|
||||
self:DebugPrint("ReorderReplacements : sort ", a, b)
|
||||
if a then
|
||||
if b then
|
||||
return a < b
|
||||
else
|
||||
return a
|
||||
end
|
||||
else
|
||||
return b
|
||||
end
|
||||
end)]]
|
||||
|
||||
self:DebugPrint("ReorderReplacements : sortedByOrder")
|
||||
self:DebugPrint(sortedByOrder)
|
||||
|
||||
local sortedReplacements = {}
|
||||
local index = 0
|
||||
for _, replName in ipairs(sortedByOrder) do
|
||||
sortedReplacements["replacement_"..index] = replacements[replName]
|
||||
sortedReplacements["replacement_"..index].order = index
|
||||
index = index + 1
|
||||
end
|
||||
|
||||
--self:DebugPrint("ReorderReplacements : sorted table")
|
||||
--self:DebugPrint(sortedReplacements)
|
||||
return sortedReplacements
|
||||
end
|
@ -1,15 +1,15 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
|
||||
<Script file="libs\LibStub\LibStub.lua"/>
|
||||
<Include file="libs\CallbackHandler-1.0\CallbackHandler-1.0.xml"/>
|
||||
<Include file="libs\AceAddon-3.0\AceAddon-3.0.xml"/>
|
||||
<Include file="libs\AceConfig-3.0\AceConfig-3.0.xml"/>
|
||||
<Include file="libs\AceConsole-3.0\AceConsole-3.0.xml"/>
|
||||
<Include file="libs\AceDB-3.0\AceDB-3.0.xml"/>
|
||||
<Include file="libs\AceDBOptions-3.0\AceDBOptions-3.0.xml"/>
|
||||
<Include file="libs\AceGUI-3.0\AceGUI-3.0.xml"/>
|
||||
<Include file="libs\AceEvent-3.0\AceEvent-3.0.xml" />
|
||||
<Include file="libs\AceLocale-3.0\AceLocale-3.0.xml" />
|
||||
<Include file="libs\AceHook-3.0\AceHook-3.0.xml"/>
|
||||
<Script file="Libs\LibStub\LibStub.lua"/>
|
||||
<Include file="Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml"/>
|
||||
<Include file="Libs\AceAddon-3.0\AceAddon-3.0.xml"/>
|
||||
<Include file="Libs\AceConfig-3.0\AceConfig-3.0.xml"/>
|
||||
<Include file="Libs\AceConsole-3.0\AceConsole-3.0.xml"/>
|
||||
<Include file="Libs\AceDB-3.0\AceDB-3.0.xml"/>
|
||||
<Include file="Libs\AceDBOptions-3.0\AceDBOptions-3.0.xml"/>
|
||||
<Include file="Libs\AceGUI-3.0\AceGUI-3.0.xml"/>
|
||||
<Include file="Libs\AceEvent-3.0\AceEvent-3.0.xml" />
|
||||
<Include file="Libs\AceLocale-3.0\AceLocale-3.0.xml" />
|
||||
<Include file="Libs\AceHook-3.0\AceHook-3.0.xml"/>
|
||||
</Ui>
|
||||
|
Loading…
Reference in New Issue