Squad sprite loader - AUTOMATIC1111/IntoTheBreachLua GitHub Wiki

This is a small script that can simplify loading custom sprites for your squad with mod loader.

Code for sprite loader: https://github.com/AUTOMATIC1111/IntoTheBreachLua/wiki/squad_sprite_loader.lua (put the file into your mod's scripts directory)

Example usage is: (in code below, self refers to the mod loader's mod object - put it into your init function - function init(self) ... end)

require(self.scriptPath.."squad_sprite_loader")(self, {
    {
        Name = "AUTO_MechBig",
        Filename = "auto_mech_big",
        Path = "units", 
        ResourcePath = "units/player",
        
        Default =           { PosX = -19, PosY = -14 },
        Animated =          { PosX = -19, PosY = -14, NumFrames = 4 },
        Submerged =         { PosX = -17, PosY = -4 },
        Broken =            { PosX = -17, PosY = -2 },
        SubmergedBroken =   { PosX = -14, PosY = 6 },
        Icon =              {},
    },
    {
        Name = "AUTO_MechIdle",
        Filename = "auto_mech_idle",
      
        Default =           { PosX = -18, PosY = -5 },
        Animated =          { PosX = -18, PosY = -5, NumFrames = 4 },
        Submerged =         { PosX = -18, PosY = 8 },
        Broken =            { PosX = -18, PosY = -5 },
        SubmergedBroken =   { PosX = -18, PosY = 8 },
        Icon =              {},
    },
    {
        Name = "AUTO_MechSpider",
        Filename = "auto_mech_spider",
       
        Default =           { PosX = -20, PosY = -1 },
        Animated =          { PosX = -20, PosY = -1, NumFrames = 4 },
        Submerged =         { PosX = -22, PosY = 8 },
        Broken =            { PosX = -20, PosY = 1 },
        SubmergedBroken =   { PosX = -19, PosY = 10 },
        Icon =              {},
    },
})

In the snippet, require(self.scriptPath.."squad_sprite_loader") creates a sprite loader function, which is immediately called with two argumnents: mod object (self) and a table of mech sprites you want to create.

Each mech sprite has following fields:

  • Name - the name of the created animation. Use that name when creating a pawn object: BigMech = Pawn:new { ..., Image = "AUTO_MechBig", ...}
  • Filename - base name of your sprite in mod's file system. If your sprite is named mech_artillery.png, then the Filename field would be mech_artillery.
  • Path - path to the sprite in mod's file system. If the full filename of your sprite is C:/steam/steamapps/common/Into the Breach/mods/big_guys/pictures/units/mechs/auto_mech_spider.png, then Path would be pictures/units/mechs. Can be omitted and defaults to "units".
  • ResourcePath - this indicates where inside the resource.dat your pictures should be injected. Can be omitted and defaults to "units/player".
  • Default, Animated, Submerged, Broken, SubmergedBroken, Icon - each is an object that is used to create respective animation for the mech. You can specify PosX, PosY parameters which indicate how the game should position the sprite on the board, as well as NumFrames - the number of frames in animation. Any additional parameters that you specify will also be passed to the constructor of respective animation. Each specified animation will require an image file named, respectively: filename.png, filename_a.png, filename_w.png, filename_broken.png, filename_w_broken.png, filename_ns.png. Additionally, if you specify Icon, you also must provide highlight file - filename_h.png.

For reference, code above is equivalent to:

	local function replaceSprite(self, name)
		modApi:appendAsset("img/units/player/"..name..".png",self.resourcePath.."/units/"..name..".png")
	end

	sprites = {
		"auto_mech_big",
		"auto_mech_idle",
		"auto_mech_spider",	
	}

	for i, name in ipairs(sprites) do
		replaceSprite(self, name)
		replaceSprite(self, name.."_a")
		replaceSprite(self, name.."_broken")
		replaceSprite(self, name.."_ns")
		replaceSprite(self, name.."_h")
		replaceSprite(self, name.."_w")
		replaceSprite(self, name.."_w_broken")
	end
	
	ANIMS.AUTO_MechBig =			ANIMS.MechUnit:new{ Image = "units/player/auto_mech_big.png", PosX = -19, PosY = -14 }
	ANIMS.AUTO_MechBiga =			ANIMS.MechUnit:new{ Image = "units/player/auto_mech_big_a.png", PosX = -19, PosY = -14, NumFrames = 4 }
	ANIMS.AUTO_MechBigw =			ANIMS.MechUnit:new{ Image = "units/player/auto_mech_big_w.png", PosX = -17, PosY = -4 }
	ANIMS.AUTO_MechBig_broken = 	ANIMS.MechUnit:new{ Image = "units/player/auto_mech_big_broken.png", PosX = -17, PosY = -2 }
	ANIMS.AUTO_MechBigw_broken =	ANIMS.MechUnit:new{ Image = "units/player/auto_mech_big_w_broken.png", PosX = -14, PosY = 6 }
	ANIMS.AUTO_MechBig_ns = 		ANIMS.MechIcon:new{ Image = "units/player/auto_mech_big_ns.png" }
	
	ANIMS.AUTO_MechIdle = 		ANIMS.MechUnit:new{ Image = "units/player/auto_mech_idle.png", PosX = -18, PosY = -5 }
	ANIMS.AUTO_MechIdlea = 		ANIMS.MechUnit:new{ Image = "units/player/auto_mech_idle_a.png", PosX = -18, PosY = -5, NumFrames = 4 }
	ANIMS.AUTO_MechIdlew = 		ANIMS.MechUnit:new{ Image = "units/player/auto_mech_idle_w.png", PosX = -18, PosY = 8 }
	ANIMS.AUTO_MechIdle_broken = 	ANIMS.MechUnit:new{ Image = "units/player/auto_mech_idle_broken.png", PosX = -18, PosY = -5 }
	ANIMS.AUTO_MechIdlew_broken = 	ANIMS.MechUnit:new{ Image = "units/player/auto_mech_idle_w_broken.png", PosX = -18, PosY = 8 }
	ANIMS.AUTO_MechIdle_ns =	 ANIMS.MechIcon:new{ Image = "units/player/auto_mech_idle_ns.png" }

	ANIMS.AUTO_MechSpider = 		ANIMS.MechUnit:new{ Image = "units/player/auto_mech_spider.png", PosX = -20, PosY = -1}
	ANIMS.AUTO_MechSpidera = 		ANIMS.MechUnit:new{ Image = "units/player/auto_mech_spider_a.png", PosX = -20, PosY = -1, NumFrames = 4 }
	ANIMS.AUTO_MechSpiderw = 		ANIMS.MechUnit:new{ Image = "units/player/auto_mech_spider_w.png", PosX = -22, PosY = 8 }
	ANIMS.AUTO_MechSpider_broken = 	ANIMS.MechUnit:new{ Image = "units/player/auto_mech_spider_broken.png", PosX = -20, PosY = 1 }
	ANIMS.AUTO_MechSpiderw_broken = ANIMS.MechUnit:new{ Image = "units/player/auto_mech_spider_w_broken.png", PosX = -19, PosY = 10 }
	ANIMS.AUTO_MechSpider_ns = 		ANIMS.MechIcon:new{ Image = "units/player/auto_mech_spider_ns.png" }