NETAssemblyImporter.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. }
  47. return true;
  48. }
  49. bool NETAssemblyImporter::LoadSettingsInternal(JSONValue& jsonRoot)
  50. {
  51. if (!AssetImporter::LoadSettingsInternal(jsonRoot))
  52. return false;
  53. JSONValue import = jsonRoot.Get("NETAssemblyImporter");
  54. assemblyJSON_.SetType(JSON_NULL);
  55. const JSONValue& ajson = import.Get("AssemblyJSON");
  56. if (ajson.IsObject())
  57. {
  58. assemblyJSON_ = ajson.GetObject();
  59. ResourceCache* cache = GetSubsystem<ResourceCache>();
  60. NETAssemblyFile* assemblyFile = cache->GetResource<NETAssemblyFile>(asset_->GetPath());
  61. if (assemblyFile)
  62. assemblyFile->ParseAssemblyJSON(assemblyJSON_);
  63. }
  64. return true;
  65. }
  66. bool NETAssemblyImporter::SaveSettingsInternal(JSONValue& jsonRoot)
  67. {
  68. if (!AssetImporter::SaveSettingsInternal(jsonRoot))
  69. return false;
  70. JSONValue import;
  71. import.SetType(JSON_OBJECT);
  72. import.Set("AssemblyJSON", assemblyJSON_);
  73. jsonRoot.Set("NETAssemblyImporter", import);
  74. return true;
  75. }
  76. Resource* NETAssemblyImporter::GetResource(const String& typeName)
  77. {
  78. ResourceCache* cache = GetSubsystem<ResourceCache>();
  79. NETAssemblyFile* assemblyFile = cache->GetResource<NETAssemblyFile>(asset_->GetPath());
  80. return assemblyFile;
  81. }
  82. }