No Man's Sky Wiki
(wortstellung)
K (test)
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 47: Zeile 47:
 
local ilink = require("Module:Ilink")
 
local ilink = require("Module:Ilink")
 
tables = 'PoC_Crafting'
 
tables = 'PoC_Crafting'
fields = 'PoC_Crafting._pageName,PoC_Crafting.ResourceQtys,PoC_Crafting.Output,PoC_Crafting.Blueprint'
+
fields = 'PoC_Crafting._pageName,PoC_Crafting.RessourcenAnzahl,PoC_Crafting.Ausgabe,PoC_Crafting.Bauplan'
 
local title = mw.title.getCurrentTitle().rootText
 
local title = mw.title.getCurrentTitle().rootText
 
local args = {
 
local args = {
where = 'PoC_Crafting.Resources HOLDS "' .. title .. '"',
+
where = 'PoC_Crafting.Ressourcen HOLDS "' .. title .. '"',
 
-- Remove line duplicate in case resource appears several times in the Resources list
 
-- Remove line duplicate in case resource appears several times in the Resources list
groupBy = 'PoC_Crafting._pageName,ResourceQtys',
+
groupBy = 'PoC_Crafting._pageName,RessourcenAnzahl',
 
limit = 1000
 
limit = 1000
 
}
 
}
Zeile 68: Zeile 68:
 
-- For each recipe, display a list entry
 
-- For each recipe, display a list entry
 
local name = v["PoC_Crafting._pageName"]
 
local name = v["PoC_Crafting._pageName"]
local ingredients = v["PoC_Crafting.ResourceQtys"]
+
local ingredients = v["PoC_Crafting.RessourcenAnzahl"]
local output = v["PoC_Crafting.Output"]
+
local output = v["PoC_Crafting.Ausgabe"]
local blueprint = v["PoC_Crafting.Blueprint"]
+
local blueprint = v["PoC_Crafting.Bauplan"]
 
text = text .. p.FormatResources(name, ingredients, output, blueprint)
 
text = text .. p.FormatResources(name, ingredients, output, blueprint)
 
end
 
end

Aktuelle Version vom 2. Oktober 2021, 20:09 Uhr

Die Dokumentation für dieses Modul kann unter Modul:PoC-Crafting/Doku erstellt werden

local p = {}

--[[
 Return a list entry (<li>...</li>) for each recipe which parameters are provided
 Every parameter is required, except for the recipe name which can be empty (and is then elegantly stripped from output)
]]--
function p.FormatResources(name, resources, output, blueprint)
    local ilink = require("Module:Ilink")
    if resources == '' then
        -- Failsafe
        return ''
    end
    local ingredients = mw.text.split(resources,'µ£',true)
    local ingredientsCount = table.maxn(ingredients)
    text = "\n<li data-ing='" .. table.concat(ingredients, " ") .. "' data-ingN='" .. ingredientsCount .. "' data-out='" .. output .. "' data-time='" .. blueprint .. "'> " .. ilink.Main({args={name, ""}}) .. "&nbsp;&nbsp;--&nbsp;&nbsp;"
    for i, ingredient in ipairs(ingredients) do
        local tuple = mw.text.split(ingredient,'; ',true)
        if table.maxn(tuple) <= 1 then
            --[[
             split will always return at least 2 parts
             In case of a single ingredient, splitting over "µ£", the last one will be empty.
             Hence, splitting tis empty part over "; " yields a single part, which is detectable and acts as the end of the ingredients list
            ]]--
            break
        end

        if i > 1 then
            -- From the 2nd ingredient to the end of the list, prefix with "  +  "
            text = text .. "&nbsp;&nbsp;+&nbsp;&nbsp;"
        end
        text = text .. "[[" .. tuple[1] .. "|<span class='itemlink ajaxttlink'>" .. tuple[1] .. "</span>]] x" .. tuple[2]
    end
    text = text .. "&nbsp;&nbsp;&rarr;&nbsp;&nbsp;" .. ilink.Main({args={name,""}})
    if tonumber(output) > 1 then
        -- Gracefully hides output quantity when 1 ("normal" output, cf. https://nomanssky.gamepedia.com/Special:CommentPermalink/10248#comment10248)
        text = text .. " x" .. output
    end
    text = text .. "</li>"
    return text
end

--[[
 Provide an unordered HTML list (<ul>...</ul>) of recipes containing the current page's item
]]--
function p.List(frame) 
    local cargo = mw.ext.cargo
    local ilink = require("Module:Ilink")
    tables = 'PoC_Crafting'
    fields = 'PoC_Crafting._pageName,PoC_Crafting.RessourcenAnzahl,PoC_Crafting.Ausgabe,PoC_Crafting.Bauplan'
    local title = mw.title.getCurrentTitle().rootText
    local args = {
        where = 'PoC_Crafting.Ressourcen HOLDS "' .. title .. '"',
        -- Remove line duplicate in case resource appears several times in the Resources list
        groupBy = 'PoC_Crafting._pageName,RessourcenAnzahl',
        limit = 1000
    }
    if frame.args[1] ~= '' then
        tables = 'PoC_Crafting,Version_info'
        args.join = 'PoC_Crafting._pageName = Version_info._pageName'
        args.where = args.where .. ' AND Version_info.Version = "' .. frame.args[1] .. '"'
    end
    local results = cargo.query( tables, fields, args )
    local text = "'''" .. title .. "''' wird "
    if table.maxn(results) > 0 then
        -- Recipes have been found with the current page's item as resource
        text = text .. "als [[Bestandtetile|Bestandteil]] für die [[Herstellung]] der folgenden Produkte verwendet:\n<ul>"
        for i, v in ipairs(results) do
            -- For each recipe, display a list entry
            local name = v["PoC_Crafting._pageName"]
            local ingredients = v["PoC_Crafting.RessourcenAnzahl"]
            local output = v["PoC_Crafting.Ausgabe"]
            local blueprint = v["PoC_Crafting.Bauplan"]
            text = text .. p.FormatResources(name, ingredients, output, blueprint)
        end
        text = text .. "</ul>"
    else
        -- No recipe has been found with the current page's item as resource; Placeholder could be replaced with empty string or an error message if that should never happen
        text = text .. "nicht als [[Bestandteile|Bestandteil]] für die [[Herstellung]] verwendet.\n"
    end
    return text
end

return p