Esempio n. 1
0
func GetEntityData(ent datatype.Entityer, base bool, depth int) *SaveEntity {
	if !base && !ent.IsSave() {
		return nil
	}
	s := &SaveEntity{}
	ent.SyncToDb()
	s.Typ = ent.ObjTypeName()
	s.DBId = ent.GetDbId()
	s.Obj = ent.GetSaveLoader()
	s.Index = ent.GetIndex()
	if ent.Base() != nil {
		s.Base = GetEntityData(ent.Base(), true, depth)
	}
	if base {
		return s
	}
	if depth > 1 {
		return s
	}

	clds := ent.GetChilds()
	l := len(clds)
	if l > 0 {
		s.Childs = make([]*SaveEntity, 0, l)
		for _, e := range clds {
			if e != nil {
				if child := GetEntityData(e, false, depth+1); child != nil {
					s.Childs = append(s.Childs, child)
				}
			}
		}
	}

	return s
}
Esempio n. 2
0
func GetItemInfo(obj datatype.Entityer, syncchild bool) (*datatype.EntityInfo, error) {
	item := &datatype.EntityInfo{}
	buffer := new(bytes.Buffer)
	enc := gob.NewEncoder(buffer)
	err := enc.Encode(obj)
	if err != nil {
		log.LogError("encode ", obj.ObjTypeName(), "error,", err)
		return nil, err
	}
	item.Type = obj.ObjTypeName()
	item.Caps = obj.GetCapacity()
	item.DbId = obj.GetDbId()
	item.ObjId = obj.GetObjId()
	item.Index = obj.GetIndex()
	item.Data = buffer.Bytes()

	if syncchild {
		ls := obj.GetChilds()
		if len(ls) > 0 {
			item.Childs = make([]*datatype.EntityInfo, 0, len(ls))
		}
		for _, c := range ls {
			if c != nil {
				child, err := GetItemInfo(c, syncchild)
				if err != nil {
					return nil, err
				}
				item.Childs = append(item.Childs, child)
			}
		}
	}

	return item, nil
}
Esempio n. 3
0
func (gd *GlobalDataHelper) RecClear(self datatype.Entityer, rec datatype.Recorder) {
	if !gd.isServer {
		return
	}
	v := gd.dataChange()

	for _, client := range gd.globalclients {
		if client.disable || client.status == STATUS_NONE { //没有开启
			continue
		}

		app := GetAppById(client.appid)
		if app == nil {
			continue
		}

		app.CallBack(nil, "GlobalHelper.GlobalDataRecClear", gd.OnDataChanged, self.GetIndex(), v, rec.GetName())
	}
}
Esempio n. 4
0
//数据属性变动同步
func (gd *GlobalDataHelper) Update(self datatype.Entityer, index int16, value interface{}) {
	if !gd.isServer {
		return
	}
	v := gd.dataChange()

	for _, client := range gd.globalclients {
		if client.disable || client.status == STATUS_NONE { //没有开启
			continue
		}

		app := GetAppById(client.appid)
		if app == nil {
			continue
		}

		app.CallBack(nil, "GlobalHelper.GlobalDataUpdate", gd.OnDataChanged, self.GetIndex(), v, index, datatype.NewAny(0, value))
	}
}