I got the following data model:
public class Player {
// enum to integer (count)
@Getter
private MapProperty<ResourceType, Integer> resourceCards = new SimpleMapProperty<>();
public void addResource(final ResourceType resourceType, final int amount) {
this.resourceCards.get().put(resourceType, this.resourceCards.get().get(resourceType) + amount);
}
}
public class Game {
@Getter
@Setter
private ObjectProperty<Player> currentPlayer = new SimpleObjectProperty<>();
}
Binding the map to a text property is quite easy:
final Label label = new Label();
label.textProperty().bind(EasyBind.select(game.getCurrentPlayer()).selectObject(player -> player.getResourceCards().asString()));
I would like to display the total amount of resource cards in the label.
Example:
Map: {Water=0, Gold=2, Lumber=5}
Label: 7
Map: {Water=0, Gold=0, Lumber=0}
Label: 0
How can I achieve this with JavaFX Bindings or/and EasyBind?