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.
78 lines
1.6 KiB
78 lines
1.6 KiB
package action
|
|
|
|
import (
|
|
"git.reya.zone/reya/hexmap/server/state"
|
|
)
|
|
|
|
func (x *ServerActionPB) ToGo() (Server, error) {
|
|
switch action := x.Action.(type) {
|
|
case nil:
|
|
return nil, state.ErrOneofNotSet
|
|
case *ServerActionPB_Client:
|
|
return action.Client.ToGo()
|
|
default:
|
|
panic("A case was missed in ServerActionPB.ToGo!")
|
|
}
|
|
}
|
|
|
|
func (x *ClientActionPB) ToGo() (Client, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
switch action := x.Action.(type) {
|
|
case nil:
|
|
return nil, state.ErrOneofNotSet
|
|
case *ClientActionPB_CellSetColor:
|
|
return action.CellSetColor.ToGo()
|
|
case *ClientActionPB_UserSetActiveColor:
|
|
return action.UserSetActiveColor.ToGo(), nil
|
|
default:
|
|
panic("A case was missed in ClientActionPB.ToGo!")
|
|
}
|
|
}
|
|
|
|
func (x *CellSetColorPB) ToGo() (*CellColor, error) {
|
|
at, err := x.At.ToGo()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &CellColor{
|
|
At: at,
|
|
Color: state.ColorFromInt(x.Color),
|
|
}, nil
|
|
}
|
|
|
|
func (c CellColor) ToServerPB() *ServerActionPB {
|
|
return serverPBFromClient(c)
|
|
}
|
|
|
|
func (c CellColor) ToClientPB() *ClientActionPB {
|
|
return &ClientActionPB{
|
|
Action: &ClientActionPB_CellSetColor{
|
|
CellSetColor: &CellSetColorPB{
|
|
Color: c.Color.ToInt(),
|
|
At: c.At.ToPB(),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (x *UserSetActiveColorPB) ToGo() *UserActiveColor {
|
|
return &UserActiveColor{
|
|
Color: state.ColorFromInt(x.Color),
|
|
}
|
|
}
|
|
|
|
func (c UserActiveColor) ToServerPB() *ServerActionPB {
|
|
return serverPBFromClient(c)
|
|
}
|
|
|
|
func (c UserActiveColor) ToClientPB() *ClientActionPB {
|
|
return &ClientActionPB{
|
|
Action: &ClientActionPB_UserSetActiveColor{
|
|
UserSetActiveColor: &UserSetActiveColorPB{
|
|
Color: c.Color.ToInt(),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|