Skip to content

Commit

Permalink
Merge branch 'client-server' of github.com:Cardshifter/Cardshifter in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
Zomis committed Sep 18, 2014
2 parents 21e6ae7 + f61e593 commit ef41ed2
Show file tree
Hide file tree
Showing 10 changed files with 585 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.cardshifter.server.incoming.StartGameRequest;
import com.cardshifter.server.incoming.UseAbilityMessage;
import com.cardshifter.server.outgoing.CardInfoMessage;
import com.cardshifter.server.outgoing.EntityRemoveMessage;
import com.cardshifter.server.outgoing.GameMessage;
import com.cardshifter.server.outgoing.NewGameMessage;
import com.cardshifter.server.outgoing.PlayerMessage;
Expand All @@ -17,6 +18,7 @@
import com.cardshifter.server.outgoing.UseableActionMessage;
import com.cardshifter.server.outgoing.WaitMessage;
import com.cardshifter.server.outgoing.WelcomeMessage;
import com.cardshifter.server.outgoing.ZoneChangeMessage;
import com.cardshifter.server.outgoing.ZoneMessage;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.fasterxml.jackson.databind.JavaType;
Expand All @@ -33,6 +35,8 @@ public class MessageTypeIdResolver implements TypeIdResolver {
clazzes.put("startgame", StartGameRequest.class);
clazzes.put("use", UseAbilityMessage.class);
clazzes.put("requestTargets", RequestTargetsMessage.class);
clazzes.put("zoneChange", ZoneChangeMessage.class);
clazzes.put("entityRemoved", EntityRemoveMessage.class);

clazzes.put("resetActions", ResetAvailableActionsMessage.class);
clazzes.put("game", GameMessage.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.cardshifter.server.outgoing;

import com.cardshifter.server.messages.Message;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class EntityRemoveMessage extends Message {

private final int entity;

@JsonCreator
public EntityRemoveMessage(@JsonProperty("entity") int entity) {
super("entityRemoved");
this.entity = entity;
}

public int getEntity() {
return entity;
}

@Override
public String toString() {
return "EntityRemoveMessage [entity=" + entity + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.cardshifter.server.outgoing;

import com.cardshifter.server.messages.Message;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class ZoneChangeMessage extends Message {

private final int entity;
private final int sourceZone;
private final int destinationZone;

@JsonCreator
public ZoneChangeMessage(@JsonProperty("entity") int entity,
@JsonProperty("sourceZone") int sourceZone, @JsonProperty("destinationZone") int destinationZone) {
super("zoneChange");
this.entity = entity;
this.sourceZone = sourceZone;
this.destinationZone = destinationZone;
}

public int getEntity() {
return entity;
}

public int getSourceZone() {
return sourceZone;
}

public int getDestinationZone() {
return destinationZone;
}

@Override
public String toString() {
return "ZoneChangeMessage [entity=" + entity + ", sourceZone="
+ sourceZone + ", destinationZone=" + destinationZone + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class EventExecutor {

private static final Logger logger = LogManager.getLogger(EventExecutor.class);

protected final Map<Class<? extends IEvent>, Collection<EventHandler<?>>> bindings;

public EventExecutor() {
Expand All @@ -26,10 +31,12 @@ private <T extends IEvent> T executeEvent(T event, Predicate<EventHandler<?>> pr
}

public <T extends IEvent> T executePostEvent(T event) {
logger.debug("Execute pre event " + event);
return executeEvent(event, eh -> eh.isAfter());
}

public <T extends IEvent> T executePreEvent(T event) {
logger.debug("Execute post event " + event);
return executeEvent(event, eh -> !eh.isAfter());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

package com.cardshifter.client;

import com.cardshifter.server.outgoing.UseableActionMessage;
import javafx.scene.Group;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class ActionButton extends Group {

private final UseableActionMessage message;
private final GameClientController controller;
private final double sizeX;
private final double sizeY;

public ActionButton(UseableActionMessage message, GameClientController controller, double sizeX, double sizeY) {
this.message = message;
this.controller = controller;
this.sizeX = sizeX;
this.sizeY = sizeY;
this.setUpRectangle();
this.setUpLabel();
this.setOnMouseClicked(this::actionButtonClicked);
}
private void setUpRectangle() {
Rectangle actionBack = new Rectangle(0, 0, this.sizeX, this.sizeY);
actionBack.setFill(Color.BLUEVIOLET);
this.getChildren().add(actionBack);
}
private void setUpLabel() {
Label actionLabel = new Label();
actionLabel.setText(this.message.getAction());
actionLabel.relocate(this.sizeX/2.5, 0);
this.getChildren().add(actionLabel);
}

private void actionButtonClicked(MouseEvent event) {
this.controller.createAndSendMessage(this.message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.cardshifter.client;

import com.cardshifter.server.outgoing.CardInfoMessage;
import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class CardHandDocumentController implements Initializable {

@FXML private Label strength;
@FXML private Label health;
@FXML private Label cardId;
@FXML private Label manaCost;
@FXML private Label scrapCost;
@FXML private Label cardType;
@FXML private Label creatureType;
@FXML private Label enchStrength;
@FXML private Label enchHealth;
@FXML private Rectangle background;
@FXML private AnchorPane anchorPane;

//Initialization
private AnchorPane root;
private final CardInfoMessage card;
public CardHandDocumentController(CardInfoMessage message, GameClientController controller) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("CardHandDocument.fxml"));
loader.setController(this);
root = loader.load();
}
catch (Exception e) {
throw new RuntimeException(e);
}

this.card = message;
this.setCardId();
this.setCardLabels();
this.setActionForRootPane();
}

private void setActionForRootPane() {
this.anchorPane.setOnMouseClicked(this::actionOnClick);
}
private void actionOnClick(MouseEvent event) {
System.out.println("Action detected on card" + this.cardId.textProperty());
}

public AnchorPane getRootPane() {
return this.anchorPane;
}

public void setRectangleColorActive() {
background.setFill(Color.YELLOW);
}

private void setCardId() {
int newId = card.getId();
cardId.setText(String.format("CardId = %d", newId));
}

private void setCardLabels() {
for(String key : this.card.getProperties().keySet()) {
if (key.equals("SICKNESS")) {

} else if (key.equals("MANA_COST")) {
manaCost.setText(String.format("Mana Cost = %d", this.card.getProperties().get(key)));
} else if (key.equals("ATTACK")) {
strength.setText(this.card.getProperties().get(key).toString());
} else if (key.equals("HEALTH")) {
health.setText(this.card.getProperties().get(key).toString());
} else if (key.equals("ATTACK_AVAILABLE")) {

}
}

/*
List<ECSResourceData> keyList = new ArrayList<>();
Resources.processResources(card, data -> keyList.add(data));
for (ECSResourceData string : keyList) {
ECSResource resource = string.getResource();
int value = string.get();
if (resource == PhrancisResources.HEALTH) {
health.setText(String.valueOf(string.get()));
} else if (resource == PhrancisResources.ATTACK) {
strength.setText(String.valueOf(string.get()));
} else if (resource == PhrancisResources.MANA_COST) {
manaCost.setText(String.format("Mana Cost = %d", string.get()));
} else if (resource == PhrancisResources.SCRAP_COST) {
scrapCost.setText(String.format("Scrap Cost = %d", value));
}
// } else if (resource == PhrancisResources.st string.equals("enchStrength")) {
// enchStrength.setText(String.format("Enchantment Strength = %d", card.data.get("enchStrength").toint()));
// } else if (string.equals("enchHealth")) {
// enchHealth.setText(String.format("Enchantment Health = %d", card.data.get("enchHealth").toint()));
// }
}
if (card.hasComponent(CreatureTypeComponent.class)) {
creatureType.setText(card.getComponent(CreatureTypeComponent.class).getCreatureType());
}
// } else if (string.equals("cardType")) {
// cardType.setText(String.format(card.data.get("cardType").tojstring()));
*/
}

//Boilerplate code
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}

}

0 comments on commit ef41ed2

Please sign in to comment.