예제 #1
0
// LoadConfig is needed as a backdoor to factory not being inititalized
func LoadConfig(file string) types.JGameObject {
	defer debug.Trace().UnTrace()

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

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

	goc := types.JGoc{}
	serialization.SerializeInPlace(&goc, holder)
	return &goc
}
예제 #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 {
		debug.Fatal("OpenFile (", file, "):", err)
	}

	holder, err := support.ReadData(data)
	if err != nil {
		debug.Fatal("ReadData (", file, "):", err)
	}

	m := holder.(map[string]interface{})
	typename, found := m["Type"]
	if !found {
		debug.Fatal("'Type' member not found in holder")
	}
	obj := serialization.FactoryFunc(typename.(string)).(types.JGameObject)
	serialization.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
}