「モジュール:Grid/Item」の版間の差分

提供:Azipedia
ナビゲーションに移動 検索に移動
(took from ftb wiki)
 
編集の要約なし
1行目: 1行目:
local p = {}
local p = {}


local g = require("Module:Common")
local g = require("Module:FTBCommon")
local s = require("Module:Sprite")
local s = require("Module:FTBSprite")
local cn = require("Module:Grid/Crafting_Square_Numbers")
local cn = require("Module:Grid/Crafting_Square_Numbers")



2022年5月22日 (日) 21:40時点における版

このモジュールについての説明文ページを モジュール:Grid/Item/doc に作成できます

local p = {}

local g = require("Module:FTBCommon")
local s = require("Module:FTBSprite")
local cn = require("Module:Grid/Crafting_Square_Numbers")

function p.makeItem(name, amount, img, link, tooltip, top, left, fill, isDict)
	local output = '<div data-tooltip="' .. tooltip .. '" class="tooltip griditem" '
	output = output .. 'style="top:' .. g.px(top) .. ';left:' .. g.px(left)
	if g.isGiven(fill) then
		output = output .. ';background-color:' .. fill .. ';'
	end
	output = output .. '">'
	if isDict then
		output = output .. '<div style="position:absolute;">' .. g.img('Grid_Ore_Dictionary.png',32,link,name) .. '</div>'
	end
	output = output .. g.img(img, 32, link, name) .. '</div>'
	
	if amount > 1 then
		output = output .. '<div data-tooltip="' .. tooltip .. '" class="tooltip gridamount" '
		output = output .. 'style="top:' .. g.px(top + 16) .. ';left:' .. g.px(left - 4)
		output = output .. '">' .. cn.makeCraftingNumbers(amount, link) .. '</div>'
	end
	
	return output
end

function p.main(frame)
	local frame, args = g.getFrameAndArgs(frame)
	
	if not g.isGiven(args.name) then
		return ''
	end
	
	local tooltip = ''
	if g.isGiven(args.chance) and tonumber(args.chance) then
		local chance = tonumber(args.chance)
		if chance < 0 then
			chance = 0
		end
		if chance > 100 then
			chance = 100
		end
		tooltip = tooltip .. chance .. '% chance of&nbsp;'
	end
	
	local amount = 1
	if g.isGiven(args.amount) and tonumber(args.amount) then
		amount = tonumber(args.amount)
	end
	
	if amount > 1 then
		tooltip = tooltip .. amount .. '&nbsp;'
	elseif g.isGiven(args.liquid) and tonumber(args.liquid) then 
		local liquid = tonumber(args.liquid) * 1000
		tooltip = tooltip .. liquid .. 'mB of&nbsp;'
	end
	
	tooltip = tooltip .. args.name
	
	local tooltext = args.tooltext
	if g.isGiven(tooltext) then
		if g.isGiven(args.noname) then
			tooltip = tooltext
		else
			tooltip = tooltext .. ' - ' .. tooltip
		end
	end
	
	local image = args.image
	if not g.isGiven(image) then
		image = 'Grid ' .. args.name .. '.png'
	end
	
	local dict = args.dict
	local isDict = false
	if g.isGiven(dict) then
		tooltip = dict .. ' - ' .. tooltip
		isDict = true
	end
	
	local link = args.link
	if not g.isGiven(link) then
		if g.isGiven(dict) and 
			((not g.isGiven(args.dictamount)) or 
				tonumber(args.dictamount) > 1) then
			link = dict
		else
			link = args.name
		end
	end
	
	local top = 0
	if g.isGiven(args.top) and tonumber(args.top) then
		top = tonumber(args.top)
	end
	
	local left = 0
	if g.isGiven(args.left) and tonumber(args.left) then
		left = tonumber(args.left)
	end
	
	return p.makeItem(args.name, amount, image, link, tooltip, top, left, args.fill, isDict)
end

return p