diff --git a/internal/game/data/common.go b/internal/game/data/common.go index 9aa9c33..6d44ec5 100644 --- a/internal/game/data/common.go +++ b/internal/game/data/common.go @@ -31,6 +31,7 @@ const ( TypeAccount TypePassword TypeExpectingDirectInput + TypeExpectingYNAnswer ) type Direction byte diff --git a/internal/game/data/player.go b/internal/game/data/player.go index e9c866b..fc551bf 100644 --- a/internal/game/data/player.go +++ b/internal/game/data/player.go @@ -47,3 +47,9 @@ type ExpectingDirectInput struct{} func (e ExpectingDirectInput) Type() ecs.ComponentType { return TypeExpectingDirectInput } + +type ExpectingYNAnswer struct{} + +func (e ExpectingYNAnswer) Type() ecs.ComponentType { + return TypeExpectingYNAnswer +} diff --git a/internal/game/logic/event/input.go b/internal/game/logic/event/input.go index 53ede5c..8aa7321 100644 --- a/internal/game/logic/event/input.go +++ b/internal/game/logic/event/input.go @@ -36,27 +36,26 @@ func HandleSubmitInput(w *ecs.World, event ecs.Entity) (err error) { return createCommandParseError("No connection id found for event") } - player := ecs.NilEntity() - - for p := range ecs.IterateEntitiesWithComponent[data.IsPlayerComponent](w) { - playerConnId, ok := ecs.GetComponent[data.ConnectionIdComponent](w, p) - - if ok && playerConnId.ConnectionId == eventConnId.ConnectionId { - player = p - break - } - } + player := world.FindPlayerByConnectionId(w, eventConnId.ConnectionId) if player == ecs.NilEntity() { return createCommandParseError("Unable to find valid player with provided connection id") } + if world.IsPlayerInDirectInputMode(w, player) { + + } + tokens, err := tokenize(commandString.Command) if err != nil { return createCommandParseError("Error with tokenization: ", err) } + if world.IsPlayerInYNAnswerMode(w, player) { + + } + cmd := world.CreateTokenizedCommand(w, player, commandString.Command, tokens) world.CreateParseCommandEvent(w, cmd) diff --git a/internal/game/logic/world/player.go b/internal/game/logic/world/player.go index 9967fdc..016c988 100644 --- a/internal/game/logic/world/player.go +++ b/internal/game/logic/world/player.go @@ -13,7 +13,6 @@ func CreateJoiningPlayer(world *ecs.World, connectionId uuid.UUID) (entity ecs.E ecs.SetComponent(world, entity, data.PlayerStateComponent{State: data.PlayerStateJoining}) ecs.SetComponent(world, entity, data.NameComponent{Name: connectionId.String()}) ecs.SetComponent(world, entity, data.IsPlayerComponent{}) - ecs.SetComponent(world, entity, data.InputBufferComponent{InputBuffer: ""}) return } @@ -37,3 +36,18 @@ func SendDisconnectMessageToPlayer(world *ecs.World, player ecs.Entity, message CreateClosingGameOutput(world, connId.ConnectionId, []byte(message)) } + +func FindPlayerByConnectionId(w *ecs.World, connectionId uuid.UUID) (entity ecs.Entity) { + player := ecs.NilEntity() + + for p := range ecs.IterateEntitiesWithComponent[data.IsPlayerComponent](w) { + playerConnId, ok := ecs.GetComponent[data.ConnectionIdComponent](w, p) + + if ok && playerConnId.ConnectionId == connectionId { + player = p + break + } + } + + return player +}