NETAssemblyImporter.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <Atomic/IO/Log.h>
  23. #include <Atomic/IO/File.h>
  24. #include <Atomic/Resource/ResourceCache.h>
  25. #include <Atomic/Resource/Image.h>
  26. #include <AtomicNET/NETScript/CSComponentAssembly.h>
  27. #include "../NETTools/NETToolSystem.h"
  28. #include "Asset.h"
  29. #include "AssetDatabase.h"
  30. #include "NETAssemblyImporter.h"
  31. namespace ToolCore
  32. {
  33. NETAssemblyImporter::NETAssemblyImporter(Context* context, Asset *asset) : AssetImporter(context, asset)
  34. {
  35. requiresCacheFile_ = false;
  36. }
  37. NETAssemblyImporter::~NETAssemblyImporter()
  38. {
  39. }
  40. void NETAssemblyImporter::SetDefaults()
  41. {
  42. AssetImporter::SetDefaults();
  43. }
  44. bool NETAssemblyImporter::Import()
  45. {
  46. NETToolSystem* tools = GetSubsystem<NETToolSystem>();
  47. assemblyJSON_.SetType(JSON_NULL);
  48. if (tools->InspectAssembly(asset_->GetPath(), assemblyJSON_))
  49. {
  50. if (!assemblyJSON_.IsObject())
  51. {
  52. assemblyJSON_.SetType(JSON_NULL);
  53. }
  54. else
  55. {
  56. ResourceCache* cache = GetSubsystem<ResourceCache>();
  57. CSComponentAssembly* assemblyFile = cache->GetResource<CSComponentAssembly>(asset_->GetPath());
  58. if (assemblyFile)
  59. assemblyFile->ParseAssemblyJSON(assemblyJSON_);
  60. }
  61. }
  62. return true;
  63. }
  64. bool NETAssemblyImporter::LoadSettingsInternal(JSONValue& jsonRoot)
  65. {
  66. if (!AssetImporter::LoadSettingsInternal(jsonRoot))
  67. return false;
  68. JSONValue import = jsonRoot.Get("NETAssemblyImporter");
  69. assemblyJSON_.SetType(JSON_NULL);
  70. const JSONValue& ajson = import.Get("AssemblyJSON");
  71. if (ajson.IsObject())
  72. {
  73. assemblyJSON_ = ajson.GetObject();
  74. ResourceCache* cache = GetSubsystem<ResourceCache>();
  75. CSComponentAssembly* assemblyFile = cache->GetResource<CSComponentAssembly>(asset_->GetPath());
  76. if (assemblyFile)
  77. assemblyFile->ParseAssemblyJSON(assemblyJSON_);
  78. }
  79. return true;
  80. }
  81. bool NETAssemblyImporter::SaveSettingsInternal(JSONValue& jsonRoot)
  82. {
  83. if (!AssetImporter::SaveSettingsInternal(jsonRoot))
  84. return false;
  85. JSONValue import;
  86. import.SetType(JSON_OBJECT);
  87. import.Set("AssemblyJSON", assemblyJSON_);
  88. jsonRoot.Set("NETAssemblyImporter", import);
  89. return true;
  90. }
  91. Resource* NETAssemblyImporter::GetResource(const String& typeName)
  92. {
  93. ResourceCache* cache = GetSubsystem<ResourceCache>();
  94. CSComponentAssembly* assemblyFile = cache->GetResource<CSComponentAssembly>(asset_->GetPath());
  95. return assemblyFile;
  96. }
  97. }