1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 08:40:34 +03:00

Merge branch 'master' of github.com:Marginal/EDMarketConnector

This commit is contained in:
Jonathan Harris 2015-09-02 16:32:06 +01:00
commit 0505db63c9
2 changed files with 30 additions and 15 deletions

View File

@ -12,9 +12,18 @@ import outfitting
import companion
# Map draft EDDN outfitting to Coriolis
slot_map = {
'HugeHardpoint' : 'hardpoints',
'LargeHardpoint' : 'hardpoints',
'MediumHardpoint' : 'hardpoints',
'SmallHardpoint' : 'hardpoints',
'TinyHardpoint' : 'utility',
'Slot' : 'internal',
}
# Map draft E:D Shipyard & 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
# http://cdn.coriolis.io/schemas/ship-loadout/2.json
ship_map = dict(companion.ship_map)
ship_map['Asp'] = 'Asp Explorer'
@ -26,17 +35,9 @@ 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'),
(None, 'cargoHatch'), # not available in the Companion API data
('Power Plant', 'powerPlant'),
('Thrusters', 'thrusters'),
('Frame Shift Drive', 'frameShiftDrive'),
@ -80,7 +81,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([
@ -90,6 +91,7 @@ def export(data):
('internal', []),
])),
])
maxpri = 0
# Correct module ordering relies on the fact that "Slots" in the data are correctly ordered alphabetically.
# Correct hardpoint ordering additionally relies on the fact that "Huge" < "Large" < "Medium" < "Small"
@ -110,9 +112,12 @@ 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
])
maxpri = max(maxpri, thing['priority'])
if module['name'] in bulkheads:
# Bulkheads are just strings
@ -147,6 +152,12 @@ def export(data):
except:
if __debug__: raise
# Cargo Hatch status is not available in the data - fake something up
loadout['components']['standard']['cargoHatch'] = OrderedDict([
('enabled', True),
('priority', maxpri),
])
# Construct description
string = json.dumps(loadout, indent=2)

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))