-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make it possible to construct ships by type
- Loading branch information
Showing
4 changed files
with
386 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:cli/cache/caches.dart'; | ||
import 'package:cli/cli.dart'; | ||
import 'package:cli/third_party/compare.dart'; | ||
|
||
bool _jsonCompare(Ship actual, Ship expected) { | ||
final diff = findDifferenceBetweenStrings( | ||
jsonEncode(actual.toJson()), | ||
jsonEncode(expected.toJson()), | ||
); | ||
if (diff != null) { | ||
logger.info('Ship differs from expected: ${diff.which}'); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/// Log a warning if the purchased ship does not match the expected template. | ||
// void verifyShipMatchesTemplate(Ship ship, ShipType shipType) { | ||
// final fromTemplate = makeShipForComparison( | ||
// type: shipType, | ||
// shipSymbol: ship.shipSymbol, | ||
// factionSymbol: ship.registration.factionSymbol, | ||
// origin: ship.nav.route.origin, | ||
// now: ship.nav.route.arrival, | ||
// ); | ||
// } | ||
|
||
Future<void> command(FileSystem fs, ArgResults argResults) async { | ||
final shipCache = ShipCache.loadCached(fs)!; | ||
final ships = shipCache.ships; | ||
for (final ship in ships) { | ||
final frameSymbol = ship.frame.symbol; | ||
final shipType = shipTypeFromFrame(frameSymbol); | ||
if (shipType == null) { | ||
logger.info('Unknown ship type for $frameSymbol'); | ||
continue; | ||
} | ||
final exampleShip = makeShipForComparison( | ||
type: shipType, | ||
shipSymbol: ship.shipSymbol, | ||
factionSymbol: FactionSymbols.fromJson(ship.registration.factionSymbol)!, | ||
nav: ship.nav, | ||
fuel: ship.fuel, | ||
cargo: ship.cargo, | ||
); | ||
if (exampleShip == null) { | ||
logger.info('Failed to make example ship for $shipType'); | ||
continue; | ||
} | ||
_jsonCompare(ship, exampleShip); | ||
} | ||
} | ||
|
||
void main(List<String> args) async { | ||
await runOffline(args, command); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.