• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Difference between revisions of "Module:View/Quest"

From Kancolle Wiki
Jump to navigation Jump to search
(Undo revision 1105928 by Alephnaught27 (talk))
Line 33: Line 33:
  
 
local function render(args, frame)
 
local function render(args, frame)
   local category = args.explicit[1]
+
  -- Filter term ([1] = pattern to match, [2] = data element to match)
   local data = Data.load('Quest', category)
+
   local filter = (args.explicit['filter'] or nil)
 +
   local categories = (args.explicit['categories'] or { args.explicit[1] })
 
   local result = {}
 
   local result = {}
 
   table.insert(result, table_header)
 
   table.insert(result, table_header)
   for i, q in ipairs(data) do
+
   for cat in categories do
    -- table.insert(result, _.format(table_row, q))
+
    local data = Data.load('Quest', cat)
    table.insert(result, _.format(table_row, {
+
    if (type(filter) == nil) or (string.match(data[filter[2]], filter[1])) then
      label = q.label,
+
      for i, q in ipairs(data) do
      title = q.title,
+
        -- table.insert(result, _.format(table_row, q))
      title_en = q.title_en,
+
        table.insert(result, _.format(table_row, {
      detail_en = q.detail_en,
+
          label = q.label,
      reward_fuel = q.reward_fuel,
+
          title = q.title,
      reward_ammo = q.reward_ammo,
+
          title_en = q.title_en,
      reward_steel = q.reward_steel,
+
          detail_en = q.detail_en,
      reward_bauxite = q.reward_bauxite,
+
          reward_fuel = q.reward_fuel,
      reward_other = q.reward_other,
+
          reward_ammo = q.reward_ammo,
      note = q.note,
+
          reward_steel = q.reward_steel,
      letter = q.label:sub(1, 1)
+
          reward_bauxite = q.reward_bauxite,
    }))
+
          reward_other = q.reward_other,
 +
          note = q.note,
 +
          letter = q.label:sub(1, 1)
 +
        }))
 +
      end
 +
    end
 
   end
 
   end
 
   table.insert(result, table_footer)
 
   table.insert(result, table_footer)

Revision as of 22:49, 16 August 2019

Documentation for this module may be created at Module:View/Quest/doc

local _ = require('Module:Core')
local Data = require('Module:Data')
local View = require('Module:View')

-- [[Category:Todo]]:
-- * Support render : Args -> UI tree in Module:View, currently Args -> String
-- * Module:View/Table for table UI tree construction

local table_header = [=[{|style="width:100%;text-align:center" cellspacing="0"
|style="width:4%"|ID
|style="width:35%"|Requirements
|style="width:0.5%"|
|style="width:20%"|[[File:Fuel.png|30px|link=Tutorial: FAQ#How do resources work in this game?]][[File:Ammunition.png|30px|link=Tutorial: FAQ#How do resources work in this game?]][[File:Steel.png|30px|link=Tutorial: FAQ#How do resources work in this game?]][[File:Bauxite.png|30px|link=Tutorial: FAQ#How do resources work in this game?]]
|style="width:0.5%"|
|style="width:20%"|Rewards
|style="width:0.5%"|
|style="width:30%"|Note
|-]=]

local table_footer = '|}'

local table_row = [=[|- id="${label}" class="q${letter}"
|rowspan="2"|'''${label}'''
|colspan="11"|'''<span lang="ja">${title}</span>'''<br>''${title_en}''
|- class="qd${letter}"
|${detail_en}
|
|${reward_fuel} / ${reward_ammo} / ${reward_steel} / ${reward_bauxite}
|
|''${reward_other}''
|
|${note}]=]

local function render(args, frame)
  -- Filter term ([1] = pattern to match, [2] = data element to match)
  local filter = (args.explicit['filter'] or nil)
  local categories = (args.explicit['categories'] or { args.explicit[1] })
  local result = {}
  table.insert(result, table_header)
  for cat in categories do
    local data = Data.load('Quest', cat)
    if (type(filter) == nil) or (string.match(data[filter[2]], filter[1])) then
      for i, q in ipairs(data) do
        -- table.insert(result, _.format(table_row, q))
        table.insert(result, _.format(table_row, {
          label = q.label,
          title = q.title,
          title_en = q.title_en,
          detail_en = q.detail_en,
          reward_fuel = q.reward_fuel,
          reward_ammo = q.reward_ammo,
          reward_steel = q.reward_steel,
          reward_bauxite = q.reward_bauxite,
          reward_other = q.reward_other,
          note = q.note,
          letter = q.label:sub(1, 1)
        }))
      end
    end
  end
  table.insert(result, table_footer)
  return frame:preprocess(_.join(result, '\n'))
end

return View(render)