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.
37 lines
855 B
37 lines
855 B
package action
|
|
|
|
import (
|
|
"go.uber.org/zap/zapcore"
|
|
"hexmap-server/state"
|
|
)
|
|
|
|
const (
|
|
UserActiveColorType = "USER_ACTIVE_COLOR"
|
|
)
|
|
|
|
// 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) Type() SyncableType {
|
|
return UserActiveColorType
|
|
}
|
|
|
|
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
|
|
}
|
|
|