Subnautica Wiki
Advertisement

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Receptury/opis

local p = {}

-- Construct a display options table out of arguments
local function construct_display_options (templateArgs)
    -- KEYWORDS: [htmlgen] [htmlgen modules]
    local _htmlgen_default = 'tabela'
    local _htmlgen_mods = {
        ['równania'] = 'Moduł:Receptury/Html',
        ['tabela'] = 'Moduł:Receptury/Html2'
    }
    
    -- KEYWORDS: [make display options]
    return {
        ["htmlgen"] = require (
            _htmlgen_mods[
                templateArgs['styl'] or _htmlgen_default
            ] or _htmlgen_mods[_htmlgen_default]
        ),
        ["hideFromCategories"] = templateArgs["ignoruj to wystąpienie w kategoriach"] == 'tak',
        ["features"] = {
            -- KEYWORDS: [determine display features]
            ["machineHeaders"] = true,
            ["machineSubcategories"] = false,
            ["collapsible"] = true
        }
    }
end

-- Show a single recipe.
-- KEYWORDS: [public function] [single] [single recipe]
--           [render single recipe]
function p.show_single_recipe(frame)
    local templateArgs = frame:getParent().args
    local recipeTableQueries = require ('Module:Receptury/Odpytywanie')
    local _requestedItem = templateArgs["przedmiotu"]
    local _displayOptions = construct_display_options (templateArgs)
    
    return recipeTableQueries.findItemRecipe (_requestedItem, _displayOptions)
end

-- Show all recipes made with an ingredient.
-- KEYWORDS: [public function] [by ingredient] [recipes by]
function p.show_recipes_by_ingredient(frame)
    local templateArgs = frame:getParent().args
    local recipeTableQueries = require ('Module:Receptury/Odpytywanie')
    local _ingredient = templateArgs["wykorzystujące składnik"]
    local _displayOptions = construct_display_options (templateArgs)
    _displayOptions["tableHeader"] = '[[Przedmioty]] tworzone z użyciem: ' .. _ingredient
    
    return recipeTableQueries.findRecipesByCondition (
        -- Search filter
        function (
            itemName,
            itemRecipe,
            additionalFilterData
        )
            for __ingredient, _ in pairs(itemRecipe["składniki"]) do
                if __ingredient:lower() == additionalFilterData:lower() then
                    return true
                end
            end

            return false
        end,
        _ingredient,
        -- Callback
        function (
            recipeTable,
            itemCount,
            itemList,
            displayOptions
        )
            local _htmlgen = displayOptions["htmlgen"]
            
            return _htmlgen.construct_item_list (
                recipeTable,
                itemList,
                displayOptions
            )
        end,
        _displayOptions
    )
end

-- Show all recipes made with a specific machine.
-- KEYWORDS: [public function] [by machine] [recipes by]
function p.show_recipes_by_machine(frame)
    local templateArgs = frame:getParent().args
    local recipeTableQueries = require ('Module:Receptury/Odpytywanie')
    local _machine = templateArgs["wykorzystujące maszynę"]
    local _displayOptions = construct_display_options (templateArgs)
    
    return recipeTableQueries.findRecipesByCondition (
        -- Search filter
        function (itemName, itemRecipe, additionalFilterData)
            return itemRecipe["urządzenie"] == additionalFilterData
        end,
        _machine,
        -- Callback
        function (
            recipeTable,
            itemCount,
            itemList,
            displayOptions
        )
            local _htmlgen = displayOptions["htmlgen"]
            
            return _htmlgen.construct_item_list (
                recipeTable,
                itemList,
                displayOptions
            )
        end,
        _displayOptions
    )
end

-- Dispatch the invocation to a proper function, based
-- on the arguments.
-- KEYWORDS: [public function] [dispatch] [auto]
function p.auto(frame)
    local templateArgs = frame:getParent().args
    
    if templateArgs["przedmiotu"] ~= nil then
        return p.show_single_recipe (frame)
    elseif templateArgs["wykorzystujące składnik"] ~= nil then
        return p.show_recipes_by_ingredient (frame)
    elseif templateArgs["wykorzystujące maszynę"] ~= nil then
        return p.show_recipes_by_machine (frame)
    else
        return '<span style="color: red; font-size: 20px; font-weight: bold">'
            .. 'Nieprawidłowe użycie modułu. [[Template:Receptury/doc|Dokumentacja szablonu.]]'
            .. '</span>' .. (templateArgs["ignoruj to wystąpienie w kategoriach"] ~= 'tak' and '[[Kategoria:Artykuły z błędami modułu receptur]]' or '')
    end
end

function p.list(frame)
    local recipeTableQueries = require ('Module:Receptury/Odpytywanie')
    
    local args = frame:getParent().args
    local templateOptions = {
        ["findSingle"] = args["przedmiotu"],
        ["findIngredient"] = args["wykorzystujące składnik"],
        ["findMachine"] = args["wykorzystujące maszynę"],
        ["findEverything"] = args["wszystko"],
        ["findByTag"] = args["szukaj po tagu"],
        ["hideFromCategories"] = args["ignoruj to wystąpienie w kategoriach"],
        ["displayOptions"] = {
            ["machineHeaders"] = true,
            ["machineSubcategories"] = false,
            ["collapsible"] = true
        }
    }
    
    -- Throw an error if there are no filters at all
    if templateOptions["findSingle"] == nil
        and templateOptions["findIngredient"] == nil
        and templateOptions["findMachine"] == nil
        and templateOptions["findByTag"] == nil
        and templateOptions["findEverything"] == nil then
        return '<span style="color: red; font-size: 20px; font-weight: bold">'
            .. 'Nieprawidłowe użycie modułu. [[Template:Receptury/doc|Dokumentacja szablonu.]]'
            .. '</span>' .. (templateOptions["hideFromCategories"] ~= 'tak' and '[[Kategoria:Artykuły z błędami modułu receptur]]' or '')
    end
    
    -- Check if a single recipe is requested and
    -- return it
    if templateOptions["findSingle"] ~= nil then
        return recipeTableQueries.findItemRecipe (templateOptions["findSingle"], filterData)
    end
    
    -- Alter display options
    if templateOptions["findMachine"] ~= nil then
        templateOptions["displayOptions"]["machineHeaders"] = false
        templateOptions["displayOptions"]["machineSubcategories"] = true
    end
    
    -- Return recipes as a HTMl string
    return recipeTableQueries.findRecipesByCondition (
        -- Custom filter that checks the filter data
        -- and combines required filters
        function (item, recipe, filterData)
            if templateOptions["findEverything"] == "tak" then
                return true
            end
            
            local finalResult = true
            
            if templateOptions["findByTag"] == nil and recipe["tag"] ~= nil then
                return false
            end
            
            if templateOptions["findByTag"] ~= nil and recipe["tag"] ~= filterData["findByTag"] then
                return false
            end
            
            if templateOptions["findIngredient"] ~= nil then
                finalResult = finalResult
                                and recipeTableQueries.filter_HasIngredient(
                                    item,
                                    recipe,
                                    templateOptions["findIngredient"]
                                )
            end
            
            if templateOptions["findMachine"] ~= nil then
                finalResult = finalResult
                                and recipeTableQueries.filter_UsesMachine(
                                    item,
                                    recipe,
                                    templateOptions["findMachine"]
                                )
            end
            
            return finalResult
        end,
        templateOptions,
        -- Ustawienia wyświetlania
        templateOptions["displayOptions"]
    )
    
end

return p
Advertisement