2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:RSRange

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

The module was created for showing the crash range of Rolling Sky barriers.

You can use the template {{RSRange}} to show it.

Don't rewrite this model unless you are sure that it can work after rewriting.

More information can be got here: Template:RSRange(Template Page) and Template:RSRange/doc(Template Information Document).

-- This is an attempt to create a simpler way to build Rolling Sky barriers' crash range.
-- It requires one string input to describe the mapping of the range.
-- It generates a CSS grid instance for graphical output.
-- Crappy code originally by One-Six(U:公的驱逐舰) first use for Arknights 
-- And then rewritten by AsanoKanadeko in order to use it for RS. 
-- However, I don't know whether it can use or not after my rewrite. It sounds stupid.

local p = {}

-- Interpret input string and break it into a 2D array
local function interpret ( s )
	local dataTable = {}
	local i = 1
	local j = 1
	dataTable[1] = {}
	-- Ignore newline at end of description string,
	-- then break string into individual char.
	for c in string.gmatch(s:gsub("n+$",""),".") do
		-- 'e' marks end of center row for symmetrical ranges.
		-- Generate the mirror and then break.
		if (c == 'e') then
			local iBar = i
			while (i > 1) do
				iBar = iBar + 1
				i = i - 1
				dataTable[iBar] = dataTable[i]
			end
			break
		-- 'r' marks end of center line which is below current line for symmetrical ranges.
		-- Generate the mirror and then break.
		elseif (c == 'r') then
			local iBar = i
			i = i + 1
			while (i > 1) do
				iBar = iBar + 1
				i = i - 1
				dataTable[iBar] = dataTable[i]
			end
			break
		-- 'n' marks end of row. Create the next row.
		elseif (c == 'n') then 
			i = i + 1
			j = 1
			dataTable[i] = {}
		-- Not control char; add char to array and point to next var.
		else 
			dataTable[i][j] = c
			j = j + 1
		end
	end
	j = nil
	-- Check for longest row. 
	-- If rows are not all of the same length, mark for space padding.
	i = 1
	local maxWidth = table.getn(dataTable[1])
	local needSpacePadding = false
	while (dataTable[i] ~= nil) do
		if (table.getn(dataTable[i]) > maxWidth) then
			maxWidth = table.getn(dataTable[i])
			needSpacePadding = true
		elseif (table.getn(dataTable[i]) < maxWidth) then
			needSpacePadding = true
		end
		i = i + 1
	end
	-- Space padding.
	i = 1
	while (needSpacePadding and dataTable[i] ~= nil) do
		local length = table.getn(dataTable[i])
		for j = table.getn(dataTable[i]) + 1, maxWidth do
			dataTable[i][j] = 'o'
		end
		i = i + 1
	end
	return dataTable
end

-- Generate grid from parsed data table
local function genGrid ( dataTable )
	-- prep output string with <div> head.
	local outputString = '<div style="display:grid;grid-gap:2px;margin:5px; box-sizing:content-box;width:'..(17 * table.getn(dataTable[1]) - 2)..'px;height:'..(17 * table.getn(dataTable) - 2)..'px;">'
	for i = 1, table.getn(dataTable) do
		for j = 1, table.getn(dataTable[i]) do
			-- 3height: solid box
			if (dataTable[i][j] == 's') then
				outputString = outputString..'<div style="width:15px;height:15px;background-color:#808080;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"></div>' 
			-- floor: hollow box with solid border
			elseif (dataTable[i][j] == 'x') then
				outputString = outputString..'<div style="width:11px;height:11px;border:2px solid #808080;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"></div>' 
			-- sky: hollow box with dotted border
			elseif (dataTable[i][j] == 'k') then
				outputString = outputString..'<div style="width:11px;height:11px;border:2px dotted #808080;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"></div>'
			-- space: placeholder box
			elseif (dataTable[i][j] == 'o') then
				outputString = outputString..'<div style="width:15px;height:15px;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"></div>'
			-- binary bridge
			elseif (dataTable[i][j] == 'b') then
				outputString = outputString..'<div style="width:11px;height:11px;border:2px solid #808080;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..';background-color:#444444"></div>'
			-- illegal input: warning box
			else
				outputString = outputString..'<div title="Warning from Module:RSRange&gt; Illegal value ('..dataTable[i][j]..') was found in the format string. Location: (R'..i..',C'..j..')." style="width:15px;height:15px;background-color:#FFCCCC;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"><sup><span style="text-align:center;color:#F00">×</span></sup></div>'
			end
		end
	end
	--return output (after closing the <div>)
	return outputString.."</div>"
end

-- Get and return grid from from raw description string
function p.main ( frame )
	return genGrid( interpret( frame.args[1] ) )
end

-- Return all legal chars in description string in string form
function p.legalChar ( frame )
	return 'oxskner'
end

return p