Create some subroutines and test
This commit is contained in:
36
src/game/rule/operation/bool.go
Normal file
36
src/game/rule/operation/bool.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package operation
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"local/sandbox/cards/src/entity"
|
||||
)
|
||||
|
||||
type Bool func(*entity.Game, interface{}) bool
|
||||
|
||||
var boolStringified = map[string]Bool{
|
||||
"charge": charge,
|
||||
"deal": deal,
|
||||
"bet": bet,
|
||||
"trade": trade,
|
||||
"end": end,
|
||||
}
|
||||
|
||||
func (foo *Bool) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return foo.FromString(s)
|
||||
}
|
||||
|
||||
func (foo *Bool) FromString(s string) error {
|
||||
for k, v := range boolStringified {
|
||||
if k == s {
|
||||
*foo = v
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("unknown bool method " + s)
|
||||
}
|
||||
Reference in New Issue
Block a user