Line 1: |
Line 1: |
| local U = require('Module:Core') | | local U = require('Module:Core') |
| + | |
| + | local ShipList = {} |
| + | |
| + | function ShipList.findID(frame) |
| + | for id, data in pairs(ShipList.KanmusuData) do |
| + | if ShipList.KanmusuData[id].name[3] == frame.args[1] then |
| + | return id |
| + | end |
| + | end |
| + | return "NotInDB" |
| + | end |
| + | |
| + | function ShipList.getSortedIDList() |
| + | local IDList = {} |
| + | for id, data in pairs(ShipList.KanmusuData) do |
| + | IDList[#IDList + 1] = id |
| + | local x = #IDList |
| + | while x > 1 and IDList[x] < IDList[x - 1] do |
| + | IDList[x - 1], IDList[x] = IDList[x], IDList[x - 1] |
| + | x = x - 1 |
| + | end |
| + | end |
| + | return IDList |
| + | end |
| + | |
| + | function ShipList.TotalAircraft(frame) |
| + | local shipID = frame.args[1] |
| + | -- if tonumber(shipID) == nil then |
| + | -- shipID = ShipList.findID(frame) |
| + | -- end |
| + | local ship = ShipList.KanmusuData[shipID] |
| + | local total = 0 |
| + | if ship.aircraft ~= "" then |
| + | for i, planes in pairs(ship.aircraft) do |
| + | if ship.aircraft[i] == nil or ship.aircraft[i] == "" then |
| + | total = total + 0 |
| + | else |
| + | total = total + ship.aircraft[i] |
| + | end |
| + | end |
| + | end |
| + | return total |
| + | end |
| + | |
| + | function ShipList.getWikiPage(id) |
| + | --finding name of wiki page of ship |
| + | shipname = ShipList.KanmusuData[id]["name"][3] |
| + | pagename = shipname |
| + | if string.sub(id,1,-2) == "Mist" then -- fleet of fog check |
| + | if string.sub(id, -1) == '1' then |
| + | pagename = 'Iona_(fog)' |
| + | elseif string.sub(id, -1) == '2' then |
| + | pagename = 'Takao_(fog)' |
| + | elseif string.sub(id, -1) == '3' then |
| + | pagename = 'Haruna_(fog)' |
| + | else |
| + | pagename = 'Fleet of Fog' |
| + | end |
| + | else |
| + | shipbasename = mw.text.split(shipname, '%s')[1] |
| + | --Prinz/Graf/Teste check (for ship names that are 2 or more words) |
| + | if mw.text.split(shipname, '%s')[2] ~= nil and not (mw.text.split(shipname, '%s')[2] == "Kai" or |
| + | mw.text.split(shipname, '%s')[2] == "A" or mw.text.split(shipname, '%s')[2] == "Zwei" or |
| + | mw.text.split(shipname, '%s')[2] == "Drei" or mw.text.split(shipname, '%s')[2] == "Due") then |
| + | shipbasename = shipbasename .. ' ' .. mw.text.split(shipname, '%s')[2] |
| + | end |
| + | pagename = shipbasename |
| + | end |
| + | return pagename |
| + | end |
| + | |
| + | ShipList.KanmusuData = mw.loadData('Module:Data/Ship') |
| + | |
| + | local shipdb = ShipList |
| | | |
| local shipmodule = {} | | local shipmodule = {} |
− | local shipdb = require("Module:ShipDatabase")
| + | |
| shipmodule.data = shipdb.KanmusuData | | shipmodule.data = shipdb.KanmusuData |
| | | |