Changes

another item attempt. doesn't work. revert if needed.
Line 9: Line 9:  
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 ItemCollection = require('Module:Collection/Items')
 +
-- 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")
Line 21: Line 22:  
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 51: Line 51:  
     return U.imap(EquipmentCollection, function(e) return e._name end)
 
     return U.imap(EquipmentCollection, function(e) return e._name end)
 
     end,
 
     end,
 +
    item = function()
 +
    item = true
 +
    return U.imap(ItemCollection, function(e) return e._name end)
 +
    end,
 +
    --[[
 
     allEquipment = function()
 
     allEquipment = function()
 
     equipment = true
 
     equipment = true
Line 71: Line 76:  
         return result
 
         return result
 
     end,
 
     end,
 +
    ]]--
 
}
 
}
   Line 121: Line 127:  
     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 130: Line 137:  
             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,
Line 148: Line 156:  
     card = function(obj)
 
     card = function(obj)
 
     if not obj or not obj.lua_name then
 
     if not obj or not obj.lua_name then
     return ' '
+
     if equipment then --attempted to stop equipment from being filtered out, as equip cards weren't showing up. Don't know if this only works for equip and if I broke the original funtion's intention. This may not work at filtering out errors -chocolatecravinghobo
 +
    else
 +
    return ' '
 +
    end
 
     end
 
     end
 
         if obj.hp then
 
         if obj.hp then
Line 185: Line 196:  
         end
 
         end
 
     end,
 
     end,
     scrap = function(eq)
+
     scrap_string = function(eq)
 
         local scrap = eq:scrap()
 
         local scrap = eq:scrap()
 
         return string.format("%s/%s/%s/%s", scrap.fuel or 0, scrap.ammo or 0, scrap.steel or 0, scrap.bauxite or 0)
 
         return string.format("%s/%s/%s/%s", scrap.fuel or 0, scrap.ammo or 0, scrap.steel or 0, scrap.bauxite or 0)
Line 192: Line 203:  
     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 198: Line 209:  
     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 213: Line 239:     
local function format_value(key, ship, target)
 
local function format_value(key, ship, target)
    local formatting_function = formatting_functions[key]
+
local keys = mw.text.split(key, "%s*%.%s*")
    if formatting_function then
+
local result = ship
        return formatting_function(ship, target)
+
for _, key in ipairs(keys) do
    end
+
    local formatting_function = formatting_functions[key]
    --[[
+
    if formatting_function then
    if shipCapabilities[key] then
+
        result = formatting_function(result, target)
        local a, b = shipCapabilities[key](shipCapabilities)
+
    else
        return format_lua(b or a)
+
    local lua = result[key] or result['_' .. key]
    end
+
    if type(lua) == "function" then
    ]]--
+
        result = lua(result)
    local lua = ship[key]
+
    else
    if type(lua) == "function" then
+
        result = lua
        return format_lua(lua(ship))
+
    end
    else
+
    end
        return format_lua(lua)
+
if type(result) ~= 'table' then
    end
+
return format_lua(result)
 +
end
 +
    --[[
 +
    if shipCapabilities[key] then
 +
        local a, b = shipCapabilities[key](shipCapabilities)
 +
        return format_lua(b or a)
 +
    end
 +
    ]]--
 +
end
 +
return format_lua(result)
 
end
 
end
   Line 364: Line 399:  
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
     local xs = mw.text.split(kv[2], "%s*,%s*")
+
    -- obj.x.y.z can be obj:x():y():z(), etc.
     table.insert(filterArgs, {kv[1], xs})
+
     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 382: Line 421:  
        for _, e in ipairs(enumerating_function()) do
 
        for _, e in ipairs(enumerating_function()) do
 
        local ship
 
        local ship
        if equipment then
+
        if equipment or item then
 
        ship = Equipment(e)
 
        ship = Equipment(e)
 
        else
 
        else
Line 389: Line 428:  
        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 test2 = false
 
local test2 = false
for _, e2 in ipairs(kv[2]) do
+
 
if tostring(ship[kv[1]](ship)) == e2 then
+
local obj = ship
 +
for _, k in ipairs(ksvs[1]) do
 +
local g = obj[k]
 +
if type(g) == 'function' then
 +
obj = g(obj)
 +
if type(obj) == 'nil' then
 +
obj = '??'
 +
break
 +
end
 +
elseif type(g) == 'table' 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
 
test2 = true
 
break
 
break
 
end
 
end
 
end
 
end
 +
 
if not test2 then
 
if not test2 then
 
test = false
 
test = false
Line 412: Line 471:  
sequence_length = #sequence
 
sequence_length = #sequence
 
        end
 
        end
 +
    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
 
    elseif arg == "#" or prefix == "?" then
 
    table.insert(actions, string.sub(arg, 2))
 
    table.insert(actions, string.sub(arg, 2))
Line 422: Line 492:  
   local x = a[sort](a)
 
   local x = a[sort](a)
 
   local y = b[sort](b)
 
   local y = b[sort](b)
 +
  if x == nil then return true end
 +
  if y == nil then return false end
 
   if x < y then return true end
 
   if x < y then return true end
 
   if x > y then return false end
 
   if x > y then return false end
Line 450: Line 522:  
end
 
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"}))
 +
mw.log(interpret({"!Ayanami", "?scrap_string", "?scrap.fuel", "?scrap_fuel", "?_scrap_fuel"}))
 +
mw.log(interpret({'@all_names', '~class.name~Akizuki Class', '?api_id', '?banner', '?link', '?japanese_name', '?code_link', '?class_number', '?firepower_max', '?torpedo_max', '?night_battle_power', '?aa_max', '?asw_max', '?los_max', '?luck', '?hp', '?armor_max', '?evasion_max', '?slots', '?fuel', '?ammo', sort = 'class_number,rarity,api_id'}))
 +
end
 +
 +
-- print(p.test())
 
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,
 
}
 
}
advmod, cssedit, Interface administrators, janitor, Moderators, prechecked, Widget editors
7,932

edits