Line 4: |
Line 4: |
| local Ship = require("Module:Ship") | | local Ship = require("Module:Ship") |
| local ShipIterator = require("Module:ShipIterator") | | local ShipIterator = require("Module:ShipIterator") |
| + | local ShipCapabilities = require("Module:ShipCapabilities") |
| | | |
| local args = nil | | local args = nil |
| local ship = nil | | local ship = nil |
| + | local shipCapabilities = nil |
| local frame = nil | | local frame = nil |
| | | |
Line 76: |
Line 78: |
| return formatting_function(ship) | | return formatting_function(ship) |
| else | | else |
− | local lua = ship[key] | + | if shipCapabilities[key] then |
− | if type(lua) == "function" then
| + | local a, b = shipCapabilities[key](shipCapabilities) |
− | return format_lua(lua(ship)) | + | return format_lua(b or a) |
| else | | else |
− | return format_lua(lua) | + | local lua = ship[key] |
| + | if type(lua) == "function" then |
| + | return format_lua(lua(ship)) |
| + | else |
| + | return format_lua(lua) |
| + | end |
| end | | end |
| end | | end |
Line 101: |
Line 108: |
| sequence_position = sequence_position + 1 | | sequence_position = sequence_position + 1 |
| ship = Ship(ship_key) | | ship = Ship(ship_key) |
| + | shipCapabilities = ShipCapabilities{ ship = ship } |
| elseif prefix == "!" then | | elseif prefix == "!" then |
| local ship_key = string.sub(arg, 2) | | local ship_key = string.sub(arg, 2) |
− | ship = Ship(ship_key) | + | if string.sub(ship_key, 1, 3) == "eq:" and ship then |
| + | local eqs = string.sub(ship_key, 4) |
| + | local equipment = {} |
| + | for eq in string.gmatch(eqs, '([^,]+)') do |
| + | table.insert(equipment, { equipment = eq }) |
| + | end |
| + | ship._equipment = equipment |
| + | else |
| + | local parts = string.gmatch(ship_key, '([^:]+)') |
| + | local i = 1 |
| + | for part in parts do |
| + | if i == 1 then |
| + | ship_key = part |
| + | ship = Ship(ship_key) |
| + | shipCapabilities = ShipCapabilities{ ship = ship } |
| + | elseif i == 2 then |
| + | local equipment = {} |
| + | for eq in string.gmatch(part, '([^,]+)') do |
| + | table.insert(equipment, { equipment = eq }) |
| + | end |
| + | ship._equipment = equipment |
| + | end |
| + | i = i + 1 |
| + | end |
| + | end |
| elseif prefix == "#" and args.format == "table" then | | elseif prefix == "#" and args.format == "table" then |
| return "|-\n" | | return "|-\n" |
Line 172: |
Line 204: |
| | | |
| function Calc.test() | | function Calc.test() |
− | | + | mw.log( |
| + | Calc.format(nil, { |
| + | "!Nagato/Kai Ni: Prototype 41cm Triple Gun Mount, Prototype 41cm Triple Gun Mount", |
| + | "?day_battle" |
| + | }) |
| + | ) |
| end | | end |
| | | |
| return Calc | | return Calc |