Refactor: set the message that game data was successfully loaded in a more portable place #3027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In particular, this change is to set the "Loaded data for game $gameId." message only in the public method
load_api_game_data()
which is directly invoked by the API, not in the internal methodload_game()
.Taking a step back: the context in which we're having so much trouble with
$this->message
over in #2131 is that there are two different high-level patterns of the message we want to set for the user:This confusion comes to a head with tournaments because tournaments introduce logical actions which are taken as a result of
submitTurn
, so as far as the site is concerned, they're part of thesubmitTurn
workflow. But as far as the player who calledsubmitTurn
is concerned, they are not. From that player's POV, if their turn causes the end of a game which causes the next round of the tournament which causes the creation of many more games, which causes armies to be deployed and wars to be won and lost... none of that matters, they just want to know what happened during the game as a result of their attack.So the long-term fix is to do a bigger refactor of how we set
$this->message
which does a better job of allowing internal methods to propagate pieces of user-friendly message text upwards, and public functions to decide what message to send.And in the immediate term, to unblock tournaments, we can take the most limited version of that basic approach for specifically the pieces of message text that are causing problems with tournaments right now. That means:
$this->message
should be set in the public interface method.For the
load_game()
case, that second one is all that's needed, and that's what this PR does, as a proof-of-concept that it's easy and harmless to make that change, and i believe it will actually address the relevant problem in the PR.For the
create_game()
case, this is showing up a slightly more complicated issue, which is that tournament game creation is calling the publiccreate_game()
method. So Shadowshade should do a refactor that moves all the logic ofcreate_game()
into a protected method, so you can have an actual public method that just makes the API call and returns it with a friendly message. That should be simple, and should get us to "public interface methods shouldn't invoke other public interface methods."