The Binding of Isaac: Rebirth

The Binding of Isaac: Rebirth

Character Costume Protector
 This topic has been pinned, so it's probably important
Benny  [developer] 8 Jul, 2021 @ 2:15pm
How to do the thing
Requirements for using this library:
  • A custom character (duh)
  • The PlayerType of your character
  • A flight costume for your character, of which will be used at any time you gain flight



Loading the library into your mod:
Obtain the lua file and bundle it with your mod. In your main.lua, after where you register your mod, input this:

local yourmodhere = RegisterMod("mymod", 1) local costumeProtector = include("character_costume_protector") costumeProtector:init(yourmodhere)

The yourmodhere variable and using "mymod" as its name is purely an example. Make sure to use your own mod's RegisterMod with custom names.



Adding your character to the library:
Putting your character into the system involves calling a function inside a player init callback. These are the only requirements for the library to add your character. A clear example shown below:

local PLAYER_EEVEE = Isaac.GetPlayerTypeByName("Eevee", false) local COSTUME_EEVEE_FLIGHT = Isaac.GetCostumeIdByPath("gfx/characters/costume_eevee_flight.anm2") function mod:PlayerInit(player) costumeProtector:AddPlayer( PLAYER_EEVEE, --Your character's PlayerType "gfx/characters/costumes/character_eevee.png", --Your character's spritesheet COSTUME_EEVEE_FLIGHT --Flight costume ) end mod:AddCallback(ModCallbacks.MC_POST_PLAYER_INIT, mod.PlayerInit)

There's also room to optionally add a regular null costume and/or a flight spritesheet, like the one Azazel has where the wings are part of his character spritesheet. Just extend the function as shown below. You can simply leave one as "nil" if you want one but not the other.

costumeProtector:AddPlayer( PLAYER_EEVEE, "gfx/characters/costumes/character_eevee.png", COSTUME_EEVEE_FLIGHT, "gfx/characters/costumes/character_eevee_flight.png", --Your character's spritesheet, but customized to have your flight costume. COSTUME_EEVEE --Your character's additional costume. Hair, ears, whatever. )



Whitelisting item costumes:
Want to support some specific items that you're fine with having on your character? Just give them a whitelist! This is a simple function you can call that goes right after the "AddPlayer" function. This accepts an unlimited amount of ONLY collectible items. Example below:

costumeProtector:ItemCostumeWhitelist( PLAYER_EEVEE, { CollectibleType.COLLECTIBLE_SAD_ONION, CollectibleType.COLLECTIBLE_PONY } )

When the library resets your costume, it checks if you have the item or the effect of the item in order to apply that item's costume, with some manual exceptions to where some are only added with their effect active. This mainly applies to active items. You can edit this "only on effect" list if you wish, or even add your own custom items to it.



Whitelisting null costumes:
Same as the item costumes, but for null costumes instead! You can do this by simply putting in the NullItemID. Example below:

costumeProtector:NullItemCostumeWhitelist( PLAYER_EEVEE, { NullItemID.ID_GUPPY, NullItemID.ID_BOB } )

When the library resets your costume, it only checks if you have these null effects active in order to apply them. Some NullItemIDs (IDs for null costumes) do not double as a check for their effect, making them useless.



Custom Callbacks
That's right, this library comes with easy-to-use callbacks! In the case you need to fix something that the library can't take into account (but you don't want to touch the library), just use any of the three callbacks I've created, used like so:

-MC_POST_COSTUME_INIT - Triggers once after your player is initiated at the start of a run and their costume has been added
-MC_POST_COSTUME_RESET - Triggers every time your player's costume is reset by the library
-MC_POST_COSTUME_DEINIT - Triggers if you switch PlayerTypes/characters in a run that hasn't been added to the library (From your mod or other mods!), removing the custom costumes and re-adding the item costumes.

Example:
local function postCostumeReset(player) if player:GetData().IsCool then player:AddNullCostume(COSTUME_COOL) end end costumeProtector.AddCallback("MC_POST_COSTUME_RESET", postCostumeReset)
Last edited by Benny; 10 Oct, 2021 @ 11:21am