work on slash command core
This commit is contained in:
parent
da6316ea52
commit
6f61e5b513
1 changed files with 18 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
local core = LibStub("AceAddon-3.0"):NewAddon("AllTheLittleThings", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
|
local core = LibStub("AceAddon-3.0"):NewAddon("AllTheLittleThings", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
|
||||||
|
local db
|
||||||
atlt = core
|
atlt = core
|
||||||
|
|
||||||
local defaults = {
|
local defaults = {
|
||||||
|
@ -25,7 +26,8 @@ core:SetDefaultModulePrototype(prototype)
|
||||||
core:SetDefaultModuleLibraries("AceConsole-3.0")
|
core:SetDefaultModuleLibraries("AceConsole-3.0")
|
||||||
|
|
||||||
function core:OnInitialize()
|
function core:OnInitialize()
|
||||||
self.db = LibStub("AceDB-3.0"):New("AllTheLittleThingsDB", defaults, "Default")
|
db = LibStub("AceDB-3.0"):New("AllTheLittleThingsDB", defaults, "Default")
|
||||||
|
self.db = db
|
||||||
self:RegisterChatCommand("atlt", "MainSlashHandle")
|
self:RegisterChatCommand("atlt", "MainSlashHandle")
|
||||||
|
|
||||||
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("AllTheLittleThings", options)
|
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("AllTheLittleThings", options)
|
||||||
|
@ -40,6 +42,7 @@ function core:OnDisable()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- two registry functions called with self=mod
|
-- two registry functions called with self=mod
|
||||||
|
local defaultsTimer
|
||||||
function core:RegisterOptions(modOptions, modDefaults)
|
function core:RegisterOptions(modOptions, modDefaults)
|
||||||
local name = self:GetName()
|
local name = self:GetName()
|
||||||
defaults.profile[name] = modDefaults
|
defaults.profile[name] = modDefaults
|
||||||
|
@ -48,6 +51,13 @@ function core:RegisterOptions(modOptions, modDefaults)
|
||||||
type = 'group',
|
type = 'group',
|
||||||
args = modOptions
|
args = modOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if defaultsTimer then
|
||||||
|
core:CancelTimer(defaultsTimer)
|
||||||
|
end
|
||||||
|
defaultsTimer = core:ScheduleTimer(function()
|
||||||
|
db:RegisterDefaults(defaults)
|
||||||
|
end, 0.01)
|
||||||
end
|
end
|
||||||
|
|
||||||
function core:RegisterSlashCommand(callback, ...)
|
function core:RegisterSlashCommand(callback, ...)
|
||||||
|
@ -58,17 +68,21 @@ function core:RegisterSlashCommand(callback, ...)
|
||||||
long = string.len(slash)>string.len(long) and slash or long
|
long = string.len(slash)>string.len(long) and slash or long
|
||||||
end
|
end
|
||||||
|
|
||||||
slashList[long] = ("%s:%s()"):format(self:GetName(), callback)
|
slashList[long] = ("|cff33ff99%s|r:%s()"):format(self:GetName(), callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
function core:MainSlashHandle(msg)
|
function core:MainSlashHandle(msg)
|
||||||
local _, e, command = string.find("(%S+)", msg)
|
local _, e, command = msg:find("(%S+)")
|
||||||
msg = string.sub(msg, e+1)
|
|
||||||
|
|
||||||
if command and slashCallback[command] then
|
if command and slashCallback[command] then
|
||||||
|
msg = msg:sub(e+1)
|
||||||
slashCallback[command](msg)
|
slashCallback[command](msg)
|
||||||
else
|
else
|
||||||
-- print all commands
|
-- print all commands
|
||||||
|
print("|cff33ff99AllTheLittleThings|r available commands:")
|
||||||
|
for cmd,call in pairs(slashList) do
|
||||||
|
print((" %s - %s"):format(cmd, call))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue