Line 1: |
Line 1: |
| -- Example how to not write modules. | | -- Example how to not write modules. |
| | | |
− | local _ = require('Module:Core') | + | local U = require('Module:Core') |
| local JSON = require('Module:Core/JSON') | | local JSON = require('Module:Core/JSON') |
| local loadData = require('Module:Data').load | | local loadData = require('Module:Data').load |
− | | + | local getArgs = require('Module:GetArgs') |
| local ShipBattleCardKai = require('Module:ShipBattleCardKai') | | local ShipBattleCardKai = require('Module:ShipBattleCardKai') |
| local EquipmentCardKai = require('Module:EquipmentCardKai') | | local EquipmentCardKai = require('Module:EquipmentCardKai') |
Line 47: |
Line 47: |
| ]=] | | ]=] |
| | | |
− | -- [[Category:Todo]]: need something better here
| + | local function getFleetName(fleet, event) |
− | local friendTypes = require('Module:Fleet/Names') | + | local names = require('Module:Fleet/Names')[event] or {} |
− | | |
− | local function getFleetType(fleet, event)
| |
− | local names = friendTypes[event] or {}
| |
| if names[1] then | | if names[1] then |
− | for i, o in ipairs(names) do | + | for _, f in ipairs(names) do |
− | for i, ship in ipairs(o.ships) do | + | for _, ship in ipairs(f.ships) do |
− | if _.ifindBy(fleet, function (e) return _.startsWith(e.ship, ship) end) then | + | if U.ifindBy(fleet, function (e) return U.startsWith(e.ship, ship) end) then |
− | return o.name | + | return f.name |
| end | | end |
| end | | end |
Line 62: |
Line 59: |
| else | | else |
| for name, ships in pairs(names) do | | for name, ships in pairs(names) do |
− | for i, ship in ipairs(ships) do | + | for _, ship in ipairs(ships) do |
− | if _.ifindBy(fleet, function (e) return _.startsWith(e.ship, ship) end) then | + | if U.ifindBy(fleet, function (e) return U.startsWith(e.ship, ship) end) then |
| return name | | return name |
| end | | end |
Line 75: |
Line 72: |
| return string.format( | | return string.format( |
| '<span class="explain" title="%s">~/%s</span>', | | '<span class="explain" title="%s">~/%s</span>', |
− | _.ijoin(hps, ', '), | + | U.ijoin(hps, ', '), |
| maxHp | | maxHp |
| ) | | ) |
Line 82: |
Line 79: |
| local function renderFriend(args, frame) | | local function renderFriend(args, frame) |
| -- local data = loadData('Fleet/Friend/' .. args.friend) | | -- local data = loadData('Fleet/Friend/' .. args.friend) |
− | local success, data = _.requireModule('Data/Fleet/Friend/' .. args.friend) | + | local success, data = U.requireModule('Data/Fleet/Friend/' .. args.friend) |
| if not success then | | if not success then |
| return "''No data''" | | return "''No data''" |
Line 88: |
Line 85: |
| local groups = {} | | local groups = {} |
| for i, e in pairs(data) do | | for i, e in pairs(data) do |
− | if not args.map or _.ifind(e.maps, args.map) then | + | if not args.map or U.ifind(e.maps, args.map) then |
− | local fleetType = getFleetType(e.fleet, args.friend) | + | local fleetType = getFleetName(e.fleet, args.friend) |
| groups[fleetType] = groups[fleetType] or {} | | groups[fleetType] = groups[fleetType] or {} |
| table.insert(groups[fleetType], e) | | table.insert(groups[fleetType], e) |
Line 96: |
Line 93: |
| local result = {} | | local result = {} |
| table.insert(result, '{{#tag:tabber|') | | table.insert(result, '{{#tag:tabber|') |
− | for i, fleetType in ipairs(_.isort(_.keys(groups))) do | + | for i, fleetType in ipairs(U.isort(U.keys(groups))) do |
| local fleets = groups[fleetType] | | local fleets = groups[fleetType] |
| table.sort(fleets, function(a, b) | | table.sort(fleets, function(a, b) |
| local l1 = table.getn(a.fleet) | | local l1 = table.getn(a.fleet) |
| local l2 = table.getn(b.fleet) | | local l2 = table.getn(b.fleet) |
− | local ships1 = _.ijoin(_.imap(a.fleet, function (e) return e.ship end), ', ') | + | local ships1 = U.ijoin(U.imap(a.fleet, function (e) return e.ship end), ', ') |
− | local ships2 = _.ijoin(_.imap(b.fleet, function (e) return e.ship end), ', ') | + | local ships2 = U.ijoin(U.imap(b.fleet, function (e) return e.ship end), ', ') |
| if ships1 == ships2 then | | if ships1 == ships2 then |
| return l1 < l2 | | return l1 < l2 |
Line 113: |
Line 110: |
| table.insert(result, string.format('|-| %s =', 'Variant ' .. i)) | | table.insert(result, string.format('|-| %s =', 'Variant ' .. i)) |
| if table.getn(fleet.notes) > 0 then | | if table.getn(fleet.notes) > 0 then |
− | table.insert(result, _.ijoin(fleet.notes, '<br>')) | + | table.insert(result, U.ijoin(fleet.notes, '<br>')) |
| end | | end |
| table.insert(result, tableHeaderFriend) | | table.insert(result, tableHeaderFriend) |
Line 191: |
Line 188: |
| return table.concat(result, '\n') | | return table.concat(result, '\n') |
| end | | end |
− |
| |
− | local getArgs = require('Module:GetArgs')
| |
| | | |
| return { | | return { |