Content added Content deleted
No edit summary |
mNo edit summary |
||
Line 86:
---@return string
local function find_from_table(table, num)
for i, v in ipairs(table) do
if i == num then
Line 107 ⟶ 106:
function mod.get_volume(frame)
local args, pargs = util.get_args_and_pargs(frame)
local num = args[1] or pargs[1] or #tanko_items + 1
local mode = args[2] or pargs[2] or ""
|
Revision as of 23:00, May 13, 2024
Usage:
{{#invoke:Which Volume|get_volume|num|mode=mode}}
mode must be either tanko, headers, or normal. Not providing a mode will make it default to normal. Code will default to TBA if it cannot find a valid entry.
Code uses Module:Which_Volume/tanko_data.json to keep the tanko data, please update this if anything changes.
---@param items table
---@param start integer
---@param stop integer
---@param item string
---@return table
local function append_to(items, start, stop, item)
for i = start,stop do
items[i] = item
end
return items
end
-- Let me explain myself here, the stuff under the "tanko" section was so massive i felt like using
-- mw.loadJsonData was the best move here.
local tanko_items = {}
local tanko_json = mw.loadJsonData('Module:Which_Volume/tanko_data.json')
for _, t in ipairs(tanko_json) do
append_to(tanko_items, t.start, t.stop, t.item)
end
local headers = {
[1] = "Osamu Mikumo",
[2] = "Yūichi Jin",
[3] = "Yūma Kuga",
[4] = "Yūichi Jin 2",
[5] = "Osamu Mikumo 2",
[6] = "Large-Scale Invasion",
[7] = "Large-Scale Invasion 2",
[8] = "Large-Scale Invasion 3",
[9] = "Large-Scale Invasion 4",
[10] = "Osamu Mikumo 3",
[11] = "Tamakoma Second",
[12] = "Tamakoma Second 2",
[13] = "Osamu Mikumo 4",
[14] = "Yūichi Jin 3",
[15] = "Galopoula",
[16] = "Tamakoma Second 3",
[17] = "Tamakoma Second 4",
[18] = "Hyuse",
[19] = "Tamakoma Branch",
[20] = "Tamakoma Second 5",
[21] = "Yuba Squad",
[22] = "Chika Amatori",
[23] = "Away Mission Test",
[24] = "Away Mission Test 2",
[25] = "Away Mission Test 3",
[26] = "Away Mission Test 4",
[27] = "Away Mission Test 5"
}
local normal = {
[1]="Osamu Mikumo (volume){{!}}{{#if: {{{Name|}}}|Osamu Mikumo|1}}",
[2]="Yūichi Jin (volume){{!}}{{#if: {{{Name|}}}|Yūichi Jin|2}}",
[3]="Yūma Kuga (volume){{!}}{{#if: {{{Name|}}}|Yūma Kuga|3}}",
[4]="Yūichi Jin 2 (volume){{!}}{{#if: {{{Name|}}}|Yūichi Jin 2|4}}",
[5]="Osamu Mikumo 2 (volume){{!}}{{#if: {{{Name|}}}|Osamu Mikumo 2|5}}",
[6]="Large-Scale Invasion (volume){{!}}{{#if: {{{Name|}}}|Large-Scale Invasion|6}}",
[7]="Large-Scale Invasion 2 (volume){{!}}{{#if: {{{Name|}}}|Large-Scale Invasion 2|7}}",
[8]="Large-Scale Invasion 3 (volume){{!}}{{#if: {{{Name|}}}|Large-Scale Invasion 3|8}}",
[9]="Large-Scale Invasion 4 (volume){{!}}{{#if: {{{Name|}}}|Large-Scale Invasion 4|9}}",
[10]="Osamu Mikumo 3 (volume){{!}}{{#if: {{{Name|}}}|Osamu Mikumo 3|10}}",
[11]="Tamakoma Second (volume){{!}}{{#if: {{{Name|}}}|Tamakoma Second|11}}",
[12]="Tamakoma Second 2 (volume){{!}}{{#if: {{{Name|}}}|Tamakoma Second 2|12}}",
[13]="Osamu Mikumo 4 (volume){{!}}{{#if: {{{Name|}}}|Osamu Mikumo 4|13}}",
[14]="Yūichi Jin 3 (volume){{!}}{{#if: {{{Name|}}}|Yūichi Jin 3|14}}",
[15]="Galopoula (volume){{!}}{{#if: {{{Name|}}}|Galopoula|15}}",
[16]="Tamakoma Second 3 (volume){{!}}{{#if: {{{Name|}}}|Tamakoma Second 3|16}}",
[17]="Tamakoma Second 4 (volume){{!}}{{#if: {{{Name|}}}|Tamakoma Second 4|17}}",
[18]="Hyuse (volume){{!}}{{#if: {{{Name|}}}|Hyuse|18}}",
[19]="Tamakoma Branch (volume){{!}}{{#if: {{{Name|}}}|Tamakoma Branch|19}}",
[20]="Tamakoma Second 5 (volume){{!}}{{#if: {{{Name|}}}|Tamakoma Second 5|20}}",
[21]="Yuba Squad (volume){{!}}{{#if: {{{Name|}}}|Yuba Squad|21}}",
[22]="Chika Amatori (volume){{!}}{{#if: {{{Name|}}}|Chika Amatori|22}}",
[23]="Away Mission Test (volume){{!}}{{#if: {{{Name|}}}|Away Mission Test|23}}",
[24]="Away Mission Test 2 (volume){{!}}{{#if: {{{Name|}}}|Away Mission Test 2|24}}",
[25]="Away Mission Test 3 (volume){{!}}{{#if: {{{Name|}}}|Away Mission Test 3|25}}",
[26]="Away Mission Test 4 (volume){{!}}{{#if: {{{Name|}}}|Away Mission Test 4 |26}}",
[27]="Away Mission Test 5 (volume){{!}}{{#if: {{{Name|}}}|Away Mission Test 5|27}}"
}
---@param table table
---@param num integer
---@return string
local function find_from_table(table, num)
for i, v in ipairs(table) do
if i == num then
return v
end
end
return "TBA"
end
local util = require("Module:Util")
local mod = {
find_from_table = find_from_table,
append_to = append_to,
tanko_items = tanko_items,
headers = headers,
normal = normal
}
function mod.get_volume(frame)
local args, pargs = util.get_args_and_pargs(frame)
local num = args[1] or pargs[1] or #tanko_items + 1
local mode = args[2] or pargs[2] or ""
if mode == "tanko" then
return frame:preprocess(find_from_table(tanko_items, num))
elseif mode == "headers" then
return frame:preprocess(find_from_table(headers, num))
else
return frame:preprocess(find_from_table(normal, num))
end
end
return mod