Модуль:RecipeData

Версия от 12:09, 22 декабря 2021; JustPlayer (обсуждение | вклад) (JustPlayer изменил модель содержимого страницы Модуль:RecipeData с «Scribunto» на «JavaScript»)
local p = {}

local lib = require('Module:Feature')

function p.get(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	
	local data     = require('Module:RecipeData/data')
    local recipe   = args['recipe'] or args[1]
    local datatype = args['datatype'] or args[2]
    local num      = tonumber(args['num']) or 1
    
    local result = data[recipe]
    
    for k, v in ipairs(result) do
    	if tonumber(num) == k then
    		if datatype == 'name' then
    			return v['name']
    		elseif datatype == 'image' then
    			return v['image']
    		elseif datatype == 'count' then
    			return v['count']
    		elseif datatype == 'chance' then
    			if v['chance'] == nil then
    				v['chance'] = "?"
    			end
    			if v['chance'] == 100 then
    				v['chance'] = ">99"
    			end
    			return v['chance']
    		elseif datatype == 'catalyst' then
    			if v['chance'] == nil then
    				return "?"
    			end
				return math.floor((100 - v['chance']) / 2.5)
			elseif datatype == 'types' then
				local count = p.ingredients(v['ingredients'])
				if count == 1 or count == 2 then
					type = 1
				elseif count == 3 or count == 4 then
					type = 2
				else
					type = 3
				end
				
				return type
    		end
    	end
    end
    
end

function p.getRecipeItems(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get     = require ('Module:RecipeData/getter')
	local recipe  = args['recipe'] or args[1]
	local items   = "ingredients"
	local num     = tonumber(args['num']) or 1
	local str     = ""

	local result = get[items](recipe)
	for k, v in ipairs(result) do
		if tonumber(num) == k then
			for k2, v2 in ipairs(v['ingredients']) do
				if tonumber(args['index']) == k2 then
					str= mw.ustring.format('%s/%s', v2[1], v2[2])
				end
			end
		end
    end
    
    return tostring(str)
end

function p.ingredients(items)
	local count
	for k, v in ipairs(items) do
		count = k
	end
	
	return count
end

return p