Add setting for checker movement speed

This commit is contained in:
Trevor Slocum 2024-01-11 13:25:52 -08:00
parent 262ad93e51
commit 84896b2982
4 changed files with 15 additions and 4 deletions

View file

@ -5,6 +5,13 @@ import (
"fmt"
)
const (
SpeedSlow int8 = 0
SpeedMedium int8 = 1
SpeedFast int8 = 2
SpeedInstant int8 = 3
)
type Event struct {
Type string
Player string
@ -119,6 +126,7 @@ type EventSettings struct {
Moves bool
Flip bool
Advanced bool
Speed int8
}
type EventReplay struct {

View file

@ -11,4 +11,5 @@ type account struct {
moves bool
flip bool
advanced bool
speed int8
}

View file

@ -52,7 +52,8 @@ CREATE TABLE account (
pips smallint NOT NULL DEFAULT 1,
moves smallint NOT NULL DEFAULT 0,
flip smallint NOT NULL DEFAULT 0,
advanced smallint NOT NULL DEFAULT 0
advanced smallint NOT NULL DEFAULT 0,
speed smallint NOT NULL DEFAULT 0
);
CREATE TABLE game (
id serial PRIMARY KEY,
@ -344,7 +345,7 @@ func loginAccount(passwordSalt string, username []byte, password []byte) (*accou
a := &account{}
var autoplay, highlight, pips, moves, flip, advanced int
err = tx.QueryRow(context.Background(), "SELECT id, email, username, password, autoplay, highlight, pips, moves, flip, advanced FROM account WHERE username = $1 OR email = $2", bytes.ToLower(bytes.TrimSpace(username)), bytes.ToLower(bytes.TrimSpace(username))).Scan(&a.id, &a.email, &a.username, &a.password, &autoplay, &highlight, &pips, &moves, &flip, &advanced)
err = tx.QueryRow(context.Background(), "SELECT id, email, username, password, autoplay, highlight, pips, moves, flip, advanced FROM account WHERE username = $1 OR email = $2", bytes.ToLower(bytes.TrimSpace(username)), bytes.ToLower(bytes.TrimSpace(username))).Scan(&a.id, &a.email, &a.username, &a.password, &autoplay, &highlight, &pips, &moves, &flip, &advanced, &a.speed)
if err != nil {
return nil, nil
} else if len(a.password) == 0 {

View file

@ -175,6 +175,7 @@ COMMANDS:
Moves: a.moves,
Flip: a.flip,
Advanced: a.advanced,
Speed: a.speed,
})
} else {
cmd.client.account = 0
@ -1094,7 +1095,7 @@ COMMANDS:
}
name := string(bytes.ToLower(params[0]))
settings := []string{"autoplay", "highlight", "pips", "moves", "flip", "advanced"}
settings := []string{"autoplay", "highlight", "pips", "moves", "flip", "advanced", "speed"}
var found bool
for i := range settings {
if name == settings[i] {
@ -1108,7 +1109,7 @@ COMMANDS:
}
value, err := strconv.Atoi(string(params[1]))
if err != nil || value < 0 {
if err != nil || value < 0 || (name == "speed" && value > 3) || (name != "speed" && value > 1) {
cmd.client.sendNotice("Invalid setting value provided.")
continue
}