From 424304d9a875438883debbe533e8dd4488cda574 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Mon, 3 Aug 2015 17:24:18 +0300 Subject: [PATCH] add fields to profile --- client/src/main/java/ru/trader/Main.java | 2 +- client/src/main/java/ru/trader/Settings.java | 4 +- .../src/main/java/ru/trader/core/Profile.java | 76 ++++++++++++++++--- 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/client/src/main/java/ru/trader/Main.java b/client/src/main/java/ru/trader/Main.java index c4e944c..807b3c5 100644 --- a/client/src/main/java/ru/trader/Main.java +++ b/client/src/main/java/ru/trader/Main.java @@ -28,7 +28,7 @@ public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception { SETTINGS = new Settings(new File("profile.properties")); - SETTINGS.load(); + SETTINGS.load(World.getMarket()); Locale locale = SETTINGS.getLocale(); if (locale != null){ Localization.setLocale(locale); diff --git a/client/src/main/java/ru/trader/Settings.java b/client/src/main/java/ru/trader/Settings.java index 479aab1..f67acf2 100644 --- a/client/src/main/java/ru/trader/Settings.java +++ b/client/src/main/java/ru/trader/Settings.java @@ -26,7 +26,7 @@ public class Settings { profile = new Profile(new Ship()); } - public void load() { + public void load(Market market) { try (InputStream is = new FileInputStream(file)) { values.load(is); } catch (FileNotFoundException e) { @@ -34,7 +34,7 @@ public class Settings { } catch (IOException e) { LOG.error("Error on load settings", e); } - profile = Profile.readFrom(values); + profile = Profile.readFrom(values, market); } public void save(){ diff --git a/core/src/main/java/ru/trader/core/Profile.java b/core/src/main/java/ru/trader/core/Profile.java index 00ff47c..78ec64e 100644 --- a/core/src/main/java/ru/trader/core/Profile.java +++ b/core/src/main/java/ru/trader/core/Profile.java @@ -5,10 +5,14 @@ import java.util.Properties; public class Profile { public static enum PATH_PRIORITY {FAST, ECO} + private String name; private double balance; + private Place system; + private Vendor station; + private Ship ship; + private boolean docked; private int jumps; private int lands; - private Ship ship; private boolean refill; private int routesCount; //Scorer multipliers @@ -35,6 +39,14 @@ public class Profile { pathPriority = PATH_PRIORITY.FAST; } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public double getBalance() { return balance; } @@ -43,6 +55,38 @@ public class Profile { this.balance = balance; } + public Place getSystem() { + return system; + } + + public void setSystem(Place system) { + this.system = system; + } + + public Vendor getStation() { + return station; + } + + public void setStation(Vendor station) { + this.station = station; + } + + public Ship getShip() { + return ship; + } + + public void setShip(Ship ship) { + this.ship = ship; + } + + public boolean isDocked() { + return docked; + } + + public void setDocked(boolean docked) { + this.docked = docked; + } + public int getJumps() { return jumps; } @@ -59,14 +103,6 @@ public class Profile { this.lands = lands; } - public Ship getShip() { - return ship; - } - - public void setShip(Ship ship) { - this.ship = ship; - } - public boolean withRefill() { return refill; } @@ -139,10 +175,26 @@ public class Profile { this.pathPriority = pathPriority; } - public static Profile readFrom(Properties values){ + public static Profile readFrom(Properties values, Market market){ Ship ship = Ship.readFrom(values); Profile profile = new Profile(ship); + profile.setName(values.getProperty("profile.name","Cmdr NoName")); profile.setBalance(Double.valueOf(values.getProperty("profile.balance","1000"))); + String v = values.getProperty("profile.system", null); + if (v != null){ + Place system = market.get(v); + profile.setSystem(system); + v = values.getProperty("profile.station", null); + if (v != null && system != null){ + profile.setStation(system.get(v)); + } else { + profile.setStation(null); + } + } else { + profile.setSystem(null); + profile.setStation(null); + } + profile.setDocked(Boolean.valueOf(values.getProperty("profile.docked","false"))); profile.setJumps(Integer.valueOf(values.getProperty("profile.jumps", "6"))); profile.setLands(Integer.valueOf(values.getProperty("profile.lands", "4"))); profile.setPathPriority(PATH_PRIORITY.valueOf(values.getProperty("profile.search.priority", "FAST"))); @@ -157,7 +209,11 @@ public class Profile { } public void writeTo(Properties values){ + values.setProperty("profile.name", String.valueOf(name)); values.setProperty("profile.balance", String.valueOf(balance)); + values.setProperty("profile.system", String.valueOf(system != null ? system.getName():"")); + values.setProperty("profile.station", String.valueOf(station != null ? station.getName():"")); + values.setProperty("profile.docked", String.valueOf(docked)); values.setProperty("profile.jumps", String.valueOf(jumps)); values.setProperty("profile.lands", String.valueOf(lands)); values.setProperty("profile.search.priority", String.valueOf(pathPriority));