Start input system

This commit is contained in:
Miroslav Vasilev 2025-07-02 20:42:25 +03:00
parent d71bd8f5a2
commit 0e1d664fc3
Signed by: mvv
GPG key ID: 92BACFBE98721A3F
4 changed files with 31 additions and 11 deletions

View file

@ -31,6 +31,7 @@ const (
TypeAccount TypeAccount
TypePassword TypePassword
TypeExpectingDirectInput TypeExpectingDirectInput
TypeExpectingYNAnswer
) )
type Direction byte type Direction byte

View file

@ -47,3 +47,9 @@ type ExpectingDirectInput struct{}
func (e ExpectingDirectInput) Type() ecs.ComponentType { func (e ExpectingDirectInput) Type() ecs.ComponentType {
return TypeExpectingDirectInput return TypeExpectingDirectInput
} }
type ExpectingYNAnswer struct{}
func (e ExpectingYNAnswer) Type() ecs.ComponentType {
return TypeExpectingYNAnswer
}

View file

@ -36,27 +36,26 @@ func HandleSubmitInput(w *ecs.World, event ecs.Entity) (err error) {
return createCommandParseError("No connection id found for event") return createCommandParseError("No connection id found for event")
} }
player := ecs.NilEntity() player := world.FindPlayerByConnectionId(w, eventConnId.ConnectionId)
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
}
}
if player == ecs.NilEntity() { if player == ecs.NilEntity() {
return createCommandParseError("Unable to find valid player with provided connection id") return createCommandParseError("Unable to find valid player with provided connection id")
} }
if world.IsPlayerInDirectInputMode(w, player) {
}
tokens, err := tokenize(commandString.Command) tokens, err := tokenize(commandString.Command)
if err != nil { if err != nil {
return createCommandParseError("Error with tokenization: ", err) return createCommandParseError("Error with tokenization: ", err)
} }
if world.IsPlayerInYNAnswerMode(w, player) {
}
cmd := world.CreateTokenizedCommand(w, player, commandString.Command, tokens) cmd := world.CreateTokenizedCommand(w, player, commandString.Command, tokens)
world.CreateParseCommandEvent(w, cmd) world.CreateParseCommandEvent(w, cmd)

View file

@ -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.PlayerStateComponent{State: data.PlayerStateJoining})
ecs.SetComponent(world, entity, data.NameComponent{Name: connectionId.String()}) ecs.SetComponent(world, entity, data.NameComponent{Name: connectionId.String()})
ecs.SetComponent(world, entity, data.IsPlayerComponent{}) ecs.SetComponent(world, entity, data.IsPlayerComponent{})
ecs.SetComponent(world, entity, data.InputBufferComponent{InputBuffer: ""})
return return
} }
@ -37,3 +36,18 @@ func SendDisconnectMessageToPlayer(world *ecs.World, player ecs.Entity, message
CreateClosingGameOutput(world, connId.ConnectionId, []byte(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
}