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

Module:BAGrowthMaterial

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

该模块实现{{蔚蓝档案技能材料}}的功能。请不要直接调用此模块。

  1. -- Module:BAGrowthMaterial
  2. -- Made with ♥ by User:Leranjun
  3. -- This module implements {{tl|蔚蓝档案技能材料}}.
  4. -- Please refrain from invoking this module directly.
  5. local p = {}
  6. -- unpack() was deprecated in Lua 5.1
  7. table.unpack = table.unpack or unpack
  8. local getArgs = require("Module:Arguments").getArgs
  9. local function isempty(s)
  10. return not (s and s ~= "")
  11. end
  12. function p.main(frame)
  13. return p._main(getArgs(frame), frame)
  14. end
  15. -- Types of skill levels
  16. local TYPES = {
  17. "ex",
  18. "otr"
  19. }
  20. local TYPENAMES = {
  21. ex = "EX技能",
  22. otr = "其他技能"
  23. }
  24. function p._main(args, frame)
  25. -- For expanding templates later
  26. if (not frame) then
  27. frame = mw.getCurrentFrame()
  28. end
  29. -- Initialise table structure
  30. local r = '{| class="wikitable ba-table ba-center ba-growth-table mw-collapsible mw-collapsed"\n|-\n'
  31. local data = p.parse(args)
  32. -- Initialise table header
  33. r = r .. '! colspan=' .. data.count.total .. ' class="ba-header" | 材料需求\n'
  34. for _, type in ipairs(TYPES) do
  35. -- Initialise column header for type
  36. r = r .. "|-\n"
  37. r = r .. "! rowspan=" .. #data[type] .. " | " .. TYPENAMES[type] .. "\n"
  38. -- Iterate through levels of type
  39. for i, lvl_t in ipairs(data[type]) do
  40. -- Ignore new row for first level
  41. if (i ~= 1) then
  42. r = r .. "|-\n"
  43. end
  44. -- Initialise column header for specific level
  45. r = r .. "! " .. lvl_t.fromlevel .. " → " .. lvl_t.fromlevel + 1 .. "\n"
  46. -- Add credits cell
  47. r = r .. '| class="ba-bg-dark" | ' .. frame:expandTemplate {
  48. title = "蔚蓝档案材料",
  49. args = {
  50. "信用点数",
  51. type = "Item",
  52. num = lvl_t.credits,
  53. }
  54. } .. "\n"
  55. -- Make sure all rows have equal number of columns
  56. for j = 1, data.count.maxcol, 1 do
  57. -- Add new cell anyway
  58. if (j == 1) then
  59. r = r .. "| "
  60. else
  61. r = r .. " || "
  62. end
  63. -- Only add item if exists
  64. if (lvl_t.items[j]) then
  65. r = r .. frame:expandTemplate {
  66. title = "蔚蓝档案材料",
  67. args = {
  68. lvl_t.items[j],
  69. type = "Item",
  70. num = lvl_t.quantity[j],
  71. }
  72. }
  73. end
  74. end
  75. r = r .. "\n"
  76. end
  77. end
  78. r = r .. "|}"
  79. return r
  80. end
  81. function p.parse(args)
  82. --[[
  83. Arguments:
  84. {
  85. LevelName: "Item:Quantity;Item:Quantity;...",
  86. ...
  87. }
  88. where LevelName is a String of form "${TypeName}\d+"
  89. e.g. ex1, ex2, otr1, otr2
  90. where TypeName is a String in TYPES
  91. e.g. ex, otr
  92. e.g. {
  93. ex1 = "信用点数:80000;初级战术教育BD(三一):12;水晶埴轮碎片:19",
  94. ex2 = "信用点数:500000;中级战术教育BD(三一):12;初级战术教育BD(三一):18;破损的水晶埴轮:10;罗洪特抄本书页:26",
  95. ex3 = "信用点数:3000000;高级战术教育BD(三一):12;中级战术教育BD(三一):18;修好的水晶埴轮:10;毁损的罗洪特抄本:28",
  96. ex4 = "信用点数:10000000;最高级战术教育BD(三一):8;高级战术教育BD(三一):18;完整的水晶埴轮:9;编辑过的罗洪特抄本:20",
  97. otr1 = "初级技术笔记(三一):5;信用点数:5000",
  98. otr2 = "初级技术笔记(三一):8;信用点数:7500",
  99. otr3 = "中级技术笔记(三一):5;初级技术笔记(三一):12;水晶埴轮碎片:4;信用点数:60000",
  100. otr4 = "中级技术笔记(三一):8;破损的水晶埴轮:4;罗洪特抄本书页:13;信用点数:90000",
  101. otr5 = "高级技术笔记(三一):5;中级技术笔记(三一):12;破损的水晶埴轮:9;罗洪特抄本书页:21;信用点数:60000",
  102. }
  103. Returns:
  104. {
  105. TypeName = TypeDataTable,
  106. TypeName = TypeDataTable,
  107. ...
  108. count = {
  109. total = Int, -- Total number of rows
  110. maxcol = Int, -- Maximum number of items after "credits"
  111. }
  112. }
  113. where TypeDataTable is a Table of form:
  114. {
  115. fromlevel: Int, -- Current level before upgrade
  116. credits: Int, -- Number of credits required
  117. items: {
  118. String, -- Name of item 1
  119. String, -- Name of item 2
  120. ...
  121. },
  122. quantity: {
  123. Int, -- Quantity of item 1,
  124. Int, -- Quantity of item 2,
  125. ...
  126. },
  127. }
  128. ]]
  129. local r = {}
  130. -- Storing count data for table display
  131. local count = {
  132. total = 0,
  133. maxcol = 0,
  134. }
  135. for _, type in ipairs(TYPES) do
  136. -- Stores data for this type of skill
  137. local type_dat = {}
  138. local i = 1
  139. local lvl = type .. i
  140. local raw = args[lvl]
  141. while raw do
  142. -- Update counter
  143. count.total = count.total + 1
  144. -- Initialise current level data
  145. -- Note: parallel arrays are used for items and quantity to preserve input order, as Lua can guarantee the traversal order for numerical-indexed arrays only.
  146. local cur_dat = {
  147. fromlevel = i,
  148. items = {},
  149. quantity = {},
  150. }
  151. -- Split raw string input into items-quantity pairs
  152. for v in mw.text.gsplit(raw, ";") do
  153. v = mw.text.trim(v)
  154. if isempty(v) then
  155. break
  156. end
  157. item, quantity = table.unpack(mw.text.split(v, ":"))
  158. if isempty(item) or isempty(quantity) then
  159. error(lvl .. "材料或数量为空,请检查")
  160. end
  161. if item == "信用点数" then
  162. -- Store credits separately
  163. cur_dat.credits = quantity
  164. else
  165. -- Add item and quantity to parallel arrays
  166. table.insert(cur_dat.items, item)
  167. table.insert(cur_dat.quantity, quantity)
  168. end
  169. end
  170. -- Update max column count
  171. if (#cur_dat.items > count.maxcol) then
  172. count.maxcol = #cur_dat.items
  173. end
  174. -- Add to main table
  175. table.insert(type_dat, cur_dat)
  176. i = i + 1
  177. lvl = type .. i
  178. raw = args[lvl]
  179. end
  180. -- Add to return table
  181. r[type] = type_dat
  182. end
  183. -- Add count data to return table
  184. r.count = count
  185. return r
  186. end
  187. return p