2025-06-26 23:48:54 +03:00
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.haedhutner.dev/mvv/LastMUD/internal/ecs"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EventType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
EventPlayerConnect EventType = "PlayerConnect"
|
2025-06-27 14:58:52 +03:00
|
|
|
EventPlayerDisconnect EventType = "PlayerDisconnect"
|
|
|
|
EventPlayerCommand EventType = "PlayerCommand"
|
2025-06-27 21:36:15 +03:00
|
|
|
EventParseCommand EventType = "ParseCommand"
|
|
|
|
EventCommandExecuted EventType = "CommandExecuted"
|
2025-06-27 14:58:52 +03:00
|
|
|
EventPlayerSpeak EventType = "PlayerSpeak"
|
2025-06-26 23:48:54 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type EventComponent struct {
|
|
|
|
EventType EventType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (is EventComponent) Type() ecs.ComponentType {
|
|
|
|
return TypeEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreatePlayerConnectEvent(world *ecs.World, connectionId uuid.UUID) {
|
|
|
|
event := ecs.NewEntity()
|
|
|
|
|
|
|
|
ecs.SetComponent(world, event, EventComponent{EventType: EventPlayerConnect})
|
|
|
|
ecs.SetComponent(world, event, ConnectionIdComponent{ConnectionId: connectionId})
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreatePlayerDisconnectEvent(world *ecs.World, connectionId uuid.UUID) {
|
|
|
|
event := ecs.NewEntity()
|
|
|
|
|
|
|
|
ecs.SetComponent(world, event, EventComponent{EventType: EventPlayerDisconnect})
|
|
|
|
ecs.SetComponent(world, event, ConnectionIdComponent{ConnectionId: connectionId})
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreatePlayerCommandEvent(world *ecs.World, connectionId uuid.UUID, command string) {
|
|
|
|
event := ecs.NewEntity()
|
|
|
|
|
|
|
|
ecs.SetComponent(world, event, EventComponent{EventType: EventPlayerCommand})
|
|
|
|
ecs.SetComponent(world, event, ConnectionIdComponent{ConnectionId: connectionId})
|
|
|
|
ecs.SetComponent(world, event, CommandStringComponent{Command: command})
|
|
|
|
}
|
2025-06-27 21:36:15 +03:00
|
|
|
|
|
|
|
func CreateParseCommandEvent(world *ecs.World, command ecs.Entity) {
|
|
|
|
event := ecs.NewEntity()
|
|
|
|
|
|
|
|
ecs.SetComponent(world, event, EventComponent{EventType: EventParseCommand})
|
|
|
|
ecs.SetComponent(world, event, EntityComponent{Entity: command})
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateCommandExecutedEvent(world *ecs.World, command ecs.Entity) {
|
|
|
|
event := ecs.NewEntity()
|
|
|
|
|
|
|
|
ecs.SetComponent(world, event, EventComponent{EventType: EventCommandExecuted})
|
|
|
|
ecs.SetComponent(world, event, EntityComponent{Entity: command})
|
|
|
|
}
|