From ecf9fa27993d9babca4aeaf343c5191e86cc3de9 Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Sun, 9 Jan 2011 16:48:34 +0000 Subject: [PATCH] Skeleton slash command implementation --- TomTomLite.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/TomTomLite.lua b/TomTomLite.lua index ca2a832..37cb0d7 100644 --- a/TomTomLite.lua +++ b/TomTomLite.lua @@ -383,3 +383,59 @@ function addon:WORLD_MAP_UPDATE() end end end + +--[[------------------------------------------------------------------------- +-- Slash command registration +-------------------------------------------------------------------------]]-- + +SLASH_TOMTOMLITE1 = "/ttl" +SLASH_TOMTOMLITE2 = "/tomtomlite" +SLASH_TOMTOMLITE3 = "/tt" + +local wrongseparator = "(%d)" .. (tonumber("1.1") and "," or ".") .. "(%d)" +local rightseparator = "%1" .. (tonumber("1.1") and "." or ",") .. "%2" + +SlashCmdList["TOMTOMLITE"] = function(msg, editbox) + -- Attempt to fix any pairs of coordinates in any form so they work. This + -- should correctly handle cases where the user uses a number format that + -- is different than their current locale, i.e. someone using 34,45 when + -- their numeric locale expects 34.45 (for the number 35 and 45 hundreths). + -- Additionally, if the two numbers are separaed by a comma, i.e. + -- 45.34, 54.13 then this comma will be removed. + -- + -- Thanks to Phanx for working out the best way to do this + local msgfix = msg:gsub("(%d)[%.,] (%d)", "%1 %2"):gsub(wrongseparator, rightseparator) + + local tokens = {} + for token in msgfix:gmatch("%S+") do + table.insert(tokens, token) + end + + local verb = tokens[1] and tokens[1]:lower() + + if verb == "set" then + if not tonumber(tokens[2]) then + -- A zone has been specified as the first argument so find the boundary + local zoneEnd = 2 + for idx, token in ipairs(tokens) do + if tonumber(token) then + zoneEnd = idx - 1 + break + end + end + + local zone = table.concat(tokens, " ", 2, zoneEnd) + local x, y, desc = unpack(tokens, zoneEnd + 1) + + -- The description may be multiple tokens as well + if desc then + desc = table.concat(tokens, " ", zoneEnd + 3) + end + + -- TODO: Try to find a match for the zone/map name + else + self:Printf(L["Usage for /ttl:"]) + self:Printf(L[" * set [zone] [desc] - sets a waypoint"]) + end + end +end -- 1.7.9.5