置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

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).

  1. -- This is an attempt to create a simpler way to build Rolling Sky barriers' crash range.
  2. -- It requires one string input to describe the mapping of the range.
  3. -- It generates a CSS grid instance for graphical output.
  4. -- Crappy code originally by One-Six(U:公的驱逐舰) first use for Arknights
  5. -- And then rewritten by AsanoKanadeko in order to use it for RS.
  6. -- However, I don't know whether it can use or not after my rewrite. It sounds stupid.
  7. local p = {}
  8. -- Interpret input string and break it into a 2D array
  9. local function interpret ( s )
  10. local dataTable = {}
  11. local i = 1
  12. local j = 1
  13. dataTable[1] = {}
  14. -- Ignore newline at end of description string,
  15. -- then break string into individual char.
  16. for c in string.gmatch(s:gsub("n+$",""),".") do
  17. -- 'e' marks end of center row for symmetrical ranges.
  18. -- Generate the mirror and then break.
  19. if (c == 'e') then
  20. local iBar = i
  21. while (i > 1) do
  22. iBar = iBar + 1
  23. i = i - 1
  24. dataTable[iBar] = dataTable[i]
  25. end
  26. break
  27. -- 'r' marks end of center line which is below current line for symmetrical ranges.
  28. -- Generate the mirror and then break.
  29. elseif (c == 'r') then
  30. local iBar = i
  31. i = i + 1
  32. while (i > 1) do
  33. iBar = iBar + 1
  34. i = i - 1
  35. dataTable[iBar] = dataTable[i]
  36. end
  37. break
  38. -- 'n' marks end of row. Create the next row.
  39. elseif (c == 'n') then
  40. i = i + 1
  41. j = 1
  42. dataTable[i] = {}
  43. -- Not control char; add char to array and point to next var.
  44. else
  45. dataTable[i][j] = c
  46. j = j + 1
  47. end
  48. end
  49. j = nil
  50. -- Check for longest row.
  51. -- If rows are not all of the same length, mark for space padding.
  52. i = 1
  53. local maxWidth = table.getn(dataTable[1])
  54. local needSpacePadding = false
  55. while (dataTable[i] ~= nil) do
  56. if (table.getn(dataTable[i]) > maxWidth) then
  57. maxWidth = table.getn(dataTable[i])
  58. needSpacePadding = true
  59. elseif (table.getn(dataTable[i]) < maxWidth) then
  60. needSpacePadding = true
  61. end
  62. i = i + 1
  63. end
  64. -- Space padding.
  65. i = 1
  66. while (needSpacePadding and dataTable[i] ~= nil) do
  67. local length = table.getn(dataTable[i])
  68. for j = table.getn(dataTable[i]) + 1, maxWidth do
  69. dataTable[i][j] = 'o'
  70. end
  71. i = i + 1
  72. end
  73. return dataTable
  74. end
  75. -- Generate grid from parsed data table
  76. local function genGrid ( dataTable )
  77. -- prep output string with <div> head.
  78. 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;">'
  79. for i = 1, table.getn(dataTable) do
  80. for j = 1, table.getn(dataTable[i]) do
  81. -- 3height: solid box
  82. if (dataTable[i][j] == 's') then
  83. outputString = outputString..'<div style="width:15px;height:15px;background-color:#808080;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"></div>'
  84. -- floor: hollow box with solid border
  85. elseif (dataTable[i][j] == 'x') then
  86. outputString = outputString..'<div style="width:11px;height:11px;border:2px solid #808080;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"></div>'
  87. -- sky: hollow box with dotted border
  88. elseif (dataTable[i][j] == 'k') then
  89. outputString = outputString..'<div style="width:11px;height:11px;border:2px dotted #808080;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"></div>'
  90. -- space: placeholder box
  91. elseif (dataTable[i][j] == 'o') then
  92. outputString = outputString..'<div style="width:15px;height:15px;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..'"></div>'
  93. -- binary bridge
  94. elseif (dataTable[i][j] == 'b') then
  95. outputString = outputString..'<div style="width:11px;height:11px;border:2px solid #808080;grid-area:'..i..'/'..j..'/'..(i + 1)..'/'..(j + 1)..';background-color:#444444"></div>'
  96. -- illegal input: warning box
  97. else
  98. 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>'
  99. end
  100. end
  101. end
  102. --return output (after closing the <div>)
  103. return outputString.."</div>"
  104. end
  105. -- Get and return grid from from raw description string
  106. function p.main ( frame )
  107. return genGrid( interpret( frame.args[1] ) )
  108. end
  109. -- Return all legal chars in description string in string form
  110. function p.legalChar ( frame )
  111. return 'oxskner'
  112. end
  113. return p