Ejemplo n.º 1
0
// LoadConfig serialize in a GameObject from a text file.
func LoadConfig(file string) GameObject {
	defer debug.Trace().UnTrace()

	data, err := support.OpenFile(file)
	if err != nil {
		support.LogFatal("Failed to open Config file: " + file)
	}

	holder, err := support.ReadData(data)
	if err != nil {
		support.LogFatal("Failed to read in Config file: " + file)
		return nil
	}

	goc := Goc{}
	SerializeInPlace(&goc, holder)
	return &goc
}
Ejemplo n.º 2
0
// s := f.Create(f1, Name("space"))
// goc1 := f.Create(f2, Owner(s), Name("goc1"))
// goc2 := f.Create(f2, Owner(s), Dispatcher(d))
func (f *Factory) Create(file string, opts ...FactoryOpt) types.JGameObject {
	defer debug.Trace().UnTrace()

	// read in game object data

	data, err := support.OpenFile(file)
	if err != nil {
		support.LogFatal("Failed to open Config file: " + file)
	}

	holder, err := support.ReadData(data)
	if err != nil {
		support.LogFatal("Failed to read in Config file: " + file)
		return nil
	}

	m := v.(map[string]interface{})
	typename, err := m["Type"]
	if err != nil {
		log.Panic(err)
	}
	obj := factoryFunc(typename.(string))
	SerializeInPlace(obj, holder)

	// apply options to game object
	for _, opt := range opts {
		opt(obj)
	}

	// check for transform, check for dispatcher, name etc

	if obj.Name() == "" {
		obj.SetName(fmt.Sprint("obj", len(f.ObjList)))
	}

	// add game object to factory

	f.ObjList = append(f.ObjList, obj)
	return obj
	// h := types.JGameObject{id: len(f.ObjList)}
	// f.NameMap[obj.Name()] = h
	// return h
}