Module:CraftingRecipe

From Pacific Drive Wiki

Produces a list of ingredients where each row contains the ingredient's icon, its name (which doubles as a link to the ingredient's page) and the amount required.

Arguments:

  • ingredients - a comma-separated list of key=value pairs; values can contain any character except ",";
  • recipe_tier - inserts an extra info row at the top, indicating which crafting station is required for this recipe. Possible values:
    • wb_1 - tier 1 recipes for workbenches
    • wb_2 - tier 2 recipes for workbenches
    • wb_3 - tier 3 recipes for workbenches
    • fab - recipes for the Fabrication Station

local p = {}

p.tier_classes = {
    -- items craftable at workbenches; naming is kind of complicated
    -- since workbenches themselves seem to rank from tier 0 to 2 yet their recipes rank from tier 1 to 3
    workbench = {
        icon = 'WORKBENCH-TIER.png',
        name = 'Workbench Recipe',
        color = '#dce3a0'
    },
    -- items craftable at the fabrication station (i.e. auto shop upgrades); numberless
    fabrication_station = {
        icon = 'WORKBENCH-TIER.png',
        name = 'Fabrication Station Recipe',
        color = '#dce3a0'
    }
   -- extend for items craftable at the outfitting station?
}

p.items = {
    scrap_metal = {
        icon = 'STEEL-SCRAP.png',
        name = 'Scrap Metal',
        color = '#821c8d',
    },
    copper_wire = {
        icon = 'COPPER WIRE.png',
        name = 'Copper Wire',
        color = '#9b0d4c',
    },
    explosives = {
        icon = 'EXPLOSIVE.png',
        name = 'Explosives',
        color = '#C29400',
    },
    electronics = {
        icon = 'CIRCUITRY.png',
        name = 'Electronics',
        color = '#df0d20',
    },
    plasma = {
        icon = 'PLASMA.png',
        name = 'Plasma',
        color = '#39868e',
    },
    plastic = {
        icon = 'PLASTIC.png',
        name = 'Plastic',
        color = '#1b6c19',
    },
    duct_tape = {
        icon = 'TAPE.png',
        name = 'Duct Tape',
        color = '#df0d20',
    },
    gas_cylinder = {
        icon = 'GAS-CYLINDER.png',
        name = 'Gas Cylinder',
        color = '#005266',
    },
    gear = {
        icon = 'GEAR.png',
        name = 'Gear',
        color = '#f8f7aa',
    },
    rubber = {
        icon = 'RUBBER.png',
        name = 'Rubber',
        color = '#f5bb00',
    },
    pressurized_cartridges = {
        icon = 'PRESS-CYLINDER.png',
        name = 'Pressurized Cartridges',
        color = '#1b6c19',
    },
    thermosap_crystal = {
        icon = 'THERMOFLUX-CRYSTAL.png',
        name = 'ThermoSap Crystal',
        color = '#f5bb00',
    },    
    ninev_battery = {
        icon = '9V-BATTERY.png',
        name = '9v Battery',
        color = '#39868e',
    },   
    glass_shards = {
        icon = 'GLASS.png',
        name = 'Glass Shards',
        color = '#75951b',
    },  
    chemicals = {
        icon = 'CHEMICALS.png',
        name = 'Chemicals',
        color = '#f5bb00',
    },   
    marsh_eggs = {
        icon = 'MACROPHAGE.png',
        name = 'Marsh Eggs',
        color = '#821c8d',
    },
    bulb = {
        icon = 'BULB.png',
        name = 'Bulb',
        color = '#f8f7aa',
    },
    steel_sheet = {
        icon = 'STEEL-SHEET Inverted.png',
        name = 'Steel Sheet',
        color = '#f8f7aa',
    },
    lead_platelet = {
        icon = 'LEAD.png',
        name = 'Lead Platelet',
        color = '#75951b',
    },
    fabric = {
        icon = 'FABRIC.png',
        name = 'Fabric',
        color = '#005266',
    },
    bioflare = {
        icon = 'Bioflare.png',
        name = 'Bioflare',
        color = '#df0d20',
    },
    road_flare = {
        icon = 'FLARE.png',
        name = 'Road Flare',
        color = '#df0d20',
    },
    circuit_board = {
        icon = 'BREADBOARD.png',
        name = 'Circuit Board',
        color = '#f8f7aa',
    },
    carbonfiberglass = {
        icon = 'CARBON-FIBREGLASS.png',
        name = 'Carbonfiberglass',
        color = '#f8f7aa',
    },
    olympium_fragment = {
        icon = 'ANOMALY-METAL.png', -- Placeholder
        name = 'Olympium Fragment',
        color = '#770a3c',
    },
    lim_magnet = {
        icon = 'MAGNET.png',
        name = 'LIM Magnet',
        color = '#005266',
    },
    lim_chip = {
        icon = 'LIM-CHIP.png',
        name = 'LIM Chip',
        color = '#f8f7aa',
    },
    red_balloon = {
        icon = 'GRAVITY-GEL.png',
        name = 'Red Balloon',
        color = '#df0d20',
    },
    swamp_coral = {
        icon = 'BIOLUMINESCENCE.png',
        name = 'Swamp Coral',
        color = '#b00b1d',
    },
    tree_candy = {
        icon = 'TREE_CANDY.png',
        name = 'Tree Candy',
        color = '#770a3c',
    },
    energy_corrupted = {
        icon = 'Corrupted_Anchor.png',
        name = 'Corrupted Energy (kLIM)',
        color = '#aa0063',
    },
    energy_stable = {
        icon = 'Stable_Anchor.png',
        name = 'Stable Energy (kLIM)',
        color = '#c0b354',
    },
    energy_unstable = {
        icon = 'Unstable_Anchor.png',
        name = 'Unstable Energy (kLIM)',
        color = '#cb3801',
    }
}

function p.main(frame)
    local res = ''
    local block_format_string = '%s<div style="color: #eaecc3; display: flex; align-items: center; max-width: 24em; padding: 0; margin: 0; border: solid; border-color: %s; border-width: 2px;"><span style="margin: 0; padding-left: 8px; padding-right: 8px;">[[File:%s|26px|alt=Icon for the %s resource]]</span><span style="width: 14em; border-left: solid; border-color: %s; border-width: 2px; font-size: 24px; padding: 2px 8px 2px 8px; margin: 0;">[[%s]]</span><span style="padding-right: 8px; font-size: 24px; white-space: nowrap;">%s</span></div>'
    local tier = frame.args.recipe_tier

    -- if the recipe tier is specified, insert its line at the top of the ingredient list
    if tier == 'wb_1' or tier == 'wb_2' or tier == 'wb_3' then
        local tier_num = mw.text.split(tier, '_', true)[2]
        local tier_cl = p.tier_classes.workbench
        res = string.format('%s[[Category:Workbench_Tier_%s]]', res, tier_num)
        res = string.format(block_format_string, res, tier_cl.color, tier_cl.icon, tier_cl.name, tier_cl.color, tier_cl.name, 'Tier ' .. tier_num)
    elseif tier == 'fab' then
        local tier_cl = p.tier_classes.fabrication_station
        res = string.format('%s[[Category:Fabrication_Station]]', res)
        res = string.format(block_format_string, res, tier_cl.color, tier_cl.icon, tier_cl.name, tier_cl.color, tier_cl.name, '')
    end
    -- additional tier options go here, if necessary

    -- write out the ingredient list
    for pair_raw in mw.text.gsplit(frame.args.ingredients, ',', true) do
        local pair = mw.text.split(pair_raw, '=', true)
        local key = pair[1]
        local value = pair[2]
        local item = p.items[key]
        if not item then
            return string.format("Item %s not found.", key)
        end
        res = string.format(block_format_string, res, item.color, item.icon, item.name, item.color, item.name, value)
    end
    return res
end

return p