From 484de84362e05638d8038d15524118903b00f12c Mon Sep 17 00:00:00 2001 From: Aldric Ducreux Date: Mon, 15 Apr 2024 18:52:34 +0200 Subject: [PATCH] Ovveride currentroute in routes for export + command feedback --- APR-Recorder.toc | 4 +- Commands.lua | 90 ++++++++++++------- Core.lua | 100 ---------------------- frames/autocompleteLocales.lua | 2 + frames/fillersSelection.lua | 1 + frames/selectButton.lua | 2 + helper/RouteManagement.lua | 152 +++++++++++++++++++++++++++++++++ Utils.lua => helper/Utils.lua | 30 ------- 8 files changed, 218 insertions(+), 163 deletions(-) create mode 100644 helper/RouteManagement.lua rename Utils.lua => helper/Utils.lua (78%) diff --git a/APR-Recorder.toc b/APR-Recorder.toc index fc33345..dd165c3 100644 --- a/APR-Recorder.toc +++ b/APR-Recorder.toc @@ -23,7 +23,9 @@ locales/locales.xml Core.lua Config.lua -Utils.lua +helper/Utils.lua +helper/RouteManagement.lua + Commands.lua Event.lua diff --git a/Commands.lua b/Commands.lua index a843dc9..fa0ec84 100644 --- a/Commands.lua +++ b/Commands.lua @@ -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 = { @@ -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 @@ -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 @@ -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() @@ -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 @@ -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') @@ -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') @@ -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') @@ -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 @@ -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 diff --git a/Core.lua b/Core.lua index fb02c81..adf03f5 100644 --- a/Core.lua +++ b/Core.lua @@ -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 diff --git a/frames/autocompleteLocales.lua b/frames/autocompleteLocales.lua index b1d28d5..1f96f5c 100644 --- a/frames/autocompleteLocales.lua +++ b/frames/autocompleteLocales.lua @@ -99,4 +99,6 @@ function AprRC.autocomplete:SetExtraLineText(key) end currentStep[propertyName] = key + + print("|cff00bfffExtraLineTexts|r Added") end diff --git a/frames/fillersSelection.lua b/frames/fillersSelection.lua index a61fb64..afe9fab 100644 --- a/frames/fillersSelection.lua +++ b/frames/fillersSelection.lua @@ -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) diff --git a/frames/selectButton.lua b/frames/selectButton.lua index 466a48e..e9e5567 100644 --- a/frames/selectButton.lua +++ b/frames/selectButton.lua @@ -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) @@ -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) diff --git a/helper/RouteManagement.lua b/helper/RouteManagement.lua new file mode 100644 index 0000000..a213aac --- /dev/null +++ b/helper/RouteManagement.lua @@ -0,0 +1,152 @@ +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 + +function AprRC:SplitQuestAndObjective(questID) + local id, objective = questID:match("([^%-]+)%-([^%-]+)") + if id and objective then + return tonumber(id), tonumber(objective) + end + return tonumber(questID) +end + +function AprRC:saveQuestInfo() + AprRC:Debug("Save QuestInfo") + AprRC.lastQuestState = AprRC.lastQuestState or {} + for i = 1, C_QuestLog.GetNumQuestLogEntries() do + local info = C_QuestLog.GetInfo(i) + if info and not info.isHidden then + local objectives = C_QuestLog.GetQuestObjectives(info.questID) + if objectives then + for index, objective in ipairs(objectives) do + AprRC.lastQuestState[info.questID] = AprRC.lastQuestState[info.questID] or {} + AprRC.lastQuestState[info.questID][index] = { numFulfilled = objective.numFulfilled } + end + end + end + end +end + +function AprRC:IsInInstanceQuest() + local isIntance, type = IsInInstance() + return isIntance and type == "scenario" +end + +function AprRC:FindRouteByName(routeName) + if not AprRCData or not AprRCData.Routes or #AprRCData.Routes == 0 then + AprRC:Debug("No routes available", nil) + return nil, nil + end + + for index, route in ipairs(AprRCData.Routes) do + if route.name == routeName then + AprRC:Debug("Route find at ", index) + return route, index + end + end + + AprRC:Debug("No routes available for the name: ", routeName) + return nil, nil +end + +function AprRC:UpdateRouteByName(routeName, newRouteData) + local route, index = self:FindRouteByName(routeName) + if route and index then + AprRCData.Routes[index] = newRouteData + return true + else + return false + end +end diff --git a/Utils.lua b/helper/Utils.lua similarity index 78% rename from Utils.lua rename to helper/Utils.lua index 6a3cfb7..550f9ce 100644 --- a/Utils.lua +++ b/helper/Utils.lua @@ -34,36 +34,6 @@ function AprRC:IsTableEmpty(table) return false end -function AprRC:SplitQuestAndObjective(questID) - local id, objective = questID:match("([^%-]+)%-([^%-]+)") - if id and objective then - return tonumber(id), tonumber(objective) - end - return tonumber(questID) -end - -function AprRC:saveQuestInfo() - AprRC:Debug("Save QuestInfo") - AprRC.lastQuestState = AprRC.lastQuestState or {} - for i = 1, C_QuestLog.GetNumQuestLogEntries() do - local info = C_QuestLog.GetInfo(i) - if info and not info.isHidden then - local objectives = C_QuestLog.GetQuestObjectives(info.questID) - if objectives then - for index, objective in ipairs(objectives) do - AprRC.lastQuestState[info.questID] = AprRC.lastQuestState[info.questID] or {} - AprRC.lastQuestState[info.questID][index] = { numFulfilled = objective.numFulfilled } - end - end - end - end -end - -function AprRC:IsInInstanceQuest() - local isIntance, type = IsInInstance() - return isIntance and type == "scenario" -end - function AprRC:GetItemIDFromLink(link) local _, _, itemID = string.find(link, "item:(%d+):") return itemID