-- Takes `ORE_TEMPLATE` as an input parameter - specifies which files in `templates/ores/<template>.vsp`
-- to use.
-- Takes `ORE_MATERIAL` as an input parameter - specifies which material to apply to the template.

use_script("variableMaterials.lua");
use_script("uniformMaterials.lua");

local templ = vsp_from_assets("templates/ores/" .. ORE_TEMPLATE .. ".vsp");
local material = variable_materials[ORE_MATERIAL];

local default_props = {
    color = color_from_rgb(255, 0, 255),
    lightspec = 0,
    bias = color_from_rgb(0, 0, 0),
    refract = 0,
};

local maps = {};
local color_to_props = {};

color_to_props[color_from_rgb(255, 0, 0)] = material[1];
color_to_props[color_from_rgb(0, 255, 0)] = material[2];
color_to_props[color_from_rgb(0, 0, 255)] = material[3];
color_to_props[color_from_rgb(255, 0, 255)] = material[4];
color_to_props[WHITE] = uniform_materials.stone;

for prop_name, prop_default in pairs(default_props) do
    local remap_table = {};

    for key_color, props in pairs(color_to_props) do
        local prop_value = props[prop_name];
        if prop_value == nil then
            prop_value = prop_default;
        end
        remap_table[key_color] = prop_value;
    end

    local map = vsp_clone(templ);
    vsp_color_remap(map, remap_table);
    maps[prop_name .. "map"] = map;
end

export_frame("default", maps);