Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domain Modeling - Design Workflow: join room #82

Open
kayac-chang opened this issue May 18, 2023 · 3 comments
Open

Domain Modeling - Design Workflow: join room #82

kayac-chang opened this issue May 18, 2023 · 3 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@kayac-chang
Copy link
Collaborator

implement design of https://hackmd.io/KvV2Ou3HS9uN11OUpsAUzA?both#Workflow-join-room

@kayac-chang kayac-chang added the help wanted Extra attention is needed label May 18, 2023
@JohnsonMao JohnsonMao self-assigned this Jun 1, 2023
@JohnsonMao
Copy link
Contributor

JohnsonMao commented Jun 1, 2023

Command

type JoinRoomCommand = {
    playerId: string;
    roomId: string;
}

Event

type JoinRoomEvent = {
    playerId: string;
    roomId: string;
}

Error

type PlayerLimitError = Error & {
    name: 'PlayerLimitError'
    message: 'Exceeded game player limit'
}

type JoinRoomError =
    | PlayerLimitError
    | EventSourceReadError
    | EventSourceWriteError

Model

type GameRoom = {
    playerIds: string[];
    roomId: string;
    status: 'wait for join' | 'game started';
};

Type

type JoinRoom = (eventsource: EventSource, command: JoinRoomCommand) => ResultAsync<JoinRoomEvent, JoinRoomError>

Workflow

workflow: join room
    input:
        event source
        join room command
    output:
        async result of 
            ok -> game room
            err -> join room error
    step:
        read all events from event source
            if error occured:
                return event source read error
        checkPlayerCountAgainstGameLimit
            if exceeded game player limit:
                return player limit error
        append event to event source
            if error occured:
                return event source write error
            otherwise:
                return game room

@kayac-chang
Copy link
Collaborator Author

@JohnsonMao
I also consider that
should we add the current status of the game room, such like 'wait for join' | 'game started' ?
because I think we should not let player joined if game already started.

@JohnsonMao
Copy link
Contributor

I agree with your consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants