Skip to content

Commit

Permalink
MiniTom: Add support for zone names
Browse files Browse the repository at this point in the history
  • Loading branch information
Wutname1 committed Dec 5, 2022
1 parent 981b10f commit 7d2870f
Show file tree
Hide file tree
Showing 7 changed files with 1,947 additions and 11 deletions.
85 changes: 74 additions & 11 deletions Modules/MiniTom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,57 @@ local SUI = SUI
local module = SUI:NewModule('Module_MiniTom') ---@type SUI.Module
module.DisplayName = 'MiniTom'
module.description = 'Enables /way command to set a waypoint on your map'
local HBD = LibStub('HereBeDragons-2.0')

---@class MiniTomDB
local DBDefaults = {}

---Get the MapID for a zone name
---@param zoneName string
function module:GetMapID(zoneName)
local matches = {}

---@diagnostic disable-next-line: undefined-field
for mapID, mapInfo in pairs(HBD.mapData) do
local lname = mapInfo.name:lower()
local lzone = zoneName:lower()
if lname:match(lzone) then
return mapID
-- table.insert(matches, {id = mapID, name = mapInfo.name})
end
end

if #matches == 1 then
return matches[1].id
elseif #matches > 1 then
SUI:Print('Multiple matches found for zone name')
for i = 1, #matches do
SUI:Print(matches[i].id)
SUI:Print(matches[i].name)
end
else
SUI:Print('No matches found for zone name')
end
end

---Set a waypoint on the map
---@param mapID number
---@param x number
---@param y number
---@param desc? string
function module:SetPoint(mapID, x, y, desc)
if C_Map.CanSetUserWaypointOnMap(mapID) then
local mapPoint = UiMapPoint.CreateFromCoordinates(mapID, tonumber(x) / 100, tonumber(y) / 100, 0)
if mapPoint then
C_Map.SetUserWaypoint(mapPoint)
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
SUI:Print('Waypoint set' .. (desc and ' for ' .. desc or ''))
end
else
SUI:Print('Cannot set waypoint on this map')
end
end

local function Options()
---@type AceConfigOptionsTable
local OptTable = {
Expand Down Expand Up @@ -43,22 +90,38 @@ function module:OnEnable()
end

function SetWaypoint(args)
local x, y = strsplit(' ', args, 2)
-- Remove any commas or periods from the numbers
args = args:gsub('(%d)[%.,] (%d)', '%1 %2')
local inputSections = {}
-- Split the string
for item in args:gmatch('%S+') do
table.insert(inputSections, item)
end

if (x == nil or x == '' or type(tonumber(x)) ~= 'number' or y == nil or y == '' or type(tonumber(y)) ~= 'number') then
return
-- Find the first number and use that to determine the end of the zone name
local zoneEnd
for i = 1, #inputSections do
local token = inputSections[i]
if tonumber(token) then
zoneEnd = i - 1
break
end
end

local mapID = C_Map.GetBestMapForUnit('player')
if C_Map.CanSetUserWaypointOnMap(mapID) then
local mapPoint = UiMapPoint.CreateFromCoordinates(mapID, tonumber(x) / 100, tonumber(y) / 100, 0)
if mapPoint then
C_Map.SetUserWaypoint(mapPoint)
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
SUI:Print('Waypoint set')
local zone = table.concat(inputSections, ' ', 1, zoneEnd)
local x, y, desc = select(zoneEnd + 1, unpack(inputSections))

if inputSections[1] and not tonumber(inputSections[1]) then
-- Find MapID
local mapID = module:GetMapID(zone)
if mapID then
module:SetPoint(mapID, x, y, desc)
else
SUI:Print('Invalid zone name')
end
else
SUI:Print('Cannot set waypoint on this map')
local mapID = C_Map.GetBestMapForUnit('player')
module:SetPoint(mapID, x, y, desc)
end
end

Expand Down
1 change: 1 addition & 0 deletions SpartanUI.toc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Core\Handlers\BugWindow.lua
libs\LibCompress\LibCompress.lua
libs\LibBase64-1.0\LibBase64-1.0.lua
libs\LibDualSpec-1.0\LibDualSpec-1.0.lua
libs\HereBeDragons\HereBeDragons-2.0.lua
libs\WagoAnalyticsShim\Shim.lua
libs\LibSharedMedia-3.0\lib.xml
libs\AceGUI-3.0-SharedMediaWidgets\widget.xml
Expand Down
1 change: 1 addition & 0 deletions SpartanUI_Mainline.toc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Core\Handlers\BugWindow.lua
libs\LibCompress\LibCompress.lua
libs\LibBase64-1.0\LibBase64-1.0.lua
libs\LibDualSpec-1.0\LibDualSpec-1.0.lua
libs\HereBeDragons\HereBeDragons-2.0.lua
libs\WagoAnalyticsShim\Shim.lua
libs\LibSharedMedia-3.0\lib.xml
libs\AceGUI-3.0-SharedMediaWidgets\widget.xml
Expand Down
8 changes: 8 additions & 0 deletions libs/HereBeDragons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Lib: HereBeDragons

## [2.06-release](https://github.com/Nevcairiel/HereBeDragons/tree/2.06-release) (2021-05-08)
[Full Changelog](https://github.com/Nevcairiel/HereBeDragons/compare/2.05-release...2.06-release) [Previous Releases](https://github.com/Nevcairiel/HereBeDragons/releases)

- Fixup Luacheck
- Update API check to be independent of WoW version
- Add transform and worldmap data for BC
Loading

0 comments on commit 7d2870f

Please sign in to comment.