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.
43 lines
1.4 KiB
43 lines
1.4 KiB
package action
|
|
|
|
import (
|
|
"errors"
|
|
"go.uber.org/zap/zapcore"
|
|
"hexmap-server/state"
|
|
)
|
|
|
|
var (
|
|
// ErrNoOp is returned when an action has no effect.
|
|
ErrNoOp = errors.New("action's effects were already applied, or it's an empty action")
|
|
// 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).
|
|
ErrNoTransparentColors = errors.New("transparent colors not allowed")
|
|
)
|
|
|
|
type SyncableType string
|
|
|
|
// Syncable is the interface for actions that can be shared between clients.
|
|
type Syncable interface {
|
|
zapcore.ObjectMarshaler
|
|
// Type gives the Javascript type that is sent over the wire.
|
|
Type() SyncableType
|
|
// Apply causes the action's effects to be applied to s, mutating it in place.
|
|
// All syncable.Actions must conform to the standard that if an action can't be correctly applied, or if it would
|
|
// have no effect, it returns an error without changing s.
|
|
// If an action can be correctly applied but would have no effect, it should return ErrNoOp.
|
|
// If an action is correctly applied and has an effect, it should return nil.
|
|
Apply(s *state.Synced) error
|
|
}
|
|
|
|
type SyncableSlice []Syncable
|
|
|
|
func (s SyncableSlice) MarshalLogArray(encoder zapcore.ArrayEncoder) error {
|
|
var finalErr error = nil
|
|
for _, a := range s {
|
|
err := encoder.AppendObject(a)
|
|
if err != nil && finalErr == nil {
|
|
finalErr = err
|
|
}
|
|
}
|
|
return finalErr
|
|
}
|
|
|