Fixed remembering self-referential choices (#12167)

* Fixed remembering self-referential choices

* Rename filtered message to auto answer message

* Always use auto answer message
This commit is contained in:
Alexander Novotny 2024-04-22 23:58:26 -04:00 committed by GitHub
parent 40143c648f
commit 42906f519b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 6 deletions

View file

@ -89,6 +89,12 @@ public class FeedbackPanel extends javax.swing.JPanel {
// allows yes/no auto-answers for ability related
this.helper.setOriginalId((UUID) options.get(ORIGINAL_ID));
}
if (options != null && options.containsKey(AUTO_ANSWER_MESSAGE)) {
// Uses a filtered message for remembering choice if the original message contains a self-reference
this.helper.setAutoAnswerMessage((String) options.get(AUTO_ANSWER_MESSAGE));
} else {
this.helper.setAutoAnswerMessage(message);
}
break;
case CONFIRM:
setButtonState("OK", "Cancel", mode);

View file

@ -64,6 +64,7 @@ public class HelperPanel extends JPanel {
// originalId of feedback causing ability
private UUID originalId;
private String message;
private String autoAnswerMessage; // Filtered version of message which is used for remembering answers to text
private UUID gameId;
private boolean gameNeedFeedback = false;
@ -462,6 +463,10 @@ public class HelperPanel extends JPanel {
this.dialogTextArea.setText(message, this.getWidth());
}
public void setAutoAnswerMessage(String autoAnswerMessage) {
this.autoAnswerMessage = autoAnswerMessage;
}
public void setTextArea(String message) {
this.dialogTextArea.setText(message, this.getWidth());
}
@ -523,19 +528,23 @@ public class HelperPanel extends JPanel {
public void handleAutoAnswerPopupMenuEvent(ActionEvent e) {
switch (e.getActionCommand()) {
case CMD_AUTO_ANSWER_ID_YES:
SessionHandler.sendPlayerAction(REQUEST_AUTO_ANSWER_ID_YES, gameId, originalId.toString() + '#' + message);
SessionHandler.sendPlayerAction(REQUEST_AUTO_ANSWER_ID_YES, gameId,
originalId.toString() + '#' + autoAnswerMessage);
clickButton(btnLeft);
break;
case CMD_AUTO_ANSWER_ID_NO:
SessionHandler.sendPlayerAction(REQUEST_AUTO_ANSWER_ID_NO, gameId, originalId.toString() + '#' + message);
SessionHandler.sendPlayerAction(REQUEST_AUTO_ANSWER_ID_NO, gameId,
originalId.toString() + '#' + autoAnswerMessage);
clickButton(btnRight);
break;
case CMD_AUTO_ANSWER_NAME_YES:
SessionHandler.sendPlayerAction(REQUEST_AUTO_ANSWER_TEXT_YES, gameId, message);
SessionHandler.sendPlayerAction(REQUEST_AUTO_ANSWER_TEXT_YES, gameId,
autoAnswerMessage);
clickButton(btnLeft);
break;
case CMD_AUTO_ANSWER_NAME_NO:
SessionHandler.sendPlayerAction(REQUEST_AUTO_ANSWER_TEXT_NO, gameId, message);
SessionHandler.sendPlayerAction(REQUEST_AUTO_ANSWER_TEXT_NO, gameId,
autoAnswerMessage);
clickButton(btnRight);
break;
case CMD_AUTO_ANSWER_RESET_ALL:

View file

@ -59,5 +59,6 @@ public final class Constants {
public static final String ORIGINAL_ID = "originalId";
public static final String SECOND_MESSAGE = "secondMessage";
public static final String HINT_TEXT = "hintText";
public static final String AUTO_ANSWER_MESSAGE = "autoAnswerMessage";
}
}

View file

@ -406,6 +406,7 @@ public class HumanPlayer extends PlayerImpl {
MessageToClient messageToClient = new MessageToClient(message, secondMessage);
Map<String, Serializable> options = new HashMap<>(2);
String autoAnswerMessage = message; // Removes self-referential text for the purposes of auto-answering
if (trueText != null) {
options.put("UI.left.btn.text", trueText);
}
@ -414,18 +415,21 @@ public class HumanPlayer extends PlayerImpl {
}
if (source != null) {
//options.put(Constants.Option.ORIGINAL_ID, "")
autoAnswerMessage = autoAnswerMessage.replace(getRelatedObjectName(source, game), "{this}");
}
options.put(Constants.Option.AUTO_ANSWER_MESSAGE, autoAnswerMessage);
// auto-answer
Boolean answer = null;
if (source != null) {
// ability + text
answer = requestAutoAnswerId.get(source.getOriginalId() + "#" + message);
answer = requestAutoAnswerId
.get(source.getOriginalId() + "#" + autoAnswerMessage);
}
if (answer == null) {
// text
answer = requestAutoAnswerText.get(message);
answer = requestAutoAnswerText.get(autoAnswerMessage);
}
if (answer != null) {
return answer;