func Example_actionList() {
	exampleObjectFileData := []byte(`
{
"Type": "Goc",
"Components": [
    {
        "Type": "kernel.ActionList",
        "Sequence": [
            {
                "Type": "kernel.alistTestMoveAction",
                "X": 20,
                "Y": 30
            },

            {"Type": "kernel.alistTestPrintNewLineAction"},

            {
                "Type": "kernel.ParallelAction",
                "Actions": [
                    {
                        "Type": "kernel.alistTestJumpAction"
                    },
                    {
                        "Type": "kernel.alistTestPlaySoundAction",
                        "Sound": "jump.wav"
                    }
                ]
            },

            {"Type": "kernel.alistTestPrintNewLineAction"},

            {
                "Type": "kernel.alistTestSpinAction",
                "Dir": "counterclock"
            }
        ]
    },

    {"Type": "kernel.alistTestTransformComp" }
]
}`)

	goc := Goc{}
	holder, _ := support.ReadData(exampleObjectFileData)
	SerializeInPlace(&goc, holder)
	alist := goc.GetComp("ActionList").(*ActionList)

	for !alist.IsFinished() {
		alist.Run()
	}

	// Output:
	// move -> (10, 15)
	// move -> (20, 30)
	//
	// jump
	// play sound jump.wav
	//
	// spin counterclock
}
Beispiel #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) JGameObjectHandle {
	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)
	h := JGameObjectHandle{id: len(f.ObjList)}
	f.NameMap[obj.Name()] = h
	return h
}