Add game option for using idle timer. Implementation when not using idle timer is it instead uses Integer.MAX_VALUE as the number of milliseconds.
This commit is contained in:
parent
5d26113605
commit
bdf288a379
|
@ -349,6 +349,9 @@ HttpSession hSession = request.getSession(true);
|
|||
</select>
|
||||
Having more than 10 players may get cramped!
|
||||
<br/>
|
||||
<input type="checkbox" checked="checked" id="use_timer_template" class="use_timer" />
|
||||
<label id="use_timer_template_label" for="use_timer_template">Use idle timer</label>
|
||||
<br/>
|
||||
<fieldset class="card_sets">
|
||||
<legend>Card Sets</legend>
|
||||
Select at least one of: <span class="base_card_sets"></span>
|
||||
|
|
|
@ -177,6 +177,17 @@ cah.ajax.Builder.prototype.withPassword = function(password) {
|
|||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean}
|
||||
* useTimer Whether or not the game should use the idle timer.
|
||||
* @returns {cah.ajax.Builder} This object.
|
||||
*/
|
||||
cah.ajax.Builder.prototype.withUseTimer = function(useTimer) {
|
||||
this.assertNotExecuted_();
|
||||
this.data[cah.$.AjaxRequest.USE_TIMER] = useTimer;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean}
|
||||
* wall Whether or not this is a warn-all ("wall").
|
||||
|
|
|
@ -33,6 +33,7 @@ cah.$.AjaxRequest.prototype.dummyForAutocomplete = undefined;
|
|||
cah.$.AjaxRequest.WALL = "wall";
|
||||
cah.$.AjaxRequest.MESSAGE = "m";
|
||||
cah.$.AjaxRequest.CARD_ID = "cid";
|
||||
cah.$.AjaxRequest.USE_TIMER = "ut";
|
||||
cah.$.AjaxRequest.GAME_ID = "gid";
|
||||
cah.$.AjaxRequest.CARD_SETS = "css";
|
||||
cah.$.AjaxRequest.SERIAL = "s";
|
||||
|
@ -175,6 +176,7 @@ cah.$.GameInfo.prototype.dummyForAutocomplete = undefined;
|
|||
cah.$.GameInfo.HOST = "H";
|
||||
cah.$.GameInfo.STATE = "S";
|
||||
cah.$.GameInfo.PLAYERS = "P";
|
||||
cah.$.GameInfo.USE_TIMER = "ut";
|
||||
cah.$.GameInfo.CARD_SETS = "css";
|
||||
cah.$.GameInfo.ID = "gid";
|
||||
cah.$.GameInfo.PLAYER_LIMIT = "pL";
|
||||
|
|
|
@ -86,6 +86,7 @@ cah.Game = function(id) {
|
|||
$("#game_password_template_label", this.optionsElement_).attr("for", "game_password_" + id);
|
||||
$("#game_hide_password_template_label", this.optionsElement_).attr("for",
|
||||
"game_hide_password_" + id);
|
||||
$("#use_timer_template_label", this.optionsElement_).attr("for", "use_timer_" + id);
|
||||
|
||||
$("#score_limit_template", this.optionsElement_).attr("id", "score_limit_" + id);
|
||||
$("#player_limit_template", this.optionsElement_).attr("id", "player_limit_" + id);
|
||||
|
@ -93,6 +94,7 @@ cah.Game = function(id) {
|
|||
$("#game_password_template", this.optionsElement_).attr("id", "game_password_" + id);
|
||||
$("#game_fake_password_template", this.optionsElement_).attr("id", "game_fake_password_" + id);
|
||||
$("#game_hide_password_template", this.optionsElement_).attr("id", "game_hide_password_" + id);
|
||||
$("#use_timer_template", this.optionsElement_).attr("id", "use_timer_" + id);
|
||||
|
||||
for ( var key in cah.CardSet.list) {
|
||||
/** @type {cah.CardSet} */
|
||||
|
@ -283,6 +285,7 @@ cah.Game = function(id) {
|
|||
$(".game_show_options", this.element_).click(cah.bind(this, this.showOptionsClick_));
|
||||
$("select", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
||||
$("input", this.optionsElement_).blur(cah.bind(this, this.optionChanged_));
|
||||
$(".use_timer", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
||||
$(".card_set", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
||||
$(".game_hide_password", this.optionsElement_).click(cah.bind(this, this.showOrHidePassword_));
|
||||
|
||||
|
@ -741,6 +744,11 @@ cah.Game.prototype.updateGameStatus = function(data) {
|
|||
$(".score_limit", this.optionsElement_).val(gameInfo[cah.$.GameInfo.SCORE_LIMIT]);
|
||||
$(".player_limit", this.optionsElement_).val(gameInfo[cah.$.GameInfo.PLAYER_LIMIT]);
|
||||
$(".game_password", this.optionsElement_).val(gameInfo[cah.$.GameInfo.PASSWORD]);
|
||||
if (gameInfo[cah.$.GameInfo.USE_TIMER]) {
|
||||
$(".use_timer", this.optionsElement_).attr("checked", "checked");
|
||||
} else {
|
||||
$(".use_timer", this.optionsElement_).removeAttr("checked");
|
||||
}
|
||||
var cardSetIds = gameInfo[cah.$.GameInfo.CARD_SETS];// .split(',');
|
||||
$(".card_set", this.optionsElement_).removeAttr("checked");
|
||||
for ( var key in cardSetIds) {
|
||||
|
@ -1202,7 +1210,8 @@ cah.Game.prototype.optionChanged_ = function(e) {
|
|||
cah.Ajax.build(cah.$.AjaxOperation.CHANGE_GAME_OPTIONS).withGameId(this.id_).withScoreLimit(
|
||||
$(".score_limit", this.optionsElement_).val()).withPlayerLimit(
|
||||
$(".player_limit", this.optionsElement_).val()).withCardSets(cardSetIds).withPassword(
|
||||
$(".game_password", this.optionsElement_).val()).run();
|
||||
$(".game_password", this.optionsElement_).val()).withUseTimer(
|
||||
!!$('.use_timer', this.optionsElement_).attr('checked')).run();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -210,6 +210,7 @@ public class Constants {
|
|||
PLAYER_LIMIT("pL"),
|
||||
SCORE_LIMIT("sl"),
|
||||
SERIAL("s"),
|
||||
USE_TIMER("ut"),
|
||||
WALL("wall");
|
||||
|
||||
private final String field;
|
||||
|
@ -595,7 +596,9 @@ public class Constants {
|
|||
PLAYERS("P"),
|
||||
@DuplicationAllowed
|
||||
SCORE_LIMIT(AjaxRequest.SCORE_LIMIT),
|
||||
STATE("S");
|
||||
STATE("S"),
|
||||
@DuplicationAllowed
|
||||
USE_TIMER(AjaxRequest.USE_TIMER);
|
||||
|
||||
private final String key;
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ public class Game {
|
|||
private int scoreGoal = 8;
|
||||
private final Set<CardSet> cardSets = new HashSet<CardSet>();
|
||||
private String password = "";
|
||||
private boolean useTimer = true;
|
||||
private final Session hibernateSession;
|
||||
|
||||
/**
|
||||
|
@ -364,15 +365,16 @@ public class Game {
|
|||
return password;
|
||||
}
|
||||
|
||||
public void updateGameSettings(final int scoreLimit, final int playerLimit,
|
||||
final Set<CardSet> cardSets1, final String password1) {
|
||||
this.scoreGoal = scoreLimit;
|
||||
this.maxPlayers = playerLimit;
|
||||
public void updateGameSettings(final int newScoreGoal, final int newMaxPlayers,
|
||||
final Set<CardSet> newCardSets, final String newPassword, final boolean newUseTimer) {
|
||||
this.scoreGoal = newScoreGoal;
|
||||
this.maxPlayers = newMaxPlayers;
|
||||
synchronized (this.cardSets) {
|
||||
this.cardSets.clear();
|
||||
this.cardSets.addAll(cardSets1);
|
||||
this.cardSets.addAll(newCardSets);
|
||||
}
|
||||
this.password = password1;
|
||||
this.password = newPassword;
|
||||
this.useTimer = newUseTimer;
|
||||
|
||||
final HashMap<ReturnableData, Object> data = getEventMap();
|
||||
data.put(LongPollResponse.EVENT, LongPollEvent.GAME_OPTIONS_CHANGED.toString());
|
||||
|
@ -421,6 +423,7 @@ public class Game {
|
|||
info.put(GameInfo.CARD_SETS, cardSetIds);
|
||||
info.put(GameInfo.PLAYER_LIMIT, maxPlayers);
|
||||
info.put(GameInfo.SCORE_LIMIT, scoreGoal);
|
||||
info.put(GameInfo.USE_TIMER, useTimer);
|
||||
if (includePassword) {
|
||||
info.put(GameInfo.PASSWORD, password);
|
||||
}
|
||||
|
@ -638,7 +641,9 @@ public class Game {
|
|||
}
|
||||
}
|
||||
|
||||
final int playTimer = PLAY_TIMEOUT_BASE + (PLAY_TIMEOUT_PER_CARD * blackCard.getPick());
|
||||
// Perhaps figure out a better way to do this...
|
||||
final int playTimer = useTimer ? PLAY_TIMEOUT_BASE
|
||||
+ (PLAY_TIMEOUT_PER_CARD * blackCard.getPick()) : Integer.MAX_VALUE;
|
||||
|
||||
final HashMap<ReturnableData, Object> data = getEventMap();
|
||||
data.put(LongPollResponse.EVENT, LongPollEvent.GAME_STATE_CHANGE.toString());
|
||||
|
@ -824,8 +829,9 @@ public class Game {
|
|||
killRoundTimer();
|
||||
state = GameState.JUDGING;
|
||||
|
||||
final int judgeTimer = JUDGE_TIMEOUT_BASE
|
||||
+ (JUDGE_TIMEOUT_PER_CARD * playedCards.size() * blackCard.getPick());
|
||||
// Perhaps figure out a better way to do this...
|
||||
final int judgeTimer = useTimer ? JUDGE_TIMEOUT_BASE
|
||||
+ (JUDGE_TIMEOUT_PER_CARD * playedCards.size() * blackCard.getPick()) : Integer.MAX_VALUE;
|
||||
|
||||
HashMap<ReturnableData, Object> data = getEventMap();
|
||||
data.put(LongPollResponse.EVENT, LongPollEvent.GAME_STATE_CHANGE.toString());
|
||||
|
|
|
@ -55,7 +55,14 @@ public class ChangeGameOptionHandler extends GameWithPlayerHandler {
|
|||
if (password == null) {
|
||||
password = "";
|
||||
}
|
||||
game.updateGameSettings(scoreLimit, playerLimit, cardSets, password);
|
||||
// We're not directly assigning this with Boolean.valueOf() because we want to default to
|
||||
// true if it isn't specified, though that should never happen.
|
||||
boolean useTimer = true;
|
||||
final String useTimerString = request.getParameter(AjaxRequest.USE_TIMER);
|
||||
if (null != useTimerString && !"".equals(useTimerString)) {
|
||||
useTimer = Boolean.valueOf(useTimerString);
|
||||
}
|
||||
game.updateGameSettings(scoreLimit, playerLimit, cardSets, password, useTimer);
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return error(ErrorCode.BAD_REQUEST);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue