Start input system
This commit is contained in:
parent
d71bd8f5a2
commit
0e1d664fc3
4 changed files with 31 additions and 11 deletions
|
@ -31,6 +31,7 @@ const (
|
|||
TypeAccount
|
||||
TypePassword
|
||||
TypeExpectingDirectInput
|
||||
TypeExpectingYNAnswer
|
||||
)
|
||||
|
||||
type Direction byte
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue