예제 #1
0
파일: kernel.go 프로젝트: mysll/flynet
//通过配置文件加载
func (k *Kernel) LoadFromConfig(object Entityer, configid string) error {
	err := helper.LoadFromConfig(configid, object)
	res := 0
	callee := GetCallee(object.ObjTypeName())
	if err == nil {
		for _, cl := range callee {
			res = cl.OnLoad(object, share.LOAD_CONFIG)
			if res == 0 {
				break
			}
		}
		object.SetConfig(configid)
	}
	return err
}
예제 #2
0
파일: kernel.go 프로젝트: mysll/flynet
func (k *Kernel) loadObj(parent Entityer, data *share.SaveEntity) (ent Entityer, err error) {
	ent, err = k.factory.Create(data.Typ)
	if err != nil {
		log.LogError("load object failed:", err)
		return
	}
	ent.SetPropHooker(k)
	if parent == nil {
		ent.SetLoading(true)
	}

	callee := GetCallee(data.Typ)
	res := 0
	for _, cl := range callee {
		res = cl.OnCreate(ent, parent)
		if res == 0 {
			break
		}
	}

	ent.SetDbId(data.DBId)

	configid := ent.GetConfigFromDb(data.Obj)
	if configid != "" {
		helper.LoadFromConfig(configid, ent)
	}

	ent.SyncFromDb(data.Obj)
	//加载父类
	if ent.Base() != nil {
		err = k.loadBase(ent.Base(), data.Base)
		if err != nil {
			log.LogMessage("load object base failed:", err)
			return
		}
	}

	caps := ent.GetCapacity()
	if caps == -1 {
		ent.SetCapacity(-1, 16)
	} else {
		ent.SetCapacity(caps, caps)
	}

	if parent != nil {
		if parent.GetCapacity() == -1 {
			_, err = k.addChild(parent, ent, -1)
		} else {
			_, err = k.addChild(parent, ent, data.Index)
		}
		if err != nil {
			log.LogError(err)
		}
	}

	//加载子对象
	if data.Childs != nil && len(data.Childs) > 0 {
		for _, c := range data.Childs {
			if c != nil {
				_, err = k.loadObj(ent, c)
				if err != nil {
					log.LogError("load object child err:", err)
				}
			}
		}

	}

	if parent == nil {
		ent.SetLoading(false)
	}

	ent.ClearDirty()
	ent.ClearModify()
	return
}