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
|
TypeAccount
|
||||||
TypePassword
|
TypePassword
|
||||||
TypeExpectingDirectInput
|
TypeExpectingDirectInput
|
||||||
|
TypeExpectingYNAnswer
|
||||||
)
|
)
|
||||||
|
|
||||||
type Direction byte
|
type Direction byte
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue