Version 0.5.0
- add replacements via options UI - restructure debug functions
This commit is contained in:
@@ -4,40 +4,6 @@ local Grichelde = _G.Grichelde
|
||||
|
||||
-- upvalues and constants
|
||||
|
||||
-- faster function lookups by mapping to local refs
|
||||
Grichelde.functions = {}
|
||||
Grichelde.functions.type = _G.type
|
||||
Grichelde.functions.print = _G.print
|
||||
Grichelde.functions.pairs = _G.pairs
|
||||
Grichelde.functions.ipairs = _G.ipairs
|
||||
Grichelde.functions.tContains = _G.tContains
|
||||
Grichelde.functions.tFilter = function(t, cond, extr)
|
||||
local filtered = {}
|
||||
for key, value in Grichelde.functions.pairs(t) do
|
||||
if cond(key, value) then
|
||||
local val = extr(key, value)
|
||||
Grichelde.functions.tInsert(filtered, #filtered + 1, val)
|
||||
end
|
||||
end
|
||||
return filtered
|
||||
end
|
||||
Grichelde.functions.tInsert = _G.table.insert
|
||||
Grichelde.functions.tConcat = _G.table.concat
|
||||
Grichelde.functions.select = _G.select
|
||||
Grichelde.functions.unpack = _G.unpack
|
||||
Grichelde.functions.find = _G.string.find
|
||||
Grichelde.functions.sub = _G.string.sub
|
||||
Grichelde.functions.gsub = _G.string.gsub
|
||||
Grichelde.functions.match = _G.strmatch
|
||||
Grichelde.functions.join = _G.strjoin
|
||||
Grichelde.functions.toLower = _G.strlower
|
||||
Grichelde.functions.toUpper = _G.strupper
|
||||
Grichelde.functions.format = _G.string.format
|
||||
Grichelde.functions.rep = _G.string.rep
|
||||
Grichelde.functions.trim = _G.strtrim
|
||||
Grichelde.functions.length = _G.string.len
|
||||
Grichelde.functions.toString = _G.tostring
|
||||
|
||||
-- colors:
|
||||
Grichelde.COLOR_CODES = {}
|
||||
Grichelde.COLOR_CODES.PREFIX = "|c00FFAA00"
|
||||
@@ -54,41 +20,105 @@ Grichelde.COLOR_CODES.CLOSE = _G.FONT_COLOR_CODE_CLOSE or "|r";
|
||||
|
||||
Grichelde.slashCommands = { "/s", "/say", "/e", "/em", "/me", "/emote", "/y", "/yell", "/sh", "/shout", "/p", "/party", "/pl", "/partyleader", "/g", "/gc", "/guild", "/o", "/osay", "/officer", "/raid", "/rsay", "/rl", "/raidleader", "/rw", "/raidwarning", "/i", "/instance", "/bg", "/battleground", "/w", "/whisper", "/t", "/tell", "/send", "/r", "/reply" }
|
||||
|
||||
Grichelde.defaultConfig = {
|
||||
global = {},
|
||||
profile = {
|
||||
enabled = true,
|
||||
channels = {
|
||||
["*"] = false,
|
||||
say = true,
|
||||
emote = false,
|
||||
yell = true,
|
||||
party = true,
|
||||
partyLeader = true,
|
||||
guild = true,
|
||||
officer = true,
|
||||
},
|
||||
replacements = {
|
||||
["**"] = {
|
||||
searchText = "",
|
||||
replaceText = "",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
},
|
||||
replacement_0 = {
|
||||
order = 1,
|
||||
searchText = "s",
|
||||
replaceText = "ch",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
},
|
||||
replacement_1 = {
|
||||
order = 2,
|
||||
searchText = "t",
|
||||
replaceText = "ck",
|
||||
caseSensitive = false,
|
||||
consolidate = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
local function nilOrEmpty(s)
|
||||
return s == nil or s:trim() == ""
|
||||
end
|
||||
|
||||
local function spairs(t , orderFunc)
|
||||
-- collect the keys
|
||||
local sortedKeys = {}
|
||||
-- for every non-nil value
|
||||
for key, _ in Grichelde.functions.pairs(t) do
|
||||
Grichelde.functions.tInsert(sortedKeys, key)
|
||||
end
|
||||
|
||||
if orderFunc then
|
||||
Grichelde.functions.tSort(sortedKeys, function(a, b) return orderFunc(sortedKeys, a, b) end)
|
||||
else
|
||||
Grichelde.functions.tSort(sortedKeys)
|
||||
end
|
||||
|
||||
-- return the iterator function
|
||||
local it = 0
|
||||
return function()
|
||||
it = it + 1
|
||||
if sortedKeys[it] then
|
||||
return sortedKeys[it], t[sortedKeys[it]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function tFilter(t, cond, extr)
|
||||
local filtered = {}
|
||||
for key, value in Grichelde.functions.pairs(t) do
|
||||
if cond(key, value) then
|
||||
local val = extr(key, value)
|
||||
Grichelde.functions.tInsert(filtered, #filtered + 1, val)
|
||||
end
|
||||
end
|
||||
return filtered
|
||||
end
|
||||
|
||||
local function tSize(t)
|
||||
local size = 0
|
||||
if (t) then
|
||||
-- for every non-nil value
|
||||
for _, _ in Grichelde.functions.pairs(t) do
|
||||
size = size + 1
|
||||
end
|
||||
end
|
||||
return size
|
||||
end
|
||||
|
||||
local function tClone(orig)
|
||||
local orig_type = Grichelde.functions.type(orig)
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
copy = {}
|
||||
-- for every non-nil value
|
||||
for orig_key, orig_value in Grichelde.functions.tNext, orig, nil do
|
||||
copy[tClone(orig_key)] = tClone(orig_value)
|
||||
end
|
||||
Grichelde.functions.setmetatable(copy, tClone(Grichelde.functions.getmetatable(orig)))
|
||||
else -- number, string, boolean, etc
|
||||
copy = orig
|
||||
end
|
||||
return copy
|
||||
end
|
||||
|
||||
-- faster function lookups by mapping to local refs
|
||||
Grichelde.functions = {}
|
||||
Grichelde.functions.type = _G.type
|
||||
Grichelde.functions.print = _G.print
|
||||
Grichelde.functions.nilOrEmpty = nilOrEmpty
|
||||
Grichelde.functions.pairs = _G.pairs
|
||||
Grichelde.functions.ipairs = _G.ipairs
|
||||
Grichelde.functions.spairs = spairs
|
||||
Grichelde.functions.tContains = _G.tContains
|
||||
Grichelde.functions.tFilter = tFilter
|
||||
Grichelde.functions.tInsert = _G.table.insert
|
||||
Grichelde.functions.tConcat = _G.table.concat
|
||||
Grichelde.functions.tSize = tSize
|
||||
Grichelde.functions.tSort = _G.table.sort
|
||||
Grichelde.functions.tClone = tClone
|
||||
Grichelde.functions.tNext = _G.next
|
||||
Grichelde.functions.setmetatable = _G.setmetatable
|
||||
Grichelde.functions.getmetatable = _G.getmetatable
|
||||
Grichelde.functions.select = _G.select
|
||||
Grichelde.functions.unpack = _G.unpack
|
||||
Grichelde.functions.find = _G.string.find
|
||||
Grichelde.functions.sub = _G.string.sub
|
||||
Grichelde.functions.gsub = _G.string.gsub
|
||||
Grichelde.functions.match = _G.strmatch
|
||||
Grichelde.functions.join = _G.strjoin
|
||||
Grichelde.functions.split = _G.strsplit
|
||||
Grichelde.functions.toLower = _G.strlower
|
||||
Grichelde.functions.toUpper = _G.strupper
|
||||
Grichelde.functions.format = _G.string.format
|
||||
Grichelde.functions.rep = _G.string.rep
|
||||
Grichelde.functions.trim = _G.strtrim
|
||||
Grichelde.functions.length = _G.string.len
|
||||
Grichelde.functions.toString = _G.tostring
|
||||
Grichelde.functions.toNumber = _G.tonumber
|
||||
Grichelde.functions.max = _G.math.max
|
||||
Grichelde.functions.min = _G.math.min
|
||||
Reference in New Issue
Block a user