Added Bag feature to colorize recipe parts that are fulfilled by bag content
Improved bag of crafting calculator code quality a bit
This commit is contained in:
1 parent
87a786ea1e
commit
6cb646ef34
3 files changed
+52
-35
No files matched your search
+12
-2
@@ -852,7 +852,7 @@ end
|
|||||||
-- Result: "3{{Crafting1}}2{{Crafting2}}3{{Crafting3}}"
|
-- Result: "3{{Crafting1}}2{{Crafting2}}3{{Crafting3}}"
|
||||||
local emptyPickupTable = {}
|
local emptyPickupTable = {}
|
||||||
for i=1,29 do emptyPickupTable[i] = 0 end
|
for i=1,29 do emptyPickupTable[i] = 0 end
|
||||||
function EID:tableToCraftingIconsMerged(craftTable)
|
function EID:tableToCraftingIconsMerged(craftTable, indicateCompleteContent)
|
||||||
local sortedList = {table.unpack(craftTable)}
|
local sortedList = {table.unpack(craftTable)}
|
||||||
local filteredList = {table.unpack(emptyPickupTable)}
|
local filteredList = {table.unpack(emptyPickupTable)}
|
||||||
for _,nr in ipairs(sortedList) do
|
for _,nr in ipairs(sortedList) do
|
||||||
@@ -861,12 +861,22 @@ function EID:tableToCraftingIconsMerged(craftTable)
|
|||||||
local iconString = ""
|
local iconString = ""
|
||||||
for nr,count in ipairs(filteredList) do
|
for nr,count in ipairs(filteredList) do
|
||||||
if (count > 0) then
|
if (count > 0) then
|
||||||
iconString = iconString..count.."{{Crafting"..nr.."}}"
|
local completedColoring = indicateCompleteContent and EID:bagContaingsItem(nr, count) and "{{ColorBagComplete}}" or ""
|
||||||
|
iconString = iconString..completedColoring..count.."{{Crafting"..nr.."}}{{CR}}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return iconString
|
return iconString
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function EID:bagContaingsItem(itemID, itemCount)
|
||||||
|
local foundCount = 0
|
||||||
|
for _, bagItem in ipairs(EID.BagItems) do
|
||||||
|
if bagItem == itemID then
|
||||||
|
foundCount = foundCount + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return foundCount == itemCount
|
||||||
|
end
|
||||||
|
|
||||||
function EID:handleHUDElement(hudElement)
|
function EID:handleHUDElement(hudElement)
|
||||||
local alteredHudElement = {}
|
local alteredHudElement = {}
|
||||||
|
|||||||
+39
-33
@@ -615,6 +615,35 @@ local function calcFloorItems()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function qualitySort(a, b)
|
||||||
|
if (pickupValues[a+1] == pickupValues[b+1]) then
|
||||||
|
return a > b
|
||||||
|
else
|
||||||
|
return pickupValues[a+1] > pickupValues[b+1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--this combination algorithm was adopted from this Java code: https://stackoverflow.com/a/16256122
|
||||||
|
--note that it will run into duplicates, for example if you have eight pennies and a key, it can't tell the difference between
|
||||||
|
--PPPPPPPK (pennies 1-7) and PPPPPPPK (pennies 2-8) and PPPPPPPK (pennies 1-4,6-8) etc..., I don't know of a way to prevent that
|
||||||
|
local function combinations(arr, length, startPos, tempResult, randResults, newResults)
|
||||||
|
local length = length or 8
|
||||||
|
local startPos = startPos or 1
|
||||||
|
local tempResult = tempResult or {}
|
||||||
|
if (length == 0) then
|
||||||
|
local resultString = table.concat(tempResult,",")
|
||||||
|
if (randResults[resultString] == nil) then
|
||||||
|
randResults[resultString] = {table.unpack(tempResult)}
|
||||||
|
newResults[resultString] = {table.unpack(tempResult)}
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for i = startPos, #arr-length+1 do
|
||||||
|
tempResult[8-length+1] = arr[i]
|
||||||
|
combinations(arr,length-1, i+1, tempResult, randResults, newResults)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--code from InputHelper in MCM
|
--code from InputHelper in MCM
|
||||||
local HotkeyToString = {}
|
local HotkeyToString = {}
|
||||||
for key,num in pairs(Keyboard) do
|
for key,num in pairs(Keyboard) do
|
||||||
@@ -630,8 +659,8 @@ function EID:handleBagOfCraftingRendering()
|
|||||||
trackBagActivated()
|
trackBagActivated()
|
||||||
detectBagContentShift()
|
detectBagContentShift()
|
||||||
|
|
||||||
local tableToCraftingIcons = EID.tableToCraftingIconsMerged
|
local tableToCraftingIconsFunc = EID.tableToCraftingIconsMerged
|
||||||
if EID.Config["BagOfCraftingDisplayIcons"] then tableToCraftingIcons = EID.tableToCraftingIconsFull end
|
if EID.Config["BagOfCraftingDisplayIcons"] then tableToCraftingIconsFunc = EID.tableToCraftingIconsFull end
|
||||||
|
|
||||||
--prevent our hotkeys from triggering as they're set
|
--prevent our hotkeys from triggering as they're set
|
||||||
if not ModConfigMenu or not ModConfigMenu.IsVisible then
|
if not ModConfigMenu or not ModConfigMenu.IsVisible then
|
||||||
@@ -731,13 +760,6 @@ function EID:handleBagOfCraftingRendering()
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function qualitySort(a, b)
|
|
||||||
if (pickupValues[a+1] == pickupValues[b+1]) then
|
|
||||||
return a > b
|
|
||||||
else
|
|
||||||
return pickupValues[a+1] > pickupValues[b+1]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--sort by ingredient quality
|
--sort by ingredient quality
|
||||||
table.sort(itemQuery, qualitySort)
|
table.sort(itemQuery, qualitySort)
|
||||||
@@ -787,7 +809,7 @@ function EID:handleBagOfCraftingRendering()
|
|||||||
local bestQualityDesc = EID:getDescriptionEntry("CraftingBestQuality")
|
local bestQualityDesc = EID:getDescriptionEntry("CraftingBestQuality")
|
||||||
|
|
||||||
if (#EID.BagItems > 0) then EID:appendToDescription(customDescObj, bagQualityDesc .. " " .. bagQuality .. "#" .. bagResult .. "#") end
|
if (#EID.BagItems > 0) then EID:appendToDescription(customDescObj, bagQualityDesc .. " " .. bagQuality .. "#" .. bagResult .. "#") end
|
||||||
if (bestQuality > bagQuality) then EID:appendToDescription(customDescObj, bestQualityDesc .. " " .. bestQuality .. "#{{Blank}} " .. tableToCraftingIcons(self,mostValuableSimp) .. "#" .. bestResult .. "#") end
|
if (bestQuality > bagQuality) then EID:appendToDescription(customDescObj, bestQualityDesc .. " " .. bestQuality .. "#{{Blank}} " .. tableToCraftingIconsFunc(self, mostValuableSimp, true) .. "#" .. bestResult .. "#") end
|
||||||
|
|
||||||
EID:printDescription(customDescObj)
|
EID:printDescription(customDescObj)
|
||||||
return true
|
return true
|
||||||
@@ -824,27 +846,8 @@ function EID:handleBagOfCraftingRendering()
|
|||||||
mostValuable[i] = itemQuery[i]
|
mostValuable[i] = itemQuery[i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--this combination algorithm was adopted from this Java code: https://stackoverflow.com/a/16256122
|
|
||||||
--note that it will run into duplicates, for example if you have eight pennies and a key, it can't tell the difference between
|
if (#mostValuable >= 8) then combinations(mostValuable, nil, nil, nil, randResults, newResults) end
|
||||||
--PPPPPPPK (pennies 1-7) and PPPPPPPK (pennies 2-8) and PPPPPPPK (pennies 1-4,6-8) etc..., I don't know of a way to prevent that
|
|
||||||
local function combinations(arr, length, startPos, tempResult)
|
|
||||||
local length = length or 8
|
|
||||||
local startPos = startPos or 1
|
|
||||||
local tempResult = tempResult or {}
|
|
||||||
if (length == 0) then
|
|
||||||
local resultString = table.concat(tempResult,",")
|
|
||||||
if (randResults[resultString] == nil) then
|
|
||||||
randResults[resultString] = {table.unpack(tempResult)}
|
|
||||||
newResults[resultString] = {table.unpack(tempResult)}
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for i = startPos, #arr-length+1 do
|
|
||||||
tempResult[8-length+1] = arr[i]
|
|
||||||
combinations(arr,length-1,i+1,tempResult)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if (#mostValuable >= 8) then combinations(mostValuable) end
|
|
||||||
|
|
||||||
--do random pulls for some more recipe choices
|
--do random pulls for some more recipe choices
|
||||||
if (not skipRandom) then
|
if (not skipRandom) then
|
||||||
@@ -924,16 +927,18 @@ function EID:handleBagOfCraftingRendering()
|
|||||||
EID:appendToDescription(customDescObj, "!!! " .. hotkeyString .. "#")
|
EID:appendToDescription(customDescObj, "!!! " .. hotkeyString .. "#")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Bag content display
|
||||||
if #EID.BagItems >0 then
|
if #EID.BagItems >0 then
|
||||||
if #EID.BagItems >= 8 then
|
if #EID.BagItems >= 8 then
|
||||||
local recipe = EID:calculateBagOfCrafting(EID.BagItems)
|
local recipe = EID:calculateBagOfCrafting(EID.BagItems)
|
||||||
EID:appendToDescription(customDescObj, "{{Collectible"..recipe.."}} ")
|
EID:appendToDescription(customDescObj, "{{Collectible"..recipe.."}} ")
|
||||||
end
|
end
|
||||||
local bagDesc = EID:getDescriptionEntry("CraftingBagContent").."(Beta)"
|
local bagDesc = EID:getDescriptionEntry("CraftingBagContent")
|
||||||
EID:appendToDescription(customDescObj, bagDesc..EID:tableToCraftingIconsMerged(EID.BagItems).."#")
|
EID:appendToDescription(customDescObj, bagDesc..EID:tableToCraftingIconsMerged(EID.BagItems).."#")
|
||||||
--debug the bag order
|
--debug the bag order
|
||||||
--EID:appendToDescription(customDescObj, EID:tableToCraftingIconsFull(EID.BagItems, false).."#")
|
--EID:appendToDescription(customDescObj, EID:tableToCraftingIconsFull(EID.BagItems, false).."#")
|
||||||
end
|
end
|
||||||
|
-- Room content display
|
||||||
if #roomItems >0 then
|
if #roomItems >0 then
|
||||||
if #roomItems == 8 then
|
if #roomItems == 8 then
|
||||||
local recipe = EID:calculateBagOfCrafting(roomItems)
|
local recipe = EID:calculateBagOfCrafting(roomItems)
|
||||||
@@ -942,6 +947,7 @@ function EID:handleBagOfCraftingRendering()
|
|||||||
local roomDesc = EID:getDescriptionEntry("CraftingRoomContent")
|
local roomDesc = EID:getDescriptionEntry("CraftingRoomContent")
|
||||||
EID:appendToDescription(customDescObj, roomDesc..EID:tableToCraftingIconsMerged(roomItems).."#")
|
EID:appendToDescription(customDescObj, roomDesc..EID:tableToCraftingIconsMerged(roomItems).."#")
|
||||||
end
|
end
|
||||||
|
-- Floot content display
|
||||||
if #EID.bagOfCraftingFloorQuery >0 and #roomItems ~= #EID.bagOfCraftingFloorQuery then
|
if #EID.bagOfCraftingFloorQuery >0 and #roomItems ~= #EID.bagOfCraftingFloorQuery then
|
||||||
if #EID.bagOfCraftingFloorQuery == 8 then
|
if #EID.bagOfCraftingFloorQuery == 8 then
|
||||||
local recipe = EID:calculateBagOfCrafting(EID.bagOfCraftingFloorQuery)
|
local recipe = EID:calculateBagOfCrafting(EID.bagOfCraftingFloorQuery)
|
||||||
@@ -1025,7 +1031,7 @@ function EID:handleBagOfCraftingRendering()
|
|||||||
if v[3] then customDescObj.Description = customDescObj.Description.." {{Collectible" .. v[3] .. "}} " end
|
if v[3] then customDescObj.Description = customDescObj.Description.." {{Collectible" .. v[3] .. "}} " end
|
||||||
end
|
end
|
||||||
|
|
||||||
customDescObj.Description = customDescObj.Description..tableToCraftingIcons(self,v[1])
|
customDescObj.Description = customDescObj.Description..tableToCraftingIconsFunc(self, v[1], true)
|
||||||
prevItem = v[2]
|
prevItem = v[2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -307,6 +307,7 @@ EID.InlineColors = {
|
|||||||
["ColorPastelBlue"] = KColor(0.3882, 0.5216, 1, 1),
|
["ColorPastelBlue"] = KColor(0.3882, 0.5216, 1, 1),
|
||||||
["ColorLavender"] = KColor(0.7451, 0.3686, 1, 1),
|
["ColorLavender"] = KColor(0.7451, 0.3686, 1, 1),
|
||||||
["ColorLightOrange"] = KColor(1, 0.6353, 0.3686, 1),
|
["ColorLightOrange"] = KColor(1, 0.6353, 0.3686, 1),
|
||||||
|
["ColorBagComplete"] = KColor(0, 1, 0, 0.6),
|
||||||
-- Swag Colors
|
-- Swag Colors
|
||||||
|
|
||||||
-- Rainbow color effect
|
-- Rainbow color effect
|
||||||
|
|||||||
Reference in new issue
Block a user