Skip to content

Commit

Permalink
Ovveride currentroute in routes for export + command feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Neogeekmo committed Apr 15, 2024
1 parent cae4bc9 commit 484de84
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 163 deletions.
4 changes: 3 additions & 1 deletion APR-Recorder.toc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ locales/locales.xml

Core.lua
Config.lua
Utils.lua
helper/Utils.lua
helper/RouteManagement.lua

Commands.lua
Event.lua

Expand Down
90 changes: 58 additions & 32 deletions Commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,43 @@ local function CanDoCommand()
end
function AprRC.command:SlashCmd(input)
local inputText = string.lower(input)
if inputText == "export" then
if AprRCData.CurrentRoute.name ~= "" then
AprRC:UpdateRouteByName(AprRCData.CurrentRoute.name, AprRCData.CurrentRoute)
end
APR.RouteQuestStepList[AprRCData.CurrentRoute.name] = AprRCData.CurrentRoute.steps
APR.RouteList.Custom[AprRCData.CurrentRoute.name] = AprRCData.CurrentRoute.name:match("%d+-(.*)")
AprRC.export.Show()
return
elseif inputText == "forcereset" or inputText == "fr" then
AprRC:ResetData()
return
elseif inputText == "help" or inputText == "h" then
print(L_APR["COMMAND_LIST"] .. ":")
print("|cffeda55f/aprrc grind |r- " .. "Grind")
print("|cffeda55f/aprrc class |r- " .. "Class")
print("|cffeda55f/aprrc gender |r- " .. "Gender")
print("|cffeda55f/aprrc race |r- " .. "Race")
print("|cffeda55f/aprrc spelltrigger |r- " .. "SpellTrigger")
print("|cffeda55f/aprrc button, btn |r- " .. "Button")
print("|cffeda55f/aprrc noachievement |r- " .. "DontHaveAchievement")
print("|cffeda55f/aprrc achievement |r- " .. "HasAchievement")
print("|cffeda55f/aprrc fillers, filler |r- " .. "Fillers")
print("|cffeda55f/aprrc faction |r- " .. "Faction")
print("|cffeda55f/aprrc noarrow |r- " .. "NoArrow")
print("|cffeda55f/aprrc qpartdb |r- " .. "QpartDB")
print("|cffeda55f/aprrc pickupdb |r- " .. "PickUpDB")
print("|cffeda55f/aprrc waypoint |r- " .. "Waypoint")
print("|cffeda55f/aprrc range |r- " .. "Range")
print("|cffeda55f/aprrc qpartpart |r- " .. "QpartPart")
print("|cffeda55f/aprrc donedb |r- " .. "DoneDB")
print("|cffeda55f/aprrc eta |r- " .. "ETA")
print("|cffeda55f/aprrc zonetrigger |r- " .. "ZoneStepTrigger")
print("|cffeda55f/aprrc text, txt |r- " .. "ExtraLineText")
print("|cffeda55f/aprrc help, h |r- " .. L_APR["HELP_COMMAND"])
print("|cffeda55f/aprrc forcereset, fr |r- " .. "Clear the Saved Variables")
return
end
if CanDoCommand() then
if inputText == "waypoint" then
local step = {
Expand All @@ -23,18 +60,20 @@ function AprRC.command:SlashCmd(input)
}
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
print("|cff00bfffWaypoint|r Added")
return
elseif inputText == "range" then
AprRC.questionDialog:CreateEditBoxPopupWithCallback("Range (number)", function(text)
local currentStep = AprRC:GetLastStep()
currentStep.Range = tonumber(text, 10)
print("|cff00bfffRange|r Added")
end)
return
elseif inputText == "eta" then
AprRC.questionDialog:CreateEditBoxPopupWithCallback("ETA (second)", function(text)
local currentStep = AprRC:GetLastStep()
currentStep.ETA =
tonumber(text, 10)
currentStep.ETA = tonumber(text, 10)
print("|cff00bfffETA|r Added")
end)
return
elseif inputText == "grind" then
Expand All @@ -43,6 +82,7 @@ function AprRC.command:SlashCmd(input)
step.Grind = tonumber(text, 10)
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
print("|cff00bfffGrind|r Added")
end)
return
elseif inputText == "noarrow" then
Expand All @@ -51,6 +91,7 @@ function AprRC.command:SlashCmd(input)
-- remove useless coord for NoArrow
currentStep.Coord = nil
currentStep.Range = nil
print("|cff00bfffNoArrow|r Added")
return
elseif inputText == "text" or inputText == "txt" then
AprRC.autocomplete:Show()
Expand All @@ -65,6 +106,7 @@ function AprRC.command:SlashCmd(input)
AprRC.questionDialog:CreateEditBoxPopupWithCallback("SpellTrigger (Spell ID)", function(text)
local currentStep = AprRC:GetLastStep()
currentStep.SpellTrigger = tonumber(text, 10)
print("|cff00bfffSpellTrigger -" .. tonumber(text, 10) .. "|r Added")
end)
return
elseif inputText == "pickupdb" then
Expand All @@ -79,6 +121,7 @@ function AprRC.command:SlashCmd(input)
tinsert(currentStep.PickUpDB, qID)
end
end
print("|cff00bfffPickUpDB - " .. tonumber(questId, 10) .. "|r Added")
end)
else
print('Missing PickUp option on current step')
Expand All @@ -97,6 +140,7 @@ function AprRC.command:SlashCmd(input)
tinsert(currentStep.QpartDB, qID)
end
end
print("|cff00bfffQpartDB - " .. tonumber(questId, 10) .. "|r Added")
end)
else
print('Missing Qpart option on current step')
Expand All @@ -114,6 +158,7 @@ function AprRC.command:SlashCmd(input)
tinsert(currentStep.DoneDB, qID)
end
end
print("|cff00bfffDoneDB - " .. tonumber(questId, 10) .. "|r Added")
end)
else
print('Missing Done option on current step')
Expand All @@ -125,34 +170,41 @@ function AprRC.command:SlashCmd(input)
local y, x = UnitPosition("player")
if x and y then
currentStep.ZoneStepTrigger = { x = x, y = y, Range = 15 }
print("|cff00bfffZoneStepTrigger|r Added")
end
return
elseif inputText == "faction" then
local currentStep = AprRC:GetLastStep()
currentStep.Faction = UnitFactionGroup("player")
print("|cff00bfffFaction - " .. UnitFactionGroup("player") .. "|r Added")
return
elseif inputText == "race" then
local currentStep = AprRC:GetLastStep()
currentStep.Race = select(2, UnitRace("player"))
print("|cff00bfffRace - " .. select(2, UnitRace("player")) .. "|r Added")
return
elseif inputText == "gender" then
local currentStep = AprRC:GetLastStep()
currentStep.Gender = UnitSex("player")
print("|cff00bfffGender - " .. UnitSex("player") .. "|r Added")
return
elseif inputText == "class" then
local currentStep = AprRC:GetLastStep()
currentStep.Class = select(2, UnitClass("player"))
print("|cff00bfffClass - " .. select(2, UnitClass("player")) .. "|r Added")
return
elseif inputText == "achievement" then
AprRC.questionDialog:CreateEditBoxPopupWithCallback("Has Achievement (ID)", function(text)
local currentStep = AprRC:GetLastStep()
currentStep.HasAchievement = tonumber(text, 10)
print("|cff00bfffHasAchievement - " .. tonumber(text, 10) .. "|r Added")
end)
return
elseif inputText == "noachievement" then
AprRC.questionDialog:CreateEditBoxPopupWithCallback("Dont Have Achievement (ID)", function(text)
local currentStep = AprRC:GetLastStep()
currentStep.DontHaveAchievement = tonumber(text, 10)
print("|cff00bfffDontHaveAchievement - " .. tonumber(text, 10) .. "|r Added")
end)
return
elseif inputText == "save" then
Expand All @@ -163,40 +215,14 @@ function AprRC.command:SlashCmd(input)
AprRC.settings.profile.recordBarFrame.isRecording = false
AprRC.record:StopRecord()
-- AprRCData.CurrentRoute = { name = "", steps = { {} } }
print("|cff00bfff ZoneDoneSave |r Added")
else
print('You current route is empty')
end
return
end
end
if inputText == "export" then
APR.RouteQuestStepList[AprRCData.CurrentRoute.name] = AprRCData.CurrentRoute.steps
APR.RouteList.Custom[AprRCData.CurrentRoute.name] = AprRCData.CurrentRoute.name:match("%d+-(.*)")
AprRC.export.Show()
elseif inputText == "help" or inputText == "h" then
print(L_APR["COMMAND_LIST"] .. ":")
print("|cffeda55f/aprrc grind |r- " .. "Grind")
print("|cffeda55f/aprrc class |r- " .. "Class")
print("|cffeda55f/aprrc gender |r- " .. "Gender")
print("|cffeda55f/aprrc race |r- " .. "Race")
print("|cffeda55f/aprrc spelltrigger |r- " .. "SpellTrigger")
print("|cffeda55f/aprrc button, btn |r- " .. "Button")
print("|cffeda55f/aprrc noachievement |r- " .. "DontHaveAchievement")
print("|cffeda55f/aprrc achievement |r- " .. "HasAchievement")
print("|cffeda55f/aprrc fillers, filler |r- " .. "Fillers")
print("|cffeda55f/aprrc faction |r- " .. "Faction")
print("|cffeda55f/aprrc noarrow |r- " .. "NoArrow")
print("|cffeda55f/aprrc qpartdb |r- " .. "QpartDB")
print("|cffeda55f/aprrc pickupdb |r- " .. "PickUpDB")
print("|cffeda55f/aprrc waypoint |r- " .. "Waypoint")
print("|cffeda55f/aprrc range |r- " .. "Range")
print("|cffeda55f/aprrc qpartpart |r- " .. "QpartPart")
print("|cffeda55f/aprrc donedb |r- " .. "DoneDB")
print("|cffeda55f/aprrc eta |r- " .. "ETA")
print("|cffeda55f/aprrc zonetrigger |r- " .. "ZoneStepTrigger")
print("|cffeda55f/aprrc text, txt |r- " .. "ExtraLineText")
print("|cffeda55f/aprrc help, h |r- " .. L_APR["HELP_COMMAND"])
else
AprRC.settings:OpenSettings(AprRC.title)
end

-- Default
AprRC.settings:OpenSettings(AprRC.title)
end
100 changes: 0 additions & 100 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,103 +44,3 @@ function AprRC:OnInitialize()
-- Register to Chat
C_ChatInfo.RegisterAddonMessagePrefix("AprRCChat")
end

---------------------------------------------------------------------------------------
---------------------------------- Route Management -----------------------------------
---------------------------------------------------------------------------------------

function AprRC:ResetData()
AprRCData = {}
AprRCData.CurrentRoute = { name = "", steps = { {} } }
AprRCData.Routes = {}
end

function AprRC:InitRoute(name)
local mapID = C_Map.GetBestMapForUnit("player")
AprRCData.CurrentRoute = { name = mapID .. '-' .. name, steps = { {} } }
tinsert(AprRCData.Routes, AprRCData.CurrentRoute)
end

function AprRC:UpdateRoute()
local currentRouteName = AprRCData.CurrentRoute.name
for i, route in ipairs(AprRCData.Routes) do
if route.name == currentRouteName then
AprRCData.Routes[i] = AprRCData.CurrentRoute
break
end
end
end

function AprRC:NewStep(step)
AprRC:Debug("NewStep", step)
local lastStep = AprRC:GetLastStep()
if AprRC:IsTableEmpty(lastStep) then
AprRCData.CurrentRoute.steps = {}
end
tinsert(AprRCData.CurrentRoute.steps, step)
end

function AprRC:GetStepByIndex(index)
return AprRCData.CurrentRoute.steps[index]
end

function AprRC:HasStepOption(stepOption)
local step = self:GetLastStep()
if step and step[stepOption] then
return true
end
return false
end

function AprRC:SetStepCoord(step, range)
local y, x, z, mapID = UnitPosition("player")
if x and y and not step.NoArrow then
step.Coord = { x = x, y = y }
step.Zone = C_Map.GetBestMapForUnit("player")
step.Range = range
end
end

-- Check if the your are to far away from the current step to create a new one
-- Distance = 5 by default
function AprRC:IsCurrentStepFarAway(distance)
local step = self:GetLastStep()
if not step or not step.Coord then
return
end

distance = distance or step.Range or 5
local playerY, playerX = UnitPosition("player")
local deltaX, deltaY = playerX - step.Coord.x, step.Coord.y - playerY
local currentDistance = (deltaX * deltaX + deltaY * deltaY) ^ 0.5

return currentDistance > distance
end

function AprRC:GetLastStep()
return AprRCData.CurrentRoute.steps[#AprRCData.CurrentRoute.steps]
end

function AprRC:FindClosestIncompleteQuest()
for i = #AprRCData.CurrentRoute.steps, 1, -1 do
local step = AprRCData.CurrentRoute.steps[i]

for _, optionType in ipairs({ "PickUp", "Done", "Qpart" }) do
local questList = step[optionType]

if questList and optionType == "Qpart" then
for questID, _ in pairs(questList) do
if not C_QuestLog.IsQuestFlaggedCompleted(questID) then
return questID
end
end
elseif questList then
for _, questID in ipairs(questList) do
if not C_QuestLog.IsQuestFlaggedCompleted(questID) then
return questID
end
end
end
end
end
end
2 changes: 2 additions & 0 deletions frames/autocompleteLocales.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ function AprRC.autocomplete:SetExtraLineText(key)
end

currentStep[propertyName] = key

print("|cff00bfffExtraLineTexts|r Added")
end
1 change: 1 addition & 0 deletions frames/fillersSelection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function AprRC.fillers:Show()
currentStep.Fillers[quest.questID] = {}
end
tinsert(currentStep.Fillers[quest.questID], objective.objectiveID)
print("|cff00bfffFillers - [" .. quest.title .. "] - " .. objective.objectiveID .. "|r Added")
AceGUI:Release(frame)
end)
questGroup:AddChild(objectiveLabel)
Expand Down
2 changes: 2 additions & 0 deletions frames/selectButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function AprRC.SelectButton:Show()
AprRC.questionDialog:CreateEditBoxPopupWithCallback("Item Button (ID)", function(text)
local currentStep = AprRC:GetLastStep()
currentStep.Button = tonumber(text, 10)
print("|cff00bfff Button |r Added")
end)
end)
buttonGroup:AddChild(btnItem)
Expand All @@ -37,6 +38,7 @@ function AprRC.SelectButton:Show()
AprRC.questionDialog:CreateEditBoxPopupWithCallback("Spell Button (ID)", function(text)
local currentStep = AprRC:GetLastStep()
currentStep.SpellButton = tonumber(text, 10)
print("|cff00bfff SpellButton |r Added")
end)
end)
buttonGroup:AddChild(btnSpell)
Expand Down
Loading

0 comments on commit 484de84

Please sign in to comment.