Changes

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 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:Data/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 Ship = require("Module:Ship")
   Line 21: Line 21:  
local target = nil
 
local target = nil
 
local equipment = nil
 
local equipment = nil
local filterArgs = {}
  −
local sorted = false
   
local sequence = nil
 
local sequence = nil
 
local sequence_length = nil
 
local sequence_length = nil
 
local sequence_position = nil
 
local sequence_position = nil
local env = {}
+
-- local sorted = false
 +
-- local env = {}
    
local enumerating_functions = {
 
local enumerating_functions = {
Line 32: Line 31:  
     base_names = function() return require('Module:Collection/ShipsBase') end,
 
     base_names = function() return require('Module:Collection/ShipsBase') end,
 
     all_names = function() return require('Module:Collection/Ships') end,
 
     all_names = function() return require('Module:Collection/Ships') end,
 +
    remodel_names = function()
 +
    local all_names = require('Module:Collection/Ships')
 +
    local base_names = require('Module:Collection/ShipsBase')
 +
    local result = {}
 +
    for _, name in ipairs(all_names) do
 +
    if not U.includes(base_names, name) then
 +
    local ship = Ship(name)
 +
    if ship._implementation_date then
 +
    table.insert(result, name)
 +
    end
 +
    end
 +
    end
 +
    return result
 +
    end,
 
     enemy = function() return require('Module:Collection/EnemyShips') end,
 
     enemy = function() return require('Module:Collection/EnemyShips') end,
     equipment = function() return U.imap(EquipmentCollection, function(e) return e._name end) end,
+
     equipment = function()
 +
    equipment = true
 +
    return U.imap(EquipmentCollection, function(e) return e._name end)
 +
    end,
 +
    --[[
 
     allEquipment = function()
 
     allEquipment = function()
 +
    equipment = true
 
         local result = {}
 
         local result = {}
 
         for i = 1, 700 do
 
         for i = 1, 700 do
Line 44: Line 62:  
     end,
 
     end,
 
     enemyEquipment = function()
 
     enemyEquipment = function()
 +
    equipment = true
 
         local result = {}
 
         local result = {}
 
         for i = 501, 700 do
 
         for i = 501, 700 do
Line 52: Line 71:  
         return result
 
         return result
 
     end,
 
     end,
 +
    ]]--
 
}
 
}
   Line 102: Line 122:  
     end,
 
     end,
 
     code = function(obj) return equipment and Formatting:format_equipment_type(obj:type()) or Formatting:format_ship_code(obj:type()) end,
 
     code = function(obj) return equipment and Formatting:format_equipment_type(obj:type()) or Formatting:format_ship_code(obj:type()) end,
 +
    code_link = function(obj) return string.format("[[%s]]", Formatting:format_ship_code(obj:type())) end,
 
     type = function(obj) return equipment and Formatting:format_equipment_type(obj:type()) or Formatting:format_ship_type(obj:type()) end,
 
     type = function(obj) return equipment and Formatting:format_equipment_type(obj:type()) or Formatting:format_ship_type(obj:type()) end,
 
     icon = function(obj)
 
     icon = function(obj)
Line 111: Line 132:  
             end
 
             end
 
         else
 
         else
             return obj.icon and ([[<span data-sort-value="]] .. (obj._type or '0') .. [=[">[[File:]=] .. Formatting:format_equipment_icon(obj:icon()) .. "]]</span>") or ''
+
        return obj.icon and ([=[[[File:]=] .. Formatting:format_equipment_icon(obj:icon()) .. "]]") or ''
 +
             -- return obj.icon and ([[<span data-sort-value="]] .. (obj._type or '0') .. [=[">[[File:]=] .. Formatting:format_equipment_icon(obj:icon()) .. "]]</span>") or ''
 
         end
 
         end
 
     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) return string.format("[[%s]]", equipment and obj:name() or obj:unique_name()) end,
    --[[
  −
    link = function(obj)
  −
        if obj._dummy then
  −
            local link = ShipsByApiId[obj._api_id]
  −
            if link then
  −
                link = link:gsub('/', ' ')
  −
            end
  −
            return link and Formatting:format_link(link) or ''
  −
        else
  −
            return Formatting:format_link(obj:link())
  −
        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 186: Line 195:  
     development_rate = function(eq) return Development.formatRates(eq) end,
 
     development_rate = function(eq) return Development.formatRates(eq) end,
 
     development_hq = function(eq) return Development.formatHQ(eq) end,
 
     development_hq = function(eq) return Development.formatHQ(eq) end,
     backMinusRarity = function(ship) return ship:back() - ship:rarity() end,
+
     backMinusRarity = function(ship) return (ship:back() or 0) - (ship:rarity() or 0) end,
 
     rarity_bg = function(ship)
 
     rarity_bg = function(ship)
 
         return string.format('style="background:%s"|%s<br>%s', Formatting:format_ship_back(ship:rarity()), ship:rarity() or '??', Formatting:format_ship_rarity(ship:rarity()))
 
         return string.format('style="background:%s"|%s<br>%s', Formatting:format_ship_back(ship:rarity()), ship:rarity() or '??', Formatting:format_ship_rarity(ship:rarity()))
Line 192: Line 201:  
     back_bg = function(ship)
 
     back_bg = function(ship)
 
         return string.format('style="background:%s"|%s<br>%s', Formatting:format_ship_back(ship:back()), ship:back() or '??', Formatting:format_ship_rarity(ship:back()))
 
         return string.format('style="background:%s"|%s<br>%s', Formatting:format_ship_back(ship:back()), ship:back() or '??', Formatting:format_ship_rarity(ship:back()))
 +
    end,
 +
    same_day_remodel_links = function(ship)
 +
    local result = { string.format("[[%s]]", ship:name()) }
 +
    local visited = {}
 +
visited[ship:name()] = true
 +
    while true do
 +
    local next = ship:remodel_to()
 +
    if not next then break end
 +
    ship = Ship(next)
 +
    if ship._implementation_date then break end
 +
    if visited[ship:name()] then break end
 +
    visited[ship:name()] = true
 +
    table.insert(result, string.format("[[%s]]", ship:name()))
 +
    end
 +
    return table.concat(result, ", ")
 
     end,
 
     end,
 
}
 
}
Line 358: Line 382:  
local function interpret(args_)
 
local function interpret(args_)
 
args = args_
 
args = args_
 +
local filterArgs = {}
 
     for _, arg in ipairs(args) do
 
     for _, arg in ipairs(args) do
 
     local prefix = string.sub(arg, 1, 1)
 
     local prefix = string.sub(arg, 1, 1)
 
     if prefix == "~" then
 
     if prefix == "~" then
     local kv = mw.text.split(string.sub(arg, 2), "%s*~%s*")
+
    -- ~x.y.z~a.b.c means obj.x.y.z == a or obj.x.y.z == b or obj.x.y.z == c
     table.insert(filterArgs, kv)
+
    -- obj.x.y.z can be obj:x():y():z(), etc.
 +
     local ksvs = mw.text.split(string.sub(arg, 2), "%s*~%s*")
 +
    local ks = mw.text.split(ksvs[1], "%s*%.%s*")
 +
    local vs = mw.text.split(ksvs[2], "%s*,%s*")
 +
     table.insert(filterArgs, {ks, vs})
 
     end
 
     end
 
     end
 
     end
Line 374: Line 403:  
        sequence = {}
 
        sequence = {}
 
        for _, e in ipairs(enumerating_function()) do
 
        for _, e in ipairs(enumerating_function()) do
        local ship = Ship(e)
+
        local ship
 +
        if equipment then
 +
        ship = Equipment(e)
 +
        else
 +
        ship = Ship(e)
 +
        end
 
        if #filterArgs > 0 then
 
        if #filterArgs > 0 then
 
    local test = true
 
    local test = true
for _, kv in ipairs(filterArgs) do
+
for _, ksvs in ipairs(filterArgs) do
--local xs = mw.text.split(kv[2], "%s*,%s*")
+
local test2 = false
--local test2 = false
+
 
--for _, e2 in ipairs(xs) do
+
local obj = ship
if tostring(ship[kv[1]](ship)) ~= kv[2] then
+
for _, k in ipairs(ksvs[1]) do
--test2 = true
+
local g = obj[k]
--break
+
if type(g) == 'function' then
--end
+
obj = g(obj)
--end
+
elseif type(g) == 'table' then
--if not test2 then
+
obj = g
 +
else
 +
obj = g
 +
break
 +
end
 +
end
 +
local v1 = tostring(obj)
 +
 
 +
for _, v2 in ipairs(ksvs[2]) do
 +
if v1 == v2 then
 +
test2 = true
 +
break
 +
end
 +
end
 +
 
 +
if not test2 then
 
test = false
 
test = false
 
break
 
break
Line 401: Line 450:  
sequence_length = #sequence
 
sequence_length = #sequence
 
        end
 
        end
    elseif prefix == "?" then
+
    elseif prefix == '!' then
 +
    local name = string.sub(arg, 2)
 +
    local obj = Ship(name)
 +
    if not obj:hp() then
 +
    equipment = true
 +
    obj = Equipment(name)
 +
    end
 +
    sequence = {}
 +
    table.insert(sequence, obj)
 +
        sequence_position = 1
 +
sequence_length = 1
 +
    elseif arg == "#" or prefix == "?" then
 
    table.insert(actions, string.sub(arg, 2))
 
    table.insert(actions, string.sub(arg, 2))
 
    end
 
    end
Line 424: Line 484:  
     end
 
     end
 
         for _, arg in ipairs(actions) do
 
         for _, arg in ipairs(actions) do
            local value = format_arg(format_value(arg, ship)) -- interpret_arg(arg)
+
        if arg == '' then
            if value then
+
        if args.format == "table" then
                table.insert(values, value)
+
        table.insert(values, "|-\n")
 +
        end
 +
        else
 +
            local value = ship and format_arg(format_value(arg, ship)) -- interpret_arg(arg)
 +
            if value then
 +
                table.insert(values, value)
 +
            end
 
             end
 
             end
 
         end
 
         end
 
     until not sequence_length or sequence_position > sequence_length
 
     until not sequence_length or sequence_position > sequence_length
 
     return table.concat(values, args.concat or (args.format == "table" and "" or ", "))
 
     return table.concat(values, args.concat or (args.format == "table" and "" or ", "))
 +
end
 +
 +
local function test()
 +
mw.log(interpret({"@base_names", "~is_battleship~true", "?link", sort = "type,id"}))
 +
mw.log(interpret({"@base_names", "~class.name~Kagerou Class", "?link", sort = "type,id"}))
 +
mw.log(interpret({"!Saiun", "?icon"}))
 
end
 
end
    
return {
 
return {
 
format = function(frame) return interpret(U.getTemplateArgs(frame).explicit) end,
 
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,
+
test = test,
 
}
 
}
cssedit, gkautomate
6,926

edits