TG: Shadowglen finetune
[WoW-TourGuide.git] / Parser.lua
blob17d570ae8453ae253e52caa0c59425898bf863bc
3 local actiontypes = {
4 A = "ACCEPT",
5 C = "COMPLETE",
6 T = "TURNIN",
7 K = "KILL",
8 R = "RUN",
9 t = "TRAIN",
10 H = "HEARTH",
11 h = "SETHEARTH",
12 G = "GRIND",
13 F = "FLY",
14 f = "GETFLIGHTPOINT",
15 N = "NOTE",
16 B = "BUY",
17 b = "BOAT",
18 U = "USE",
22 function TourGuide:GetObjectiveTag(tag, i)
23 self:Debug(11, "GetObjectiveTag", tag, i)
24 i = i or self.current
25 local tags = self.tags[i]
26 if not tags then return end
28 if tag == "O" then return tags:find("|O|")
29 elseif tag == "L" then
30 local _, _, lootitem, lootqty = tags:find("|L|(%d+)%s?(%d*)|")
31 lootqty = tonumber(lootqty) or 1
33 return lootitem, lootqty
34 end
36 return select(3, tags:find("|"..tag.."|([^|]*)|?"))
37 end
40 local myclass = UnitClass("player")
41 local titlematches = {"For", "A", "The", "Or", "In", "Then", "From", "To"}
42 local function ParseQuests(...)
43 local accepts, turnins, completes = {}, {}, {}
44 local uniqueid = 1
45 local actions, quests, tags = {}, {}, {}
46 local i, haserrors = 1, false
48 for j=1,select("#", ...) do
49 local text = select(j, ...)
50 local _, _, class = text:find("|C|([^|]+)|")
52 if text ~= "" and (not class or class == myclass) then
53 local _, _, action, quest, tag = text:find("^(%a) ([^|]*)(.*)")
54 assert(actiontypes[action], "Unknown action: "..text)
55 quest = quest:trim()
56 if not (action == "A" or action =="C" or action =="T") then
57 quest = quest.."@"..uniqueid.."@"
58 uniqueid = uniqueid + 1
59 end
61 actions[i], quests[i], tags[i] = actiontypes[action], quest, tag
63 i = i + 1
65 -- Debuggery
66 if not string.find(text, "|NODEBUG|") then
67 if action == "A" then accepts[quest] = true
68 elseif action == "T" then turnins[quest] = true
69 elseif action == "C" then completes[quest] = true end
71 if action == "A" or action == "C" or action == "T" then
72 -- Catch bad Title Case
73 for _,word in pairs(titlematches) do
74 if quest:find("[^:]%s"..word.."%s") or quest:find("[^:]%s"..word.."$") or quest:find("[^:]%s"..word.."@") then
75 TourGuide:DebugF(1, "%s %s -- Contains bad title case", action, quest)
76 haserrors = true
77 end
78 end
80 if quest:find("[“”’]") then
81 TourGuide:DebugF(1, "%s %s -- Contains bad char", action, quest)
82 haserrors = true
83 end
84 end
86 local _, _, comment = string.find(text, "(|[NLUC]V?|[^|]+)$") or string.find(text, "(|[NLUC]V?|[^|]+) |[NLUC]V?|")
87 if comment then
88 TourGuide:Debug(1, "Unclosed comment: ".. comment)
89 haserrors = true
90 end
91 end
92 end
93 end
95 -- More debug
96 for quest in pairs(accepts) do if not turnins[quest] then TourGuide:DebugF(1, "Quest has no 'turnin' objective: %s", quest) end end
97 for quest in pairs(turnins) do if not accepts[quest] then TourGuide:DebugF(1, "Quest has no 'accept' objective: %s", quest) end end
98 for quest in pairs(completes) do if not accepts[quest] and not turnins[quest] then TourGuide:DebugF(1, "Quest has no 'accept' and 'turnin' objectives: %s", quest) end end
100 if haserrors and TourGuide:IsDebugEnabled() then TourGuide:Print("This guide contains errors") end
102 return actions, quests, tags
106 function TourGuide:LoadGuide(name)
107 if not name then return end
109 self.db.char.currentguide = name
110 if not self.guides[name] then self.db.char.currentguide = self.guidelist[1] end
111 self:DebugF(1, "Loading guide: %s", name)
112 self.guidechanged = true
113 local _, _, zonename = name:find("^(.*) %(.*%)$")
114 self.zonename = zonename
115 self.actions, self.quests, self.tags = ParseQuests(string.split("\n", self.guides[self.db.char.currentguide]()))