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

Changes

Jump to navigation Jump to search
no edit summary
Line 1: Line 1: −
-- Example how to not write modules.
+
local U = require('Module:Core')
 
  −
local _ = require('Module:Core')
  −
local JSON = require('Module:Core/JSON')
   
local loadData = require('Module:Data').load
 
local loadData = require('Module:Data').load
 
+
local getArgs = require('Module:GetArgs')
 
local Ship = require('Module:Ship')
 
local Ship = require('Module:Ship')
 
local Equipment = require('Module:Equipment')
 
local Equipment = require('Module:Equipment')
local ShipBattleCardKai = require('Module:ShipBattleCardKai')
  −
local EquipmentCardKai = require('Module:EquipmentCardKai')
  −
local ShipsByApiId = require('Module:Collection/ShipsByApiId')
  −
local EquipmentByApiId = require('Module:Collection/EquipmentByApiId')
      
local function getShipCard(ship)
 
local function getShipCard(ship)
    local s = Ship(ship)
+
  local s = Ship(ship)
    local i = s:id() or s:true_id()
+
  local i = s:id() or s:true_id()
    local is = i and (i < 10 and '00' .. i or i < 100 and '0' .. i or i) or '?'
+
  local is = i and (i < 10 and '00' .. i or i < 100 and '0' .. i or i) or '?'
    return '[[File:KanMusu' .. is .. 'Banner.png|160px|link=' .. s:base_name() .. ']]<br>[[' .. s:base_name() .. '|' .. s:name() .. ']]'
+
  return '[[File:KanMusu' .. is .. 'Banner.png|160px|link=' .. s:base_name() .. ']]<br>[[' .. s:base_name() .. '|' .. s:name() .. ']]'
 
end
 
end
    
local function getEquipmentCard(eq)
 
local function getEquipmentCard(eq)
    return '[[File:Equipment' .. (Equipment(eq):id() or '?') .. '-1.png|100px|link=' .. eq .. ']]'
+
  return '[[File:Equipment' .. (Equipment(eq):id() or '?') .. '-1.png|100px|link=' .. eq .. ']]'
 
end
 
end
   −
local function fromModule(name)
+
local function getFleetName(fleet, event)
     local result = ''
+
  local names = require('Module:Fleet/Names')[event] or {}
 +
  if names[1] then
 +
    for _, f in ipairs(names) do
 +
      for i, ship in ipairs(f.ships) do
 +
        for j, e in ipairs(fleet) do
 +
          if f.flagship then
 +
            if i == 1 and j == 1 and string.sub(e.ship, 1, string.len(ship)) == ship then
 +
              return f.name
 +
            end
 +
          else
 +
            if string.sub(e.ship, 1, string.len(ship)) == ship then
 +
              return f.name
 +
            end
 +
          end
 +
        end
 +
      end
 +
     end
 +
  else
 +
    for name, ships in pairs(names) do
 +
      for _, ship in ipairs(ships) do
 +
        for _, e in ipairs(fleet) do
 +
          if string.sub(e.ship, 1, string.len(ship)) == ship then
 +
            return name
 +
          end
 +
        end
 +
      end
 +
    end
 +
  end
 +
  return 'Unassorted'
 +
end
   −
    return result
+
local function formatHp(hps, maxHp)
 +
  return string.format('<span class="explain" title="%s">~/%s</span>', U.ijoin(hps, ', '), maxHp)
 
end
 
end
   −
local tableHeaderFriend = [=[{|class="wikitable" style="text-align:center"
+
local tableStart =
 +
  [=[{|class="wikitable mw-collapsible mw-collapsed" style="text-align:center"
 +
!colspan="11"|%s
 +
|-
 
!Ship
 
!Ship
 
!Lv.
 
!Lv.
Line 39: Line 65:  
![[File:Icon Armor.png]]]=]
 
![[File:Icon Armor.png]]]=]
   −
local tableHeaderSimple = [=[{|class="wikitable" style="text-align:center"
+
local function render(args)
!Ship
+
  local data = loadData('Fleet/Friend', args.friend)
!colspan="4"|Equipment
+
  local groups = {}
]=]
+
  for _, e in pairs(data) do
 
+
    if not args.map or U.ifind(e.maps, args.map) then
local fleetNames = require('Module:Fleet/Names')
+
      local fleetType = getFleetName(e.fleet, args.friend)
+
      groups[fleetType] = groups[fleetType] or {}
local function getFleetName(fleet, event)
+
      table.insert(groups[fleetType], e)
    local names = fleetNames[event] or {}
+
    end
    if names[1] then
+
  end
        for _, f in ipairs(names) do
+
  local fleetTypes = U.isort(U.keys(groups))
            for i, ship in ipairs(f.ships) do
+
  local result = {}
                for j, e in ipairs(fleet) do
+
  table.insert(result, string.format(tableStart, U.ijoin(groups[fleetTypes[1]][1].notes, ', ')))
                    if f.flagship then
+
  for _, fleetType in ipairs(fleetTypes) do
                        if i == 1 and j == 1 and string.sub(e.ship, 1, string.len(ship)) == ship then
+
    local fleets = groups[fleetType]
                            return f.name
+
    table.sort(
                        end
+
      fleets,
                    else
+
      function(a, b)
                        if string.sub(e.ship, 1, string.len(ship)) == ship then
+
        local l1 = table.getn(a.fleet)
                            return f.name
+
        local l2 = table.getn(b.fleet)
                        end
+
        local ships1 =
                    end
+
          U.ijoin(
                end
+
          U.imap(
 +
            a.fleet,
 +
            function(e)
 +
              return e.ship
 
             end
 
             end
        end
+
          ),
    else
+
          ', '
         for name, ships in pairs(names) do
+
         )
            for _, ship in ipairs(ships) do
+
        local ships2 =
                for _, e in ipairs(fleet) do
+
          U.ijoin(
                    if string.sub(e.ship, 1, string.len(ship)) == ship then
+
          U.imap(
                        return name
+
            b.fleet,
                    end
+
            function(e)
                end
+
              return e.ship
 
             end
 
             end
 +
          ),
 +
          ', '
 +
        )
 +
        if ships1 == ships2 then
 +
          return l1 < l2
 
         end
 
         end
    end
+
        return ships1 < ships2
    return 'Unassorted'
+
      end
end
  −
 
  −
local function formatHp(hps, maxHp)
  −
    return string.format(
  −
        '<span class="explain" title="%s">~/%s</span>',
  −
        _.ijoin(hps, ', '),
  −
        maxHp
   
     )
 
     )
end
+
     for i, fleet in ipairs(fleets) do
 
+
      table.insert(result, string.format('|-\n!colspan="11"|%s', fleetType .. ' (Variant' .. i .. ')'))
local function renderFriend(args, frame)
+
      for _, ship in ipairs(fleet.fleet) do
    -- local data = loadData('Fleet/Friend/' .. args.friend)
+
        table.insert(
    local success, data = _.requireModule('Data/Fleet/Friend/' .. args.friend)
+
          result,
    if not success then
+
          string.format(
        return "''No data''"
+
            '|-\n|%s||%s||%s||%s||%s||%s||%s||%s||%s||%s||%s',
    end
+
            getShipCard(ship.ship),
    local groups = {}
+
            ship.level,
     for i, e in pairs(data) do
+
            ship.equipment[1] and getEquipmentCard(ship.equipment[1]) or 'style="background:grey;width:100px"| ',
        if not args.map or _.ifind(e.maps, args.map) then
+
            ship.equipment[2] and getEquipmentCard(ship.equipment[2]) or 'style="background:grey;width:100px"| ',
            local fleetType = getFleetName(e.fleet, args.friend)
+
            ship.equipment[3] and getEquipmentCard(ship.equipment[3]) or 'style="background:grey;width:100px"| ',
            groups[fleetType] = groups[fleetType] or {}
+
            ship.equipment[4] and getEquipmentCard(ship.equipment[4]) or 'style="background:grey;width:100px"| ',
            table.insert(groups[fleetType], e)
+
            type(ship.hp) == 'table' and formatHp(ship.hp, ship.maxHp) or ship.hp ~= ship.maxHp and string.format('%s/%s', ship.hp, ship.maxHp) or
        end
+
              ship.maxHp,
    end
+
            ship.firepower,
    local result = {}
+
            ship.torpedo,
    table.insert(result, '{{#tag:tabber|')
+
            ship.aa,
    for i, fleetType in ipairs(_.isort(_.keys(groups))) do
+
            ship.armor
        local fleets = groups[fleetType]
+
          )
        table.sort(fleets, function(a, b)
+
         )
            local l1 = table.getn(a.fleet)
+
      end
            local l2 = table.getn(b.fleet)
  −
            local ships1 = _.ijoin(_.imap(a.fleet, function (e) return e.ship end), ', ')
  −
            local ships2 = _.ijoin(_.imap(b.fleet, function (e) return e.ship end), ', ')
  −
            if ships1 == ships2 then
  −
                return l1 < l2
  −
            end
  −
            return ships1 < ships2
  −
        end)
  −
        table.insert(result, string.format('{{!}}-{{!}} %s =', fleetType))
  −
        table.insert(result, '<tabber>')
  −
        for i, fleet in ipairs(fleets) do
  −
            table.insert(result, string.format('|-| %s =', 'Variant ' .. i))
  −
            if table.getn(fleet.notes) > 0 then
  −
                table.insert(result, _.ijoin(fleet.notes, '<br>'))
  −
            end               
  −
            table.insert(result, tableHeaderFriend)
  −
            for j, ship in ipairs(fleet.fleet) do
  −
                table.insert(result, string.format(
  −
                    '|-\n|%s||%s||%s||%s||%s||%s||%s||%s||%s||%s||%s',
  −
                    getShipCard(ship.ship),
  −
                    ship.level,
  −
                    ship.equipment[1] and getEquipmentCard(ship.equipment[1]) or 'style="background:grey;width:100px"| ',
  −
                    ship.equipment[2] and getEquipmentCard(ship.equipment[2]) or 'style="background:grey;width:100px"| ',
  −
                    ship.equipment[3] and getEquipmentCard(ship.equipment[3]) or 'style="background:grey;width:100px"| ',
  −
                    ship.equipment[4] and getEquipmentCard(ship.equipment[4]) or 'style="background:grey;width:100px"| ',
  −
                    type(ship.hp) == 'table' and formatHp(ship.hp, ship.maxHp) or ship.hp ~= ship.maxHp and string.format('%s/%s', ship.hp, ship.maxHp) or ship.maxHp,
  −
                    ship.firepower,
  −
                    ship.torpedo,
  −
                    ship.aa,
  −
                    ship.armor
  −
                ))
  −
            end
  −
            table.insert(result, '|}')
  −
        end
  −
        table.insert(result, '</tabber>')
  −
    end
  −
    table.insert(result, '}}')
  −
    return table.concat(result, '\n')
  −
end
  −
 
  −
local function render(args, frame)
  −
    if args.friend then
  −
        return renderFriend(args, frame)
  −
    end
  −
    local result = {}
  −
    local firstCell = true
  −
    local openTab = false
  −
    local openSubtab = false
  −
    for _, arg in ipairs(args) do
  −
        if arg:sub(0, 2) == '!!' then
  −
            if openSubtab then
  −
                table.insert(result, string.format('|}\n|-| %s =\n' .. tableHeaderSimple, arg:sub(3)))
  −
            else
  −
                table.insert(result, string.format('<tabber>\n|-| %s =\n' .. tableHeaderSimple, arg:sub(3)))
  −
                openSubtab = true
  −
            end
  −
         elseif arg:sub(0, 1) == '!' then
  −
            if openSubtab then
  −
                table.insert(result, '|}\n</tabber>')
  −
                openSubtab = false
  −
            end
  −
            if openTab then
  −
                table.insert(result, string.format('{{!}}-{{!}} %s =', arg:sub(2)))
  −
            else
  −
                table.insert(result, string.format('{{#tag:tabber|\n{{!}}-{{!}} %s =', arg:sub(2)))
  −
                openTab = true
  −
            end
  −
        elseif arg:sub(0, 1) == '~' then
  −
            table.insert(result, fromModule(arg:sub(2)))
  −
        elseif arg == '-' then
  −
            table.insert(result, '|-')
  −
            firstCell = true
  −
        else
  −
            if firstCell then
  −
                table.insert(result, '|' .. getShipCard(arg))
  −
                firstCell = false
  −
            else
  −
                table.insert(result, '|' .. getEquipmentCard(arg))
  −
            end
  −
        end
   
     end
 
     end
    if openSubtab then
+
  end
        table.insert(result, '|}\n</tabber>')
+
  table.insert(result, '|}')
        openSubtab = false
+
  return table.concat(result, '\n')
    end
  −
    if openTab then
  −
        table.insert(result, '}}')
  −
        openTab = false
  −
    end
  −
    return table.concat(result, '\n')
   
end
 
end
  −
local getArgs = require('Module:GetArgs')
      
return {
 
return {
    render = function(frame)
+
  render = function(frame)
    return frame:preprocess(render(getArgs{ frame = frame:getParent() }))
+
    return frame:preprocess(render(getArgs {frame = frame:getParent()}))
    end,
+
  end
    test1 = render({
  −
        '!1 DD',
  −
        '!!Example 1',
  −
        '-', '1', 'Type 3 Active Sonar',
  −
        '!!Example 2',
  −
        '-', 'Yuudachi/Kai Ni', '282', '282',
  −
        '!2 DD',
  −
        '!!Example 1',
  −
        '-', 'Yuudachi/Kai Ni', 'Type 3 Active Sonar',
  −
        '-', 'Shigure/Kai Ni', 'Type 3 Active Sonar',
  −
        '!!Example 2',
  −
        '-', 'Yuudachi/Kai Ni', 'Type 3 Active Sonar', 'Type 3 Active Sonar',
  −
        '-', 'Shigure/Kai Ni', 'Type 3 Active Sonar', 'Type 3 Active Sonar',
  −
    }),
  −
    test2 = render({
  −
        friend = 'Early Fall 2018 Event',
  −
    }),
  −
    test3 = render({
  −
        friend = 'Early Fall 2018 Event',
  −
        map = 'E-5',
  −
    }),
   
}
 
}
  −
-- print(p.test1)
  −
-- print(p.test2)
  −
-- print(p.test3)
 
cssedit, gkautomate
7,064

edits

Navigation menu