Added detection of bag of crafting content shifts

This commit is contained in:
Wofsauge committed 2021-05-30 20:31:28 +02:00
1 parent 1bd04bc72f
commit 9e837ac368
3 files changed
+29 -5

No files matched your search

+1
View File
@@ -650,6 +650,7 @@ EID.descriptions["en_us"].horsepills={
[9999] = {"", "Golden Pill", "Random horse pill effect#Destroys itself after a few uses"}, -- golden Pill
}
EID.descriptions["en_us"].CraftingBagContent = "Pickups in bag:"
EID.descriptions["en_us"].CraftingRoomContent = "Pickups in room:"
EID.descriptions["en_us"].CraftingResults = "Results:#(Scroll: Hold TAB + Shoot △/▽)"
+6 -4
View File
@@ -726,9 +726,10 @@ end
-- Example input: {1,2,3,4,5,6,7,8}
-- Result: "{{Crafting8}}{{Crafting7}}{{Crafting6}}{{Crafting5}}{{Crafting4}}{{Crafting3}}{{Crafting2}}{{Crafting1}}"
function EID:tableToCraftingIconsFull(craftTable)
table.sort(craftTable, function(a, b) return a > b end)
local sortedList = {table.unpack(craftTable)}
table.sort(sortedList, function(a, b) return a > b end)
local iconString = ""
for _,nr in ipairs(craftTable) do
for _,nr in ipairs(sortedList) do
iconString = iconString.."{{Crafting"..nr.."}}"
end
return iconString
@@ -738,9 +739,10 @@ end
-- Example input: {1,1,1,2,2,3,3,3}
-- Result: "3{{Crafting3}}2{{Crafting2}}3{{Crafting1}}"
function EID:tableToCraftingIconsMerged(craftTable)
table.sort(craftTable, function(a, b) return a > b end)
local sortedList = {table.unpack(craftTable)}
table.sort(sortedList, function(a, b) return a > b end)
local filteredList = {}
for _,nr in ipairs(craftTable) do
for _,nr in ipairs(sortedList) do
if filteredList[nr] == nil then
filteredList[nr] = 1
else
+22 -1
View File
@@ -435,6 +435,9 @@ EID:AddCallback(ModCallbacks.MC_POST_ENTITY_REMOVE, function(_, bag)
local craftingIDs = EID:getBagOfCraftingID(e.Variant, e.SubType)
if craftingIDs ~= nil then
for _,v in ipairs(craftingIDs) do
if #EID.BagItems >= 8 then
table.remove(EID.BagItems, 1)
end
table.insert(EID.BagItems, v)
end
end
@@ -455,6 +458,21 @@ local function trackBagHolding()
end
end
local function shiftBagContent()
local newContent = {}
for i=2,#EID.BagItems do
table.insert(newContent, EID.BagItems[i])
end
table.insert(newContent, EID.BagItems[1])
EID.BagItems = newContent
end
local function detectBagContentShift()
if Input.IsActionTriggered(ButtonAction.ACTION_DROP, 0) or Input.IsActionTriggered(ButtonAction.ACTION_DROP, 1) then
shiftBagContent()
end
end
-----------------------------
-----------------------------
-----------RENDERING---------
@@ -471,6 +489,7 @@ EID.BagItems = {}
function EID:handleBagOfCraftingRendering()
trackBagHolding()
detectBagContentShift()
local results = {}
local floorItems = {}
local pickups = Isaac.FindByType(5, -1, -1, true, false)
@@ -501,6 +520,7 @@ function EID:handleBagOfCraftingRendering()
if #itemQuery < 8 then
return false
end
table.sort(itemQuery, function(a, b) return a > b end)
local queryString = table.concat(itemQuery,",")
if randResultCache[queryString] == nil then
@@ -537,8 +557,9 @@ function EID:handleBagOfCraftingRendering()
local customDescObj = EID:getDescriptionObj(5, 100, 710)
local roomDesc = EID.descriptions[EID.Config["Language"]].CraftingRoomContent or EID.descriptions["en_us"].CraftingRoomContent
local bagContentDesc = EID.descriptions[EID.Config["Language"]].CraftingBagContent or EID.descriptions["en_us"].CraftingBagContent
local resultDesc = EID.descriptions[EID.Config["Language"]].CraftingResults or EID.descriptions["en_us"].CraftingResults
customDescObj.Description = "Items in Bag:#"..EID:tableToCraftingIconsMerged(EID.BagItems).."#"
customDescObj.Description = bagContentDesc.."#"..EID:tableToCraftingIconsMerged(EID.BagItems).."#"
customDescObj.Description = customDescObj.Description ..roomDesc.."#"..EID:tableToCraftingIconsMerged(floorItems).."#"..resultDesc
if Input.IsActionPressed(ButtonAction.ACTION_MAP, 0) or Input.IsActionPressed(ButtonAction.ACTION_MAP, 1) then