{{ $view := . }}{{ $API := $view.API -}}
package godot

import (
	"git.alfi.li/gamelang/gdnative-go"
	"log"
)

/*------------------------------------------------------------------------------
//   This code was generated by a tool.
//
//   Changes to this file may cause incorrect behavior and will be lost if
//   the code is regenerated. Any updates should be done in
//   "convert.go.tmpl" so they can be included in the generated
//   code.
//----------------------------------------------------------------------------*/

// getActualClass will return the concrete class type of the godot object based on
// the given class name.
func getActualClass(className gdnative.String, obj gdnative.Object) ObjectImplementer {
	// Check to see if we already have an instance of this object in our Go instance registry.
	if debug {
		log.Println("Checking to see if", obj.ID(), "is in registry:", InstanceRegistry)
	}
	if instance, ok := InstanceRegistry.Get(obj.ID()); ok {
		if debug {
			log.Println("Class instance already found in registry!")
		}
		return instance.(ObjectImplementer)
	}

	switch className {
		{{ range $i, $api := $view.APIs -}}
			{{ if $view.IsValidClass $api.Name $api.BaseClass -}}
				{{ if (not $api.Singleton) -}}
					case "{{ $api.Name }}":
						class := &{{ $view.SetClassName $api.Name $api.Singleton }}{}
						class.SetBaseObject(obj)
						return class
				{{ end -}}
			{{ end -}}
		{{ end -}}
	}
	log.Println("Could not find conversion for '" + className + "'. Defaulting to Object...")
	return &Object{owner: obj}
}

