mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Update detailed export to SLEF
This commit is contained in:
@@ -7,7 +7,6 @@ import ActiveLink from './ActiveLink';
|
||||
import cn from 'classnames';
|
||||
import { Cogs, CoriolisLogo, Hammer, Help, Rocket, StatsBars } from './SvgIcons';
|
||||
import Persist from '../stores/Persist';
|
||||
import { toDetailedExport } from '../shipyard/Serializer';
|
||||
import ModalDeleteAll from './ModalDeleteAll';
|
||||
import ModalExport from './ModalExport';
|
||||
import ModalHelp from './ModalHelp';
|
||||
@@ -16,7 +15,8 @@ import Slider from './Slider';
|
||||
import Announcement from './Announcement';
|
||||
import { outfitURL } from '../utils/UrlGenerators';
|
||||
import autoBind from 'auto-bind';
|
||||
import { Factory } from 'ed-forge';
|
||||
import { Factory, Ship } from 'ed-forge';
|
||||
import { chain, entries } from 'lodash';
|
||||
|
||||
const SIZE_MIN = 0.65;
|
||||
const SIZE_RANGE = 0.55;
|
||||
@@ -208,20 +208,6 @@ export default class Header extends TranslatedComponent {
|
||||
this.context.showModal(<ModalDeleteAll />);
|
||||
};
|
||||
|
||||
/**
|
||||
* Show export modal with backup data
|
||||
* @param {SyntheticEvent} e Event
|
||||
*/
|
||||
_showBackup(e) {
|
||||
let translate = this.context.language.translate;
|
||||
e.preventDefault();
|
||||
this.context.showModal(<ModalExport
|
||||
title={translate('backup')}
|
||||
description={translate('PHRASE_BACKUP_DESC')}
|
||||
data={Persist.getAll()}
|
||||
/>);
|
||||
};
|
||||
|
||||
/**
|
||||
* Show export modal with detailed export
|
||||
* @param {SyntheticEvent} e Event
|
||||
@@ -230,10 +216,22 @@ export default class Header extends TranslatedComponent {
|
||||
let translate = this.context.language.translate;
|
||||
e.preventDefault();
|
||||
|
||||
const builds = chain(Persist.getBuilds())
|
||||
.values()
|
||||
.map((builds) => Object.values(builds))
|
||||
.flatMap()
|
||||
.map((code) => new Ship(code))
|
||||
.value();
|
||||
|
||||
this.context.showModal(<ModalExport
|
||||
title={translate('detailed export')}
|
||||
description={translate('PHRASE_EXPORT_DESC')}
|
||||
data={toDetailedExport(Persist.getBuilds())}
|
||||
data={JSON.stringify(builds.map((build) => {
|
||||
return {
|
||||
header: { appName: 'Inara', 'appVersion': '1.0' },
|
||||
data: build.toJSON(),
|
||||
};
|
||||
}))}
|
||||
/>);
|
||||
}
|
||||
|
||||
@@ -432,10 +430,9 @@ export default class Header extends TranslatedComponent {
|
||||
<hr />
|
||||
<ul style={{ width: '100%' }}>
|
||||
{translate('builds')} & {translate('comparisons')}
|
||||
<li><Link href="#" className='block' onClick={this._showBackup.bind(this)}>{translate('backup')}</Link></li>
|
||||
<li><Link href="#" className='block' onClick={this._showDetailedExport.bind(this)}>{translate('detailed export')}</Link></li>
|
||||
<li><Link href="#" className='block' onClick={this._showImport.bind(this)}>{translate('import')}</Link></li>
|
||||
<li><Link href="#" className='block' onClick={this._showDeleteAll.bind(this)}>{translate('delete all')}</Link></li>
|
||||
<li><Link href="#" className='block' onClick={this._showDetailedExport}>{translate('detailed export')}</Link></li>
|
||||
<li><Link href="#" className='block' onClick={this._showImport}>{translate('import')}</Link></li>
|
||||
<li><Link href="#" className='block' onClick={this._showDeleteAll}>{translate('delete all')}</Link></li>
|
||||
</ul>
|
||||
<hr />
|
||||
<table style={{ width: 300, backgroundColor: 'transparent' }}>
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
import { ModuleGroupToName, MountMap, BulkheadNames } from './Constants';
|
||||
import * as Utils from '../utils/UtilityFunctions';
|
||||
import LZString from 'lz-string';
|
||||
import { outfitURL } from '../utils/UrlGenerators';
|
||||
|
||||
/**
|
||||
* Generates ship-loadout JSON Schema standard object
|
||||
* @param {Object} standard model
|
||||
* @return {Object} JSON Schema
|
||||
*/
|
||||
function standardToSchema(standard) {
|
||||
if (standard.m) {
|
||||
let o = {
|
||||
class: standard.m.class,
|
||||
rating: standard.m.rating,
|
||||
enabled: Boolean(standard.enabled),
|
||||
priority: standard.priority + 1
|
||||
};
|
||||
|
||||
if (standard.m.name) {
|
||||
o.name = standard.m.name;
|
||||
}
|
||||
|
||||
if (standard.m.mods && Object.keys(standard.m.mods).length > 0) {
|
||||
o.modifications = standard.m.mods;
|
||||
}
|
||||
|
||||
if (standard.m.blueprint && Object.keys(standard.m.blueprint).length > 0) {
|
||||
o.blueprint = standard.m.blueprint;
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates ship-loadout JSON Schema slot object
|
||||
* @param {Object} slot Slot model
|
||||
* @return {Object} JSON Schema Slot
|
||||
*/
|
||||
function slotToSchema(slot) {
|
||||
if (slot.m) {
|
||||
let o = {
|
||||
class: slot.m.class,
|
||||
rating: slot.m.rating,
|
||||
enabled: Boolean(slot.enabled),
|
||||
priority: slot.priority + 1,
|
||||
group: ModuleGroupToName[slot.m.grp]
|
||||
};
|
||||
|
||||
if (slot.m.name) {
|
||||
o.name = slot.m.name;
|
||||
}
|
||||
if (slot.m.mount) {
|
||||
o.mount = MountMap[slot.m.mount];
|
||||
}
|
||||
if (slot.m.missile) {
|
||||
o.missile = slot.m.missile;
|
||||
}
|
||||
if (slot.m.mods && Object.keys(slot.m.mods).length > 0) {
|
||||
o.modifications = slot.m.mods;
|
||||
}
|
||||
if (slot.m.blueprint && Object.keys(slot.m.blueprint).length > 0) {
|
||||
o.blueprint = slot.m.blueprint;
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes a comparion and all of the ships to zipped
|
||||
* Base 64 encoded JSON.
|
||||
* @param {string} name Comparison name
|
||||
* @param {array} builds Array of ship builds
|
||||
* @param {array} facets Selected facets
|
||||
* @param {string} predicate sort predicate
|
||||
* @param {boolean} desc sort order
|
||||
* @return {string} Zipped Base 64 encoded JSON
|
||||
*/
|
||||
export function fromComparison(name, builds, facets, predicate, desc) {
|
||||
return LZString.compressToBase64(JSON.stringify({
|
||||
n: name,
|
||||
b: builds.map((b) => { return { s: b.id, n: b.buildName, c: b.toString() }; }),
|
||||
f: facets,
|
||||
p: predicate,
|
||||
d: desc ? 1 : 0
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses the comarison data string back to an object.
|
||||
* @param {string} code Zipped Base 64 encoded JSON comparison data
|
||||
* @return {Object} Comparison data object
|
||||
*/
|
||||
export function toComparison(code) {
|
||||
return JSON.parse(LZString.decompressFromBase64(Utils.fromUrlSafe(code)));
|
||||
};
|
||||
Reference in New Issue
Block a user