comparison Modules/Crafting.lua @ 133:5eefa40e2a29

Trimmed trailing spaces
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 15 Sep 2010 21:34:57 -0700
parents 78c6d905c2e1
children a529a4a4ccbe
comparison
equal deleted inserted replaced
132:0eaec1b52a63 133:5eefa40e2a29
74 function Crafting.GetQueueDestination() 74 function Crafting.GetQueueDestination()
75 local dest = ItemAuditor.db.profile.queue_destination 75 local dest = ItemAuditor.db.profile.queue_destination
76 if dest and queueDestinations[dest] then 76 if dest and queueDestinations[dest] then
77 return queueDestinations[dest], dest 77 return queueDestinations[dest], dest
78 end 78 end
79 -- If there is none selected or the selected option has 79 -- If there is none selected or the selected option has
80 -- dissapeared, choose the first one in the list 80 -- dissapeared, choose the first one in the list
81 for name, func in pairs(queueDestinations) do 81 for name, func in pairs(queueDestinations) do
82 if dest then 82 if dest then
83 ItemAuditor:Print("%s is no longer available as a queue destination. %s is the new default", dest, name) 83 ItemAuditor:Print("%s is no longer available as a queue destination. %s is the new default", dest, name)
84 end 84 end
85 ItemAuditor.db.profile.queue_destination = name 85 ItemAuditor.db.profile.queue_destination = name
86 return func, name 86 return func, name
87 end 87 end
88 88
89 error('Unable to determine queue destination.') 89 error('Unable to determine queue destination.')
90 end 90 end
91 91
92 function ItemAuditor:GetCraftingThreshold() 92 function ItemAuditor:GetCraftingThreshold()
93 return self.db.char.profitable_threshold 93 return self.db.char.profitable_threshold
120 if money then 120 if money then
121 cellFrame.text:SetText(ItemAuditor:FormatMoney(tonumber(money))) 121 cellFrame.text:SetText(ItemAuditor:FormatMoney(tonumber(money)))
122 else 122 else
123 cellFrame.text:SetText("") 123 cellFrame.text:SetText("")
124 end 124 end
125 125
126 end 126 end
127 end 127 end
128 128
129 local craftingCols = { 129 local craftingCols = {
130 { name= "Item", width = 200, defaultsort = "desc", 130 { name= "Item", width = 200, defaultsort = "desc",
133 local data = realData[realrow] 133 local data = realData[realrow]
134 cellFrame.text:SetText(data.link) 134 cellFrame.text:SetText(data.link)
135 end 135 end
136 end, 136 end,
137 }, 137 },
138 { name= "Cost Each", width = 100, align = "RIGHT", 138 { name= "Cost Each", width = 100, align = "RIGHT",
139 ['DoCellUpdate'] = displayMoney, 139 ['DoCellUpdate'] = displayMoney,
140 }, 140 },
141 { name= "Est Sale Each", width = 100, align = "RIGHT", 141 { name= "Est Sale Each", width = 100, align = "RIGHT",
142 ['DoCellUpdate'] = displayMoney, 142 ['DoCellUpdate'] = displayMoney,
143 }, 143 },
144 { name= "Decided By", width = 125, align = "RIGHT", 144 { name= "Decided By", width = 125, align = "RIGHT",
145 145
146 }, 146 },
147 { name= "craft", width = 50, align = "RIGHT", 147 { name= "craft", width = 50, align = "RIGHT",
148 148
149 }, 149 },
150 { name= "Have Mats", width = 60, align = "RIGHT", 150 { name= "Have Mats", width = 60, align = "RIGHT",
151 151
152 }, 152 },
153 { name= "Profit Each", width = 100, align = "RIGHT", 153 { name= "Profit Each", width = 100, align = "RIGHT",
154 ['DoCellUpdate'] = displayMoney, 154 ['DoCellUpdate'] = displayMoney,
155 }, 155 },
156 } 156 }
157 157
158 function Crafting.ExportToSkillet(data) 158 function Crafting.ExportToSkillet(data)
159 local skillString = select(3, string.find(data.recipeLink, "^|%x+|H(.+)|h%[.+%]")) 159 local skillString = select(3, string.find(data.recipeLink, "^|%x+|H(.+)|h%[.+%]"))
160 local _, skillId = strsplit(":", skillString) 160 local _, skillId = strsplit(":", skillString)
161 161
162 ItemAuditor:AddToQueue(skillId,tradeSkillIndex, data.queue) 162 ItemAuditor:AddToQueue(skillId,tradeSkillIndex, data.queue)
163 end 163 end
164 164
165 Crafting.RegisterQueueDestination('Skillet', Crafting.ExportToSkillet) 165 Crafting.RegisterQueueDestination('Skillet', Crafting.ExportToSkillet)
166 166
174 elseif type(destination) == 'string' then 174 elseif type(destination) == 'string' then
175 destination = queueDestinations[destination] 175 destination = queueDestinations[destination]
176 else 176 else
177 error('destination must be a function or a string') 177 error('destination must be a function or a string')
178 end 178 end
179 179
180 local index = 1 180 local index = 1
181 local data = ItemAuditor:GetCraftingRow(index) 181 local data = ItemAuditor:GetCraftingRow(index)
182 while data do 182 while data do
183 if data.queue > 0 then 183 if data.queue > 0 then
184 destination(data) 184 destination(data)
185 end 185 end
186 index = index + 1 186 index = index + 1
187 data = ItemAuditor:GetCraftingRow(index) 187 data = ItemAuditor:GetCraftingRow(index)
188 188
189 end 189 end
190 end 190 end
191 191
192 -- ItemAuditor:GetModule('Crafting').filter_queued = false 192 -- ItemAuditor:GetModule('Crafting').filter_queued = false
193 Crafting.filter_have_mats = false 193 Crafting.filter_have_mats = false
216 local btnProcess = false 216 local btnProcess = false
217 local function ShowCrafting(container) 217 local function ShowCrafting(container)
218 if craftingContent == false then 218 if craftingContent == false then
219 local window = container.frame 219 local window = container.frame
220 craftingContent = CreateFrame("Frame",nil,window) 220 craftingContent = CreateFrame("Frame",nil,window)
221 craftingContent:SetBackdropColor(0, 0, 1, 0.5) 221 craftingContent:SetBackdropColor(0, 0, 1, 0.5)
222 craftingContent:SetBackdropBorderColor(1, 0, 0, 1) 222 craftingContent:SetBackdropBorderColor(1, 0, 0, 1)
223 223
224 craftingContent:SetPoint("TOPLEFT", window, 10, -50) 224 craftingContent:SetPoint("TOPLEFT", window, 10, -50)
225 craftingContent:SetPoint("BOTTOMRIGHT",window, -10, 10) 225 craftingContent:SetPoint("BOTTOMRIGHT",window, -10, 10)
226 226
227 craftingTable = ScrollingTable:CreateST(craftingCols, 22, nil, nil, craftingContent ) 227 craftingTable = ScrollingTable:CreateST(craftingCols, 22, nil, nil, craftingContent )
228 228
229 IAcc = craftingContent 229 IAcc = craftingContent
230 IAccWindow = window 230 IAccWindow = window
231 craftingTable.frame:SetPoint("TOPLEFT",craftingContent, 0,0) 231 craftingTable.frame:SetPoint("TOPLEFT",craftingContent, 0,0)
232 craftingTable.frame:SetPoint("BOTTOMRIGHT", craftingContent, 0, 30) 232 craftingTable.frame:SetPoint("BOTTOMRIGHT", craftingContent, 0, 30)
233 233
234 craftingTable:RegisterEvents({ 234 craftingTable:RegisterEvents({
235 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) 235 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
236 if realrow then 236 if realrow then
237 if column == 1 then 237 if column == 1 then
238 local data = realData[realrow] 238 local data = realData[realrow]
263 end, 263 end,
264 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) 264 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
265 GameTooltip:Hide() 265 GameTooltip:Hide()
266 end, 266 end,
267 }); 267 });
268 268
269 local craftingView = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate") 269 local craftingView = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate")
270 craftingView:SetText("View") 270 craftingView:SetText("View")
271 craftingView:SetSize(50, 25) 271 craftingView:SetSize(50, 25)
272 craftingView:SetPoint("BOTTOMLEFT", craftingContent, 0, 0) 272 craftingView:SetPoint("BOTTOMLEFT", craftingContent, 0, 0)
273 273
295 end) 295 end)
296 296
297 297
298 btnProcess = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate") 298 btnProcess = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate")
299 btnProcess:SetText("Process") 299 btnProcess:SetText("Process")
300 btnProcess:SetSize(100, 25) 300 btnProcess:SetSize(100, 25)
301 btnProcess:SetPoint("BOTTOMRIGHT", craftingContent, 0, 0) 301 btnProcess:SetPoint("BOTTOMRIGHT", craftingContent, 0, 0)
302 btnProcess:RegisterForClicks("LeftButtonUp"); 302 btnProcess:RegisterForClicks("LeftButtonUp");
303 303
304 local function UpdateProcessTooltip(btn) 304 local function UpdateProcessTooltip(btn)
305 local data = ItemAuditor:GetCraftingRow(1) 305 local data = ItemAuditor:GetCraftingRow(1)
306 if data then 306 if data then
307 GameTooltip:SetOwner(this, "ANCHOR_CURSOR") 307 GameTooltip:SetOwner(this, "ANCHOR_CURSOR")
308 GameTooltip:SetText(format('Create %sx%s', data.link, data.queue)) 308 GameTooltip:SetText(format('Create %sx%s', data.link, data.queue))
333 end 333 end
334 if vellumLevelMap[vellumID] then 334 if vellumLevelMap[vellumID] then
335 return useVellum(vellumLevelMap[vellumID], idealVellum or vellumID) 335 return useVellum(vellumLevelMap[vellumID], idealVellum or vellumID)
336 end 336 end
337 end 337 end
338 338
339 btnProcess:SetScript("OnClick", function (self, button, down) 339 btnProcess:SetScript("OnClick", function (self, button, down)
340 local data = ItemAuditor:GetCraftingRow(1) 340 local data = ItemAuditor:GetCraftingRow(1)
341 if data then 341 if data then
342 -- This will make sure the correct tradeskill window is open. 342 -- This will make sure the correct tradeskill window is open.
343 local tradeskillName = GetTradeSkillLine() 343 local tradeskillName = GetTradeSkillLine()
344 if data.tradeskillName ~= tradeskillName then 344 if data.tradeskillName ~= tradeskillName then
345 CastSpellByName(data.tradeskillName) 345 CastSpellByName(data.tradeskillName)
346 end 346 end
347 347
348 local queue = data.queue 348 local queue = data.queue
349 local vellumID = nil 349 local vellumID = nil
350 _, _, _, _, altVerb = GetTradeSkillInfo(data.tradeSkillIndex) 350 _, _, _, _, altVerb = GetTradeSkillInfo(data.tradeSkillIndex)
351 if altVerb == 'Enchant' and LSW.scrollData[data.recipeID] ~= nil then 351 if altVerb == 'Enchant' and LSW.scrollData[data.recipeID] ~= nil then
352 vellumID = LSW.scrollData[data.recipeID]["vellumID"] 352 vellumID = LSW.scrollData[data.recipeID]["vellumID"]
365 btnProcess:SetScript("OnEnter", UpdateProcessTooltip) 365 btnProcess:SetScript("OnEnter", UpdateProcessTooltip)
366 366
367 btnProcess:SetScript("OnLeave", function() 367 btnProcess:SetScript("OnLeave", function()
368 GameTooltip:Hide() 368 GameTooltip:Hide()
369 end) 369 end)
370 370
371 btnSkillet = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate") 371 btnSkillet = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate")
372 372
373 btnSkillet:SetSize(125, 25) 373 btnSkillet:SetSize(125, 25)
374 btnSkillet:SetPoint("BOTTOMRIGHT", btnProcess, 'BOTTOMLEFT', 0, 0) 374 btnSkillet:SetPoint("BOTTOMRIGHT", btnProcess, 'BOTTOMLEFT', 0, 0)
375 btnSkillet:RegisterForClicks("LeftButtonUp"); 375 btnSkillet:RegisterForClicks("LeftButtonUp");
376 btnSkillet:SetScript("OnClick", function (self, button, down) 376 btnSkillet:SetScript("OnClick", function (self, button, down)
377 Crafting.Export() 377 Crafting.Export()
378 end) 378 end)
379 379
380 end 380 end
381 local destination = select(2, Crafting.GetQueueDestination()) 381 local destination = select(2, Crafting.GetQueueDestination())
382 btnSkillet:SetText("Export to "..destination) 382 btnSkillet:SetText("Export to "..destination)
383 383
384 craftingContent:Show() 384 craftingContent:Show()
385 385
386 if container.parent then 386 if container.parent then
387 local width = 80 387 local width = 80
388 for i, data in pairs(craftingCols) do 388 for i, data in pairs(craftingCols) do
389 width = width + data.width 389 width = width + data.width
390 end 390 end
391 container.parent:SetWidth(width); 391 container.parent:SetWidth(width);
392 end 392 end
393 393
394 ItemAuditor:RegisterEvent("TRADE_SKILL_SHOW", function() 394 ItemAuditor:RegisterEvent("TRADE_SKILL_SHOW", function()
395 if craftingContent and craftingContent:IsVisible() then 395 if craftingContent and craftingContent:IsVisible() then
396 ItemAuditor:UpdateCraftingTable() 396 ItemAuditor:UpdateCraftingTable()
397 end 397 end
398 end) 398 end)
399 ItemAuditor:UpdateCraftingTable() 399 ItemAuditor:UpdateCraftingTable()
400 400
401 return craftingContent 401 return craftingContent
402 end 402 end
403 403
404 ItemAuditor:RegisterTab('Crafting', 'tab_crafting', ShowCrafting) 404 ItemAuditor:RegisterTab('Crafting', 'tab_crafting', ShowCrafting)
405 function ItemAuditor:DisplayCrafting() 405 function ItemAuditor:DisplayCrafting()
408 408
409 local craftingDeciders = {} 409 local craftingDeciders = {}
410 410
411 function Crafting.RegisterCraftingDecider(name, decider, options) 411 function Crafting.RegisterCraftingDecider(name, decider, options)
412 craftingDeciders[name] = decider 412 craftingDeciders[name] = decider
413 413
414 ItemAuditor.Options.args.crafting_options.args['chk'..name] = { 414 ItemAuditor.Options.args.crafting_options.args['chk'..name] = {
415 type = "toggle", 415 type = "toggle",
416 name = "Enable "..name, 416 name = "Enable "..name,
417 get = function() return not ItemAuditor.db.profile.disabled_deciders[name] end, 417 get = function() return not ItemAuditor.db.profile.disabled_deciders[name] end,
418 set = function(info, value) ItemAuditor.db.profile.disabled_deciders[name] = not value end, 418 set = function(info, value) ItemAuditor.db.profile.disabled_deciders[name] = not value end,
419 order = 11, 419 order = 11,
420 } 420 }
421 421
422 if options then 422 if options then
423 ItemAuditor.Options.args.crafting_options.args['decider_'..name] = { 423 ItemAuditor.Options.args.crafting_options.args['decider_'..name] = {
424 handler = {}, 424 handler = {},
425 name = name, 425 name = name,
426 type = 'group', 426 type = 'group',
434 local newDecision = 0 434 local newDecision = 0
435 local reason = "" 435 local reason = ""
436 for name, decider in pairs(craftingDeciders) do 436 for name, decider in pairs(craftingDeciders) do
437 if not ItemAuditor.db.profile.disabled_deciders[name] and name ~= lastWinner then 437 if not ItemAuditor.db.profile.disabled_deciders[name] and name ~= lastWinner then
438 newDecision, reason = decider(data) 438 newDecision, reason = decider(data)
439 439
440 if newDecision > data.queue then 440 if newDecision > data.queue then
441 data.queue = newDecision 441 data.queue = newDecision
442 lastWinner = (reason or name) 442 lastWinner = (reason or name)
443 return Decide(data) 443 return Decide(data)
444 elseif newDecision < 0 then 444 elseif newDecision < 0 then
445 lastWinner = "" 445 lastWinner = ""
446 return 'VETO: '..(reason or name), -1 446 return 'VETO: '..(reason or name), -1
447 end 447 end
448 end 448 end
449 end 449 end
450 450
451 winner = lastWinner 451 winner = lastWinner
452 lastWinner = "" 452 lastWinner = ""
453 453
454 data.queue = ceil(data.queue / GetTradeSkillNumMade(data.tradeSkillIndex)) 454 data.queue = ceil(data.queue / GetTradeSkillNumMade(data.tradeSkillIndex))
455 455
456 return winner, data.queue 456 return winner, data.queue
457 end 457 end
458 458
459 local function isProfitable(data) 459 local function isProfitable(data)
460 if data.profit > 0 and data.profit > ItemAuditor:GetCraftingThreshold() then 460 if data.profit > 0 and data.profit > ItemAuditor:GetCraftingThreshold() then
512 return 512 return
513 end 513 end
514 local tradeskillName = GetTradeSkillLine() 514 local tradeskillName = GetTradeSkillLine()
515 Crafting.ClearProfession(tradeskillName) 515 Crafting.ClearProfession(tradeskillName)
516 shoppingList = nil 516 shoppingList = nil
517 517
518 wipe(tableData) 518 wipe(tableData)
519 519
520 local profitableItems = {} 520 local profitableItems = {}
521 local profitableIndex = 1 521 local profitableIndex = 1
522 local numChecked = 0 522 local numChecked = 0
523 local row = #(realData)+1 523 local row = #(realData)+1
524 local numTradeSkills = GetNumTradeSkills() 524 local numTradeSkills = GetNumTradeSkills()
525 if tradeskillName == 'UNKNOWN' then 525 if tradeskillName == 'UNKNOWN' then
526 numTradeSkills = 0 526 numTradeSkills = 0
527 end 527 end
528 528
529 for i = 1, numTradeSkills do 529 for i = 1, numTradeSkills do
530 local itemLink = GetTradeSkillItemLink(i) 530 local itemLink = GetTradeSkillItemLink(i)
531 local itemId = Utils.GetItemID(itemLink) 531 local itemId = Utils.GetItemID(itemLink)
532 local vellumID = nil 532 local vellumID = nil
533 533
534 local spellName = itemName 534 local spellName = itemName
535 535
536 --Figure out if its an enchant or not 536 --Figure out if its an enchant or not
537 _, _, _, _, altVerb = GetTradeSkillInfo(i) 537 _, _, _, _, altVerb = GetTradeSkillInfo(i)
538 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then 538 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then
545 local recipeLink = GetTradeSkillRecipeLink(i) 545 local recipeLink = GetTradeSkillRecipeLink(i)
546 local stackSize = 1 546 local stackSize = 1
547 if recipeLink ~= nil and itemId ~= nil then 547 if recipeLink ~= nil and itemId ~= nil then
548 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i) 548 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i)
549 local itemName, itemLink= GetItemInfo(itemId) 549 local itemName, itemLink= GetItemInfo(itemId)
550 550
551 -- This check has to be here for things like Inscription Research that don't produce an item. 551 -- This check has to be here for things like Inscription Research that don't produce an item.
552 if itemLink then 552 if itemLink then
553 local count = ItemAuditor:GetItemCount(itemId) 553 local count = ItemAuditor:GetItemCount(itemId)
554 local reagents = {} 554 local reagents = {}
555 local totalCost = 0 555 local totalCost = 0
556 for reagentId = 1, GetTradeSkillNumReagents(i) do 556 for reagentId = 1, GetTradeSkillNumReagents(i) do
557 local reagentName, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId); 557 local reagentName, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId);
558 local reagentLink = GetTradeSkillReagentItemLink(i, reagentId) 558 local reagentLink = GetTradeSkillReagentItemLink(i, reagentId)
559 local reagentTotalCost = self:GetReagentCost(reagentLink, reagentCount) 559 local reagentTotalCost = self:GetReagentCost(reagentLink, reagentCount)
560 560
561 reagents[reagentId] = { 561 reagents[reagentId] = {
562 link = reagentLink, 562 link = reagentLink,
563 itemID = Utils.GetItemID(reagentLink), 563 itemID = Utils.GetItemID(reagentLink),
564 name = reagentName, 564 name = reagentName,
565 count = reagentCount, 565 count = reagentCount,
601 tradeSkillIndex = i, 601 tradeSkillIndex = i,
602 queue = 0, 602 queue = 0,
603 winner = "", 603 winner = "",
604 tradeskillName = tradeskillName, 604 tradeskillName = tradeskillName,
605 } 605 }
606 606
607 data.winner, data.queue = Decide(data) 607 data.winner, data.queue = Decide(data)
608 --[[ 608 --[[
609 If it wasn't vetoed we need to reduce the number by how many are owned 609 If it wasn't vetoed we need to reduce the number by how many are owned
610 but this should not go below 0 610 but this should not go below 0
611 ]] 611 ]]
612 if data.queue > 0 then 612 if data.queue > 0 then
613 data.queue = max(0, data.queue - count) 613 data.queue = max(0, data.queue - count)
614 end 614 end
615 615
616 -- If a tradeskill makes 5 at a time and something asks for 9, we should only 616 -- If a tradeskill makes 5 at a time and something asks for 9, we should only
617 -- craft twice to get 10. 617 -- craft twice to get 10.
618 data.queue = ceil(data.queue / GetTradeSkillNumMade(i)) 618 data.queue = ceil(data.queue / GetTradeSkillNumMade(i))
619 619
620 realData[row] = data 620 realData[row] = data
621 nameMap[skillName] = row 621 nameMap[skillName] = row
672 need = 0, 672 need = 0,
673 characters = {} 673 characters = {}
674 } 674 }
675 local slItem = shoppingList[reagent.itemID] 675 local slItem = shoppingList[reagent.itemID]
676 676
677 677
678 if numOwned[reagent.link] < 0 and not vellumLevelMap[reagent.itemID] then 678 if numOwned[reagent.link] < 0 and not vellumLevelMap[reagent.itemID] then
679 reagent.need = min(reagent.count, abs(numOwned[reagent.link])) 679 reagent.need = min(reagent.count, abs(numOwned[reagent.link]))
680 elseif numOwned[reagent.link] >= 0 then 680 elseif numOwned[reagent.link] >= 0 then
681 reagent.need = 0 681 reagent.need = 0
682 end 682 end
742 data.haveMaterials, 742 data.haveMaterials,
743 data.profit, 743 data.profit,
744 } 744 }
745 end 745 end
746 craftingTable:SetData(tableData, true) 746 craftingTable:SetData(tableData, true)
747 747
748 if self:GetCraftingRow(1) then 748 if self:GetCraftingRow(1) then
749 btnProcess:Enable() 749 btnProcess:Enable()
750 else 750 else
751 btnProcess:Disable() 751 btnProcess:Disable()
752 end 752 end