Fixed boat position calculation
- Decoupled 'place' column data from position in table - Set position in race after first mark passed #story[15]
This commit is contained in:
@@ -76,12 +76,7 @@ public class RaceController extends Controller {
|
||||
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
|
||||
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
||||
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
||||
@Override
|
||||
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
||||
return new ReadOnlyObjectWrapper(boatInfoTable.getItems().indexOf(table.getValue()) + 1);
|
||||
}
|
||||
});
|
||||
boatPlacingColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.paint.Color;
|
||||
@@ -24,6 +25,7 @@ public class BoatInRace extends Boat {
|
||||
private boolean finished = false;
|
||||
private StringProperty currentLegName;
|
||||
private boolean started = false;
|
||||
private StringProperty position;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
@@ -36,6 +38,7 @@ public class BoatInRace extends Boat {
|
||||
super(name, velocity, abbrev);
|
||||
setColour(colour);
|
||||
currentLegName = new SimpleStringProperty("");
|
||||
position = new SimpleStringProperty("-");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,4 +238,16 @@ public class BoatInRace extends Boat {
|
||||
public void setStarted(boolean started) {
|
||||
this.started = started;
|
||||
}
|
||||
|
||||
public String getPosition() {
|
||||
return position.get();
|
||||
}
|
||||
|
||||
public StringProperty positionProperty() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position.set(Integer.toString(position + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,6 +263,7 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
//Update the boat display table in the GUI to reflect the leg change
|
||||
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
||||
boat.setPosition(startingBoats.indexOf(boat));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user