Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Update NxQuest.lua#120

Open
Thrumbar wants to merge 2 commits intomikepauer:masterfrom
Thrumbar:master
Open

Update NxQuest.lua#120
Thrumbar wants to merge 2 commits intomikepauer:masterfrom
Thrumbar:master

Conversation

@Thrumbar
Copy link
Copy Markdown
Contributor

Trying to chop down large blocks and improve readability. Have been working on this for some time and posting for fresh eyes.
The below function blocks were refactored down into smaller, more manageable functions,,

*** There is a short lag upon loading a character for the tables to fill for quest icons on map....

These are the functions that are affected
function Nx.Quest:UpdateIcons(map)
function Nx.Quest:RecordQuestsLog()

https://github.com/Thrumbar/Carbonite.Quests

Trying to chop down large blocks and improve readability.
function Nx.Quest:UpdateIcons(map)
function Nx.Quest:RecordQuestsLog()
@IrcDirk
Copy link
Copy Markdown
Collaborator

IrcDirk commented Sep 24, 2024

What parts of code did u removed? I see there is no ZygorGuidesViewer integration.

Reinsert zygor into code
@Thrumbar
Copy link
Copy Markdown
Contributor Author

Thrumbar commented Sep 27, 2024

Uodated Nx.Quest.Watch:UpdateList() by extraction out various functions. Updated depreciated code with correct C_QuestLog
entry. (GetQuestLogTitle and GetQuestTagInfo)
Functions are now with this update are

Nx.Quest.Watch:UpdateList
Nx.Quest.Watch:GetQuestFilters --Function to handle quest filters
Nx.Quest.Watch:ProcessQuests -- Process quests and return watched list
Nx.Quest.Watch:HandleAutoTarget -- Handle auto-targeting the closest quest
Nx.Quest.Watch:HandleClosestQuest -- Remember closest quest for communication
Nx.Quest.Watch:DisplayQuests -- Display quests
Nx.Quest.Watch:DisplayQuest -- Display a single quest , set quest display, display distance if available, show party description if
available and handle objective display
Nx.Quest.Watch:DisplayQuestObjectives -- Display objectives for a quest
Nx.Quest.Watch:HandleEmissaries -- Handle Emissaries display
Nx.Quest.Watch:DisplayEmissaries -- Function to display emissaries
Nx.Quest.Watch:DisplayEmissary -- Function to display a single emissary
Nx.Quest.Watch:ScanTip -- Scan tooltip for bounty
Nx.Quest.Watch:AddObjectivesToTooltip -- Helper function to add objectives to the GameTooltip
Nx.Quest.Watch:UpdateListDisplay -- Update list display

Broke down large sections of the original function into logical helper functions: GetQuestFilters, ProcessQuests, HandleAutoTarget, HandleClosestQuest, DisplayQuests, HandleEmissaries, DisplayEmissaries, and DisplayEmissary. This improves readability and maintainability.

@Thrumbar
Copy link
Copy Markdown
Contributor Author

Will update with more info when I get back from hospital with my mother who has lab test all morning.

@Thrumbar
Copy link
Copy Markdown
Contributor Author

Also will reinstall the Zygor parts with updated push

@Thrumbar
Copy link
Copy Markdown
Contributor Author

Thrumbar commented Sep 30, 2024

Changes to Nx.Quest:RecordQuestsLog also include updating GetQuestLogTitle and GetQuestTagInfo...

local s1, _, oldCnt = strfind(cur[n] or "", "(%d+)/%d+ ")
if s1 then
  oldCnt = tonumber(oldCnt)
end

local s1, _, newCnt = strfind(desc, "(%d+)/%d+ ")
if s1 then
  newCnt = tonumber(newCnt)
end

into

function Nx.Quest:extractCountFromDescription(desc)
  if desc then
    local match = string.match(desc, "(%d+)/%d+")
    return match and tonumber(match) or nil
  end
  return nil
end
local mask = 0
if (isComplete and ender) or lbCnt == 0 or (cur.Goto and quest["Start"]) then
  mask = 1
else
  for n = 1, 99 do
    local done = cur[n + 100]
    local obj = quest and quest["Objectives"] and quest["Objectives"][n]
    if not obj then break end
    if obj and not done then
      mask = mask + bit.lshift(1, n)
    end
  end
end

into

function Nx.Quest:calculateMask(cur, quest, questInfo)
  local mask = 0
  local ender = quest and (quest["End"] or quest["Start"])

  if (questInfo.isComplete and ender) or cur.LBCnt == 0 or (cur.Goto and quest["Start"]) then
    mask = 1
  else
    for n = 1, 99 do
      local done = cur[n + 100]
      local obj = quest and quest.Objectives and quest.Objectives[n]
      if not obj then break end
      if obj and not done then
        mask = mask + bit.lshift(1, n)
      end
    end
  end
  return mask
end
if Nx.qdb.profile.Quest.PartyShare and self.Watch.ButShowParty:GetPressed() then
  local pq = self.PartyQ

  for plName, pdata in pairs(pq) do
    for qId, qT in pairs(pdata) do
      local quest = Nx.Quests[qId]
      local cur = qIds[qId]

      -- Logic for handling party quests
    end
  end
end

into

function Nx.Quest:processPartyQuests(qIds, curq)
  local pq = self.PartyQ
  for plName, pdata in pairs(pq) do
    for qId, qT in pairs(pdata) do
      local quest = Nx.Quests[qId]
      local cur = qIds[qId]

      -- Logic for handling party quests
    end
  end
end
local cur = {}
cur.Goto = true
cur.Party = plName
cur.PartyDesc = format("\n|cff8080f0%s|r", plName)
cur.PartyNames = cur.PartyDesc
cur.Q = quest
cur.QI = 0
cur.QId = qId
cur.Header = "Party, " .. plName
cur.Title = name
cur.ObjText = ""
cur.Level = lvl
cur.PartySize = 1
cur.TagShort = ""
cur.Complete = qT.Complete
cur.Priority = 1
cur.Distance = 999999999

into

function Nx.Quest:createPartyQuestEntry(plName, quest, qT)
  local name, _, lvl = self:Unpack(quest.Quest)
  local partyDesc = "\n|cff8080f0" .. plName .. "|r"
  local cur = {
    Goto = true,
    Party = plName,
    PartyDesc = partyDesc,
    PartyNames = partyDesc,
    Q = quest,
    QI = 0,
    QId = quest.Id,
    Header = "Party, " .. plName,
    Title = name,
    ObjText = "",
    Level = lvl,
    PartySize = 1,
    TagShort = "",
    Complete = qT.Complete,
    Priority = 1,
    Distance = math.huge,
    LBCnt = #qT
  }

  -- More processing logic here...

  return cur
end

@Thrumbar
Copy link
Copy Markdown
Contributor Author

Changes to Nx.Quest:UpdateIcons also include updating GetQuestLogTitle and GetQuestTagInfo...

local Nx = Nx
local Quest = Nx.Quest
local Map = Nx.Map
local qLocColors = Quest.QLocColors
local ptSz = 4 * map.ScaleDraw
local navscale = Map.Maps[1].IconNavScale * 16
local showOnMap = true -- Quest.Watch.ButShowOnMap:GetPressed()

local opts = self.GOpts
local showWatchAreas = Nx.qdb.profile.Quest.MapShowWatchAreas
local trkR, trkG, trkB, trkA = Nx.Quest.Cols["trkR"], Nx.Quest.Cols["trkG"], Nx.Quest.Cols["trkB"], Nx.Quest.Cols["trkA"]
local hovR, hovG, hovB, hovA = Nx.Quest.Cols["hovR"], Nx.Quest.Cols["hovG"], Nx.Quest.Cols["hovB"], Nx.Quest.Cols["hovA"]

into

function Nx.Quest:InitializeQuestIconSettings(map)
  local Quest = Nx.Quest
  local Map = Nx.Map
  self.qLocColors = Quest.QLocColors
  self.ptSz = 4 * map.ScaleDraw
  self.navscale = Map.Maps[1].IconNavScale * 16
  self.showOnMap = true -- Quest.Watch.ButShowOnMap:GetPressed()
  self.opts = self.GOpts
  self.showWatchAreas = Nx.qdb.profile.Quest.MapShowWatchAreas
  self.trkR, self.trkG, self.trkB, self.trkA = Quest.Cols["trkR"], Quest.Cols["trkG"], Quest.Cols["trkB"], Quest.Cols["trkA"]
  self.hovR, self.hovG, self.hovB, self.hovA = Quest.Cols["hovR"], Quest.Cols["hovG"], Quest.Cols["hovB"], Quest.Cols["hovA"]
end
local typ, tid = Map:GetTargetInfo()
if typ == "Q" then
  local qid = math.floor(tid / 100)
  local i, cur = Quest:FindCur(qid)

  if cur then
    Quest:CalcDistances(cur.Index, cur.Index)
    Quest:TrackOnMap(cur.QId, tid % 100, cur.QI > 0 or cur.Party, true, true)
  end
end

into

function Nx.Quest:HandleQuestTarget(map)
  local typ, tid = Nx.Map:GetTargetInfo()
  if typ == "Q" then
    local qid = math.floor(tid / 100)
    local i, cur = Nx.Quest:FindCur(qid)

    if cur then
      Nx.Quest:CalcDistances(cur.Index, cur.Index)
      Nx.Quest:TrackOnMap(cur.QId, tid % 100, cur.QI > 0 or cur.Party, true, true)
    end
  end
end
if Nx.Tick % 10 == 0 then
  wipe(tracking)

  for trackId, trackMode in pairs(Quest.Tracking) do
    tracking[trackId] = trackMode
  end

  if showOnMap then
    for k, cur in ipairs(Quest.CurQ) do
      if cur.Q and (Nx.Quest:GetQuest(cur.QId) == "W" or cur.PartyDesc) then
        tracking[cur.QId] = (tracking[cur.QId] or 0) + 0x10000
      end
    end
  end

  self.IconTracking = tracking
end

into

`function` Nx.Quest:UpdateTrackedQuests(map)
  if Nx.Tick % 10 == 0 then
    local tracking = self.IconTracking
    wipe(tracking)
    for trackId, trackMode in pairs(Nx.Quest.Tracking) do
      tracking[trackId] = trackMode
    end
    if self.showOnMap then
      for _, cur in ipairs(Nx.Quest.CurQ) do
        if cur.Q and (Nx.Quest:GetQuest(cur.QId) == "W" or cur.PartyDesc) then
          tracking[cur.QId] = (tracking[cur.QId] or 0) + 0x10000
        end
      end
    end
    self.IconTracking = tracking
  end
end
for trackId, trackMode in pairs(tracking) do
  if QuestDataProviderMixin:ShouldShowQuest(trackId, mapType, Nx.qdb.profile.Quest.MapShowTaskObjectives, false) then
    local cur = Quest.IdToCurQ[trackId]
    local quest = cur and cur.Q or Nx.Quests[trackId]
    local qname = Nx.TXTBLUE .. "Quest: " .. (cur and cur.Title or Quest:UnpackName(quest["Quest"]))

    -- Further processing for showing quest icons...
  end
end

into

function Nx.Quest:RenderQuestIconForSingleQuest(map, cur, quest, trackMode, colorPerQ, colMax, areaTex)
  local Quest = Nx.Quest
  local qname = Nx.TXTBLUE .. "Quest: " .. (cur and cur.Title or Quest:UnpackName(quest["Quest"]))
  local mask = self.showOnMap and cur and cur.TrackMask or trackMode
  local showEnd

  if bit.band(mask, 1) > 0 then
    if not (cur and (cur.QI > 0 or cur.Party)) then
      local startName, zone, x, y = Quest:GetSEPos(quest["Start"])
      self:PlaceQuestIcon(map, zone, x, y, qname, "Start", startName)
    else
      showEnd = true
    end
  end

  if showEnd or bit.band(mask, 0x10000) > 0 then
    local obj = quest["End"] or quest["Start"]
    local endName, zone, x, y = Quest:GetSEPos(obj)
    if zone and (not cur or not cur.CompleteMerge) then
      self:PlaceQuestIcon(map, zone, x, y, qname, "End", endName)
    end
  end
end
local taskIconIndex = 1
local activeWQ = {}
if Map.UpdateMapID ~= 9000 then
  if Nx.Map.mapChange then
    taskInfoCache = C_TaskQuest.GetQuestsForPlayerByMapID(Map.UpdateMapID)
  end
  local taskInfo = taskInfoCache
  if taskInfo and Nx.db.char.Map.ShowWorldQuest then
    for i = 1, #taskInfo do
      local info = taskInfo[i]
      local questId = taskInfo[i].questId
      local title, faction = C_TaskQuest.GetQuestInfoByQuestID(questId)

      -- Further processing for showing world quest icons...
    end
  end
end

into

function Nx.Quest:HandleWorldQuests(map)
  local taskIconIndex = 1
  local activeWQ = {}
  if Nx.Map.UpdateMapID ~= 9000 then
    if Nx.Map.mapChange then
      self.taskInfoCache = C_TaskQuest.GetQuestsForPlayerByMapID(Nx.Map.UpdateMapID)
    end

    local taskInfo = self.taskInfoCache
    if taskInfo and Nx.db.char.Map.ShowWorldQuest then
      for i = 1, #taskInfo do
        local info = taskInfo[i]
        self:RenderWorldQuestIcon(map, info)
      end
    end
  end
end

-- Render individual world quest icons
function Nx.Quest:RenderWorldQuestIcon(map, info)
  local questId = info.questId
  local title, faction = C_TaskQuest.GetQuestInfoByQuestID(questId)

  local questTagInfo = C_QuestLog.GetQuestTagInfo(questId)
  if questTagInfo then
    local timeLeft = C_TaskQuest.GetQuestTimeLeftMinutes(questId)
    if QuestUtils_ShouldDisplayExpirationWarning(questId) or (timeLeft and timeLeft > 0) then
      local x, y = info.x * 100, info.y * 100
      local f = map:GetIconWQ(120)

      map:ClipFrameZ(f, x, y, 24, 24, 0)

      local selected = info.questId == C_SuperTrack.GetSuperTrackedQuestID()
      local isCriteria = self:IsWorldQuestCriteria(info.questId)

      f.worldQuest = true
      f.questID = info.questId
      f.numObjectives = info.numObjectives
      f.Texture:SetDrawLayer("OVERLAY")
      f:SetScript("OnClick", function(self, button)
        self:HandleWorldQuestClick(map, x, y, self.questID)
      end)

      if questTagInfo.tagName then
        QuestUtil.SetupWorldQuestButton(f, questTagInfo, questTagInfo.tagName, selected, isCriteria, false, true)
      else
        f:Hide()
      end

      f.texture:Hide()
    end
  end
end
-- Inside the world quest section
if ZygorGuidesViewer and ZygorGuidesViewer.WorldQuests then
  ZygorGuidesViewer.WorldQuests:SuggestWorldQuestGuideFromMap(nil, self.questID, "force", self.mapID)
end

into

-- Handle click events on world quest icons
function Nx.Quest:HandleWorldQuestClick(map, x, y, questId)
  map:SetTargetAtStr(string.format("%s, %s", x, y))
  if not InCombatLockdown() then
    if not ChatEdit_TryInsertQuestLinkForQuestID(questId) then
      local watchType = C_QuestLog.GetQuestWatchType(questId)
      local isSuperTracked = C_SuperTrack.GetSuperTrackedQuestID() == questId

      -- Zygor World Quest Guide suggestion
      if ZygorGuidesViewer and ZygorGuidesViewer.WorldQuests then
        ZygorGuidesViewer.WorldQuests:SuggestWorldQuestGuideFromMap(nil, questId, "force", Nx.Map.UpdateMapID)
      end

      if IsShiftKeyDown() then
        if watchType == Enum.QuestWatchType.Manual or (watchType == Enum.QuestWatchType.Automatic and isSuperTracked) then
          PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF)
          QuestUtil.UntrackWorldQuest(questId)
        else
          PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
          QuestUtil.TrackWorldQuest(questId, Enum.QuestWatchType.Manual)
        end
      else
        if isSuperTracked then
          PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF)
          C_SuperTrack.SetSuperTrackedQuestID(0)
        else
          PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
          if watchType ~= Enum.QuestWatchType.Manual then
            QuestUtil.TrackWorldQuest(questId, Enum.QuestWatchType.Automatic)
          end
          C_SuperTrack.SetSuperTrackedQuestID(questId)
        end
      end
    end
  end
end

@Thrumbar
Copy link
Copy Markdown
Contributor Author

Posted for comments. The full changes can be downloaded form my git if anyone wants to test and comment. Cannot test Zygor as I do not use what essentially is a paid for app.

@IrcDirk
Copy link
Copy Markdown
Collaborator

IrcDirk commented Sep 30, 2024

A lot of changes...

@Thrumbar Thrumbar closed this Oct 22, 2024
@IrcDirk IrcDirk reopened this Oct 22, 2024
@IrcDirk
Copy link
Copy Markdown
Collaborator

IrcDirk commented Oct 22, 2024

Dont close it... i need more time to analyse those changes ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants