Skip to content

Making a familiar upgradable

Valentin Lamprière edited this page Jan 10, 2022 · 14 revisions

Set a familiar available for the Sewing Machine

Sewing Machine can work with any modded familiars as long as they have been registered.

To make a familiar available for Sewing Machine, a single function call is needed :

Sewn_API:MakeFamiliarAvailable(familiarVariantID, CollectibleID)

This function allows the familiar with the ID familiarVariantID to go in the Sewing Machine. It do not have any upgrades yet, upgrades can be added by linking functions to callbacks (like for the Isaac API).

Please note that you'll want to check if Sewing Machine is enabled first with :

if Sewn_API then
   -- Sewing Machine is enabled
end

Setting upgrades for a familiar

Sewing Machine has been written to upgrade vanilla familiars. Many callbacks allow the mod to run code on events for vanilla familiars. You can use these callbacks for your modded familiars if needed (but this is not required for modded familiars). A detailed page on how to use callbacks with arguments, return values can be found here : Sewing Machine Mod Callbacks

To register a Sewing Machine callback you can use the function Sewn_API.AddCallback as :

local function myFamiliarUpdateDefault(_, myFamiliar)
   -- Called each frames for the familiar (super and ultra)
end
local function myFamiliarUpdateUltra(_, myFamiliar)
   -- Called each frames for the ultra familiar
end

Sewn_API:AddCallback(Sewn_API.Enums.ModCallbacks.FAMILIAR_UPDATE, myFamiliarUpdateDefault, familiarVariantID)
Sewn_API:AddCallback(Sewn_API.Enums.ModCallbacks.FAMILIAR_UPDATE, myFamiliarUpdateUltra, familiarVariantID,  Sewn_API.Enums.FamiliarLevelFlag.FLAG_ULTRA)

As mentioned above, these callbacks aren't required for modded familiars. You might just want to get the level of the familiars you're working on. You can get the level (Super or Ultra) of the familiar with Sewn_API.GetLevel :

local fData = familiar:GetData()
local level = Sewn_API:GetLevel(fData)

Note : These functions can also be found on this page : API functions


You can also just check if a familiar is Super (gold crown) or Ultra (diamond crown) with these functions :

local fData = familiar:GetData()
if Sewn_API:IsSuper(fData) then end
local fData = familiar:GetData()
if Sewn_API:IsUltra(fData) then end

The EID support

External Item Description (EID for short) is a must have mod which display items description. You can add upgrades descriptions when the familiar is in the Sewing Machine with :

Sewn_API:AddFamiliarDescription(
    familiarVariantID,
    "Description for the Super upgrade",
    "Description for the Ultra upgrade",
    {1, 0, 0}, -- Optional, default is {1, 1, 1} (white)
    "Familiar Optional Name" -- Optional, default is the name of the collectible
)

Note : EID have to be enabled

The Encyclopedia support

You can also add a familiar upgrades wiki in the Encyclopedia. By default the mod will add the EID description in the Encyclopedia, but you can write what you want with :

Sewn_API:AddEncyclopediaUpgrade(
    familiarVariantID,
    "Wiki for the Super upgrade",
    "Wiki for the Ultra upgrade",
    "Additional notes"
)

Note : Encyclopedia have to be enabled