From c40c2d194b72b4d9a71d05b48baaf458e405f84a Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Sat, 28 Jul 2018 09:50:31 -0700 Subject: [PATCH] Add option to disable fill-in-the-blank cards entirely. --- WebContent/game.jsp | 32 +++++++++++++------ build.properties.example | 2 ++ .../filtered-resources/WEB-INF/pyx.properties | 1 + .../java/net/socialgamer/cah/CahModule.java | 13 ++++++++ .../java/net/socialgamer/cah/data/Game.java | 8 +++-- .../socialgamer/cah/data/GameManagerTest.java | 12 ++++--- .../net/socialgamer/cah/data/GameTest.java | 2 +- 7 files changed, 52 insertions(+), 18 deletions(-) diff --git a/WebContent/game.jsp b/WebContent/game.jsp index c8eec14..4c23221 100644 --- a/WebContent/game.jsp +++ b/WebContent/game.jsp @@ -28,12 +28,22 @@ created for the user now. @author Andy Janata (ajanata@socialgamer.net) --%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +<%@ page import="com.google.inject.Injector" %> +<%@ page import="com.google.inject.Key" %> +<%@ page import="com.google.inject.TypeLiteral" %> <%@ page import="javax.servlet.http.HttpSession" %> +<%@ page import="net.socialgamer.cah.CahModule.AllowBlankCards" %> +<%@ page import="net.socialgamer.cah.RequestWrapper" %> +<%@ page import="net.socialgamer.cah.StartupUtils" %> <%@ page import="net.socialgamer.cah.data.GameOptions" %> <% // Ensure a session exists for the user. @SuppressWarnings("unused") HttpSession hSession = request.getSession(true); +RequestWrapper wrapper = new RequestWrapper(request); +ServletContext servletContext = pageContext.getServletContext(); +Injector injector = (Injector) servletContext.getAttribute(StartupUtils.INJECTOR); +boolean allowBlankCards = injector.getInstance(Key.get(new TypeLiteral(){}, AllowBlankCards.class)); %> @@ -507,16 +517,18 @@ HttpSession hSession = request.getSession(true); -
- + <% if (allowBlankCards) { %> +
+ + <% } %>
gamePermalinkFormatProvider; private final Provider showRoundLinkProvider; private final Provider roundPermalinkFormatProvider; + private final Provider allowBlankCardsProvider; private final long created = System.currentTimeMillis(); private int judgeIndex = 0; @@ -216,7 +218,8 @@ public class Game { final Metrics metrics, @ShowRoundPermalink final Provider showRoundLinkProvider, @RoundPermalinkUrlFormat final Provider roundPermalinkFormatProvider, @ShowGamePermalink final Provider showGameLinkProvider, - @GamePermalinkUrlFormat final Provider gamePermalinkFormatProvider) { + @GamePermalinkUrlFormat final Provider gamePermalinkFormatProvider, + @AllowBlankCards final Provider allowBlankCardsProvider) { this.id = id; this.connectedUsers = connectedUsers; this.gameManager = gameManager; @@ -229,6 +232,7 @@ public class Game { this.roundPermalinkFormatProvider = roundPermalinkFormatProvider; this.showGameLinkProvider = showGameLinkProvider; this.gamePermalinkFormatProvider = gamePermalinkFormatProvider; + this.allowBlankCardsProvider = allowBlankCardsProvider; state = GameState.LOBBY; } @@ -787,7 +791,7 @@ public class Game { } public WhiteDeck loadWhiteDeck(final List cardSets) { - return new WhiteDeck(cardSets, options.blanksInDeck); + return new WhiteDeck(cardSets, allowBlankCardsProvider.get() ? options.blanksInDeck : 0); } public int getRequiredWhiteCardCount() { diff --git a/src/test/java/net/socialgamer/cah/data/GameManagerTest.java b/src/test/java/net/socialgamer/cah/data/GameManagerTest.java index fdf0337..2dd3280 100644 --- a/src/test/java/net/socialgamer/cah/data/GameManagerTest.java +++ b/src/test/java/net/socialgamer/cah/data/GameManagerTest.java @@ -50,6 +50,7 @@ import com.google.inject.Injector; import com.google.inject.Provider; import com.google.inject.Provides; +import net.socialgamer.cah.CahModule.AllowBlankCards; import net.socialgamer.cah.CahModule.GamePermalinkUrlFormat; import net.socialgamer.cah.CahModule.RoundPermalinkUrlFormat; import net.socialgamer.cah.CahModule.ShowGamePermalink; @@ -121,6 +122,7 @@ public class GameManagerTest { bind(String.class).annotatedWith(RoundPermalinkUrlFormat.class).toProvider(formatProvider); bind(Boolean.class).annotatedWith(ShowGamePermalink.class).toProvider(falseProvider); bind(String.class).annotatedWith(GamePermalinkUrlFormat.class).toProvider(formatProvider); + bind(Boolean.class).annotatedWith(AllowBlankCards.class).toProvider(falseProvider); } @Provides @@ -171,15 +173,15 @@ public class GameManagerTest { assertEquals(0, gameManager.get().intValue()); gameManager.getGames().put(0, new Game(0, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider, - formatProvider, falseProvider, formatProvider)); + formatProvider, falseProvider, formatProvider, falseProvider)); assertEquals(1, gameManager.get().intValue()); gameManager.getGames().put(1, new Game(1, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider, - formatProvider, falseProvider, formatProvider)); + formatProvider, falseProvider, formatProvider, falseProvider)); assertEquals(2, gameManager.get().intValue()); gameManager.getGames().put(2, new Game(2, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider, - formatProvider, falseProvider, formatProvider)); + formatProvider, falseProvider, formatProvider, falseProvider)); // make sure it says it can't make any more assertEquals(-1, gameManager.get().intValue()); @@ -189,7 +191,7 @@ public class GameManagerTest { assertEquals(1, gameManager.get().intValue()); gameManager.getGames().put(1, new Game(1, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider, - formatProvider, falseProvider, formatProvider)); + formatProvider, falseProvider, formatProvider, falseProvider)); assertEquals(-1, gameManager.get().intValue()); // remove game 1 out from under it, to make sure it'll fix itself @@ -197,7 +199,7 @@ public class GameManagerTest { assertEquals(1, gameManager.get().intValue()); gameManager.getGames().put(1, new Game(1, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider, - formatProvider, falseProvider, formatProvider)); + formatProvider, falseProvider, formatProvider, falseProvider)); assertEquals(-1, gameManager.get().intValue()); gameManager.destroyGame(2); diff --git a/src/test/java/net/socialgamer/cah/data/GameTest.java b/src/test/java/net/socialgamer/cah/data/GameTest.java index 8ec244f..bccea41 100644 --- a/src/test/java/net/socialgamer/cah/data/GameTest.java +++ b/src/test/java/net/socialgamer/cah/data/GameTest.java @@ -79,7 +79,7 @@ public class GameTest { gmMock = createMock(GameManager.class); metricsMock = createMock(Metrics.class); game = new Game(0, cuMock, gmMock, timer, null, null, null, metricsMock, falseProvider, - formatProvider, falseProvider, formatProvider); + formatProvider, falseProvider, formatProvider, falseProvider); } @SuppressWarnings("unchecked")