local ____lualib = require("lualib_bundle")
local __TS__New = ____lualib.__TS__New
local Map = ____lualib.Map
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local CardType = ____isaac_2Dtypescript_2Ddefinitions.CardType
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local DiceFloorSubType = ____isaac_2Dtypescript_2Ddefinitions.DiceFloorSubType
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local PickupVariant = ____isaac_2Dtypescript_2Ddefinitions.PickupVariant
local ____cachedClasses = require("src.core.cachedClasses")
local game = ____cachedClasses.game
local ____decorators = require("src.decorators")
local Exported = ____decorators.Exported
local ____ISCFeature = require("src.enums.ISCFeature")
local ISCFeature = ____ISCFeature.ISCFeature
local ____ModCallbackCustom = require("src.enums.ModCallbackCustom")
local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
local ____collectibles = require("src.functions.collectibles")
local setCollectibleSubType = ____collectibles.setCollectibleSubType
local ____entities = require("src.functions.entities")
local getEntityID = ____entities.getEntityID
local ____frames = require("src.functions.frames")
local onGameFrame = ____frames.onGameFrame
local ____pickupVariants = require("src.functions.pickupVariants")
local isCollectible = ____pickupVariants.isCollectible
local ____pickupsSpecific = require("src.functions.pickupsSpecific")
local getCollectibles = ____pickupsSpecific.getCollectibles
local ____types = require("src.functions.types")
local asCollectibleType = ____types.asCollectibleType
local ____ReadonlySet = require("src.types.ReadonlySet")
local ReadonlySet = ____ReadonlySet.ReadonlySet
local ____Feature = require("src.classes.private.Feature")
local Feature = ____Feature.Feature
local ROLL_COLLECTIBLE_TYPES = __TS__New(ReadonlySet, {CollectibleType.D6, CollectibleType.ETERNAL_D6, CollectibleType.SPINDOWN_DICE})
local ROLL_FLOOR_DICE_FLOOR_SUB_TYPES = __TS__New(ReadonlySet, {DiceFloorSubType.FOUR_PIP, DiceFloorSubType.SIX_PIP})
local v = {run = {
    trackedCollectibles = __TS__New(Map),
    rollGameFrame = nil
}}
____exports.PreventCollectibleRotation = __TS__Class()
local PreventCollectibleRotation = ____exports.PreventCollectibleRotation
PreventCollectibleRotation.name = "PreventCollectibleRotation"
__TS__ClassExtends(PreventCollectibleRotation, Feature)
function PreventCollectibleRotation.prototype.____constructor(self, pickupIndexCreation, runInNFrames)
    Feature.prototype.____constructor(self)
    self.v = v
    self.preUseItem = function(____, collectibleType)
        if ROLL_COLLECTIBLE_TYPES:has(collectibleType) then
            v.run.rollGameFrame = game:GetFrameCount()
        end
        return nil
    end
    self.postUseCardSoulOfIsaac = function()
        local collectibles = getCollectibles(nil)
        for ____, collectible in ipairs(collectibles) do
            local pickupIndex = self.pickupIndexCreation:getPickupIndex(collectible)
            v.run.trackedCollectibles:delete(pickupIndex)
        end
    end
    self.postDiceRoomActivated = function(____, _player, diceFloorSubType)
        if ROLL_FLOOR_DICE_FLOOR_SUB_TYPES:has(diceFloorSubType) then
            v.run.trackedCollectibles:clear()
        end
    end
    self.postPickupChanged = function(____, pickup, oldVariant, _oldSubType, newVariant, newSubType)
        if oldVariant ~= PickupVariant.COLLECTIBLE or newVariant ~= PickupVariant.COLLECTIBLE then
            return
        end
        if asCollectibleType(nil, newSubType) == CollectibleType.NULL then
            return
        end
        local pickupIndex = self.pickupIndexCreation:getPickupIndex(pickup)
        local trackedCollectibleType = v.run.trackedCollectibles:get(pickupIndex)
        if trackedCollectibleType == nil then
            return
        end
        if v.run.rollGameFrame ~= nil and (onGameFrame(nil, v.run.rollGameFrame) or onGameFrame(nil, v.run.rollGameFrame + 1)) then
            v.run.trackedCollectibles:delete(pickupIndex)
            return
        end
        if trackedCollectibleType ~= asCollectibleType(nil, newSubType) then
            setCollectibleSubType(nil, pickup, trackedCollectibleType)
        end
    end
    self.featuresUsed = {ISCFeature.PICKUP_INDEX_CREATION, ISCFeature.RUN_IN_N_FRAMES}
    self.callbacksUsed = {{ModCallback.POST_USE_CARD, self.postUseCardSoulOfIsaac, {CardType.SOUL_OF_ISAAC}}, {ModCallback.PRE_USE_ITEM, self.preUseItem}}
    self.customCallbacksUsed = {{ModCallbackCustom.POST_DICE_ROOM_ACTIVATED, self.postDiceRoomActivated}, {ModCallbackCustom.POST_PICKUP_CHANGED, self.postPickupChanged}}
    self.pickupIndexCreation = pickupIndexCreation
    self.runInNFrames = runInNFrames
end
function PreventCollectibleRotation.prototype.preventCollectibleRotation(self, collectible, collectibleType)
    if not isCollectible(nil, collectible) then
        local entityID = getEntityID(nil, collectible)
        error("The \"preventCollectibleRotation\" function was given a non-collectible: " .. entityID)
    end
    local pickupIndex = self.pickupIndexCreation:getPickupIndex(collectible)
    v.run.trackedCollectibles:set(pickupIndex, collectibleType)
    if collectible.SubType ~= collectibleType then
        setCollectibleSubType(nil, collectible, collectibleType)
    end
    self.runInNFrames:runNextGameFrame(function()
        if collectible:Exists() and collectible.SubType ~= collectibleType then
            setCollectibleSubType(nil, collectible, collectibleType)
        end
    end)
end
__TS__DecorateLegacy({Exported}, PreventCollectibleRotation.prototype, "preventCollectibleRotation", true)
return ____exports
