Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- StartDebug();
- local mod = RegisterMod("Spindown dice preview", 1)
- local json = require "json"
- local spriteCache = {}
- ---------
- -- UTILITY
- ---
- function mod:getPreviousAvailableCollectibleSubType( entity, skipAmount )
- local subType = entity.SubType;
- local itemCfg = nil
- local skipCount = skipAmount - 1
- while itemCfg == nil do
- if subType <= 1 then return nil end
- subType = subType - 1
- itemCfg = Isaac.GetItemConfig():GetCollectible( subType )
- -- If its a valid item, subtract from skip amount
- if itemCfg~= nil and itemCfg.Hidden == false then
- skipAmount = skipAmount - 1
- end
- -- Dont count hidden items
- -- TODO: No way to check for unlocked items
- if (itemCfg ~= nil and itemCfg.Hidden == true) or (skipAmount > 0) then
- itemCfg = nil
- end
- end
- return subType
- end
- function mod:isItem( entity )
- return entity ~= nil and entity:ToPickup() ~= nil and entity.Variant == 100
- end
- ------------------
- -- MOD CALLBACKS
- ----
- function mod:onRender(t)
- local skipAmount = mod:getAvailableSkipAmount()
- if skipAmount == 0 then return nil end
- -- Checking to see if curse of the blind is active
- local curseName = Game():GetLevel():GetCurseName()
- -- Should not be able to display preview if curse of the blind is active
- if curseName ~= nil and curseName == "Curse of the Blind!" then return nil end
- local player = Isaac.GetPlayer( 0 )
- local pickups = Isaac.FindInRadius( player.Position, 600, EntityPartition.PICKUP )
- for i, entity in ipairs( pickups ) do
- if mod:isItem( entity ) then
- mod:renderCollectible( entity,skipAmount )
- end
- end
- end
- -----------
- -- MOD METHODS
- ------
- function mod:getAvailableSkipAmount()
- local playerCount = Game():GetNumPlayers()
- local currentSkipAmount = 0
- for i = 0, playerCount - 1 do
- local p = Isaac.GetPlayer(i)
- local hasCarBattery = p:HasCollectible( CollectibleType.COLLECTIBLE_CAR_BATTERY )
- local skipAmount = 1
- if p ~= nil and ( p:GetActiveItem ( ActiveSlot.SLOT_PRIMARY ) == 723 or p:GetActiveItem ( ActiveSlot.SLOT_POCKET ) == 723 ) then
- if hasCarBattery then
- skipAmount = skipAmount + 1
- end
- currentSkipAmount = math.max( currentSkipAmount, skipAmount )
- end
- end
- return currentSkipAmount
- end
- function mod:renderCollectible(entity, skipAmount)
- local previousCollectibleSubType = mod:getPreviousAvailableCollectibleSubType(entity, skipAmount)
- if previousCollectibleSubType == nil then return end
- local itemConfig = Isaac.GetItemConfig():GetCollectible( previousCollectibleSubType )
- if itemConfig ~= null then
- descriptor = itemConfig.GfxFileName
- local itemSprite
- -- So we do not have to be constantly creating and reading from spritesheet
- if spriteCache[ descriptor ] == nil then
- itemSprite = Sprite()
- itemSprite:Load("gfx/005.100_Collectible.anm2", true)
- itemSprite:ReplaceSpritesheet(1, itemConfig.GfxFileName )
- itemSprite:LoadGraphics()
- itemSprite.Color = Color(1,1,1,0.45)
- itemSprite:SetFrame("Idle", 8)
- itemSprite.Scale = Vector(0.4, 0.4)
- spriteCache[descriptor] = itemSprite
- else
- itemSprite = spriteCache[descriptor]
- end
- -- Rendering besides item
- local adjustedPosition = Vector(0,0)
- if entity:ToPickup():IsShopItem() then
- adjustedPosition = entity.Position - Vector(-22, 20)
- else
- adjustedPosition = entity.Position - Vector(-22, 38)
- end
- itemSprite:Render( Isaac.WorldToScreen( adjustedPosition ), Vector( 0,0 ), Vector( 0,0 ))
- end
- end
- mod:AddCallback( ModCallbacks.MC_POST_RENDER , mod.onRender )
Advertisement
Add Comment
Please, Sign In to add comment