Open GoogleCodeExporter opened 8 years ago
This will be too error prone. If note is too long and there is no space for EP
and GP the addon would either fail (bad) or will truncate the note (also bad).
Original comment by evlogimenos
on 14 Oct 2010 at 11:53
Original comment by evlogimenos
on 14 Oct 2010 at 11:54
Truncating the note is acceptable because that means whomever put then note
there screwed up, and this is certainly a case where something is better than
nothing.
For my purposes, the note wouldn't be bigger than 2-4 characters max and if
necessary, I can use 1-2 characters. (The note is a code for my bidding mod to
keep track of a user's raiding role. This way I can use the oNote to store
this information instead of trying to merge a database between several officers)
For my guild, EP numbers have never exceeded 1 million, and GP numbers have
never exceeded 100,000. This amounts to 12 characters, which is the same
length of a WoW name.
Since notes are 31 characters long, this leaves at most 18 characters (since 1
more is being used by the extra comma delimiter) for the note, which is more
than I need.
Here's what I require:
1. EPGP needs to be able to parse EP,GP and EP,GP,* and MAIN and MAIN,* as
valid officer note entries (* = the note).
2. EPGP needs to preserve the note, if present, when altering EPGP values in
the officer note. Truncating the note is acceptable!
Here's what I *don't* need:
1. EPGP doesn't need to support notes in import or export or logs
2. EPGP doesn't need to preserve notes when doing a full reset
3. EPGP doesn't need an interface to enter in notes
Original comment by Zensu...@gmail.com
on 14 Oct 2010 at 6:12
Reopening.
Original comment by evlogimenos
on 17 Oct 2010 at 10:07
Thank you! :) If you need any assistance, I'd be glad to help.
I was looking into the code myself and found that improving the DecodeNote()
function to look for the additional mask and adding a wrapper around GS:SetNote
calls to preserve the existing "additional note" would do the trick.
Original comment by Zensu...@gmail.com
on 18 Oct 2010 at 1:35
Here you go. I coded it for you. It's backward compatible to work with or
without notes and as a bonus, it displays the note in the tooltip. Alts can
also have their own note. I would also like to point out that if the note gets
truncated due to space/length issues, the EPGP values are preserved. Attached
is a code comparison of my changes as well as the modified version based on
5.5.22
epgp\epgp.lua
175 175 local global_config = {}
176 176 local ep_data = {}
177 177 local gp_data = {}
------------------------------------------------------------------------
178 local officer_note_data = {}
------------------------------------------------------------------------
179 178 local main_data = {}
180 179 local alt_data = {}
181 180 local ignored = {}
188 187 if note then
189 188 if note == "" then
190 189 return 0, 0
191 190 else
------------------------------------------------------------------------
192 local ep, gp, officer_note = string.match(note,
"^(%d+),(%d+),(.+)$")
193 if ep then
194 return tonumber(ep), tonumber(gp), tostring(officer_note)
195 end
196
------------------------------------------------------------------------
197 191 local ep, gp = string.match(note, "^(%d+),(%d+)$")
198 192 if ep then
199 193 return tonumber(ep), tonumber(gp)
200 194 end
201 195 end
202 196 end
203 197 end
204 198
------------------------------------------------------------------------
205 local function EncodeNote(ep, gp, officer_note)
206 if (officer_note) then
207 return string.format("%d,%d,%s",
208 math.max(ep, 0),
209 math.max(gp - global_config.base_gp, 0),
210 officer_note)
211 else
212 return string.format("%d,%d",
------------------------------------------------------------------------
213 201 math.max(ep, 0),
214 202 math.max(gp - global_config.base_gp, 0))
------------------------------------------------------------------------
215 end
------------------------------------------------------------------------
216 203 end
217 204
218 205 local function AddEPGP(name, ep, gp)
219 206 local total_ep = ep_data[name]
220 207 local total_gp = gp_data[name]
------------------------------------------------------------------------
221 local officer_note = officer_note_data[name]
------------------------------------------------------------------------
222 208 assert(total_ep ~= nil and total_gp ~=nil,
223 209 string.format("%s is not a main!", tostring(name)))
224 210
225 211 -- Compute the actual amounts we can add/subtract.
226 212 if (total_ep + ep) < 0 then
227 213 ep = -total_ep
228 214 end
229 215 if (total_gp + gp) < 0 then
230 216 gp = -total_gp
231 217 end
232 218
233 219 GS:SetNote(name, EncodeNote(total_ep + ep,
------------------------------------------------------------------------
234 total_gp + gp + global_config.base_gp,
235 officer_note))
------------------------------------------------------------------------
236 221 return ep, gp
237 222 end
238 223
437 422 local function ParseGuildNote(callback, name, note)
438 423 Debug("Parsing Guild Note for %s [%s]", name, note)
439 424 -- Delete current state about this toon.
440 425 DeleteState(name)
441 426
------------------------------------------------------------------------
442 local ep, gp, officer_note = DecodeNote(note)
------------------------------------------------------------------------
443 428 if ep then
444 429 ep_data[name] = ep
445 430 gp_data[name] = gp
------------------------------------------------------------------------
446 officer_note_data[name] = officer_note
------------------------------------------------------------------------
447 431 else
------------------------------------------------------------------------
448 local alt_name, officer_note = string.match(note, "^(.+),(.+)$")
449 if (not officer_note) then
450 alt_name = note
451 end
452 local main_ep = DecodeNote(GS:GetNote(alt_name))
------------------------------------------------------------------------
453 433 if not main_ep then
454 434 -- This member does not point to a valid main, ignore it.
------------------------------------------------------------------------
455 ignored[name] = alt_name
------------------------------------------------------------------------
456 436 else
457 437 -- Otherwise setup the alts state
------------------------------------------------------------------------
458 main_data[name] = alt_name
459 if not alt_data[alt_name] then
460 alt_data[alt_name] = {}
------------------------------------------------------------------------
461 441 end
------------------------------------------------------------------------
462 table.insert(alt_data[alt_name], name)
------------------------------------------------------------------------
463 443 ep_data[name] = nil
464 444 gp_data[name] = nil
------------------------------------------------------------------------
465 officer_note_data[name] = officer_note
------------------------------------------------------------------------
466 445 end
467 446 end
468 447 DestroyStandings()
469 448 end
953 932 function EPGP:OnEnable()
954 933 GS.RegisterCallback(self, "GuildInfoChanged", ParseGuildInfo)
955 934 GS.RegisterCallback(self, "GuildNoteChanged", ParseGuildNote)
956 935 GS.RegisterCallback(self, "GuildNoteDeleted", HandleDeletedGuildNote)
957 936
958 937 EPGP.RegisterCallback(self, "BaseGPChanged", DestroyStandings)
959 938
960 939 self:RegisterEvent("RAID_ROSTER_UPDATE")
961 940 self:RegisterEvent("GUILD_ROSTER_UPDATE")
962 941
963 942 GuildRoster()
964 943 end
------------------------------------------------------------------------
965
966 function EPGP:GetOfficerNote(name)
967 return officer_note_data[name]
968 end
------------------------------------------------------------------------
epgp\ui.lua
1289 1289 r:SetScript(
1290 1290 "OnEnter",
1291 1291 function(self)
1292 1292 GameTooltip_SetDefaultAnchor(GameTooltip, self)
1293 1293 GameTooltip:AddLine(GS:GetRank(self.name))
------------------------------------------------------------------------
1294 if EPGP:GetOfficerNote(self.name) then
1295 GameTooltip:AddLine(EPGP:GetOfficerNote(self.name), 1, 1, 1)
1296 end
------------------------------------------------------------------------
1297 1294 if EPGP:GetNumAlts(self.name) > 0 then
1298 1295 GameTooltip:AddLine("\n"..L["Alts"])
1299 1296 for i=1,EPGP:GetNumAlts(self.name) do
1300 1297 GameTooltip:AddLine(EPGP:GetAlt(self.name, i), 1, 1, 1)
1301 1298 end
1302 1299 end
1303 1300 GameTooltip:ClearAllPoints()
1304 1301 GameTooltip:SetPoint("TOPLEFT", self, "TOPRIGHT")
1305 1302 GameTooltip:Show()
1306 1303 end)
1307 1304 r:SetScript("OnLeave", function() GameTooltip:Hide() end)
1308 1305 end
Original comment by Zensu...@gmail.com
on 10 Nov 2010 at 8:42
Attachments:
Original issue reported on code.google.com by
Zensu...@gmail.com
on 13 Oct 2010 at 9:10