• 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:  
local U = require("Module:Core")
 
local U = require("Module:Core")
local Formatting = require("Module:Formatting")
+
--local Formatting = require("Module:Formatting")
local Equipment = require("Module:Equipment")
+
--local Equipment = require("Module:Equipment")
local Iterator = require("Module:Iterator")
+
--local Iterator = require("Module:Iterator")
local ShipIterator = require("Module:ShipIterator")
+
--local ShipCapabilities = require("Module:ShipCapabilities")
local ShipCapabilities = require("Module:ShipCapabilities")
+
--local ShipCardKai = require("Module:ShipCardKai")
local ShipCardKai = require("Module:ShipCardKai")
+
--local ShipBattleCardKai = require("Module:ShipBattleCardKai")
local ShipBattleCardKai = require("Module:ShipBattleCardKai")
+
--local Combat = require("Module:CalcCombat")
local Combat = require("Module:CalcCombat")
+
--local EquipmentCardKai = require("Module:EquipmentCardKai")
local EquipmentCardKai = require("Module:EquipmentCardKai")
+
--local EquipmentGraphicKai = require("Module:EquipmentGraphicKai")
local EquipmentGraphicKai = require("Module:EquipmentGraphicKai")
+
--local EquipmentCollection = require("Module:Collection/Equipment")
local EquipmentCollection = require("Module:Collection/Equipment")
+
--local AllEquipmentCollection = require("Module:Collection/EquipmentByApiId")
local AllEquipmentCollection = require("Module:Collection/EquipmentByApiId")
+
--local Development = require("Module:Development")
local Development = require("Module:Development")
+
--local ShipsByApiId = require("Module:Collection/ShipsByApiId")
local ShipsByApiId = require("Module:Collection/ShipsByApiId")
+
local Ship = require("Module:Ship")
    
local args = nil
 
local args = nil
local Ship = nil
+
-- local Ship = nil
 
local ship = nil
 
local ship = nil
 
local shipCapabilities = {}
 
local shipCapabilities = {}
 
local target = nil
 
local target = nil
 
local equipment = nil
 
local equipment = nil
local filterArg = {}
+
local filterArgs = {}
 
local sorted = false
 
local sorted = false
 
local sequence = nil
 
local sequence = nil
Line 27: Line 27:  
local sequence_position = nil
 
local sequence_position = nil
 
local env = {}
 
local env = {}
local implicitTrigger = true
      
local enumerating_functions = {
 
local enumerating_functions = {
 
     args = function() return mw.text.split(args.args, "%s*,%s*") end,
 
     args = function() return mw.text.split(args.args, "%s*,%s*") end,
     base_names = function() return ShipIterator.baseForms end,
+
     base_names = function() return require('Module:Collection/ShipsBase') end,
     all_names = function() return ShipIterator.allForms end,
+
     all_names = function() return require('Module:Collection/Ships') end,
     enemy = function() return ShipIterator.enemyForms end,
+
     enemy = function() return require('Module:Collection/EnemyShips') end,
 
     equipment = function() return U.imap(EquipmentCollection, function(e) return e._name end) end,
 
     equipment = function() return U.imap(EquipmentCollection, function(e) return e._name end) end,
 
     allEquipment = function()
 
     allEquipment = function()
Line 116: Line 115:  
     end,
 
     end,
 
     icon_damaged = function(obj) return string.format("[[File:Ship Icon %s Damaged.png|100px]]", obj:name()) end,
 
     icon_damaged = function(obj) return string.format("[[File:Ship Icon %s Damaged.png|100px]]", obj:name()) end,
 +
    link = function(obj) return string.format("[[%s]]", obj:name()) end,
 +
    --[[
 
     link = function(obj)
 
     link = function(obj)
 
         if obj._dummy then
 
         if obj._dummy then
Line 127: Line 128:  
         end
 
         end
 
     end,
 
     end,
 +
    ]]--
 
     class = function(ship) return ship:class() and ship:class():name() or "?" end,
 
     class = function(ship) return ship:class() and ship:class():name() or "?" end,
 
     implementation_date = function(ship)
 
     implementation_date = function(ship)
Line 193: Line 195:  
}
 
}
    +
--[[
 
local function addFormattingFunctions(name, table)
 
local function addFormattingFunctions(name, table)
 
     for k, v in pairs(table) do
 
     for k, v in pairs(table) do
Line 201: Line 204:  
addFormattingFunctions("FitData", require("Module:CalcFit"))
 
addFormattingFunctions("FitData", require("Module:CalcFit"))
 
addFormattingFunctions("Assets", require("Module:CalcAsset"))
 
addFormattingFunctions("Assets", require("Module:CalcAsset"))
 +
]]--
    
local function format_value(key, ship, target)
 
local function format_value(key, ship, target)
Line 207: Line 211:  
         return formatting_function(ship, target)
 
         return formatting_function(ship, target)
 
     end
 
     end
 +
    --[[
 
     if shipCapabilities[key] then
 
     if shipCapabilities[key] then
 
         local a, b = shipCapabilities[key](shipCapabilities)
 
         local a, b = shipCapabilities[key](shipCapabilities)
 
         return format_lua(b or a)
 
         return format_lua(b or a)
 
     end
 
     end
     if ship then
+
     ]]--
        local lua = ship[key]
+
    local lua = ship[key]
        if type(lua) == "function" then
+
    if type(lua) == "function" then
            return format_lua(lua(ship))
+
        return format_lua(lua(ship))
        else
+
    else
            return format_lua(lua)
+
        return format_lua(lua)
        end
   
     end
 
     end
 
end
 
end
Line 225: Line 229:  
end
 
end
    +
--[[
 
local function interpret_setter(s)
 
local function interpret_setter(s)
 
     local kv = mw.text.split(s, "%s*~%s*")
 
     local kv = mw.text.split(s, "%s*~%s*")
Line 268: Line 273:  
end
 
end
   −
local function trigger(implicit)
+
local function trigger()
implicitTrigger = implicit
   
     local ship_key = sequence[sequence_position]
 
     local ship_key = sequence[sequence_position]
    ship_key = tonumber(ship_key) or ship_key
   
     sequence_position = sequence_position + 1
 
     sequence_position = sequence_position + 1
 
     ship = Ship(ship_key)
 
     ship = Ship(ship_key)
Line 286: Line 289:  
     local prefix = string.sub(arg, 1, 1)
 
     local prefix = string.sub(arg, 1, 1)
 
     local prefix2 = string.sub(arg, 1, 2)
 
     local prefix2 = string.sub(arg, 1, 2)
     if arg == "_" then
+
     if arg == "-" then return format_arg("")
        return false
+
elseif arg == "!@" then trigger(false)
    elseif arg == "-" then
  −
        return format_arg("")
  −
    elseif prefix == "~" then
  −
    table.insert(filterArg, string.sub(arg, 2))
  −
    elseif prefix == "@" then
  −
        local enumerator = string.sub(arg, 2)
  −
        local enumerating_function = enumerating_functions[enumerator]
  −
        if enumerating_function and not sequence then
  −
            sequence = enumerating_function()
  −
            sequence_position = 1
  −
            sequence_length = #sequence
  −
        elseif not sequence then
  −
            local buildIterator = Iterator[enumerator]
  −
            if buildIterator then
  −
                sequence = {}
  −
                sequence_position = 1
  −
                local iterator = buildIterator(args)
  −
                while iterator.next() do
  −
                    table.insert(sequence, iterator.current())
  −
                end
  −
                sequence_length = #sequence
  −
            end
  −
        end
  −
        if args.sort and sequence and not sorted then
  −
        sorted = true
  −
        local sorts = mw.text.split(args.sort, "%s*,%s*")
  −
        table.sort(sequence, function(a, b)
  −
        local a = Ship(a)
  −
        local b = Ship(b)
  −
        for _, sort in ipairs(sorts) do
  −
      local x = a[sort](a)
  −
      local y = b[sort](b)
  −
      if x < y then return true end
  −
      if x > y then return false end
  −
        end
  −
return false
  −
end)
  −
        end
  −
    elseif arg == "!@" then
  −
trigger(false)
   
     elseif prefix2 == "!!" then
 
     elseif prefix2 == "!!" then
 
         local key = string.sub(arg, 3)
 
         local key = string.sub(arg, 3)
Line 355: Line 318:  
     elseif prefix == "#" and args.format == "table" then
 
     elseif prefix == "#" and args.format == "table" then
 
         return "|-\n"
 
         return "|-\n"
     elseif prefix == "?" then
+
     if prefix == "?" then
    if implicitTrigger and sequence then
  −
    trigger(true)
  −
    end
   
         local prefix2 = string.sub(arg, 1, 2)
 
         local prefix2 = string.sub(arg, 1, 2)
         if prefix2 == "??" then
+
         if prefix2 == "??" then return format_arg(format_value(string.sub(arg, 3), target, ship))
            return format_arg(format_value(string.sub(arg, 3), target, ship))
+
         elseif prefix2 == "?#" then return "?# is unimplemented" -- frame:preprocess(format{string.sub(arg, 3), this = env[this] or ""})
         elseif prefix2 == "?#" then
  −
            return "?# is unimplemented" -- frame:preprocess(format{string.sub(arg, 3), this = env[this] or ""})
   
         else
 
         else
        if #filterArg > 0 then
+
if test then
        local test = true
+
return format_arg(format_value(string.sub(arg, 2), ship, target))
        for _, e in ipairs(filterArg) do
+
else
        local kv = mw.text.split(e, "%s*~%s*")
+
return nil
        local xs = mw.text.split(kv[2], "%s*,%s*")
+
end
        local test2 = false
  −
        for _, e2 in ipairs(xs) do
  −
if tostring(ship[kv[1]](ship)) == e2 then
  −
        test2 = true
  −
        break
  −
        end
  −
        end
  −
        if not test2 then
  −
        test = false
  −
        break
  −
        end
  −
        end
  −
        if test then
  −
        return format_arg(format_value(string.sub(arg, 2), ship, target))
  −
        else
  −
        return nil
  −
        end
  −
        else
  −
            return format_arg(format_value(string.sub(arg, 2), ship, target))
  −
            end
  −
        end
   
     else
 
     else
 
         return format_arg(arg)
 
         return format_arg(arg)
Line 396: Line 333:  
end
 
end
   −
local function interpret_args(args_)
  −
args = args_
   
     Ship = args.enemy and require("Module:EnemyShip") or require("Module:Ship")
 
     Ship = args.enemy and require("Module:EnemyShip") or require("Module:Ship")
 
     if args.from and args.to then
 
     if args.from and args.to then
Line 406: Line 341:  
         sequence_position = 1
 
         sequence_position = 1
 
     end
 
     end
     local i = 1
+
 
 +
        else
 +
            local buildIterator = Iterator[enumerator]
 +
            if buildIterator then
 +
                sequence = {}
 +
                sequence_position = 1
 +
                local iterator = buildIterator(args)
 +
                while iterator.next() do
 +
                    table.insert(sequence, iterator.current())
 +
                end
 +
                sequence_length = #sequence
 +
            end
 +
 
 +
]]--
 +
 
 +
local function interpret(args_)
 +
args = args_
 +
     for _, arg in ipairs(args) do
 +
    local prefix = string.sub(arg, 1, 1)
 +
    if prefix == "~" then
 +
    local kv = mw.text.split(string.sub(arg, 2), "%s*~%s*")
 +
    table.insert(filterArgs, kv)
 +
    end
 +
    end
 +
    local actions = {}
 +
    for _, arg in ipairs(args) do
 +
    local prefix = string.sub(arg, 1, 1)
 +
    if prefix == "@" then
 +
    local enumerator = string.sub(arg, 2)
 +
        local enumerating_function = enumerating_functions[enumerator]
 +
        if enumerating_function then
 +
        sequence = {}
 +
        for _, e in ipairs(enumerating_function()) do
 +
        local ship = Ship(e)
 +
        if #filterArgs > 0 then
 +
    local test = true
 +
for _, kv in ipairs(filterArgs) do
 +
--local xs = mw.text.split(kv[2], "%s*,%s*")
 +
--local test2 = false
 +
--for _, e2 in ipairs(xs) do
 +
if tostring(ship[kv[1]](ship)) ~= kv[2] then
 +
--test2 = true
 +
--break
 +
--end
 +
--end
 +
--if not test2 then
 +
test = false
 +
break
 +
end
 +
end
 +
if test then
 +
table.insert(sequence, ship)
 +
end
 +
        else
 +
        table.insert(sequence, ship)
 +
        end
 +
        end
 +
        sequence_position = 1
 +
sequence_length = #sequence
 +
        end
 +
    elseif prefix == "?" then
 +
    table.insert(actions, string.sub(arg, 2))
 +
    end
 +
    end
 +
    if args.sort and sequence then
 +
    local sorts = mw.text.split(args.sort, "%s*,%s*")
 +
    table.sort(sequence, function(a, b)
 +
    for _, sort in ipairs(sorts) do
 +
  local x = a[sort](a)
 +
  local y = b[sort](b)
 +
  if x < y then return true end
 +
  if x > y then return false end
 +
    end
 +
return false
 +
end)
 +
    end
 
     local values = {}
 
     local values = {}
 
     repeat
 
     repeat
         for _, arg in ipairs(args) do
+
    if sequence then
             local value = interpret_arg(arg)
+
    ship = sequence[sequence_position]
 +
    sequence_position = sequence_position + 1
 +
    end
 +
         for _, arg in ipairs(actions) do
 +
             local value = format_arg(format_value(arg, ship)) -- interpret_arg(arg)
 
             if value then
 
             if value then
 
                 table.insert(values, value)
 
                 table.insert(values, value)
 
             end
 
             end
            i = i + 1
   
         end
 
         end
 
     until not sequence_length or sequence_position > sequence_length
 
     until not sequence_length or sequence_position > sequence_length
Line 420: Line 433:  
end
 
end
   −
return { format = function(frame) return interpret_args(U.getTemplateArgs(frame).explicit) end }
+
return {
 +
format = function(frame) return interpret(U.getTemplateArgs(frame).explicit) end,
 +
test = function() mw.log(interpret({"@base_names", "~is_battleship~true", "?link", sort = "type,id"})) end,
 +
}
cssedit, gkautomate
6,926

edits

Navigation menu