Line 1: |
Line 1: |
− | local U = require("Module:Utils") | + | local U = require("Module:Core") |
| local BaseData = require('Module:BaseData') | | local BaseData = require('Module:BaseData') |
| | | |
Line 56: |
Line 56: |
| | | |
| function Ship:get_table(name, model) | | function Ship:get_table(name, model) |
− | local success, ship_table = U.requireModule(name) | + | local success, ship_table = Ship.requireModule(name, self._enemy) |
− | if not success then
| |
− | success, ship_table = U.requireModule('Data/Ship/' .. name)
| |
− | end
| |
| local ship_form_table | | local ship_form_table |
| if success then | | if success then |
Line 78: |
Line 75: |
| end | | end |
| end | | end |
| + | local id = tonumber(name) |
| if not ship_form_table then | | if not ship_form_table then |
− | ship_form_table = { _name = name, _suffix = model } | + | ship_form_table = { |
| + | _name = not id and name or nil, |
| + | _suffix = not id and model or nil, |
| + | _api_id = id or nil, |
| + | _dummy = true |
| + | } |
| end | | end |
| if ship_form_table._name == nil then | | if ship_form_table._name == nil then |
Line 88: |
Line 91: |
| end | | end |
| ship_form_table._key = model | | ship_form_table._key = model |
| + | if not id and name:sub(1, 5) == 'Vita:' then |
| + | ship_form_table._vita = true |
| + | end |
| return ship_form_table | | return ship_form_table |
| end | | end |
| | | |
| function Ship:process_ship_key(ship_key) | | function Ship:process_ship_key(ship_key) |
− | local split = mw.ustring.find(ship_key, '/') | + | local split = string.find(ship_key, '/') |
| local ship_base_name, ship_suffix | | local ship_base_name, ship_suffix |
| if split == nil then | | if split == nil then |
| ship_base_name = ship_key | | ship_base_name = ship_key |
| else | | else |
− | ship_base_name = split - 1 > 0 and mw.ustring.sub(ship_key, 1, split - 1) or '' | + | ship_base_name = split - 1 > 0 and string.sub(ship_key, 1, split - 1) or '' |
− | ship_suffix = mw.ustring.sub(ship_key, split + 1, -1) | + | ship_suffix = string.sub(ship_key, split + 1, -1) |
| end | | end |
| return ship_base_name, ship_suffix | | return ship_base_name, ship_suffix |
| end | | end |
| | | |
− | function Ship:get_module(name) | + | function Ship:get_module(name, isEnemy) |
− | if name == nil then | + | if not name then |
| return nil | | return nil |
− | else
| |
− | name = self:process_ship_key(name)
| |
| end | | end |
− | return mw.ustring.format('Module:%s', name) | + | name = self:process_ship_key(name) |
| + | return string.format('Module:Data/%s/%s', isEnemy and 'Enemy' or 'Ship', name) |
| + | end |
| + | |
| + | function Ship.requireModule(name, is_enemy) |
| + | local success, ship_table |
| + | if not is_enemy then |
| + | success, ship_table = U.requireModule('Data/Ship/' .. name) |
| + | end |
| + | if not success then |
| + | success, ship_table = U.requireModule('Data/Enemy/' .. name) |
| + | end |
| + | return success, ship_table |
| end | | end |
| | | |