| Line 631: |
Line 631: |
| | function EquipmentData:gun_fit_group() | | function EquipmentData:gun_fit_group() |
| | return self._gun_fit_group | | return self._gun_fit_group |
| | + | end |
| | + | |
| | + | function EquipmentData:_load_compatibility() |
| | + | if not EquipmentCompatibility then |
| | + | EquipmentCompatibility = mw.loadData('Module:Data/EquipmentRefit') |
| | + | end |
| | + | end |
| | + | |
| | + | local function convert_compatibility(compatibility_table, equipment_type, name) |
| | + | local value = compatibility_table[name] or compatibility_table[equipment_type] |
| | + | return value == true and 1 or type(value) == 'string' and {value = 2, note = value, code = value} or 0 |
| | end | | end |
| | | | |
| | function EquipmentData:equippable(ship_type) | | function EquipmentData:equippable(ship_type) |
| | self:_load_compatibility() | | self:_load_compatibility() |
| − | local equipment_type = self:type()
| |
| − | local name = self:name()
| |
| | if not ship_type then | | if not ship_type then |
| | local result = {} | | local result = {} |
| | for ship_type, compatibility_table in pairs(EquipmentCompatibility) do | | for ship_type, compatibility_table in pairs(EquipmentCompatibility) do |
| − | result[ship_type] = compatibility_table[name] or compatibility_table[equipment_type] or 0 | + | result[ship_type] = convert_compatibility(compatibility_table, self:type(), self:name()) |
| | end | | end |
| | return result | | return result |
| | + | end |
| | + | local compatibility_table = EquipmentCompatibility[ship_type] |
| | + | if not compatibility_table then |
| | + | return nil |
| | + | end |
| | + | local compatibility = convert_compatibility(compatibility_table, self:type(), self:name()) |
| | + | if type(compatibility) ~= "table" then |
| | + | return compatibility |
| | else | | else |
| − | local compatibility_table = EquipmentCompatibility[ship_type] | + | return compatibility.value, compatibility.note |
| − | if compatibility_table then
| |
| − | local compatibility = compatibility_table[name] or compatibility_table[equipment_type] or 0
| |
| − | if type(compatibility) ~= "table" then
| |
| − | return compatibility
| |
| − | else
| |
| − | return compatibility.value, compatibility.note
| |
| − | end
| |
| − | end
| |
| − | end
| |
| − | end
| |
| − | | |
| − | function EquipmentData:_load_compatibility()
| |
| − | if not EquipmentCompatibility then
| |
| − | EquipmentCompatibility = mw.loadData('Module:EquipmentCompatibility')
| |
| | end | | end |
| | end | | end |