• 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 34: Line 34:  
function numberKey(name, context, n, default)
 
function numberKey(name, context, n, default)
 
     return context and tonumber(context[name .. (n and tostring(n) or '')]) or default
 
     return context and tonumber(context[name .. (n and tostring(n) or '')]) or default
 +
end
 +
 +
local function prefixEach(n)
 +
    return function(i)
 +
        return (i - 1) % n == 0 and string.format('!%d-%d', i, i + n)
 +
    end
 +
end
 +
 +
-- * Ship iterators.
 +
 +
function Iterator.shipsByNo(context, n)
 +
    local collection = require('Module:Collection/ShipsByNo' .. (n == 2 and 2 or 1))
 +
    local i = 0
 +
    local current
 +
    local prefixFlag = true
 +
    return {
 +
        next = function()
 +
            i = i + 1
 +
            local e = collection[i]
 +
            if e then
 +
                local prefixValue = prefixEach(10)(i)
 +
                if prefixFlag and prefixValue then
 +
                    i = i - 1
 +
                    current = prefixValue
 +
                    prefixFlag = false
 +
                else
 +
                    current = e._name
 +
                    prefixFlag = true
 +
                end
 +
                return true
 +
            end
 +
            return false
 +
        end,
 +
        current = function()
 +
            return current
 +
        end,
 +
    }
 
end
 
end
  
cssedit, gkautomate
6,928

edits

Navigation menu