convert.go.tmpl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. {{ $view := . }}{{ $API := $view.API -}}
  2. package godot
  3. import (
  4. "git.alfi.li/gamelang/gdnative-go"
  5. "log"
  6. )
  7. /*------------------------------------------------------------------------------
  8. // This code was generated by a tool.
  9. //
  10. // Changes to this file may cause incorrect behavior and will be lost if
  11. // the code is regenerated. Any updates should be done in
  12. // "convert.go.tmpl" so they can be included in the generated
  13. // code.
  14. //----------------------------------------------------------------------------*/
  15. // getActualClass will return the concrete class type of the godot object based on
  16. // the given class name.
  17. func getActualClass(className gdnative.String, obj gdnative.Object) ObjectImplementer {
  18. // Check to see if we already have an instance of this object in our Go instance registry.
  19. if debug {
  20. log.Println("Checking to see if", obj.ID(), "is in registry:", InstanceRegistry)
  21. }
  22. if instance, ok := InstanceRegistry.Get(obj.ID()); ok {
  23. if debug {
  24. log.Println("Class instance already found in registry!")
  25. }
  26. return instance.(ObjectImplementer)
  27. }
  28. switch className {
  29. {{ range $i, $api := $view.APIs -}}
  30. {{ if $view.IsValidClass $api.Name $api.BaseClass -}}
  31. {{ if (not $api.Singleton) -}}
  32. case "{{ $api.Name }}":
  33. class := &{{ $view.SetClassName $api.Name $api.Singleton }}{}
  34. class.SetBaseObject(obj)
  35. return class
  36. {{ end -}}
  37. {{ end -}}
  38. {{ end -}}
  39. }
  40. log.Println("Could not find conversion for '" + className + "'. Defaulting to Object...")
  41. return &Object{owner: obj}
  42. }