Files
cards/src/game/rule/operation/int.go
Bel LaPointe 117250f5c1 hands to int64
2021-03-17 13:36:58 -05:00

42 lines
798 B
Go

package operation
import (
"encoding/json"
"errors"
"local/sandbox/cards/src/entity"
)
type Int func(*entity.Game, interface{}) int64
var intStringified = map[string]Int{
"royalFlush": royalFlush,
"straightFlush": straightFlush,
"fourOfAKind": fourOfAKind,
"fullHouse": fullHouse,
"flush": flush,
"straight": straight,
"threeOfAKind": threeOfAKind,
"twoPair": twoPair,
"pair": pair,
"highCard": highCard,
}
func (foo *Int) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
return foo.FromString(s)
}
func (foo *Int) FromString(s string) error {
for k, v := range intStringified {
if k == s {
*foo = v
return nil
}
}
return errors.New("unknown int method " + s)
}