PC Errata conversion button

- Added a new button in the deckbuilder that converts all cards currently in the deck to applicable PC errata.  It is disabled outside of PC formats (and Anything Goes) and enabled for a single usage otherwise.
- Optimized card filter a bit so it isn't calling the card collection quite so often during format switching
This commit is contained in:
Christian 'ketura' McCarty
2024-11-16 20:45:12 -06:00
parent 1d8f55c037
commit 8d755b8726
4 changed files with 49 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import com.gempukku.lotro.async.ResponseWriter;
import com.gempukku.lotro.common.JSONDefs;
import com.gempukku.lotro.common.Side;
import com.gempukku.lotro.db.DeckDAO;
import com.gempukku.lotro.db.DeckSerialization;
import com.gempukku.lotro.draft2.SoloDraftDefinitions;
import com.gempukku.lotro.game.*;
import com.gempukku.lotro.game.formats.LotroFormatLibrary;
@@ -77,7 +78,9 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
getDeckStats(request, responseWriter);
} else if (uri.equals("/formats") && request.method() == HttpMethod.POST) {
getAllFormats(request, responseWriter);
} else {
} else if (uri.equals("/convert") && request.method() == HttpMethod.POST) {
convertErrata(request, responseWriter);
}else {
throw new HttpProcessingException(404);
}
}
@@ -444,6 +447,24 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
responseWriter.writeXmlResponse(serializeDeck(resourceOwner, deckName));
}
private void convertErrata(HttpRequest request, ResponseWriter responseWriter) throws IOException, HttpProcessingException, ParserConfigurationException {
HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request);
try {
String participantId = getFormParameterSafely(postDecoder, "participantId");
Player resourceOwner = getResourceOwnerSafely(request, participantId);
String targetFormat = getFormParameterSafely(postDecoder, "targetFormat");
String contents = getFormParameterSafely(postDecoder, "deckContents");
var format = validateFormat(targetFormat);
var originalDeck = DeckSerialization.buildDeckFromContents("", contents, format.getName(), "");
responseWriter.writeXmlResponse(serializeDeck(format.applyErrata(originalDeck)));
} finally {
postDecoder.destroy();
}
}
private void getLibraryDeck(HttpRequest request, ResponseWriter responseWriter) throws HttpProcessingException, ParserConfigurationException {
QueryStringDecoder queryDecoder = new QueryStringDecoder(request.uri());
String deckName = getQueryParameterSafely(queryDecoder, "deckName");

View File

@@ -95,6 +95,10 @@
<button id="deckListBut" title="Deck list" class="menu-button">
<span class="ui-icon ui-icon-suitcase"></span>
</button>
<button id="convertErrataBut" title="Convert to PC Errata" class="menu-button">
<span class="ui-icon ui-icon-transferthick-e-w"></span>
</button>
<select id="formatSelect" style="float: right; width: 200px;">
<option value="rev_tow_sta">Anything Goes</option>

View File

@@ -99,7 +99,7 @@ var CardFilter = Class.extend({
this.filter = this.calculateDeckFilter(this.overrideFilter);
this.start = 0;
$("#resetAllFiltersButton").click();
this.getCollection();
this.filterChanged();
},
setType: function (typeValue) {
@@ -495,10 +495,10 @@ var CardFilter = Class.extend({
$("#culture2").hide();
this.setSelect.change(() => this.setFilterChanged(that));
this.nameInput.change(this.fullFilterChanged);
this.gametextInput.change(this.fullFilterChanged);
this.sortSelect.change(this.fullFilterChanged);
this.raritySelect.change(this.fullFilterChanged);
this.nameInput.change(this.filterChanged);
this.gametextInput.change(this.filterChanged);
this.sortSelect.change(this.filterChanged);
this.raritySelect.change(this.filterChanged);
// Hide initially hidden fields
$("#twilightValueInput").prop("hidden", true);
@@ -521,7 +521,7 @@ var CardFilter = Class.extend({
", #siteNumberCompareSelect, #siteNumberValueInput" +
", #resistanceCompareSelect, #resistanceValueInput").val('').trigger('change');
that.pauseUpdates = false;
that.fullFilterChanged();
that.filterChanged();
// $("#labelDWARVEN, #labelELVEN, #labelGANDALF, #labelGONDOR, #labelROHAN, #labelSHIRE" +
// ", #labelGOLLUM, #labelDUNLAND, #labelISENGARD, #labelMORIA, #labelRAIDER, #labelSAURON" +
@@ -546,7 +546,7 @@ var CardFilter = Class.extend({
", #MEN, #ORC, #URUK_HAI, #WRAITH" +
", #ESGAROTH, #GUNDABAD, #MIRKWOOD, #SMAUG, #SPIDER, #TROLL").prop("checked", false).change();
that.pauseUpdates = false;
that.fullFilterChanged();
that.filterChanged();
});
// Triggers for filter fields changed
@@ -650,18 +650,7 @@ var CardFilter = Class.extend({
}
return that.fullFilterChanged();
},
fullFilterChanged: function() {
if(this.initialStartup && !this.pauseUpdates) {
this.filter = this.calculateDeckFilter()
this.start = 0;
this.getCollection();
}
return true;
return that.filterChanged();
},
// Callback function for when the product filter is changed

View File

@@ -528,6 +528,21 @@ var GempLotrCommunication = Class.extend({
dataType:"json"
});
},
convertErrata:function (targetFormat, contents, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/deck/convert",
cache:false,
async:false,
data:{
participantId:getUrlParam("participantId"),
targetFormat:targetFormat,
deckContents:contents},
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
dataType:"xml"
});
},
startChat:function (room, callback, errorMap) {
$.ajax({
type:"GET",