create event assignment rotation TODO
parent
76f6896d53
commit
e0080a638c
|
|
@ -34,7 +34,7 @@ func NewGames(ctx context.Context, db DB) (Games, error) {
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS events (
|
CREATE TABLE IF NOT EXISTS events (
|
||||||
game_uuid TEXT,
|
game_uuid TEXT,
|
||||||
updated DATETIME,
|
timestamp DATETIME,
|
||||||
payload TEXT
|
payload TEXT
|
||||||
);
|
);
|
||||||
`)
|
`)
|
||||||
|
|
@ -181,10 +181,6 @@ func (games Games) GameState(ctx context.Context, id string) (GameState, error)
|
||||||
player.KillWords = v
|
player.KillWords = v
|
||||||
result.Players[k] = player
|
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
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown event type %d: %s", peek.Type, payload)
|
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
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (games Games) CreateEventPlayerJoin(ctx context.Context, id string, playerJoin EventPlayerJoin) error {
|
func (games Games) CreateEventPlayerJoin(ctx context.Context, id string, player string) error {
|
||||||
return io.EOF
|
return games.createEvent(ctx, id, EventPlayerJoin{ID: player})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (games Games) CreateEventPlayerLeave(ctx context.Context, id string, playerLeave EventPlayerLeave) error {
|
func (games Games) CreateEventPlayerLeave(ctx context.Context, id string, player string) error {
|
||||||
return io.EOF
|
return games.createEvent(ctx, id, EventPlayerLeave{ID: player})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (games Games) CreateEventGameComplete(ctx context.Context, id string) error {
|
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 {
|
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 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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue