Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Added function to station remove button
Browse files Browse the repository at this point in the history
  • Loading branch information
Fi0x committed Jun 9, 2021
1 parent 4ac0f01 commit 7a2139e
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 40 deletions.
14 changes: 7 additions & 7 deletions EDCT.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:12.0.2" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:win:12.0.2" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:12.0.2" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:win:12.0.2" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:12.0.2" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:win:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:13.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:win:13.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:13.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:win:13.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:13.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:13.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:win:13.0.1" level="project" />
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.13.1" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.2</version>
<version>13.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.1</version>
<version>13.0.1</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/com/fi0x/edct/controller/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.layout.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;

import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -177,4 +179,22 @@ public COMMODITY getCurrentTrade()
{
return trades.get(currentCommodity);
}
public void removeCurrentTrade()
{
trades.remove(currentCommodity);
if(currentCommodity >= trades.size()) currentCommodity--;
}
public STATION getCurrentSellStation()
{
return trades.get(currentCommodity).BUY_PRICES.get(currentBuyStation);
}
public STATION getCurrentBuyStation()
{
return trades.get(currentCommodity).SELL_PRICES.get(currentSellStation);
}
public void removeStationFromCurrentTrade(STATION station)
{
getCurrentTrade().SELL_PRICES.remove(station);
getCurrentTrade().BUY_PRICES.remove(station);
}
}
22 changes: 16 additions & 6 deletions src/main/java/com/fi0x/edct/controller/Station.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.fi0x.edct.controller;

import com.fi0x.edct.MainWindow;
import com.fi0x.edct.data.localstorage.DBHandler;
import com.fi0x.edct.data.structures.COMMODITY;
import com.fi0x.edct.data.structures.STATION;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -67,10 +65,22 @@ private void previousStation()
@FXML
private void removeStation()
{
//TODO: Remove station from db
//TODO: Remove station from current trades
//TODO: Check if new current trade is displayable
//TODO: update displayed results
STATION s = isBuying ? resultsController.getCurrentBuyStation() : resultsController.getCurrentSellStation();
int commodityID = DBHandler.getInstance().getCommodityIDByName(resultsController.getCurrentTrade().NAME);
DBHandler.getInstance().removeStationEntry(commodityID, s.NAME, s.SYSTEM, isBuying);

resultsController.removeStationFromCurrentTrade(s);

if(!isBuying && stationID >= resultsController.getCurrentTrade().BUY_PRICES.size()) stationID = resultsController.getCurrentTrade().BUY_PRICES.size() - 1;
else if(isBuying && stationID >= resultsController.getCurrentTrade().SELL_PRICES.size()) stationID = resultsController.getCurrentTrade().SELL_PRICES.size() - 1;

if(!isBuying) resultsController.currentBuyStation = stationID;
else resultsController.currentSellStation = stationID;
resultsController.displayResults();

if(resultsController.getCurrentTrade().BUY_PRICES.size() == 0 || resultsController.getCurrentTrade().SELL_PRICES.size() == 0) resultsController.removeCurrentTrade();

resultsController.displayResults();
}

public void setStation(STATION station, boolean hasPrev, boolean hasNext)
Expand Down
27 changes: 5 additions & 22 deletions src/main/java/com/fi0x/edct/data/EDDN.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fi0x.edct.data;

import com.fi0x.edct.MainWindow;
import com.fi0x.edct.controller.Station;
import com.fi0x.edct.data.cleanup.HTMLCleanup;
import com.fi0x.edct.data.cleanup.JSONCleanup;
import com.fi0x.edct.data.localstorage.DBHandler;
Expand All @@ -18,7 +17,6 @@
import org.zeromq.ZContext;
import org.zeromq.ZMQ;

import javax.naming.Name;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.zip.DataFormatException;
Expand Down Expand Up @@ -107,18 +105,8 @@ public void run()
for(String trade : JSONCleanup.getTrades(outputString))
{
int commodityID = getInaraIDForCommodity(trade);
if(commodityID < 0)
{
if(commodityID == -2)
{
System.out.println("\t" + systemName + ", " + stationName);
STATION s = JSONCleanup.getStationTrade(systemName, stationName, padsize, stationtype, trade, false);
if(s != null) System.out.println("\t" + s.QUANTITY + "t, " + s.PRICE);
s = JSONCleanup.getStationTrade(systemName, stationName, padsize, stationtype, trade, true);
if(s != null) System.out.println("\t" + s.QUANTITY + "t, " + s.PRICE);
}
continue;
}
if(commodityID == -1) continue;


STATION station = JSONCleanup.getStationTrade(systemName, stationName, padsize, stationtype, trade, false);
if(station != null) DBHandler.getInstance().setStationData(station, commodityID, false);
Expand Down Expand Up @@ -164,15 +152,10 @@ private int getInaraIDForCommodity(String commodityJSON)
.replace("-", "")
.toLowerCase();

if(commodityName.equals(dbName))
{
return pair.getValue();
}
if(commodityName.equals(dbName)) return pair.getValue();
}

if(NameMap.isRare(commodityName) || NameMap.isIgnored(commodityName)) return -1;

Logger.WARNING("Could not find commodity key that matches: " + commodityName);
return -2;
if(!NameMap.isRare(commodityName) && !NameMap.isIgnored(commodityName)) Logger.WARNING("Could not find commodity key that matches: " + commodityName);
return -1;
}
}
26 changes: 24 additions & 2 deletions src/main/java/com/fi0x/edct/data/localstorage/DBHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ public String getCommodityNameByID(int commodityID)
return "";
}

public int getCommodityIDByName(String name)
{
ResultSet commodity = getQueryResults("SELECT inara_id "
+ "FROM commodities "
+ "WHERE commodity_name = " + makeSQLValid(name));
try
{
if(commodity != null && commodity.next())
{
return commodity.getInt("inara_id");
}
} catch(SQLException e)
{
Logger.WARNING("Could not get the id of a commodity", e);
}
return -1;
}

public Map<String, Integer> getCommodityNameIDPairs()
{
Map<String, Integer> pairs = new HashMap<>();
Expand Down Expand Up @@ -262,9 +280,13 @@ public double getSystemDistance(String system1, String system2)
return 0;
}

public void removeStationEntry(String commodityName, String stationName, String systemName, boolean isSeller)
public void removeStationEntry(int commodityID, String stationName, String systemName, boolean isSeller)
{
//TODO: Remove entry from stations
sendStatement("DELETE FROM stations " +
"WHERE commodity_id = " + commodityID + " " +
"AND station_name = " + makeSQLValid(stationName) + " " +
"AND star_system = " + makeSQLValid(systemName) + " " +
"AND is_seller = " + (isSeller ? 0 : 1));
}

public void removeOldEntries()
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/fi0x/edct/data/localstorage/NameMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public static void initializeNames()
RARE_NAMES.add("wolf1301fesh");
RARE_NAMES.add("terramaterbloodbores");
RARE_NAMES.add("borasetanipathogenetics");
RARE_NAMES.add("aganipperush");
RARE_NAMES.add("hip118311swarm");

IGNORED.add("thargoidtissuesampletype1");
IGNORED.add("thargoidtissuesampletype2");
Expand All @@ -201,6 +203,11 @@ public static void initializeNames()
IGNORED.add("s6_tissuesample_cells");
IGNORED.add("s6_tissuesample_coenosarc");
IGNORED.add("s_tissuesample_cells");
RARE_NAMES.add("transgeniconionhead");
RARE_NAMES.add("p_particulatesample");
RARE_NAMES.add("animaleffigies");
RARE_NAMES.add("alieneggs");
RARE_NAMES.add("advert1");
}

public static String convertDBToEDDN(String localName)
Expand Down

0 comments on commit 7a2139e

Please sign in to comment.