1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package main
- import (
- "fmt"
- "github.com/beanzilla/gonode"
- )
- type Location struct {
- N_System *gonode.Node `json:"-"`
- N_Planet *gonode.Node `json:"-"`
- System string `json:"system"`
- Planet string `json:"planet"`
- }
- func (l *Location) String() string {
- return fmt.Sprintf("%s in %s", l.Planet, l.System)
- }
- func (l *Location) Parse(n *gonode.Node) error {
- txt := fmt.Sprintf("%v", n.Data())
- switch Key(txt) {
- case "system":
- l.N_System = n
- l.System = Value(txt)
- case "planet":
- l.N_Planet = n
- l.Planet = Value(txt)
- }
- return nil
- }
- func (l *Location) Valid() bool {
- return l.N_Planet != nil && l.N_System != nil
- }
- func (l *Location) Update() error {
- if l.N_System == nil || l.N_Planet == nil {
- return fmt.Errorf("missing both nodes, locations are 2 nodes, can't update")
- }
- l.N_Planet.SetData(fmt.Sprintf("planet %s", Format(l.Planet)))
- l.N_System.SetData(fmt.Sprintf("system %s", Format(l.System)))
- return nil
- }
|