comparison core.lua @ 84:c87bf3e756f3

Properly handle dropdown menus for the History tab now, initially with delete-item and delete-player entries. Some code cleanup and notes for future work.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Thu, 21 Jun 2012 02:17:26 +0000
parents 940e53dd18c3
children 4771ee8eaa81
comparison
equal deleted inserted replaced
83:940e53dd18c3 84:c87bf3e756f3
818 if e.kind == 'loot' then 818 if e.kind == 'loot' then
819 if e.history_unique then 819 if e.history_unique then
820 e.unique, e.history_unique = e.history_unique, nil 820 e.unique, e.history_unique = e.history_unique, nil
821 end 821 end
822 if e.unique == nil or #e.unique == 0 then 822 if e.unique == nil or #e.unique == 0 then
823 e.unique = e.id .. ' ' .. date("%Y/%m/%d %H:%M",e.stamp) 823 e.unique = e.id .. e.person .. date("%Y/%m/%d %H:%M:%S",e.stamp)
824 end 824 end
825 end 825 end
826 end 826 end
827 end 827 end
828 828
2264 -- DAY is a loot entry with kind=='time', and controls the date printed. 2264 -- DAY is a loot entry with kind=='time', and controls the date printed.
2265 -- LOOT may be any kind of entry in the g_loot table. If present, it 2265 -- LOOT may be any kind of entry in the g_loot table. If present, it
2266 -- overrides the hour and minute printed; if absent, those values are 2266 -- overrides the hour and minute printed; if absent, those values are
2267 -- taken from the DAY entry. 2267 -- taken from the DAY entry.
2268 -- FORMAT_STRING may contain $x (x in Y/M/D/h/m) tokens. 2268 -- FORMAT_STRING may contain $x (x in Y/M/D/h/m) tokens.
2269 -- FIXME this is horribabble
2269 local format_timestamp_values, point2dee = {}, "%.2d" 2270 local format_timestamp_values, point2dee = {}, "%.2d"
2270 function addon:format_timestamp (fmt_opt, day_entry, time_entry_opt) 2271 function addon:format_timestamp (fmt_opt, day_entry, time_entry_opt)
2271 if not time_entry_opt then 2272 if not time_entry_opt then
2272 if type(fmt_opt) == 'table' then -- Two entries, default format 2273 if type(fmt_opt) == 'table' then -- Two entries, default format
2273 time_entry_opt, day_entry = day_entry, fmt_opt 2274 time_entry_opt, day_entry = day_entry, fmt_opt
2463 B: winner was generated remotely 2464 B: winner was generated remotely
2464 >need to scan and replace 2465 >need to scan and replace
2465 Detecting A is strictly an optimization. We should be able to do 2466 Detecting A is strictly an optimization. We should be able to do
2466 this code safely in all cases. 2467 this code safely in all cases.
2467 ]] 2468 ]]
2468 if winning_index ~= 1 then 2469 if
2470 --@debug@
2471 true or
2472 --@end-debug@
2473 winning_index ~= 1 then
2469 --XXX this branch still needs to be tested with live data 2474 --XXX this branch still needs to be tested with live data
2470 local cache = g_uniques:SEARCH(exist) 2475 local cache = g_uniques:SEARCH(exist)
2471 local looti,hi,ui = cache.loot, cache.history, cache.history_may 2476 local looti,hi,ui = cache.loot, cache.history, cache.history_may
2472 2477
2473 -- Active loot 2478 -- Active loot
2870 local i,h = self:get_loot_history(e.person) 2875 local i,h = self:get_loot_history(e.person)
2871 local when = self:format_timestamp (g_today, e) 2876 local when = self:format_timestamp (g_today, e)
2872 2877
2873 -- If any of these change, update the end of history_handle_disposition. 2878 -- If any of these change, update the end of history_handle_disposition.
2874 if (not e.unique) or (#e.unique==0) then 2879 if (not e.unique) or (#e.unique==0) then
2875 e.unique = e.id .. ' ' .. when 2880 e.unique = e.id .. e.person .. when
2876 end 2881 end
2877 local U = e.unique 2882 local U = e.unique
2878 tinsert (h.unique, 1, U) 2883 tinsert (h.unique, 1, U)
2879 h.when[U] = when 2884 h.when[U] = when
2880 h.id[U] = e.id 2885 h.id[U] = e.id
3098 self:redisplay() 3103 self:redisplay()
3099 end 3104 end
3100 return index 3105 return index
3101 end 3106 end
3102 3107
3103 -- Similar to _addHistoryEntry. The second arg may be a loot entry 3108 local function expunge (player, index_or_unique)
3104 -- (which used to be at LOOTINDEX), or nil (and the loot entry will 3109 local i,u
3105 -- be pulled from LOOTINDEX instead). 3110 if type(index_or_unique) == 'string' then
3106 function addon:_delHistoryEntry (lootindex, opt_e) 3111 for u = 1, #player.unique do
3107 local e = opt_e or g_loot[lootindex] 3112 if player.unique[u] == index_or_unique then
3108 if e.kind ~= 'loot' then return end 3113 i = u
3109 3114 break
3110 local from_i, from_h, hist_i = _history_by_loot_id (e, "delete") 3115 end
3116 end
3117 elseif type(index_or_unique) == 'number' then
3118 i = index_or_unique
3119 end
3120 if not i then
3121 return -- error here?
3122 end
3123 u = player.unique[i]
3124 assert(#u>0)
3125 tremove (player.unique, i)
3126 player.when[u], player.id[u], player.count[u] = nil, nil, nil
3127 g_uniques[u] = nil
3128 addon.hist_clean = nil
3129 end
3130
3131 -- Mirror of _addHistoryEntry. Arguments are either:
3132 -- E - loot entry
3133 -- U,ITEM - unique tag, and a name/itemlink for errors
3134 -- Returns true on success.
3135 function addon:_delHistoryEntry (first, second)
3136 if type(first) == 'table' then
3137 second = first.itemlink or second
3138 --elseif type(first) == 'string' then
3139 end
3140
3141 local from_i, from_h, hist_i = _history_by_loot_id (first, "delete")
3142
3111 if not from_i then 3143 if not from_i then
3112 -- from_h is the formatted error text 3144 -- from_h is the formatted error text
3113 self:Print(from_h .. " Loot will be deleted, but history will NOT be updated.", e.itemlink) 3145 return nil, (from_h
3114 return 3146 .." Loot will be deleted, but history will NOT be updated."
3115 end 3147 ):format(second)
3116 3148 end
3117 local hist_u = tremove (from_h.unique, hist_i) 3149
3118 from_h.when[hist_u] = nil 3150 expunge (from_h, hist_i)
3119 from_h.id[hist_u] = nil 3151 return true
3120 from_h.count[hist_u] = nil
3121 g_uniques[hist_u] = nil
3122 self.hist_clean = nil
3123
3124 self:Print("Removed history entry %d/%s from '%s'.", lootindex, e.itemlink, e.person)
3125 end 3152 end
3126 3153
3127 -- Any extra work for the "Mark as <x>" dropdown actions. The 3154 -- Any extra work for the "Mark as <x>" dropdown actions. The
3128 -- corresponding <x> will already have been assigned in the loot entry. 3155 -- corresponding <x> will already have been assigned in the loot entry.
3129 local deleted_cache = {} 3156 local deleted_cache = {}
3139 local name = e.person 3166 local name = e.person
3140 3167
3141 if (newdisp == 'shard' or newdisp == 'gvault') then 3168 if (newdisp == 'shard' or newdisp == 'gvault') then
3142 local name_i, name_h, hist_i = _history_by_loot_id (e, "mark") 3169 local name_i, name_h, hist_i = _history_by_loot_id (e, "mark")
3143 -- remove history entry if it exists 3170 -- remove history entry if it exists
3171 -- FIXME revist this and use expunge
3144 if hist_i then 3172 if hist_i then
3145 local c = flib.new() 3173 local c = flib.new()
3146 local hist_u = tremove (name_h.unique, hist_i) 3174 local hist_u = tremove (name_h.unique, hist_i)
3147 c.when = name_h.when[hist_u] 3175 c.when = name_h.when[hist_u]
3148 c.id = name_h.id[hist_u] 3176 c.id = name_h.id[hist_u]
3172 -- cache of stuff we've already deleted; if it's not there then just do 3200 -- cache of stuff we've already deleted; if it's not there then just do
3173 -- the same steps as _addHistoryEntry. 3201 -- the same steps as _addHistoryEntry.
3174 -- FIXME The deleted cache isn't nearly as useful now with the new data structures. 3202 -- FIXME The deleted cache isn't nearly as useful now with the new data structures.
3175 local when 3203 local when
3176 if (not e.unique) or (#e.unique==0) then 3204 if (not e.unique) or (#e.unique==0) then
3177 when = g_today and self:format_timestamp (g_today, e) or date("%Y/%m/%d %H:%M",e.stamp) 3205 when = g_today and self:format_timestamp (g_today, e) or date("%Y/%m/%d %H:%M:%S",e.stamp)
3178 e.unique = e.id .. ' ' .. when 3206 e.unique = e.id .. name .. when
3179 end 3207 end
3180 local U = e.unique 3208 local U = e.unique
3181 local c = deleted_cache[U] 3209 local c = deleted_cache[U]
3182 deleted_cache[U] = nil 3210 deleted_cache[U] = nil
3183 name_h.unique[#name_h.unique+1] = U 3211 name_h.unique[#name_h.unique+1] = U
3184 name_h.when[U] = c and c.when or when or date("%Y/%m/%d %H:%M",e.stamp) 3212 name_h.when[U] = c and c.when or when or date("%Y/%m/%d %H:%M:%S",e.stamp)
3185 name_h.id[U] = e.id -- c.id 3213 name_h.id[U] = e.id -- c.id
3186 name_h.count[U] = c and c.count or e.count 3214 name_h.count[U] = c and c.count or e.count
3187 sort_player(name_h) 3215 sort_player(name_h)
3188 g_uniques[U] = { loot = index, history = name_i } 3216 g_uniques[U] = { loot = index, history = name_i }
3189 self.hist_clean = nil 3217 self.hist_clean = nil