Commit 02fe9aa5 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

Piece JSON is working

parent 285e2a99
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -48,6 +48,19 @@ func ParsePiece(s string) Piece {
	}
}

func (p Piece) MarshalJSON() ([]byte, error) {
	return json.Marshal(p.String())
}

func (p *Piece) UnmarshalJSON(b []byte) error {
	var s string
	if err := json.Unmarshal(b, &s); err != nil {
		return err
	}
	*p = ParsePiece(s)
	return nil
}

type Point uint

const (
@@ -216,6 +229,20 @@ func ParsePoint(s string) Point {
	}
}

//func (p Point) MarshalJSON() ([]byte, error) {
//	s := p.String()
//	return json.Marshal(s)
//}
//
//func (p *Point) UnmarshalJSON(b []byte) error {
//	var s string
//	if err := json.Unmarshal(b, &s); err != nil {
//		return err
//	}
//	*p = ParsePoint(s)
//	return nil
//}

func Points() []Point {
	return []Point{
		PointA7,
@@ -272,6 +299,14 @@ type Board struct {
	Points map[Point]Piece `json:"points,omitempty"`
}

//func (b *Board) MarshalJSON() ([]byte, error) {
//
//}
//
//func (b *Board) UnmarshalJSON([]byte) error {
//
//}

func New() *Board {
	b := &Board{
		Points: make(map[Point]Piece),