From 6a917556d0e6ed65934c13f74ad2705cd57a0825 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Sun, 30 Aug 2015 04:56:48 +0100 Subject: [PATCH] Include module status and priority in Coriolis outfitting. --- coriolis.py | 26 ++++++++++++++------------ outfitting.py | 6 +++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/coriolis.py b/coriolis.py index 2bf3961d..691ef88e 100644 --- a/coriolis.py +++ b/coriolis.py @@ -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: diff --git a/outfitting.py b/outfitting.py index caee04bd..ded9e49e 100755 --- a/outfitting.py +++ b/outfitting.py @@ -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))