use_script("rotate.lua");

function mirror_x(x, y, z)
    return 7 - x, y, z
end

function mirror_y(x, y, z)
    return x, 7 - y, z
end

function generate_sprite(path, side)
    local vsp = rotate_sprite(vsp_from_assets(path), side);

    -- Due to the fact that the belt junction outputs in the *negative* or *positive*
    -- direction, simply rotating does not product the correct models.
    -- If the input side is East (1), we must mirror Y.
    -- If the input side is South (2), we must mirror X.
    if side == 1 then
        vsp = remap_voxel_positions(vsp, mirror_y)
    end

    if side == 2 then
        vsp = remap_voxel_positions(vsp, mirror_x)
    end

    return vsp
end

for side = 0, 3 do
    local stateName = "input" .. get_side_name(side);

    export_frame(stateName, {
        colormap = generate_sprite("blocksprites/beltJunction/beltJunctionColormap.vsp", side),
        lightspecmap = generate_sprite("blocksprites/beltJunction/beltJunctionLightmap.vsp", side),
    });
end