create event assignment rotation TODO

main
bel 2024-12-15 00:05:24 -07:00
parent 76f6896d53
commit e0080a638c
1 changed files with 31 additions and 15 deletions

View File

@ -34,7 +34,7 @@ func NewGames(ctx context.Context, db DB) (Games, error) {
);
CREATE TABLE IF NOT EXISTS events (
game_uuid TEXT,
updated DATETIME,
timestamp DATETIME,
payload TEXT
);
`)
@ -181,10 +181,6 @@ func (games Games) GameState(ctx context.Context, id string) (GameState, error)
player.KillWords = v
result.Players[k] = player
}
// TODO gather current assignees
// TODO get victim's target
// TODO assign victim's target to killer
// TODO randomize everyone else so not the same as before AND not self
return nil
default:
return fmt.Errorf("unknown event type %d: %s", peek.Type, payload)
@ -200,18 +196,38 @@ func (games Games) GameState(ctx context.Context, id string) (GameState, error)
return result, err
}
func (games Games) CreateEventPlayerJoin(ctx context.Context, id string, playerJoin EventPlayerJoin) error {
return io.EOF
func (games Games) CreateEventPlayerJoin(ctx context.Context, id string, player string) error {
return games.createEvent(ctx, id, EventPlayerJoin{ID: player})
}
func (games Games) CreateEventPlayerLeave(ctx context.Context, id string, playerLeave EventPlayerLeave) error {
return io.EOF
func (games Games) CreateEventPlayerLeave(ctx context.Context, id string, player string) error {
return games.createEvent(ctx, id, EventPlayerLeave{ID: player})
}
func (games Games) CreateEventGameComplete(ctx context.Context, id string) error {
return io.EOF
return games.createEvent(ctx, id, EventGameComplete{})
}
func (games Games) CreateEventAssignmentRotation(ctx context.Context, id string, killer, killed, killWord string) error {
// TODO gather current assignees
// TODO get victim's target
// TODO assign victim's target to killer
// TODO randomize everyone else so not the same as before AND not self
return io.EOF
return games.createEvent(ctx, id, v)
}
func (games Games) createEvent(ctx context.Context, id string, v any) error {
payload, err := json.Marshal(any)
if err != nil {
panic(err)
}
return games.db.Exec(ctx, `
INSERT INTO events (
game_uuid,
timestamp,
payload
) VALUES (?, ?, ?)
`, id, time.Now(), payload)
}