Removed commands and added buttons in game options + fixed minor NPE
This commit is contained in:
parent
2c56cda65d
commit
8bf269ca5b
|
@ -481,6 +481,13 @@ boolean allowBlankCards = injector.getInstance(Key.get(new TypeLiteral<Boolean>(
|
||||||
<span class="base_card_sets"></span>
|
<span class="base_card_sets"></span>
|
||||||
<span class="extra_card_sets"></span>
|
<span class="extra_card_sets"></span>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Custom Card Sets</legend>
|
||||||
|
<input type="button" class="add_custom_deck_json" value="Upload JSON"/>
|
||||||
|
<input type="button" class="add_custom_deck_url" value="Download from URL"/>
|
||||||
|
|
||||||
|
<input id="file-input" type="file" accept="application/json" style="display: none;"/>
|
||||||
|
</fieldset>
|
||||||
<% if (allowBlankCards) { %>
|
<% if (allowBlankCards) { %>
|
||||||
<br/>
|
<br/>
|
||||||
<label id="blanks_limit_label" title="Blank cards allow a player to type in their own answer.">
|
<label id="blanks_limit_label" title="Blank cards allow a player to type in their own answer.">
|
||||||
|
|
|
@ -213,22 +213,6 @@ function chatsubmit_click(game_id, parent_element) {
|
||||||
case 'names':
|
case 'names':
|
||||||
ajax = cah.Ajax.build(cah.$.AjaxOperation.NAMES);
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.NAMES);
|
||||||
break;
|
break;
|
||||||
case 'addcustomdeck_json':
|
|
||||||
if (game_id !== null) {
|
|
||||||
ajax = cah.Ajax.build(cah.$.AjaxOperation.ADD_CARDSET)
|
|
||||||
.withCustomDeckJson(text).withGameId(game_id);
|
|
||||||
} else {
|
|
||||||
cah.log.error("This command only works in a game.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'addcustomdeck_url':
|
|
||||||
if (game_id !== null) {
|
|
||||||
ajax = cah.Ajax.build(cah.$.AjaxOperation.ADD_CARDSET)
|
|
||||||
.withCustomDeckUrl(text).withGameId(game_id);
|
|
||||||
} else {
|
|
||||||
cah.log.error("This command only works in a game.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'removecustomdeck':
|
case 'removecustomdeck':
|
||||||
if (game_id !== null) {
|
if (game_id !== null) {
|
||||||
ajax = cah.Ajax.build(cah.$.AjaxOperation.REMOVE_CARDSET).withCustomDeckId(parseInt(text.split(' ')[0]))
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.REMOVE_CARDSET).withCustomDeckId(parseInt(text.split(' ')[0]))
|
||||||
|
|
|
@ -305,6 +305,8 @@ cah.Game = function(id) {
|
||||||
$(".confirm_card", this.element_).click(cah.bind(this, this.confirmClick_));
|
$(".confirm_card", this.element_).click(cah.bind(this, this.confirmClick_));
|
||||||
$(".game_show_last_round", this.element_).click(cah.bind(this, this.showLastRoundClick_));
|
$(".game_show_last_round", this.element_).click(cah.bind(this, this.showLastRoundClick_));
|
||||||
$(".game_show_options", this.element_).click(cah.bind(this, this.showOptionsClick_));
|
$(".game_show_options", this.element_).click(cah.bind(this, this.showOptionsClick_));
|
||||||
|
$(".add_custom_deck_json", this.element_).click(cah.bind(this, this.addCustomDeckJson_));
|
||||||
|
$(".add_custom_deck_url", this.element_).click(cah.bind(this, this.addCustomDeckUrl_));
|
||||||
$("select", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
$("select", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
||||||
$("input", this.optionsElement_).blur(cah.bind(this, this.optionChanged_));
|
$("input", this.optionsElement_).blur(cah.bind(this, this.optionChanged_));
|
||||||
$(".timer_multiplier", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
$(".timer_multiplier", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
||||||
|
@ -1479,6 +1481,38 @@ cah.Game.prototype.updateOptionsEnabled_ = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload custom deck with a given URL.
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
cah.Game.prototype.addCustomDeckUrl_ = function(e) {
|
||||||
|
var url = prompt("Insert a valid URL pointing to the deck.");
|
||||||
|
cah.Ajax.build(cah.$.AjaxOperation.ADD_CARDSET).withGameId(this.id_).withCustomDeckUrl(url).run();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload custom deck from JSON.
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
cah.Game.prototype.addCustomDeckJson_ = function(e) {
|
||||||
|
var gid = this.id_;
|
||||||
|
var file_input = $('#file-input')[0];
|
||||||
|
file_input.onchange = function (ee) {
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.readAsText(ee.target.files[0],'UTF-8');
|
||||||
|
reader.onload = readerEvent => {
|
||||||
|
var content = readerEvent.target.result;
|
||||||
|
cah.Ajax.build(cah.$.AjaxOperation.ADD_CARDSET).withGameId(gid).withCustomDeckJson(content).run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_input.click();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event handler for changing an option.
|
* Event handler for changing an option.
|
||||||
*
|
*
|
||||||
|
|
|
@ -90,6 +90,8 @@ public class CustomCardsService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String content = getUrlContent(url);
|
String content = getUrlContent(url);
|
||||||
|
if (content == null) return null;
|
||||||
|
|
||||||
return loadSetFromJson(content, url);
|
return loadSetFromJson(content, url);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
putCache(null, INVALID_SET_CACHE_LIFETIME, url, null);
|
putCache(null, INVALID_SET_CACHE_LIFETIME, url, null);
|
||||||
|
|
Loading…
Reference in New Issue