local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local GridEntityType = ____isaac_2Dtypescript_2Ddefinitions.GridEntityType
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local ____cachedClasses = require("core.cachedClasses")
local game = ____cachedClasses.game
local ____gridEntities = require("functions.gridEntities")
local getTopLeftWallGridIndex = ____gridEntities.getTopLeftWallGridIndex
local spawnGridEntity = ____gridEntities.spawnGridEntity
local ____log = require("functions.log")
local logError = ____log.logError
local ____shouldFire = require("shouldFire")
local shouldFireRoom = ____shouldFire.shouldFireRoom
local ____CustomCallback = require("classes.private.CustomCallback")
local CustomCallback = ____CustomCallback.CustomCallback
____exports.PostNewRoomEarly = __TS__Class()
local PostNewRoomEarly = ____exports.PostNewRoomEarly
PostNewRoomEarly.name = "PostNewRoomEarly"
__TS__ClassExtends(PostNewRoomEarly, CustomCallback)
function PostNewRoomEarly.prototype.____constructor(self)
    CustomCallback.prototype.____constructor(self)
    self.currentRoomTopLeftWallPtrHash = nil
    self.currentRoomTopLeftWallPtrHash2 = nil
    self.shouldFire = shouldFireRoom
    self.postNewRoom = function()
        self:checkRoomChanged()
    end
    self.preEntitySpawn = function()
        self:checkRoomChanged()
        return nil
    end
    self.callbacksUsed = {{ModCallback.POST_NEW_ROOM, self.postNewRoom}, {ModCallback.PRE_ENTITY_SPAWN, self.preEntitySpawn}}
end
function PostNewRoomEarly.prototype.checkRoomChanged(self)
    if self:isNewRoom() then
        local room = game:GetRoom()
        local roomType = room:GetType()
        self:fire(roomType)
    end
end
function PostNewRoomEarly.prototype.isNewRoom(self)
    local room = game:GetRoom()
    local topLeftWallGridIndex = getTopLeftWallGridIndex(nil)
    local rightOfTopWallGridIndex = topLeftWallGridIndex + 1
    local topLeftWall = room:GetGridEntity(topLeftWallGridIndex)
    local topLeftWall2 = room:GetGridEntity(rightOfTopWallGridIndex)
    if topLeftWall == nil then
        topLeftWall = spawnGridEntity(nil, GridEntityType.WALL, topLeftWallGridIndex)
        if topLeftWall == nil then
            logError("Failed to spawn a new wall for the POST_NEW_ROOM_EARLY callback (on the first try).")
            return false
        end
    end
    if topLeftWall2 == nil then
        topLeftWall2 = spawnGridEntity(nil, GridEntityType.WALL, rightOfTopWallGridIndex)
        if topLeftWall2 == nil then
            logError("Failed to spawn a new wall for the POST_NEW_ROOM_EARLY callback (on the second try).")
            return false
        end
    end
    local oldTopLeftWallPtrHash = self.currentRoomTopLeftWallPtrHash
    local oldTopLeftWallPtrHash2 = self.currentRoomTopLeftWallPtrHash2
    self.currentRoomTopLeftWallPtrHash = GetPtrHash(topLeftWall)
    self.currentRoomTopLeftWallPtrHash2 = GetPtrHash(topLeftWall2)
    return oldTopLeftWallPtrHash ~= self.currentRoomTopLeftWallPtrHash or oldTopLeftWallPtrHash2 ~= self.currentRoomTopLeftWallPtrHash2
end
return ____exports
