added improved pieces model; added functionality to notifications + todos

This commit is contained in:
Cedric Beck
2024-11-28 02:08:51 +01:00
parent 304acf17a3
commit 7da388af37
15 changed files with 27012 additions and 158 deletions

View File

@@ -3,11 +3,11 @@
public enum Asset { public enum Asset {
bigTent, bigTent,
cardStack, cardStack,
cir, cir("Models/lcir/cir_newOrigin.obj"),
heer, heer("Models/heer/heer_newOrigin.obj"),
jet, jet,
lw, lw("Models/lw/lw_newOrigin.obj"),
marine, marine("Models/marine/marine_newOrigin.obj"),
node_home_blue("Models/node_home/node_home.j3o", "Models/node_home/node_home_blue_diff.png"), node_home_blue("Models/node_home/node_home.j3o", "Models/node_home/node_home_blue_diff.png"),
node_wait_blue("Models/node_home/node_home.j3o", "Models/node_home/node_home_blue_diff.png"), node_wait_blue("Models/node_home/node_home.j3o", "Models/node_home/node_home_blue_diff.png"),
node_home_black("Models/node_home/node_home.j3o", "Models/node_home/node_home_black_diff.png"), node_home_black("Models/node_home/node_home.j3o", "Models/node_home/node_home_black_diff.png"),
@@ -54,6 +54,13 @@ public enum Asset {
this.size = 1f; this.size = 1f;
} }
Asset(String modelPath) {
String folderFileName = "./" + root + name() + "/" + name();
this.modelPath = modelPath;
this.diffPath = folderFileName + "_diff.png";;
this.size = 1f;
}
Asset(float size) { Asset(float size) {
String folderFileName = "./" + root + name() + "/" + name(); String folderFileName = "./" + root + name() + "/" + name();
this.modelPath = folderFileName + ".j3o"; this.modelPath = folderFileName + ".j3o";

View File

@@ -95,7 +95,9 @@ else if(boardSelect != null) {
} }
if(name.equals("Test") &&isPressed){ if(name.equals("Test") &&isPressed){
if(app.getView() instanceof GameView gameView){ if(app.getView() instanceof GameView gameView){
gameView.getGuiHandler().swap(); gameView.getGuiHandler().showDice();
gameView.getGuiHandler().hideDice();
gameView.getGuiHandler().showDice();
} }
} }
} }

View File

@@ -1,9 +1,5 @@
package pp.mdga.client; package pp.mdga.client;
import pp.mdga.notification.Notification;
import pp.mdga.notification.PieceInGameNotification;
import pp.mdga.notification.PlayerInGameNotification;
public enum MdgaState { public enum MdgaState {
NONE, NONE,
MAIN, MAIN,

View File

@@ -1,5 +1,7 @@
package pp.mdga.client; package pp.mdga.client;
import pp.mdga.client.board.BoardHandler;
import pp.mdga.client.gui.GuiHandler;
import pp.mdga.client.view.GameView; import pp.mdga.client.view.GameView;
import pp.mdga.client.view.LobbyView; import pp.mdga.client.view.LobbyView;
import pp.mdga.notification.*; import pp.mdga.notification.*;
@@ -68,68 +70,68 @@ private void handleLobby(Notification notification) {
private void handleGame(Notification notification) { private void handleGame(Notification notification) {
GameView gameView = (GameView) app.getView(); GameView gameView = (GameView) app.getView();
GuiHandler guiHandler = gameView.getGuiHandler();
BoardHandler boardHandler = gameView.getBoardHandler();
if (notification instanceof AcquireCardNotification) { if (notification instanceof AcquireCardNotification n) {
// Handle AcquireCardNotification guiHandler.addCard(n.getBonusCard(), n.getCardId());
} else if (notification instanceof ActivePlayerNotification n) { } else if (notification instanceof ActivePlayerNotification n) {
gameView.getGuiHandler().setActivePlayer(n.getColor()); guiHandler.setActivePlayer(n.getColor());
} else if (notification instanceof CeremonyNotification) { } else if (notification instanceof CeremonyNotification) {
app.enter(MdgaState.CEREMONY); app.enter(MdgaState.CEREMONY);
} else if (notification instanceof DiceNowNotification) { } else if (notification instanceof DiceNowNotification) {
// Handle DiceNowNotification guiHandler.showDice();
} else if (notification instanceof DicingNotification) { } else if (notification instanceof DicingNotification n) {
// Handle DicingNotification //TODO
} else if (notification instanceof DrawCardNotification) { } else if (notification instanceof DrawCardNotification n) {
// Handle DrawCardNotification //TODO ???
} else if (notification instanceof HomeMoveNotification home) { } else if (notification instanceof HomeMoveNotification home) {
gameView.getBoardHandler().moveHomePiece(home.getPieceId(), home.getHomeIndex()); boardHandler.moveHomePiece(home.getPieceId(), home.getHomeIndex());
} else if (notification instanceof InterruptNotification) { } else if (notification instanceof InterruptNotification) {
// Handle InterruptNotification //TODO
} else if (notification instanceof MovePieceNotification n) { } else if (notification instanceof MovePieceNotification n) {
if(n.isMoveStart()) { if(n.isMoveStart()) {
//StartMove //StartMove
gameView.getBoardHandler().movePieceStart(n.getPiece(), n.getMoveIndex()); boardHandler.movePieceStart(n.getPiece(), n.getMoveIndex());
} }
else { else {
//InfieldMove //InfieldMove
gameView.getBoardHandler().movePiece(n.getPiece(), n.getStartIndex(), n.getMoveIndex()); boardHandler.movePiece(n.getPiece(), n.getStartIndex(), n.getMoveIndex());
}
} else if (notification instanceof ThrowPieceNotification n) {
boardHandler.throwPiece(n.getPieceId());
} else if (notification instanceof NoShieldNotification n) {
boardHandler.unshieldPiece(n.getPieceId());
} else if (notification instanceof PlayCardNotification n) {
switch(n.getCard()){
case SWAP -> guiHandler.swap();
case TURBO -> guiHandler.turbo();
case SHIELD -> guiHandler.shield();
default -> throw new RuntimeException("invalid card");
} }
} else if (notification instanceof MoveThrowPieceNotification) {
MoveThrowPieceNotification n = (MoveThrowPieceNotification)notification;
//gameView.getBoardHandler().throwPiece(n.); //TODO
} else if (notification instanceof NoShieldNotification) {
NoShieldNotification n = (NoShieldNotification)notification;
gameView.getBoardHandler().unshieldPiece(n.getPieceId());
} else if (notification instanceof PieceInGameNotification) {
// Handle PieceInGameNotification
} else if (notification instanceof PlayCardNotification) {
// Handle PlayCardNotification
} else if (notification instanceof PlayerInGameNotification n) { } else if (notification instanceof PlayerInGameNotification n) {
// Handle PlayerInGameNotification boardHandler.addPlayer(n.getColor(),n.getPiecesList());
gameView.getBoardHandler().addPlayer(n.getColor(),n.getPiecesList()); guiHandler.addPlayer(n.getColor(),n.getName());
gameView.getGuiHandler().addPlayer(n.getColor(),n.getName());
} else if (notification instanceof ResumeNotification) { } else if (notification instanceof ResumeNotification) {
// Handle ResumeNotification } else if (notification instanceof RollDiceNotification n) {
} else if (notification instanceof RollDiceNotification) { guiHandler.rollDice(n.getEyes());
// Handle RollDiceNotification //TODO multiplicator
} else if (notification instanceof SelectableCardsNotification) { } else if (notification instanceof SelectableCardsNotification n) {
// Handle SelectableCardsNotification guiHandler.setSelectableCards(n.getCards());
} else if (notification instanceof ShieldActiveNotification) { } else if (notification instanceof ShieldActiveNotification n) {
ShieldActiveNotification n = (ShieldActiveNotification)notification; boardHandler.shieldPiece(n.getPieceId());
gameView.getBoardHandler().shieldPiece(n.getPieceId()); } else if (notification instanceof ShieldSuppressedNotification n) {
} else if (notification instanceof ShieldSuppressedNotification) { boardHandler.suppressShield(n.getPieceId());
ShieldSuppressedNotification n = (ShieldSuppressedNotification)notification;
gameView.getBoardHandler().suppressShield(n.getPieceId());
} else if (notification instanceof StartDialogNotification) { } else if (notification instanceof StartDialogNotification) {
app.enter(MdgaState.MAIN); app.enter(MdgaState.MAIN);
} else if (notification instanceof SwapPieceNotification n) { } else if (notification instanceof SwapPieceNotification n) {
gameView.getBoardHandler().swapPieces(n.getFirstPiece(), n.getSecondPiece()); boardHandler.swapPieces(n.getFirstPiece(), n.getSecondPiece());
} else if (notification instanceof WaitMoveNotification) { } else if (notification instanceof WaitMoveNotification) {
// Handle WaitMoveNotification //TODO disable all hover, highlight, etc
} else if (notification instanceof SelectableMoveNotification n) { } else if (notification instanceof SelectableMoveNotification n) {
gameView.getBoardHandler().outlineMove(n.getPieces(), n.getMoveIndexe(), n.getHomeMoves()); boardHandler.outlineMove(n.getPieces(), n.getMoveIndexe(), n.getHomeMoves());
} else if (notification instanceof SelectableSwapNotification n) { } else if (notification instanceof SelectableSwapNotification n) {
gameView.getBoardHandler().outlineSwap(n.getOwnPieces(), n.getEnemyPieces()); boardHandler.outlineSwap(n.getOwnPieces(), n.getEnemyPieces());
} else { } else {
throw new RuntimeException("notification not expected: " + notification.toString()); throw new RuntimeException("notification not expected: " + notification.toString());
} }

View File

@@ -1,5 +1,6 @@
package pp.mdga.client.gui; package pp.mdga.client.gui;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
@@ -17,6 +18,8 @@ public class DiceControl extends AbstractControl {
private boolean slerp = false; private boolean slerp = false;
private float timeElapsed = 0.0f; private float timeElapsed = 0.0f;
private float rollDuration = 0.0001f; private float rollDuration = 0.0001f;
private static final int ANGULAR_MIN = 5;
private static final int ANGULAR_MAX = 15;
@Override @Override
protected void controlUpdate(float tpf) { protected void controlUpdate(float tpf) {
@@ -64,13 +67,14 @@ protected void controlUpdate(float tpf) {
protected void controlRender(RenderManager rm, ViewPort vp) { protected void controlRender(RenderManager rm, ViewPort vp) {
} }
public void rollDice(int diceNum) { public void rollDice(int diceNum) {
if (isRolling) return; if (isRolling) return;
angularVelocity.set( angularVelocity.set(
random.nextFloat() * 1000f + 100f, FastMath.nextRandomInt(ANGULAR_MIN,ANGULAR_MAX),
random.nextFloat() * 1000f + 100f, FastMath.nextRandomInt(ANGULAR_MIN,ANGULAR_MAX),
random.nextFloat() * 1000f + 100f FastMath.nextRandomInt(ANGULAR_MIN,ANGULAR_MAX)
); );
targetRotation = getRotationForDiceNum(diceNum); targetRotation = getRotationForDiceNum(diceNum);
@@ -94,4 +98,13 @@ public static float lerp(float t) {
return (float) Math.sqrt(1 - Math.pow(t - 1, 2)); return (float) Math.sqrt(1 - Math.pow(t - 1, 2));
} }
public void randomRotation() {
Quaternion randomRotation = new Quaternion();
randomRotation.fromAngles(
FastMath.nextRandomFloat() * FastMath.TWO_PI, // Random X rotation
FastMath.nextRandomFloat() * FastMath.TWO_PI, // Random Y rotation
FastMath.nextRandomFloat() * FastMath.TWO_PI // Random Z rotation
);
spatial.setLocalRotation(randomRotation);
}
} }

View File

@@ -96,13 +96,15 @@ public void addCard(BonusCard card, UUID uuid) {
bonusCardControlMap.get(card).setNumCard(newNum); bonusCardControlMap.get(card).setNumCard(newNum);
} }
public void showDice(int rollNum){ public void rollDice(int rollNum){
if(!(1 <= rollNum && rollNum <= 6)) throw new RuntimeException("rollNum is not in the range [1,6]"); if(!(1 <= rollNum && rollNum <= 6)) throw new RuntimeException("rollNum is not in the range [1,6]");
cardLayer.addSpatial(diceControl.getSpatial());
diceControl.rollDice(rollNum); diceControl.rollDice(rollNum);
} }
public void showDice(){
cardLayer.addSpatial(diceControl.getSpatial());
}
public void hideDice(){ public void hideDice(){
cardLayer.deleteSpatial(diceControl.getSpatial()); cardLayer.deleteSpatial(diceControl.getSpatial());
} }
@@ -232,7 +234,7 @@ public CardLayer getCardLayer(){
} }
public void setSelectableCards(List<UUID> selectUuids) { public void setSelectableCards_UUID(List<UUID> selectUuids) {
for(UUID uuid : selectUuids) { for(UUID uuid : selectUuids) {
selectableCards.add(bonusCardControlMap.get(uuidBonusCardMap.get(uuid))); selectableCards.add(bonusCardControlMap.get(uuidBonusCardMap.get(uuid)));
} }
@@ -243,6 +245,17 @@ public void setSelectableCards(List<UUID> selectUuids) {
} }
} }
public void setSelectableCards(List<BonusCard> select) {
for(BonusCard uuid : select) {
selectableCards.add(bonusCardControlMap.get(uuid));
}
for(CardControl control : selectableCards){
control.setSelectable(true);
control.setHoverable(true);
control.setHighlight();
}
}
public void clearSelectableCards(){ public void clearSelectableCards(){
for(CardControl control : selectableCards){ for(CardControl control : selectableCards){
control.setSelectable(false); control.setSelectable(false);

View File

@@ -31,6 +31,8 @@ public class GameView extends MdgaView {
private SingleButtonLeftDialog leaveButton; private SingleButtonLeftDialog leaveButton;
private SingleButtonRightDialog continueButton; private SingleButtonRightDialog continueButton;
private Color ownColor = null;
public GameView(MdgaApp app) { public GameView(MdgaApp app) {
super(app); super(app);
@@ -115,4 +117,12 @@ public BoardHandler getBoardHandler() {
public GuiHandler getGuiHandler() { public GuiHandler getGuiHandler() {
return guiHandler; return guiHandler;
} }
public void setOwnColor(Color ownColor) {
this.ownColor = ownColor;
}
public Color getOwnColor() {
return ownColor;
}
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,7 @@
package pp.mdga.notification; package pp.mdga.notification;
import pp.mdga.game.BonusCard;
import java.util.UUID; import java.util.UUID;
/** /**
@@ -8,12 +10,14 @@
public class AcquireCardNotification extends Notification{ public class AcquireCardNotification extends Notification{
private UUID cardId; private UUID cardId;
private BonusCard bonusCard;
/** /**
* Constructor. * Constructor.
* @param cardId The id of the card that was acquired. * @param cardId The id of the card that was acquired.
*/ */
public AcquireCardNotification(UUID cardId) { public AcquireCardNotification(BonusCard bonusCard, UUID cardId) {
this.bonusCard = bonusCard;
this.cardId = cardId; this.cardId = cardId;
} }
@@ -24,4 +28,8 @@ public AcquireCardNotification(UUID cardId) {
public UUID getCardId() { public UUID getCardId() {
return cardId; return cardId;
} }
public BonusCard getBonusCard() {
return bonusCard;
}
} }

View File

@@ -1,64 +0,0 @@
package pp.mdga.notification;
import pp.mdga.game.Color;
import java.util.UUID;
public class MoveThrowPieceNotification extends Notification{
private UUID pieceId1;
private UUID pieceId2;
private int nodeIndex;
private Color colorPiece2;
/**
* This constructor is used to create a new MoveThrowPieceNotification
*
* @param pieceId1 the pieceId1
* @param pieceId2 the pieceId2
* @param nodeIndex the nodeIndex
* @param colorPiece2 the color
*/
public MoveThrowPieceNotification(UUID pieceId1, UUID pieceId2, int nodeIndex, Color colorPiece2) {
this.pieceId1 = pieceId1;
this.pieceId2 = pieceId2;
this.nodeIndex = nodeIndex;
this.colorPiece2 = colorPiece2;
}
/**
* This method returns the pieceId1
*
* @return the pieceId1
*/
public UUID getPieceId1() {
return pieceId1;
}
/**
* This method returns the pieceId2
*
* @return the pieceId2
*/
public UUID getPieceId2() {
return pieceId2;
}
/**
* This method returns the nodeIndex
*
* @return the nodeIndex
*/
public int getNodeIndex() {
return nodeIndex;
}
/**
* This method returns the color
*
* @return the color
*/
public Color getColor() {
return colorPiece2;
}
}

View File

@@ -1,37 +0,0 @@
package pp.mdga.notification;
import pp.mdga.game.Color;
import java.util.UUID;
/**
* Notification that a piece is in the game
*/
public class PieceInGameNotification extends Notification{
private Color color;
private UUID id;
/**
* Constructor
* @param color the color of the piece
* @param id the id of the piece
*/
PieceInGameNotification(Color color, UUID id) {
this.color = color;
this.id = id;
}
/**
* @return the color of the piece
*/
public Color getColor() {
return null;
}
/**
* @return the id of the piece
*/
public UUID getId() {
return null;
}
}

View File

@@ -0,0 +1,26 @@
package pp.mdga.notification;
import pp.mdga.game.Color;
import java.util.UUID;
public class ThrowPieceNotification extends Notification{
private UUID pieceId;
/**
* This constructor is used to create a new ThrowPieceNotification
*
* @param pieceId1 the pieceId1
* @param pieceId2 the pieceId2
* @param nodeIndex the nodeIndex
* @param colorPiece2 the color
*/
public ThrowPieceNotification(UUID pieceId) {
this.pieceId = pieceId;
}
public UUID getPieceId() {
return pieceId;
}
}