Skip to content

Commit

Permalink
Make a copy of the ship in list_nearby_sells_for
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Oct 6, 2023
1 parent e64232b commit bff025c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/cli/bin/list_nearby_sells_for.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import 'package:cli/printing.dart';
import 'package:cli/trading.dart';
import 'package:types/types.dart';

extension on Ship {
/// Returns a copy of this ship with the same properties.
Ship deepCopy() => Ship.fromJson(toJson())!;
}

Future<void> command(FileSystem fs, ArgResults argResults) async {
final marketPrices = MarketPrices.load(fs);
final systemsCache = SystemsCache.loadCached(fs)!;
Expand All @@ -20,9 +25,8 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
.firstWhere((w) => w.isAsteroidField)
.waypointSymbol;

final ship = shipCache.ships.firstWhere((s) => s.isMiner);

// This hack is OK so long as we don't write the ShipCache to disk.
final miner = shipCache.ships.firstWhere((s) => s.isMiner);
final ship = miner.deepCopy();
ship.nav.waypointSymbol = hqMine.waypoint;
ship.nav.systemSymbol = hqMine.system;
logger.info('Finding markets which buy $tradeSymbol near $hqMine.');
Expand Down

0 comments on commit bff025c

Please sign in to comment.