-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow switching playerID from Debug Panel
- Loading branch information
1 parent
f63d51c
commit 6c0a9b7
Showing
5 changed files
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #499
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolodavis Just tried the
master
branch and it looks like this is still buggy. Have you had success using it?On clicking on a player, the orange box showing the player is selected only shows up/changes when you toggle to one of the other panels. Presumably the state change doesn’t make the component re-render.
The value also doesn’t seem to be getting passed to the
<WrappedBoard>
component. If you look at the React dev tools at the bottom right,playerID
staysnull
the whole time:6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which of the following modes are you seeing the problem?
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using the React
Client
like this:Which means Singleplayer, right?
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried it with the new
multiplayer: Local()
pattern. Using that the players toggle as you click on them (after a small delay for some reason), but theplayerID
prop passed to the board component still staysnull
.6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried digging to see if I could fix this. I don’t understand the transport system thoroughly enough to open a PR, but here’s what I found:
Previously,
<WrappedBoard>
passedupdatePlayerID
and similar methods to the<Debug>
React component to be called directly.Now, the transport implementations seem to be designed to support these update actions instead of having direct communication between the Svelte debug panel and the React
<WrappedBoard>
. However,<WrappedBoard>
isn’t getting these updated values from the client. There is only a way of updating the client, which is called when props change.The simplest fix seemed to be passing in the client’s values instead of the
<WrappedBoard>
’s own values to the user’s board component:Should that be sufficient? This seemed to work, but I was running up against some bugs with my board component that I hadn’t seen before.
Also, this is all with a client using
multiplayer: Local()
. When I don’t pass amultiplayer
option to the React client, clicking on the players has no effect (as shown in the GIF above).6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had time to look at this yet (traveling this week), but my sense is that we're just not calling notifySubscribers() when the playerID is updated.
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s true (source), but
notifySubscribers()
just calls the subscriber’s callback with the return value ofgetState()
(source).playerID
,gameID
etc. aren’t included in state and the React client doesn’t ever read them from the client, so the currentnotifySubscribers()
implementation won’t update them.6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What errors were you running into? The fix that you suggested is what I had in mind as well and I don't see a reason why it should introduce new errors in the board component.
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've committed a fix at 457b29d. Can you let me know if that resolves the issue?
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! One thing I’ve noticed is that the entire board component seems to be re-rendering in a way it didn’t previously (I see some component state that seems to be re-triggered on toggling player), but for testing it works fine. Thanks!
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6c0a9b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if I check the Profiler it looks like the entire
<WrappedBoard>
is being re-rendered. There are a few sub-components that should change because they show player-specific information, but the main board component shouldn’t change.I think the clearest visual thing is that there are some tokens that have a reveal animation managed by their component state and this gets retriggered, so I guess that state is being wiped. Here’s the effect each time I change player: