Closed nicolodavis closed 4 years ago
IIRC isn't there the possibility to pass a value directly?
setActivePlayers({
value: {
...ctx.activePlayers,
[playerID]: 'stage'
}
})
That said, obvious candidates would include:
addActivePlayer
removeActivePlayer
(Side note: keep meaning to write a test for this, but I think I saw that setActivePlayers({ others: 'stage’ })
was preserving currentPlayer
if it was already in activePlayers
)
Another idea that's been growing on me is to have a simple endStage
event that's analogous to endPhase
.
All this does is that it removes the player from activePlayers
.
However, if the stage config contains a next
, or if next
is passed to endStage
, then we just take the player to that stage instead. This is exactly how phases work and I think having the same concept for stages will reduce the cognitive overhead of having to grok different APIs.
I think if we arrange things so that we just have endTurn, endPhase, endStage and setActivePlayers, that would be a nice elegant API.
Now that I’m working on moveLimit
(#452), I think setStage
would probably also need a way to set a moveLimit
, perhaps via a second options argument:
setStage('main', { moveLimit: 2 })
Otherwise users would only be able to set move limits inside setActivePlayers
.
Oh, I think that's perfectly ok.
Users can use setStage just to move between stages and setActivePlayers if they want the more advanced options.
On Wed, Sep 11, 2019, 12:00 AM Chris Swithinbank notifications@github.com wrote:
Now that I’m working on moveLimit (#452 https://github.com/nicolodavis/boardgame.io/pull/452), I think setStage would probably also need a way to set a moveLimit, perhaps via a second options argument:
setStage('main', { moveLimit: 2 })
Otherwise users would only be able to set move limits inside setActivePlayers.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nicolodavis/boardgame.io/issues/447?email_source=notifications&email_token=AABZULRMNYDLDXGJ3WZLZA3QI7ABFA5CNFSM4IRLKFH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6LTY6A#issuecomment-530005112, or mute the thread https://github.com/notifications/unsubscribe-auth/AABZULXUFO7HN5EG4K4VX3LQI7ABFANCNFSM4IRLKFHQ .
I think of setStage
as a simple "get me to this other stage". I'd prefer to have it as minimal as possible. I'm open to adding more options to it in the future, but let's wait and see how people use the new API first.
setActivePlayers
can be the swiss-army knife with all the fancy options.
@nicolodavis Totally understand.
I’ve finished work on moveLimit
in #452. My concern was that with this implementation we reset move counts when calling setActivePlayers
, so a scenario where one player’s stage changes but the others stay the same would not currently support move limits for that one player. Otherwise, you’d have to use setActivePlayers
and do something like moveLimit - numMoves
for each other player, which would be pretty complicated.
An example of just how complicated that would be:
const turn = {
activePlayers: {
all: true,
moveLimit: 4,
},
moves: {
move: (G, ctx) => {},
changeStage: (G, ctx) => {
ctx.events.setActivePlayers({
value: {
...ctx.activePlayers,
[ctx.playerID]: 'newStage',
},
moveLimit: {
value: {
...Object.keys(ctx._activePlayersMoveLimit).reduce((obj, key) => {
obj[key] =
ctx._activePlayersMoveLimit[key] -
ctx._activePlayersNumMoves[key];
return obj;
}, {}),
[ctx.playerID]: 2,
},
},
});
},
},
};
Whereas setStage
could support the same scenario like this:
const turn = {
activePlayers: {
all: true,
moveLimit: 4,
},
moves: {
move: (G, ctx) => {},
changeStage: (G, ctx) => {
ctx.events.setStage('newStage', { moveLimit: 2 });
},
},
};
OK, you've convinced me :)
Let's also support an additional argument in setStage
that accepts an object that can carry things like moveLimit
etc.
In the
phases-overhaul
branch, the only way to manipulate a player's stage is thesetActivePlayers
event.For example, to set the current player's stage to 'A', you can do:
However, this has two problems:
It clobbers the state in
activePlayers
(if some other player was in there, they would be removed).It cannot set the stage of the player that made the move (it only works on the "current player").
We could change the semantics of
setActivePlayers
to overcome these, or split it into multiple events that do different things.