Skip to content

Commit

Permalink
Added the card name to the GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
skiwi2 committed Feb 23, 2015
1 parent 12236f4 commit 9b740df
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.cardshifter.modapi.base.ECSGame;
import com.cardshifter.modapi.base.Entity;
import com.cardshifter.modapi.resources.ECSResourceMap;
import com.github.skiwi2.hearthmonitor.CardData;
import com.github.skiwi2.hearthmonitor.logapi.power.FullEntityLogEntry;
import com.github.skiwi2.hearthmonitor.model.CardDataComponent;
import com.github.skiwi2.hearthmonitor.model.HearthStoneMod;

import java.util.Objects;
Expand Down Expand Up @@ -37,14 +39,15 @@ protected void executeImpl() {
newEntity = ecsGame.newEntity();
ECSResourceMap ecsResourceMap = ECSResourceMap.createFor(newEntity);
ECSAttributeMap ecsAttributeMap = ECSAttributeMap.createFor(newEntity);
if (!fullEntityLogEntry.getCardId().isEmpty()) {
newEntity.addComponent(new CardDataComponent(CardData.getForCardId(fullEntityLogEntry.getCardId())));
}
fullEntityLogEntry.getTagValues().forEach((tag, value) -> {
if (HearthStoneMod.isHearthStoneResource(tag)) {
ecsResourceMap.set(HearthStoneMod.getHearthStoneResource(tag), Integer.parseInt(value)); //TODO catch NFE for robustness?
}
else if (HearthStoneMod.isHearthStoneAttribute(tag)) {
} else if (HearthStoneMod.isHearthStoneAttribute(tag)) {
ecsAttributeMap.set(HearthStoneMod.getHearthStoneAttribute(tag), value);
}
else {
} else {
System.out.println("Tag " + tag + " matches neither a resource nor an attribute.");
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.skiwi2.hearthmonitor.model;

import com.cardshifter.modapi.base.Component;
import com.github.skiwi2.hearthmonitor.CardData;

import java.util.Objects;

/**
* @author Frank van Heeswijk
*/
public class CardDataComponent extends Component {
private final CardData cardData;

public CardDataComponent(final CardData cardData) {
this.cardData = Objects.requireNonNull(cardData, "cardData");
}

public CardData getCardData() {
return cardData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cardshifter.modapi.resources.ECSResourceMap;
import com.cardshifter.modapi.resources.ResourceRetriever;
import com.github.skiwi2.hearthmonitor.commands.Command;
import com.github.skiwi2.hearthmonitor.model.CardDataComponent;
import com.github.skiwi2.hearthmonitor.model.Game;
import com.github.skiwi2.hearthmonitor.model.HearthStoneMod.HearthStoneAttribute;
import com.github.skiwi2.hearthmonitor.model.HearthStoneMod.HearthStoneResource;
Expand Down Expand Up @@ -158,7 +159,7 @@ private void refreshBox(final VBox box, final String controllerType) {
.stream()
.filter(entity -> Objects.equals(AttributeRetriever.forAttribute(HearthStoneAttribute.ZONE).getOrDefault(entity, ""), controllerType + " PLAY (Hero Power)"))
.forEach(entity -> {
box.getChildren().add(new Label("???" + System.lineSeparator() + getAttackAndHitPointsData(entity) + System.lineSeparator() + getSpecialEffects(entity)));
box.getChildren().add(new Label(getName(entity) + System.lineSeparator() + getAttackAndHitPointsData(entity) + System.lineSeparator() + getSpecialEffects(entity)));
});

Long deckRemainingSize = ecsGame.findEntities(entity -> (entity.hasComponent(ECSResourceMap.class) && entity.hasComponent(ECSAttributeMap.class)))
Expand All @@ -178,7 +179,7 @@ private void refreshHandBox(final VBox box, final String controllerType) {
.filter(entity -> Objects.equals(AttributeRetriever.forAttribute(HearthStoneAttribute.ZONE).getOrDefault(entity, ""), controllerType + " HAND"))
.sorted(Comparator.comparingInt(entity -> ResourceRetriever.forResource(HearthStoneResource.ZONE_POSITION).getOrDefault(entity, 0)))
.forEach(entity -> {
box.getChildren().add(new Label("???" + System.lineSeparator() + getAttackAndHitPointsData(entity) + System.lineSeparator() + getSpecialEffects(entity)));
box.getChildren().add(new Label(getName(entity) + System.lineSeparator() + getAttackAndHitPointsData(entity) + System.lineSeparator() + getSpecialEffects(entity)));
});

}
Expand All @@ -191,10 +192,17 @@ private void refreshFieldBox(final VBox box, final String controllerType) {
.filter(entity -> Objects.equals(AttributeRetriever.forAttribute(HearthStoneAttribute.ZONE).getOrDefault(entity, ""), controllerType + " PLAY"))
.sorted(Comparator.comparingInt(entity -> ResourceRetriever.forResource(HearthStoneResource.ZONE_POSITION).getOrDefault(entity, 0)))
.forEach(entity -> {
box.getChildren().add(new Label("???" + System.lineSeparator() + getAttackAndHitPointsData(entity) + System.lineSeparator() + getSpecialEffects(entity)));
box.getChildren().add(new Label(getName(entity) + System.lineSeparator() + getAttackAndHitPointsData(entity) + System.lineSeparator() + getSpecialEffects(entity)));
});
}

private static String getName(final Entity entity) {
if (!entity.hasComponent(CardDataComponent.class)) {
return "???";
}
return entity.getComponent(CardDataComponent.class).getCardData().getName();
}

private static String getAttackAndHitPointsData(final Entity entity) {
int attack = ResourceRetriever.forResource(HearthStoneResource.ATK).getOrDefault(entity, 0);
int health = ResourceRetriever.forResource(HearthStoneResource.HEALTH).getOrDefault(entity, 0);
Expand Down

0 comments on commit 9b740df

Please sign in to comment.