Skip to content

Commit

Permalink
purge last of the achievement references
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Oct 24, 2024
1 parent 8a25b2e commit 6731a13
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 92 deletions.
4 changes: 2 additions & 2 deletions client/src/main/java/screen/ClearDataDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ private void clearData()
{
return;
}
RegistryUtil.clearNode(achievements);

achievementStore.clear();
RegistryUtil.clearNode(rewards);
RegistryUtil.clearNode(savedGame);
resetPreferences();
Expand Down
9 changes: 5 additions & 4 deletions client/src/main/java/screen/GameScreen.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package screen;

import achievement.AchievementSetting;
import game.GameMode;
import object.Bid;
import object.ChallengeBid;
Expand All @@ -11,6 +12,7 @@
import java.util.Timer;
import java.util.*;

import static util.ClientGlobals.achievementStore;
import static utils.CoreGlobals.logger;

public abstract class GameScreen extends TransparentPanel
Expand Down Expand Up @@ -181,10 +183,9 @@ protected void initVariablesForNewGame()
firstRound = true;

//variables to use for perfect game achievements
int opponentTwoCoeff = opponentTwo.isEnabled()? 1:0;
int opponentThreeCoeff = opponentThree.isEnabled()? 1:0;
achievements.putInt(ACHIEVEMENTS_INT_OPPONENT_TWO_COEFF, opponentTwoCoeff);
achievements.putInt(ACHIEVEMENTS_INT_OPPONENT_THREE_COEFF, opponentThreeCoeff);
var allPlayers = new Player[]{player, opponentOne, opponentTwo, opponentThree};
var playerCount = Arrays.stream(allPlayers).filter(Player::isEnabled).count();
achievementStore.save(AchievementSetting.PlayerCount, playerCount);

bidPanel.showBidPanel(true);
setRandomPersonToStart();
Expand Down
118 changes: 53 additions & 65 deletions client/src/main/java/util/AchievementsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import object.Bid;
import object.Player;
import online.screen.GameRoom;
import org.w3c.dom.Element;
import screen.RewardDialog;
import screen.ScreenCache;
import utils.Achievement;
Expand Down Expand Up @@ -149,14 +148,11 @@ public static void checkForPerfectGame(int numberOfRounds, int cards)
return;
}

int opponentTwoCoeff = achievements.getInt(ACHIEVEMENTS_INT_OPPONENT_TWO_COEFF, 1);
int opponentThreeCoeff = achievements.getInt(ACHIEVEMENTS_INT_OPPONENT_THREE_COEFF, 1);
int totalPlayers = 2 + opponentTwoCoeff + opponentThreeCoeff;

unlockPerfectGameAchievements(numberOfRounds, totalPlayers);
long playerCount = achievementStore.get(AchievementSetting.PlayerCount);
unlockPerfectGameAchievements(numberOfRounds, playerCount);
}

public static void unlockPerfectGameAchievements(int numberOfRounds, int totalPlayers)
public static void unlockPerfectGameAchievements(int numberOfRounds, long totalPlayers)
{
if (numberOfRounds == 5)
{
Expand All @@ -181,14 +177,11 @@ public static void checkForFullBlindGame(int cards, boolean playedBlind, boolean
return;
}

int opponentTwoCoeff = achievements.getInt(ACHIEVEMENTS_INT_OPPONENT_TWO_COEFF, 1);
int opponentThreeCoeff = achievements.getInt(ACHIEVEMENTS_INT_OPPONENT_THREE_COEFF, 1);
int totalPlayers = 2 + opponentTwoCoeff + opponentThreeCoeff;

unlockFullBlindGameAchievements(totalPlayers, playedBlind, hasLookedAtCards, cardReveal);
long playerCount = achievementStore.get(AchievementSetting.PlayerCount);
unlockFullBlindGameAchievements(playerCount, playedBlind, hasLookedAtCards, cardReveal);
}

public static void unlockFullBlindGameAchievements(int totalPlayers, boolean playedBlind, boolean hasLookedAtCards,
public static void unlockFullBlindGameAchievements(long totalPlayers, boolean playedBlind, boolean hasLookedAtCards,
boolean cardReveal)
{
boolean fullyBlind = playedBlind && !hasLookedAtCards;
Expand Down Expand Up @@ -222,12 +215,9 @@ public static void unlockNuclearStrike(int myCards, int opponentCards, boolean p
{
return;
}

int opponentTwoCoeff = achievements.getInt(ACHIEVEMENTS_INT_OPPONENT_TWO_COEFF, 1);
int opponentThreeCoeff = achievements.getInt(ACHIEVEMENTS_INT_OPPONENT_THREE_COEFF, 1);
int totalPlayers = 2 + opponentTwoCoeff + opponentThreeCoeff;

if (totalPlayers == 4

long playerCount = achievementStore.get(AchievementSetting.PlayerCount);
if (playerCount == 4
&& playedBlind
&& !hasLookedAtCards
&& !cardReveal)
Expand All @@ -243,20 +233,17 @@ public static void unlockHandicapAchievements(int myCards, int opponentCards)
{
return;
}

int opponentTwoCoeff = achievements.getInt(ACHIEVEMENTS_INT_OPPONENT_TWO_COEFF, 1);
int opponentThreeCoeff = achievements.getInt(ACHIEVEMENTS_INT_OPPONENT_THREE_COEFF, 1);
int totalPlayers = 2 + opponentTwoCoeff + opponentThreeCoeff;

if (totalPlayers == 2)

long playerCount = achievementStore.get(AchievementSetting.PlayerCount);
if (playerCount == 2)
{
unlockAchievement(Achievement.HandicapTwo);
}
else if (totalPlayers == 3)
else if (playerCount == 3)
{
unlockAchievement(Achievement.HandicapThree);
}
else if (totalPlayers == 4)
else if (playerCount == 4)
{
unlockAchievement(Achievement.HandicapFour);
}
Expand Down Expand Up @@ -489,45 +476,46 @@ private static void unlockIfRequired(int achievementsEarned, int threshold, Stri

public static void updateAndUnlockSocial(ConcurrentHashMap<Integer, Player> hmPlayerByAdjustedPlayerNumber)
{
String achievementsList = achievements.get(ACHIEVEMENTS_STRING_SOCIAL_LIST, "");

for (int i=0; i<4; i++)
{
Player player = hmPlayerByAdjustedPlayerNumber.get(i);
if (player == null)
{
continue;
}

String username = player.getName();
if (!username.isEmpty()
&& !containsExact(achievementsList, username))
{
achievementsList += username;
achievementsList += ";";
}
}

achievements.put(ACHIEVEMENTS_STRING_SOCIAL_LIST, achievementsList);

String[] usernames = achievementsList.split(";");
int size = usernames.length;
if (size >= SOCIAL_THRESHOLD)
{
unlockSocial();
}
}

private static boolean containsExact(String socialStr, String username)
{
return socialStr.startsWith(username + ";")
|| socialStr.contains(";" + username + ";");
}

private static void unlockSocial()
{
unlockAchievement(Achievement.Social);
// TODO - Rethink this
// String achievementsList = achievements.get(ACHIEVEMENTS_STRING_SOCIAL_LIST, "");
//
// for (int i=0; i<4; i++)
// {
// Player player = hmPlayerByAdjustedPlayerNumber.get(i);
// if (player == null)
// {
// continue;
// }
//
// String username = player.getName();
// if (!username.isEmpty()
// && !containsExact(achievementsList, username))
// {
// achievementsList += username;
// achievementsList += ";";
// }
// }
//
// achievements.put(ACHIEVEMENTS_STRING_SOCIAL_LIST, achievementsList);
//
// String[] usernames = achievementsList.split(";");
// int size = usernames.length;
// if (size >= SOCIAL_THRESHOLD)
// {
// unlockSocial();
// }
}

// private static boolean containsExact(String socialStr, String username)
// {
// return socialStr.startsWith(username + ";")
// || socialStr.contains(";" + username + ";");
// }
//
// private static void unlockSocial()
// {
// unlockAchievement(Achievement.Social);
// }

public static void unlockKonamiCode()
{
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/kotlin/MainUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import logging.KEY_OPERATING_SYSTEM
import logging.KEY_USERNAME
import util.ClientGlobals
import util.ClientUtil
import util.CoreRegistry.INSTANCE_STRING_DEVICE_ID
import util.CoreRegistry.instance
import util.OnlineConstants
import util.Registry.INSTANCE_STRING_DEVICE_ID
import util.Registry.instance
import utils.CoreGlobals
import utils.CoreGlobals.logger
import utils.getUsername
Expand Down
1 change: 1 addition & 0 deletions client/src/main/kotlin/achievement/AchievementSetting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ object AchievementSetting {
val BookwormTime = Setting("bookwormTime", 0L)
val VanityCount = Setting("vanityCount", 0)
val ChattyCount = Setting("chattyCount", 0)
@JvmField val PlayerCount = Setting("playerCount", 0L)
@JvmField val TimePlayed = Setting("timePlayed", 0L)
@JvmField val WillUnlockCoward = Setting("willUnlockCoward", false)
@JvmField val BestStreak = Setting("bestStreak", 0)
Expand Down
2 changes: 2 additions & 0 deletions client/src/main/kotlin/preference/AbstractSettingStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ abstract class AbstractSettingStore {

abstract fun <T : Any> delete(setting: Setting<T>)

abstract fun clear()

protected abstract fun <T> findRaw(setting: Setting<T>): String?

protected abstract fun <T : Any> saveRaw(setting: Setting<T>, value: String)
Expand Down
4 changes: 4 additions & 0 deletions client/src/main/kotlin/preference/DefaultSettingStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import java.util.prefs.Preferences
class DefaultSettingStore(nodeName: String) : AbstractSettingStore() {
private val preferences = Preferences.userRoot().node(nodeName)

override fun clear() {
preferences.clear()
}

override fun addPreferenceChangeListener(listener: PreferenceChangeListener) {
preferences.addPreferenceChangeListener(listener)
}
Expand Down
4 changes: 4 additions & 0 deletions client/src/test/kotlin/preference/InMemorySettingStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class InMemorySettingStore : AbstractSettingStore() {
private val hmPreferences = mutableMapOf<String, String>()
private val listeners = mutableListOf<PreferenceChangeListener>()

override fun clear() {
hmPreferences.clear()
}

override fun addPreferenceChangeListener(listener: PreferenceChangeListener) {
listeners.add(listener)
}
Expand Down
11 changes: 0 additions & 11 deletions core/src/main/java/util/CoreRegistry.java

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/main/java/util/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class Debug implements CoreRegistry {
public class Debug {
private static DebugOutput output = null;

private static ThreadFactory loggerFactory = r -> new Thread(r, "Logger");
Expand Down
13 changes: 6 additions & 7 deletions core/src/main/java/util/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
import java.util.prefs.Preferences;


public interface Registry extends CoreRegistry
public interface Registry
{
public static final String NODE_ONLINE_REPLAY = "entropyReplayOnline";

//Actual preference wrappers
public static final Preferences achievements = Preferences.userRoot().node("entropyAchievementsNone");
public static final Preferences savedGame = Preferences.userRoot().node("entropySavedgameNone");
public static final Preferences prefs = Preferences.userRoot().node("entropyPreferencesTuuug");
public static final Preferences rewards = Preferences.userRoot().node("entropyRewardsNone");
public static final Preferences inGameReplay = Preferences.userRoot().node("entropyReplayCurrent");
public static final Preferences fileReplay = Preferences.userRoot().node("entropyReplayFile");
public static final Preferences tempReplayStore = Preferences.userRoot().node("entropyTemp");
public static final Preferences instance = Preferences.userRoot().node("entropyInstance");

// instance
public static final String INSTANCE_INT_REPLAY_CONVERSION = "replayConversion";
public static final String INSTANCE_STRING_DEVICE_ID = "deviceId";

//prefs
public static final String PREFERENCES_STRING_REPLAY_DIRECTORY = "replayDirectory";
Expand Down Expand Up @@ -120,11 +124,6 @@ public interface Registry extends CoreRegistry
public static final String REPLAY_INT_PLAYER_WON = "playerWon";
public static final String REPLAY_INT_GAME_MODE = "gameMode";

//Achievement variables, counters etc
public static final String ACHIEVEMENTS_STRING_SOCIAL_LIST = "socialList";
public static final String ACHIEVEMENTS_INT_OPPONENT_TWO_COEFF = "opponentTwoWasEnabled";
public static final String ACHIEVEMENTS_INT_OPPONENT_THREE_COEFF = "opponentThreeWasEnabled";

//rewards
public static final String REWARDS_BOOLEAN_FOUR_COLOURS = "fourColours";
//public static final String REWARDS_BOOLEAN_JOKERS = "jokers";
Expand Down

0 comments on commit 6731a13

Please sign in to comment.