functions/MiniGameFirework/blueprints/explosion.ps1

param($Blueprint, $Var, $Settings)

$Blueprint.Group('explosion')
# Init to 1 to avoid 0 Mod $stageTick being 0.
$Blueprint.Set('time', 1)

$fireworkData = $null
if ($var."firework.type" -EQ 'hearts') {
    $fireworkData = $var."fireworks.hearts"
}
else {
    $fireworkData = $var."fireworks.normal"
}

$Blueprint.OnBlueprintInit(
    $fireworkData,
    {
        param($Self, $firework)

        $randomColor = Get-Random -Minimum 0 -Maximum ($firework.Colors.Count)
        $randomExplosion = Get-Random -Minimum 0 -Maximum ($firework.Types.Count)

        # Set explosion canvas and position.
        $fireworkType = $firework.Types[$randomExplosion]
        for ($index = $fireworkType.Count - 1; $index -GE 0; $index--) {
            $Self.AddCanvas($index, $fireworkType[$index])
        }

        $yOffset = $fireworkType[0].Length / 2
        $xOffset = $fireworkType[0][0].Length / 2
        $Self.SetPos(-$xOffset, $yOffset)
        
        # Set explosion color.
        $color = $firework.Colors[$randomColor]
        $Self.ForeGround.SetColor($color)

    }
)