Skip to content

Commit

Permalink
isolate old gameMode constants to replays
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Oct 13, 2024
1 parent 32cde5a commit 43ae95b
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 148 deletions.
4 changes: 2 additions & 2 deletions client/src/main/java/online/screen/EntropyRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import object.EntropyBid;
import screen.EntropyBidPanel;
import util.CardsUtil;
import util.GameConstants;
import util.Registry;
import util.ReplayConstants;

public class EntropyRoom extends GameRoom
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public void updateScreenForChallengeOrIllegal()
public void saveModeSpecificVariablesForReplay()
{
int roundsSoFar = replay.getInt(Registry.REPLAY_INT_ROUNDS_SO_FAR, 0);
replay.putInt(Registry.REPLAY_INT_GAME_MODE, GameConstants.GAME_MODE_ENTROPY_ONLINE);
replay.putInt(Registry.REPLAY_INT_GAME_MODE, ReplayConstants.GAME_MODE_ENTROPY_ONLINE);
replay.putInt(roundsSoFar + Registry.REPLAY_INT_LAST_BID_SUIT_CODE, ((EntropyBid)lastBid).getBidSuitCode());
replayDialog.roundAdded();
}
Expand Down
7 changes: 2 additions & 5 deletions client/src/main/java/online/screen/VectropyRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import game.GameSettings;
import object.Bid;
import screen.VectropyBidPanel;
import util.AchievementsUtil;
import util.GameConstants;
import util.Registry;
import util.VectropyUtil;
import util.*;

public class VectropyRoom extends GameRoom
{
Expand Down Expand Up @@ -58,7 +55,7 @@ public void updateScreenForChallengeOrIllegal()
@Override
public void saveModeSpecificVariablesForReplay()
{
replay.putInt(Registry.REPLAY_INT_GAME_MODE, GameConstants.GAME_MODE_VECTROPY_ONLINE);
replay.putInt(Registry.REPLAY_INT_GAME_MODE, ReplayConstants.GAME_MODE_VECTROPY_ONLINE);
replayDialog.roundAdded();
}

Expand Down
1 change: 0 additions & 1 deletion client/src/main/java/screen/EntropyScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import object.EntropyBid;
import util.CardsUtil;
import util.EntropyUtil;
import util.GameConstants;
import util.Registry;

public class EntropyScreen extends GameScreen
Expand Down
1 change: 0 additions & 1 deletion client/src/main/java/screen/PreferencesPanelGameplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import game.GameMode;
import util.Debug;
import util.GameConstants;

public class PreferencesPanelGameplay extends AbstractPreferencesPanel
implements ChangeListener,
Expand Down
1 change: 0 additions & 1 deletion client/src/main/java/screen/PreferencesPanelPlayers.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import util.CpuStrategies;
import util.Debug;
import util.DialogUtil;
import util.GameConstants;
import util.TableUtil;
import util.TableUtil.DefaultModel;

Expand Down
19 changes: 6 additions & 13 deletions client/src/main/java/screen/ReplayDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@
import object.PlayerLabel;
import online.screen.GameRoom;
import online.screen.OnlineChatPanel;
import util.CardsUtil;
import util.Debug;
import util.DialogUtil;
import util.GameConstants;
import util.GameUtil;
import util.Registry;
import util.ReplayFileUtil;
import util.VectropyUtil;
import util.*;

public class ReplayDialog extends JFrame
implements ActionListener,
Expand Down Expand Up @@ -449,7 +442,7 @@ private void setSizeAndChatVisibility()
{
moonFilter.setVisible(includeMoons);
starFilter.setVisible(includeStars);
boolean online = mode == GameConstants.GAME_MODE_ENTROPY_ONLINE || mode == GameConstants.GAME_MODE_VECTROPY_ONLINE;
boolean online = ReplayFileUtil.isOnline(mode);
chatPanel.setVisible(online);

if (online)
Expand Down Expand Up @@ -700,12 +693,12 @@ private void showResult(int suitCode)
{
switch (mode)
{
case GameConstants.GAME_MODE_ENTROPY:
case GameConstants.GAME_MODE_ENTROPY_ONLINE:
case ReplayConstants.GAME_MODE_ENTROPY:
case ReplayConstants.GAME_MODE_ENTROPY_ONLINE:
showEntropyResult(suitCode);
break;
case GameConstants.GAME_MODE_VECTROPY:
case GameConstants.GAME_MODE_VECTROPY_ONLINE:
case ReplayConstants.GAME_MODE_VECTROPY:
case ReplayConstants.GAME_MODE_VECTROPY_ONLINE:
showVectropyResult(suitCode);
break;
default:
Expand Down
1 change: 0 additions & 1 deletion client/src/main/java/screen/VectropyScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import object.VectropyBid;
import util.AchievementsUtil;
import util.Debug;
import util.GameConstants;
import util.Registry;
import util.VectropyUtil;

Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/util/AchievementsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ else if (gameMode == GameMode.Vectropy)
updateStreaksForWin();
unlockWinningStreakAchievements();

if (GameUtil.isEntropy(gameMode))
if (gameMode == GameMode.Entropy)
{
unlockEntropyWinAchievements();
}
Expand Down
56 changes: 17 additions & 39 deletions client/src/main/java/util/ApiUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package util;

import game.GameMode;
import object.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import javax.swing.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -13,20 +20,6 @@
import java.util.Iterator;
import java.util.Map;

import javax.swing.JOptionPane;

import object.ApiStrategy;
import object.Bid;
import object.ChallengeBid;
import object.EntropyBid;
import object.IllegalBid;
import object.Player;
import object.VectropyBid;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class ApiUtil implements Registry
{
public static final String API_PREFIX = "API: ";
Expand All @@ -44,7 +37,7 @@ public static void sendTestMessage(int port, boolean xml)
{
if (!xml)
{
DialogUtil.showError("JSON is currently unsupported.");
DialogUtilNew.showError("JSON is currently unsupported.");
return;
}

Expand Down Expand Up @@ -96,7 +89,7 @@ private static String sendWithCatch(String messageString, int port, boolean logg
{
Debug.append("Caught " + t.getMessage() + " sending message via API.");
String question = "An error occurred connecting to the third party software.\n\nRetry?";
int option = DialogUtil.showQuestion(question, false);
int option = DialogUtilNew.showQuestion(question, false);
if (option == JOptionPane.YES_OPTION)
{
sendWithCatch(messageString, port, logging, testMode);
Expand All @@ -115,7 +108,7 @@ else if (!testMode)
}

Debug.stackTrace(t);
DialogUtil.showError("A severe error occurred communicating with the third party software. "
DialogUtilNew.showError("A severe error occurred communicating with the third party software. "
+ "\n\nLogs have been sent for investigation.");

saveStrategyErrorAndUnsetStrategies(apiStrategy, "A severe error occurred communicating with the third party software.");
Expand Down Expand Up @@ -146,7 +139,7 @@ private static String factoryXmlApiMessage(StrategyParms parms, Player player)
Document document = XmlUtil.factoryNewDocument();
Element rootElement = document.createElement(ROOT_TAG_API_MESSAGE);

int gameMode = parms.getGameMode();
GameMode gameMode = parms.getGameMode();
int totalCards = parms.getTotalNumberOfCards();
int jokerQuantity = parms.getJokerQuantity();
int jokerValue = parms.getJokerValue();
Expand All @@ -155,15 +148,8 @@ private static String factoryXmlApiMessage(StrategyParms parms, Player player)
boolean negativeJacks = parms.getNegativeJacks();
boolean cardReveal = parms.getCardReveal();
Bid lastBid = parms.getLastBid();

if (gameMode == GameConstants.GAME_MODE_ENTROPY)
{
rootElement.setAttribute("GameMode", "Entropy");
}
else if (gameMode == GameConstants.GAME_MODE_VECTROPY)
{
rootElement.setAttribute("GameMode", "Vectropy");
}

rootElement.setAttribute("GameMode", gameMode.name());

String[] playerHand = player.getHand();
Element handElement = document.createElement("PlayerHand");
Expand Down Expand Up @@ -229,14 +215,6 @@ else if (gameMode == GameConstants.GAME_MODE_VECTROPY)

private static String factoryJsonApiMessage(StrategyParms parms, Player player)
{
/*Gson gson = new Gson();
String json = gson.toJson(parms);
Debug.append("JSON parms: " + json);
return json;*/


if (parms == null
|| player == null)
{
Expand Down Expand Up @@ -285,8 +263,8 @@ private static Bid factoryBid(StrategyParms parms, Element root, String response
{
try
{
int gameMode = parms.getGameMode();
if (gameMode == GameConstants.GAME_MODE_ENTROPY)
GameMode gameMode = parms.getGameMode();
if (gameMode == GameMode.Entropy)
{
return EntropyBid.factoryFromXmlTag(root);
}
Expand All @@ -303,7 +281,7 @@ private static Bid factoryBid(StrategyParms parms, Element root, String response

saveStrategyErrorAndUnsetStrategies(apiStrategy, message);

DialogUtil.showError(message);
DialogUtilNew.showError(message);
return null;
}
}
Expand All @@ -316,7 +294,7 @@ private static void showMalformedResponseError(String response)
saveStrategyErrorAndUnsetStrategies(apiStrategy, message);

message += "\n\nRefer to the API documentation to see the responses that are accepted.";
DialogUtil.showError(message);
DialogUtilNew.showError(message);
}

private static void initialiseStrategyHashMap()
Expand Down
12 changes: 0 additions & 12 deletions client/src/main/java/util/DialogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ public static void showError(String errorText)
JOptionPane.showMessageDialog(null, errorText, "Error", JOptionPane.ERROR_MESSAGE);
}

public static void showInfoLater(final String infoText)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
showInfo(infoText);
}
});
}

public static void invokeInfoLaterAndWait(final String infoText)
{
try
Expand Down
41 changes: 8 additions & 33 deletions client/src/main/java/util/GameUtil.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package util;

import java.net.URL;
import java.util.List;

import javax.swing.ImageIcon;

import object.Bid;
import object.EntropyBid;
import object.Player;
import screen.HandPanelMk2;

import javax.swing.*;
import java.net.URL;
import java.util.List;

public class GameUtil
{
public static int getWinningPlayer(int playerCards, int opponentOneCards, int opponentTwoCards, int opponentThreeCards)
Expand Down Expand Up @@ -39,16 +36,16 @@ public static void showResultDialog(int winningPlayer, HandPanelMk2 handPanel)
switch (winningPlayer)
{
case 0:
DialogUtil.showInfo("You won!");
DialogUtilNew.showInfo("You won!");
return;
case 1:
DialogUtil.showInfo(handPanel.getOpponentOneName() + " won!");
DialogUtilNew.showInfo(handPanel.getOpponentOneName() + " won!");
return;
case 2:
DialogUtil.showInfo(handPanel.getOpponentTwoName() + " won!");
DialogUtilNew.showInfo(handPanel.getOpponentTwoName() + " won!");
return;
case 3:
DialogUtil.showInfo(handPanel.getOpponentThreeName() + " won!");
DialogUtilNew.showInfo(handPanel.getOpponentThreeName() + " won!");
return;
default:
Debug.stackTrace("Unexpected winningPlayer [" + winningPlayer + "]");
Expand Down Expand Up @@ -103,28 +100,6 @@ public static int getNextPlayer(int currentPlayer)
}
}

public static boolean isEntropy(int mode)
{
return mode == GameConstants.GAME_MODE_ENTROPY || mode == GameConstants.GAME_MODE_ENTROPY_ONLINE;
}

public static boolean isOnline(int mode)
{
return mode == GameConstants.GAME_MODE_ENTROPY_ONLINE || mode == GameConstants.GAME_MODE_VECTROPY_ONLINE;
}

public static Bid getEmptyBid(int mode, boolean includeMoons, boolean includeStars)
{
if (isEntropy(mode))
{
return new EntropyBid(0, 0);
}
else
{
return VectropyUtil.getEmptyBid(includeMoons, includeStars);
}
}

public static void populateHand(Player playerToPopulate, List<String> deck, boolean logging)
{
String hand = "";
Expand Down
3 changes: 2 additions & 1 deletion client/src/main/java/util/ReplayConverterVersion0.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package util;

import game.GameMode;
import object.Bid;
import object.ChallengeBid;
import object.EntropyBid;
Expand Down Expand Up @@ -61,7 +62,7 @@ private static String convertBidStr(String bidStr, int gameMode, boolean include
{
try
{
boolean entropy = GameUtil.isEntropy(gameMode);
boolean entropy = ReplayConstants.toGameMode(gameMode) == GameMode.Entropy;

int colorTagIndex = bidStr.indexOf("\"");
int closingQuoteIndex = bidStr.indexOf("\"", colorTagIndex + 1);
Expand Down
Loading

0 comments on commit 43ae95b

Please sign in to comment.