Exemplo n.º 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

}
Exemplo n.º 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

}
Exemplo n.º 3
0
func LoadEntity(sqlconn SqlWrapper, uid uint64, ent string, index int) (*share.SaveEntity, error) {
	si := &share.SaveEntity{}
	si.Typ = ent
	si.DBId = uid
	si.Index = index
	e := entity.CreateSaveLoader(ent)
	var childjson []byte
	err := e.Load(sqlconn, uid, ",`childinfo`", &childjson)
	if err != nil {
		return nil, err
	}
	si.Obj = e

	var childinfo []*share.SaveEntity
	json.Unmarshal(childjson, &childinfo)
	for _, c := range childinfo {
		parseEntity(c)
	}
	si.Childs = childinfo
	return si, nil
}