NETToolSystem.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/FileSystem.h>
  9. #include <AtomicNET/NETCore/NETCore.h>
  10. #include "../Project/ProjectEvents.h"
  11. #include "../ToolEnvironment.h"
  12. #include "NETToolSystem.h"
  13. #include "NETProjectGen.h"
  14. namespace ToolCore
  15. {
  16. NETToolSystem::NETToolSystem(Context* context) : Object(context)
  17. {
  18. if (context->GetEditorContext())
  19. {
  20. NETCore* core = GetSubsystem<NETCore>();
  21. if (!core->CreateDelegate("AtomicNETTools", "AtomicTools.AtomicTools", "InspectAssembly", (void**) &inspectAssemblyFunction_))
  22. {
  23. LOGERROR("NETToolSystem::NETToolSystem - Unable to resolve delagate AtomicNETTools.InspectAssembly");
  24. }
  25. SubscribeToEvent(E_PROJECTLOADED, HANDLER(NETToolSystem, HandleProjectLoaded));
  26. }
  27. }
  28. NETToolSystem::~NETToolSystem()
  29. {
  30. }
  31. void NETToolSystem::HandleProjectLoaded(StringHash eventType, VariantMap& eventData)
  32. {
  33. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  34. String projectPath = eventData[ProjectLoaded::P_PROJECTPATH].GetString();
  35. String pathName, fileName, ext;
  36. SplitPath(projectPath, pathName, fileName, ext);
  37. String netJSONPath = AddTrailingSlash(pathName) + "AtomicNET.json";
  38. if (fileSystem->FileExists(netJSONPath))
  39. {
  40. SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));
  41. #ifdef ATOMIC_PLATFORM_OSX
  42. gen->SetScriptPlatform("MACOSX");
  43. #else
  44. gen->SetScriptPlatform("WINDOWS");
  45. #endif
  46. gen->LoadProject(netJSONPath, true);
  47. gen->Generate();
  48. }
  49. }
  50. bool NETToolSystem::InspectAssembly(const String& pathToAssembly, JSONValue &json)
  51. {
  52. json.SetType(JSON_NULL);
  53. if (!inspectAssemblyFunction_)
  54. return false;
  55. String jsonString = inspectAssemblyFunction_(pathToAssembly.CString());
  56. if (!jsonString.Length())
  57. return false;
  58. return JSONFile::ParseJSON(jsonString, json);
  59. }
  60. }