1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 15:57:14 +03:00

Include module status and priority in Coriolis outfitting.

This commit is contained in:
Jonathan Harris 2015-08-30 04:56:48 +01:00
parent 6a32b5affc
commit 6a917556d0
2 changed files with 19 additions and 13 deletions

View File

@ -12,6 +12,15 @@ import outfitting
import companion
slot_map = {
'HugeHardpoint' : 'hardpoints',
'LargeHardpoint' : 'hardpoints',
'MediumHardpoint' : 'hardpoints',
'SmallHardpoint' : 'hardpoints',
'TinyHardpoint' : 'utility',
'Slot' : 'internal',
}
# Map draft EDDN outfitting to Coriolis
# https://raw.githubusercontent.com/jamesremuscat/EDDN/master/schemas/outfitting-v1.0-draft.json
# http://cdn.coriolis.io/schemas/ship-loadout/1.json
@ -26,15 +35,6 @@ category_map = {
'utility' : 'utility',
}
slot_map = {
'HugeHardpoint' : 'hardpoints',
'LargeHardpoint' : 'hardpoints',
'MediumHardpoint' : 'hardpoints',
'SmallHardpoint' : 'hardpoints',
'TinyHardpoint' : 'utility',
'Slot' : 'internal',
}
standard_map = OrderedDict([ # in output order
('Armour', 'bulkheads'),
('Power Plant', 'powerPlant'),
@ -80,7 +80,7 @@ def export(data):
ship = companion.ship_map.get(data['ship']['name'], data['ship']['name'])
loadout = OrderedDict([ # Mimic Coriolis export ordering
('$schema', 'http://cdn.coriolis.io/schemas/ship-loadout/1.json#'),
('$schema', 'http://cdn.coriolis.io/schemas/ship-loadout/2.json#'),
('name', ship_map.get(data['ship']['name'], data['ship']['name'])),
('ship', ship_map.get(data['ship']['name'], data['ship']['name'])),
('components', OrderedDict([
@ -110,8 +110,10 @@ def export(data):
category = loadout['components'][category_map[module['category']]]
thing = OrderedDict([
('class', module['class']),
('rating', module['rating']),
('class', module['class']),
('rating', module['rating']),
('enabled', module['enabled']),
('priority', module['priority']+1), # make 1-based
])
if module['name'] in bulkheads:

View File

@ -211,7 +211,7 @@ internal_map = {
# Given a module description from the Companion API returns a description of the module in the form of a
# dict { category, name, [mount], [guidance], [ship], rating, class } using the same terms found in the
# English langauge game.
# English langauge game. For fitted modules, dict also includes { enabled, priority }.
# Or returns None if the module is user-specific (i.e. decal, paintjob).
# (Given the ad-hocery in this implementation a big lookup table might have been simpler and clearer).
def lookup(module):
@ -314,6 +314,10 @@ def lookup(module):
new['class'] = name[2][4:]
new['rating'] = rating_map[name[3][5:]]
# Disposition of fitted modules
if 'on' in module and 'priority' in module:
new['enabled'], new['priority'] = module['on'], module['priority'] # priority is zero-based
# check we've filled out mandatory fields
for thing in ['category', 'name', 'class', 'rating']:
if not new.get('name'): raise AssertionError('%s: failed to set %s' % (module['id'], thing))