示例#1
0
// Unmarshal a recordjar record into a player
func (p *Player) Unmarshal(d recordjar.Decoder) {
	p.account = d.String("account")
	p.password = d.String("password")
	p.salt = d.String("salt")
	p.created = d.Time("created")

	p.Mobile.Unmarshal(d)
}
示例#2
0
func (b *Basic) Init(d recordjar.Decoder, refs map[string]recordjar.Unmarshaler) {
	b.Thing.Init(d, refs)

	// Link directional exits to locations via direction/location reference pairs
	// e.g. Exits: E→L2 S→L3 NW→L4
	for _, pair := range d.PairList("exits") {

		dir, loc := pair[0], pair[1]

		if l, ok := refs[loc].(Interface); ok {
			if dirIndex, ok := directionShortIndex[dir]; ok {
				b.LinkExit(dirIndex, l)
			}
		}
	}

}
示例#3
0
// TODO: Instead of calling Unmarshal within Init we should be calling a
// Copy/Clone function instead.
func (i *Item) Init(d recordjar.Decoder, refs map[string]recordjar.Unmarshaler) {
	for x, location := range d.KeywordList("location") {
		if l, ok := refs[location]; ok {
			if l, ok := l.(inventory.Interface); ok {
				if x == 0 {
					l.Add(i)
				} else {
					tmp := &Item{}
					tmp.Unmarshal(d)
					l.Add(tmp)
				}
				log.Printf("Added %s to %s", i.Name(), location)
			} else {
				log.Printf("Cannot add %q to %q: Not an inventory", i.Name(), location)
			}
		} else {
			log.Printf("Cannot add %q to %q: Ref not found", i.Name(), location)
		}
	}
}
示例#4
0
// Unmarshal should decode the passed recordjar.Decoder into the current
// receiver. A unique ID should be allocated automatically.
func (t *Thing) Unmarshal(d recordjar.Decoder) {
	t.name = d.String("name")
	t.description = d.String(":data:")
	t.aliases = d.KeywordList("aliases")
	t.UID = <-uid.Next
}
示例#5
0
func (i *Item) Unmarshal(d recordjar.Decoder) {
	i.weight = units.Weight(d.Int("weight"))
	i.Thing.Unmarshal(d)
}