NETAssemblyImporter.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/IO/Log.h>
  8. #include <Atomic/IO/File.h>
  9. #include <Atomic/Resource/ResourceCache.h>
  10. #include <Atomic/Resource/Image.h>
  11. #include <AtomicNET/NETCore/NETAssemblyFile.h>
  12. #include "../NETTools/NETToolSystem.h"
  13. #include "Asset.h"
  14. #include "AssetDatabase.h"
  15. #include "NETAssemblyImporter.h"
  16. namespace ToolCore
  17. {
  18. NETAssemblyImporter::NETAssemblyImporter(Context* context, Asset *asset) : AssetImporter(context, asset)
  19. {
  20. requiresCacheFile_ = false;
  21. }
  22. NETAssemblyImporter::~NETAssemblyImporter()
  23. {
  24. }
  25. void NETAssemblyImporter::SetDefaults()
  26. {
  27. AssetImporter::SetDefaults();
  28. }
  29. bool NETAssemblyImporter::Import()
  30. {
  31. NETToolSystem* tools = GetSubsystem<NETToolSystem>();
  32. assemblyJSON_.SetType(JSON_NULL);
  33. if (tools->InspectAssembly(asset_->GetPath(), assemblyJSON_))
  34. {
  35. if (!assemblyJSON_.IsObject())
  36. {
  37. assemblyJSON_.SetType(JSON_NULL);
  38. }
  39. else
  40. {
  41. ResourceCache* cache = GetSubsystem<ResourceCache>();
  42. NETAssemblyFile* assemblyFile = cache->GetResource<NETAssemblyFile>(asset_->GetPath());
  43. if (assemblyFile)
  44. assemblyFile->ParseAssemblyJSON(assemblyJSON_);
  45. }
  46. //if (assemblyJSON.IsObject())
  47. //{
  48. /*
  49. const JSONValue& enums = assemblyJSON.Get("enums");
  50. const JSONArray& components = assemblyJSON.Get("components").GetArray();
  51. for (unsigned i = 0; i < components.Size(); i++)
  52. {
  53. const JSONValue& c = components.At(i);
  54. String componentName = c.Get("name").GetString();
  55. LOGINFOF("Found NET Component %s", componentName.CString());
  56. }
  57. */
  58. //}
  59. }
  60. return true;
  61. }
  62. bool NETAssemblyImporter::LoadSettingsInternal(JSONValue& jsonRoot)
  63. {
  64. if (!AssetImporter::LoadSettingsInternal(jsonRoot))
  65. return false;
  66. JSONValue import = jsonRoot.Get("NETAssemblyImporter");
  67. assemblyJSON_.SetType(JSON_NULL);
  68. const JSONValue& ajson = import.Get("AssemblyJSON");
  69. if (ajson.IsObject())
  70. {
  71. assemblyJSON_ = ajson.GetObject();
  72. ResourceCache* cache = GetSubsystem<ResourceCache>();
  73. NETAssemblyFile* assemblyFile = cache->GetResource<NETAssemblyFile>(asset_->GetPath());
  74. if (assemblyFile)
  75. assemblyFile->ParseAssemblyJSON(assemblyJSON_);
  76. }
  77. return true;
  78. }
  79. bool NETAssemblyImporter::SaveSettingsInternal(JSONValue& jsonRoot)
  80. {
  81. if (!AssetImporter::SaveSettingsInternal(jsonRoot))
  82. return false;
  83. JSONValue import;
  84. import.SetType(JSON_OBJECT);
  85. import.Set("AssemblyJSON", assemblyJSON_);
  86. jsonRoot.Set("NETAssemblyImporter", import);
  87. return true;
  88. }
  89. Resource* NETAssemblyImporter::GetResource(const String& typeName)
  90. {
  91. ResourceCache* cache = GetSubsystem<ResourceCache>();
  92. NETAssemblyFile* assemblyFile = cache->GetResource<NETAssemblyFile>(asset_->GetPath());
  93. return assemblyFile;
  94. }
  95. }