comparison core.lua @ 24:61d932f0e8f2

Reassigning loot in the main tab also updates entries in the history tab.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Wed, 21 Sep 2011 06:21:48 +0000
parents 8664134bba4f
children cb9635999171
comparison
equal deleted inserted replaced
23:8664134bba4f 24:61d932f0e8f2
1535 id = e.id, 1535 id = e.id,
1536 when = self:format_timestamp (g_today, e), 1536 when = self:format_timestamp (g_today, e),
1537 count = e.count, 1537 count = e.count,
1538 } 1538 }
1539 tinsert (h, 1, n) 1539 tinsert (h, 1, n)
1540 end 1540 e.history_unique = n.id .. ' ' .. n.when
1541 1541 end
1542
1543 -- Create new history table based on current loot.
1542 function addon:rewrite_history (realmname) 1544 function addon:rewrite_history (realmname)
1543 local r = assert(realmname) 1545 local r = assert(realmname)
1544 self.history_all[r] = self:_prep_new_history_category (nil, r) 1546 self.history_all[r] = self:_prep_new_history_category (nil, r)
1545 self.history = self.history_all[r] 1547 self.history = self.history_all[r]
1546 1548
1559 for i,h in ipairs(self.history) do 1561 for i,h in ipairs(self.history) do
1560 tsort (h, comp) 1562 tsort (h, comp)
1561 end 1563 end
1562 end 1564 end
1563 1565
1566 -- Clears all but latest entry for each player.
1564 function addon:preen_history (realmname) 1567 function addon:preen_history (realmname)
1565 local r = assert(realmname) 1568 local r = assert(realmname)
1566 for i,h in ipairs(self.history) do 1569 for i,h in ipairs(self.history) do
1567 tsort (h, comp) 1570 tsort (h, comp)
1568 while #h > 1 do 1571 while #h > 1 do
1569 tremove (h) 1572 tremove (h)
1570 end 1573 end
1571 end 1574 end
1575 end
1576
1577 function addon:reassign_loot (index, name_to)
1578 local e = assert(g_loot[index], "trying to reassign nonexistant entry")
1579 assert(e.kind=='loot', "trying to reassign something that isn't loot")
1580 assert(type(name_to)=='string' and name_to:len()>0)
1581
1582 local name_from = e.person
1583 local tag = e.history_unique
1584 local errtxt
1585
1586 if not tag then
1587 errtxt = "Entry for %s is missing a history tag!"
1588 else
1589 local from_i,from_h = self:get_loot_history(name_from)
1590 local to_i,to_h = self:get_loot_history(name_to)
1591
1592 local hi
1593 for i,h in ipairs(from_h) do
1594 local unique = h.id .. ' ' .. h.when
1595 if unique == tag then
1596 hi = i
1597 break
1598 end
1599 end
1600 if not hi then
1601 -- 1) loot an item, 2) clear old history, 3) reassign from current loot
1602 -- Bah. Anybody that tricky is already recoding the tables directly anyhow.
1603 errtxt = "There is no record of %s ever having been assigned!"
1604 else
1605 hi = tremove (from_h, hi)
1606 tinsert (to_h, 1, hi)
1607 tsort (from_h, comp)
1608 tsort (to_h, comp)
1609 end
1610 end
1611
1612 if errtxt then
1613 self:Print(errtxt .. " Loot will be reassigned but history will NOT be updated.", e.itemlink)
1614 end
1615 e.person = name_to
1616 e.person_class = select(2,UnitClass(name_to))
1617
1618 self:Print("Reassigned entry %d from '%s' to '%s'.", index, name_from, name_to)
1572 end 1619 end
1573 end 1620 end
1574 1621
1575 1622
1576 ------ Player communication 1623 ------ Player communication