| Line 4: |
Line 4: |
| | -- Remi_Scarlet | | -- Remi_Scarlet |
| | -- I fucking hate lua. | | -- I fucking hate lua. |
| − | | + | |
| | -- 10/24/15 Added colorful blue button as per Wsewo's request. | | -- 10/24/15 Added colorful blue button as per Wsewo's request. |
| | | | |
| | + | -- 11/22/17 Modified by がか |
| | + | |
| | -- checks if data is in the array as a key | | -- checks if data is in the array as a key |
| − | | + | |
| | function valid(data, array) | | function valid(data, array) |
| | local valid = {} | | local valid = {} |
| Line 22: |
Line 24: |
| | end | | end |
| | end | | end |
| − | | + | |
| | -- returns a string representation of a table. | | -- returns a string representation of a table. |
| | -- cannot do recursive tables. Eg, only single dimensional tables will work | | -- cannot do recursive tables. Eg, only single dimensional tables will work |
| Line 46: |
Line 48: |
| | return final | | return final |
| | end | | end |
| − | | + | |
| | -- takes a string and returns string with first letter capitalized | | -- takes a string and returns string with first letter capitalized |
| | function capitalize(str) | | function capitalize(str) |
| | return (str:gsub("^%l", string.upper)) | | return (str:gsub("^%l", string.upper)) |
| | end | | end |
| − | | + | |
| | -- "info" should be higher level table of information with eg | | -- "info" should be higher level table of information with eg |
| | -- {["A"] = {["1"] = {["xp"]="120", ["main_info"] = "ta-class etc"} | | -- {["A"] = {["1"] = {["xp"]="120", ["main_info"] = "ta-class etc"} |
| Line 73: |
Line 75: |
| | return size | | return size |
| | end | | end |
| − | | + | |
| − | | + | |
| | local numCols = 0 | | local numCols = 0 |
| | for _,bool in pairs(headers) do | | for _,bool in pairs(headers) do |
| | if bool then numCols = numCols + 1 end | | if bool then numCols = numCols + 1 end |
| | end | | end |
| − |
| + | |
| | -- Will be used to uniquely identify each table with the "button" and the "table content". Normally | | -- Will be used to uniquely identify each table with the "button" and the "table content". Normally |
| | -- this would be done with like mw-customtoggle-1-1-enemy or whatnot, but since I can't | | -- this would be done with like mw-customtoggle-1-1-enemy or whatnot, but since I can't |
| Line 85: |
Line 87: |
| | -- rendering to replace the map identifier. | | -- rendering to replace the map identifier. |
| | local uniqueID = remiLib.timeHash(info) | | local uniqueID = remiLib.timeHash(info) |
| − |
| + | |
| | local classString = "mw-customtoggle-" .. tostring(uniqueID) | | local classString = "mw-customtoggle-" .. tostring(uniqueID) |
| | local idString = "mw-customcollapsible-" .. tostring(uniqueID) | | local idString = "mw-customcollapsible-" .. tostring(uniqueID) |
| − |
| + | |
| | local button = mw.html.create('div') | | local button = mw.html.create('div') |
| | button | | button |
| Line 94: |
Line 96: |
| | :addClass("globalbutton") | | :addClass("globalbutton") |
| | :wikitext("Show/Hide Nodes and Enemy Encounters") | | :wikitext("Show/Hide Nodes and Enemy Encounters") |
| − |
| + | |
| | local encounterTable = mw.html.create("table") | | local encounterTable = mw.html.create("table") |
| | encounterTable | | encounterTable |
| Line 151: |
Line 153: |
| | nodeName = nodeName .. "<br>" .. values["label"] | | nodeName = nodeName .. "<br>" .. values["label"] |
| | end | | end |
| − | | + | |
| | firstCol | | firstCol |
| | :wikitext(nodeName) | | :wikitext(nodeName) |
| Line 173: |
Line 175: |
| | end | | end |
| | firstRow:node(mw.html.create("td"):wikitext(text)):css("text-align","center") | | firstRow:node(mw.html.create("td"):wikitext(text)):css("text-align","center") |
| − |
| + | |
| | -- since first row with rowspan is handled differently, just | | -- since first row with rowspan is handled differently, just |
| | -- do it separately | | -- do it separately |
| Line 286: |
Line 288: |
| | row:node(td) | | row:node(td) |
| | end | | end |
| − | | + | |
| | encounterTable:node(row) | | encounterTable:node(row) |
| | end | | end |
| Line 294: |
Line 296: |
| | return tostring(button) .. "\n" .. tostring(encounterTable) | | return tostring(button) .. "\n" .. tostring(encounterTable) |
| | end | | end |
| − | | + | |
| | function splitAndCapitalize(s, split, join) | | function splitAndCapitalize(s, split, join) |
| | split = split or "_" | | split = split or "_" |
| Line 305: |
Line 307: |
| | return table.concat(result, join) | | return table.concat(result, join) |
| | end | | end |
| − | | + | |
| | -- 1.1. new type pattern parameter: <node>-<pattern number>_<parameter name> | | -- 1.1. new type pattern parameter: <node>-<pattern number>_<parameter name> |
| | -- 1.2. old type pattern parameter: <node letter><pattern number>_<parameter name> | | -- 1.2. old type pattern parameter: <node letter><pattern number>_<parameter name> |
| Line 311: |
Line 313: |
| | -- 3. map parameters: boss_node, final_form, post_final_form, second_phase | | -- 3. map parameters: boss_node, final_form, post_final_form, second_phase |
| | function parseParameter(param) | | function parseParameter(param) |
| − | local node, pattern, name = param:match('^(%w+)-(%d)_(.+)$') | + | local node, pattern, name |
| | + | node = param:match('^(%w+)_label$') |
| | + | if node then |
| | + | return { label = true, node = node } |
| | + | end |
| | + | node, pattern, name = param:match('^(%w+)-(%d)_(.+)$') |
| | if not node then | | if not node then |
| | node, pattern, name = param:match('^(%a)(%d)_(.+)$') | | node, pattern, name = param:match('^(%a)(%d)_(.+)$') |
| Line 317: |
Line 324: |
| | if node then | | if node then |
| | return { pattern = true, node = node, pattern = tonumber(pattern), name = name, title = splitAndCapitalize(name) } | | return { pattern = true, node = node, pattern = tonumber(pattern), name = name, title = splitAndCapitalize(name) } |
| − | end
| |
| − | node = param:match('^(%w+)_label$')
| |
| − | if node then
| |
| − | return { label = true, node = node }
| |
| | end | | end |
| | return { map = true, name = param } | | return { map = true, name = param } |
| | end | | end |
| − | | + | |
| | function parsePattern(param) | | function parsePattern(param) |
| | local node, number = param:match('^(%w+)-(%d)$') | | local node, number = param:match('^(%w+)-(%d)$') |
| Line 332: |
Line 335: |
| | return node and { node = node, number = tonumber(number) } | | return node and { node = node, number = tonumber(number) } |
| | end | | end |
| − | | + | |
| | function markNodes(mapEncounterTable, list, name) | | function markNodes(mapEncounterTable, list, name) |
| | if list then | | if list then |
| Line 344: |
Line 347: |
| | end | | end |
| | end | | end |
| − | | + | |
| | function debugPrint(x, i) | | function debugPrint(x, i) |
| | i = i or 0 | | i = i or 0 |
| Line 361: |
Line 364: |
| | end | | end |
| | end | | end |
| − | | + | |
| | function p.encounterTemplate(frame) | | function p.encounterTemplate(frame) |
| − | | + | |
| | local bossNode = frame.args.boss_node | | local bossNode = frame.args.boss_node |
| | local usedParams = {} | | local usedParams = {} |
| | local mapEncounterTable = {} | | local mapEncounterTable = {} |
| − | | + | |
| | for param, value in pairs(frame.args) do | | for param, value in pairs(frame.args) do |
| | if type(param) == "string" then | | if type(param) == "string" then |
| Line 394: |
Line 397: |
| | end | | end |
| | end | | end |
| − | | + | |
| | markNodes(mapEncounterTable, frame.args.final_form, "isFinalForm") | | markNodes(mapEncounterTable, frame.args.final_form, "isFinalForm") |
| | markNodes(mapEncounterTable, frame.args.post_final_form, "isPostFinalForm") | | markNodes(mapEncounterTable, frame.args.post_final_form, "isPostFinalForm") |
| | markNodes(mapEncounterTable, frame.args.second_phase, "isSecondPhase") | | markNodes(mapEncounterTable, frame.args.second_phase, "isSecondPhase") |
| − | | + | |
| | if frame.args.map_xp then | | if frame.args.map_xp then |
| | mapEncounterTable.map_xp = frame.args.map_xp | | mapEncounterTable.map_xp = frame.args.map_xp |
| | usedParams["Xp"] = true | | usedParams["Xp"] = true |
| | end | | end |
| − | | + | |
| | debugPrint(mapEncounterTable) | | debugPrint(mapEncounterTable) |
| | debugPrint(usedParams) | | debugPrint(usedParams) |
| | debugPrint(bossNode) | | debugPrint(bossNode) |
| − | | + | |
| | return p.renderEncounterTable(mapEncounterTable, usedParams, bossNode, true) | | return p.renderEncounterTable(mapEncounterTable, usedParams, bossNode, true) |
| − | | + | |
| | end | | end |
| − | | + | |
| | function p.replaceWordWithWikicode(str) | | function p.replaceWordWithWikicode(str) |
| | local nodeInfoImageTable = { | | local nodeInfoImageTable = { |
| Line 586: |
Line 589: |
| | ["entombed_AA_guardian_princess[%s$]"] = '[[File:Seikan1773Banner.png|2|160px|Entombed Anti-Air Guardian Princess|link=Entombed Anti-Air Guardian Princess]]' | | ["entombed_AA_guardian_princess[%s$]"] = '[[File:Seikan1773Banner.png|2|160px|Entombed Anti-Air Guardian Princess|link=Entombed Anti-Air Guardian Princess]]' |
| | } | | } |
| − | | + | |
| | if str ~= nil then | | if str ~= nil then |
| − | | + | |
| | local originalString = str | | local originalString = str |
| | str = string.lower(str) | | str = string.lower(str) |
| − | | + | |
| | for vesselName,wikicode in pairs(enemyShipTable) do | | for vesselName,wikicode in pairs(enemyShipTable) do |
| | str = str:gsub(vesselName,wikicode) | | str = str:gsub(vesselName,wikicode) |
| Line 620: |
Line 623: |
| | end | | end |
| | end | | end |
| − | | + | |
| | function p.test() | | function p.test() |
| | return p.encounterTemplate({ | | return p.encounterTemplate({ |
| Line 645: |
Line 648: |
| | }) | | }) |
| | end | | end |
| − | | + | |
| | function p.test2() | | function p.test2() |
| | return p.encounterTemplate({ | | return p.encounterTemplate({ |
| Line 667: |
Line 670: |
| | }) | | }) |
| | end | | end |
| − | | + | |
| | + | function p.test3() |
| | + | return p.encounterTemplate({ |
| | + | args = { |
| | + | ["Z1_label"] = "深海任務部隊 艦載機空襲", |
| | + | ["Z1-1_node_info"] = "1", |
| | + | ["Z1-1_form"] = "diamond", |
| | + | ["Z1-1_xp"] = "1", |
| | + | ["Z1-1_enemy_air_power"] = "151", |
| | + | ["Z1-2_node_info"] = "2", |
| | + | ["Z1-2_form"] = "diamond", |
| | + | ["Z1-2_xp"] = "1", |
| | + | ["Z1-2_enemy_air_power"] = "226", |
| | + | ["Z1-3_node_info"] = "3", |
| | + | ["Z1-3_form"] = "diamond", |
| | + | ["Z1-3_xp"] = "1", |
| | + | ["Z1-3_enemy_air_power"] = "123", |
| | + | "", |
| | + | ["final_form"] = "Z1-3", |
| | + | ["boss_node"] = "Z1", |
| | + | } |
| | + | }) |
| | + | end |
| | + | |
| | return p | | return p |