package action import ( "git.reya.zone/reya/hexmap/server/state" "go.uber.org/zap/zapcore" ) const ( CellColorType SyncableType = "CELL_COLOR" ) // CellColor is the action sent when a cell of the map has been colored a different color. type CellColor struct { // At is the location of the cell in storage coordinates. At state.StorageCoordinates `json:"at"` // Color is the color the cell has been changed to. Color state.HexColor `json:"color"` } func (c CellColor) MarshalLogObject(encoder zapcore.ObjectEncoder) error { encoder.AddString("type", string(CellColorType)) err := encoder.AddObject("at", c.At) encoder.AddString("color", c.Color.String()) return err } func (c CellColor) Type() SyncableType { return CellColorType } // Apply sets the target cell's color, or returns ErrNoOp if it can't. func (c CellColor) Apply(s *state.Synced) error { if c.Color.A < 0xF { return ErrNoTransparentColors } cell, err := s.Map.LineCells.GetCellAt(c.At) if err != nil { return err } if cell.Color == c.Color { return ErrNoOp } cell.Color = c.Color return nil }