You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1011 B
34 lines
1011 B
package action
|
|
|
|
import (
|
|
"errors"
|
|
"go.uber.org/zap/zapcore"
|
|
"hexmap-server/state"
|
|
)
|
|
|
|
// ErrNoTransparentColors is returned when a user tries to set their active color or a cell color to transparent.
|
|
// Transparent here is defined as having an alpha component of less than 15 (0xF).
|
|
var ErrNoTransparentColors error = errors.New("transparent colors not allowed")
|
|
|
|
// UserActiveColor is the action sent when the user's current color, the one being painted with, changes.
|
|
type UserActiveColor struct {
|
|
// Color is the color that is now active.
|
|
Color state.HexColor `json:"color"`
|
|
}
|
|
|
|
func (c UserActiveColor) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
|
|
encoder.AddString("color", c.Color.String())
|
|
return nil
|
|
}
|
|
|
|
// Apply sets the user's active color, or returns ErrNoOp if it can't.
|
|
func (c UserActiveColor) Apply(s *state.Synced) error {
|
|
if c.Color.A < 0xF {
|
|
return ErrNoTransparentColors
|
|
}
|
|
if s.User.ActiveColor == c.Color {
|
|
return ErrNoOp
|
|
}
|
|
s.User.ActiveColor = c.Color
|
|
return nil
|
|
}
|
|
|