Beispiel #1
0
func parseEntity(data *share.SaveEntity) error {

	if data == nil {
		return nil
	}

	bdata := data.Obj.(map[string]interface{})
	e := entity.CreateSaveLoader(data.Typ)

	err := e.Unmarshal(bdata)
	if err != nil {
		return err
	}

	data.Obj = e
	if data.Base != nil {
		err = parseEntity(data.Base)
		if err != nil {
			return err
		}
	}

	for _, c := range data.Childs {
		err = parseEntity(c)
		if err != nil {
			return err
		}
	}

	return nil

}
Beispiel #2
0
func parseEntity(data *share.SaveEntity) error {

	if data == nil {
		return nil
	}

	bdata := data.Obj.(bson.M)
	e := entity.CreateSaveLoader(data.Typ)
	for k, v := range bdata {
		if strings.HasSuffix(k, "_save_property") {
			prop := v.(bson.M)
			for k1, v1 := range prop {
				bdata[k1] = v1
			}
			delete(bdata, k)
			break
		}
	}

	err := e.Unmarshal(bdata)
	if err != nil {
		return err
	}

	data.Obj = e
	if data.Base != nil {
		err = parseEntity(data.Base)
		if err != nil {
			return err
		}
	}

	for _, c := range data.Childs {
		err = parseEntity(c)
		if err != nil {
			return err
		}
	}

	return nil

}