1,286 config.lua

Large diffs are not rendered by default.

@@ -1,4 +1,7 @@
local _, core = ...; -- Namespace
--------------------------------------
-- Namespaces
--------------------------------------
local _, core = ...

--------------------------------------
-- Custom Slash Command
@@ -7,97 +10,92 @@ core.commands = {
["start"] = core.Config.Toggle, -- this is a function (no knowledge of Config object)

["help"] = function()
print(" ");
local color = "fffb00"
print(" ")
core:Print("List of slash commands:")
core:Print("|cff00cc66/ttt start|r - start the game");
core:Print("|cff00cc66/ttt reset|r - reset the game");
core:Print("|cff00cc66/ttt exit|r - exit the game");
core:Print("|cff00cc66/ttt solo|r - enables singleplayer mode");
core:Print("|cff00cc66/ttt help|r - shows help info");
core:Print("|cff00cc66/ttt stats|r - shows the player statistics");
print(" ");
core:Print("|cff"..color.."/ttt start|r - start the game")
core:Print("|cff"..color.."/ttt reset|r - reset the AddOn configuration")
core:Print("|cff"..color.."/ttt solo|r - enables singleplayer mode")
core:Print("|cff"..color.."/ttt help|r - shows help info")
core:Print("|cff"..color.."/ttt stats|r - shows the player statistics")
print(" ")
end,

["example"] = {
["test"] = function(...)
core:Print("My Value:", tostringall(...));
core:Print("My Value:", tostringall(...))
end
},

["reset"] = function()
core.Config.ResetPosition();
core.Config.Reset();
end,

["exit"] = core.Config.Exit,
["reset"] = core.Config.ResetAddon,

["solo"] = core.Config.Singleplayer,

["stats"] = core.Config.PrintPlayerStats,
};
}

local function HandleSlashCommands(str)
if (#str == 0) then
-- User just entered "/ttt" with no additional args.
core.Config.Toggle();
return;
core.Config.Toggle()
return
end

local args = {};
local args = {}
for _, arg in ipairs({ string.split(' ', str) }) do
if (#arg > 0) then
table.insert(args, arg);
table.insert(args, arg)
end
end

local path = core.commands; -- required for updating found table.
local path = core.commands -- required for updating found table.

for id, arg in ipairs(args) do
if (#arg > 0) then -- if string length is greater than 0.
arg = arg:lower();
arg = arg:lower()
if (path[arg]) then
if (type(path[arg]) == "function") then
-- all remaining args passed to our function!
path[arg](select(id + 1, unpack(args)));
return;
path[arg](select(id + 1, unpack(args)))
return
elseif (type(path[arg]) == "table") then
path = path[arg]; -- another sub-table found!
path = path[arg] -- another sub-table found!
end
else
-- does not exist!
core.commands.help();
return;
core.commands.help()
return
end
end
end
end

function core:Print(...)
local hex = select(4, self.Config:GetThemeColor());
local prefix = string.format("|cff%s%s|r", hex:upper(), "TicTacToe");
DEFAULT_CHAT_FRAME:AddMessage(string.join(" ", prefix, ...));
local hex = select(4, self.Config:GetThemeColor())
local prefix = string.format("|cff%s%s|r", hex:upper(), "TicTacToe")
DEFAULT_CHAT_FRAME:AddMessage(string.join(" ", prefix, ...))
end

-- WARNING: self automatically becomes events frame!
function core:init(event, name)

-- allows using left and right buttons to move through chat 'edit' box
for i = 1, NUM_CHAT_WINDOWS do
_G["ChatFrame"..i.."EditBox"]:SetAltArrowKeyMode(false);
_G["ChatFrame"..i.."EditBox"]:SetAltArrowKeyMode(false)
end

----------------------------------
-- Register Slash Commands!
----------------------------------
SLASH_TicTacToe1 = "/ttt";
SlashCmdList.TicTacToe = HandleSlashCommands;
SLASH_TicTacToe1 = "/ttt"
SlashCmdList.TicTacToe = HandleSlashCommands

-- Needs to be removed, once developing is finished!
-- core.Config.Toggle();
-- core.Config.Toggle()
end



local events = CreateFrame("Frame");
events:RegisterEvent("ADDON_LOADED");
events:SetScript("OnEvent", core.init);
local events = CreateFrame("Frame")
events:RegisterEvent("ADDON_LOADED")
events:SetScript("OnEvent", core.init)
60 lib.lua
@@ -0,0 +1,60 @@
--------------------------------------
-- Namespaces
--------------------------------------
local _, core = ...
core.Lib = {} -- adds Lib table to addon namespace
local Lib = core.Lib

function Lib:FirstLetterUp(str)
local rtn = ""
for i = 1, #str do
local c = str:sub(i,i)
if (i == 1) then
rtn = rtn .. string.upper(c)
else
rtn = rtn .. string.lower(c)
end
end
return rtn
end

function Lib:SplitString(str, separator, index)
local rtn = {}
for _, arg in ipairs({ string.split(separator, str) }) do
if (#arg > 0) then
table.insert(rtn, arg)
end
end
if (index == "#") then
return rtn[#rtn]
elseif (index) then
return rtn[index]
else
return rtn
end
end


function Lib:IsNumeric(str)
local rtn
if (str) then
for i = 1, #str do
local c = str.split(i,i)
if (not((c == "0" and i ~= 1) or c == "1" or c == "2" or c == "3" or c == "4" or c == "5" or c == "6" or c == "7" or c == "8" or c == "9")) then
return false
end
end
return true
else
return false
end
end