AEEditorApp.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/Core/StringUtils.h>
  8. #include <Atomic/Engine/Engine.h>
  9. #include <Atomic/IO/FileSystem.h>
  10. #include <Atomic/Input/Input.h>
  11. #include <Atomic/Resource/ResourceCache.h>
  12. #include <Atomic/Graphics/Graphics.h>
  13. #include <Atomic/Atomic3D/AnimatedModel.h>
  14. #include <Atomic/UI/UI.h>
  15. #include <AtomicJS/Javascript/Javascript.h>
  16. #include <ToolCore/ToolEnvironment.h>
  17. #include <ToolCore/License/LicenseEvents.h>
  18. #include <ToolCore/License/LicenseSystem.h>
  19. #include "../EditorMode/AEEditorMode.h"
  20. #include "AEEditorApp.h"
  21. using namespace ToolCore;
  22. namespace AtomicEditor
  23. {
  24. extern void jsapi_init_editor(JSVM* vm);
  25. AEEditorApp::AEEditorApp(Context* context) :
  26. AEEditorCommon(context)
  27. {
  28. }
  29. void AEEditorApp::Start()
  30. {
  31. AEEditorCommon::Start();
  32. context_->RegisterSubsystem(new EditorMode(context_));
  33. vm_->SetModuleSearchPaths("AtomicEditor/JavaScript;AtomicEditor/EditorScripts;AtomicEditor/EditorScripts/AtomicEditor");
  34. // Do not create bone structure by default when in the editor
  35. // this can be toggled temporarily, for example to setup an animation preview
  36. AnimatedModel::SetBoneCreationEnabled(false);
  37. // move UI initialization to JS
  38. UI* ui = GetSubsystem<UI>();
  39. ui->Initialize("AtomicEditor/resources/language/lng_en.tb.txt");
  40. SubscribeToEvent(E_JSERROR, HANDLER(AEEditorApp, HandleJSError));
  41. SubscribeToEvent(E_EXITREQUESTED, HANDLER(AEEditorApp, HandleExitRequested));
  42. jsapi_init_editor(vm_);
  43. duk_get_global_string(vm_->GetJSContext(), "require");
  44. duk_push_string(vm_->GetJSContext(), "main");
  45. if (duk_pcall(vm_->GetJSContext(), 1) != 0)
  46. {
  47. vm_->SendJSErrorEvent();
  48. ErrorExit("Error executing main.js");
  49. }
  50. GetSubsystem<LicenseSystem>()->Initialize();
  51. }
  52. void AEEditorApp::Setup()
  53. {
  54. context_->SetEditorContext(true);
  55. AEEditorCommon::Setup();
  56. ToolEnvironment* env = GetSubsystem<ToolEnvironment>();
  57. engineParameters_["WindowTitle"] = "AtomicEditor";
  58. engineParameters_["WindowResizable"] = true;
  59. engineParameters_["FullScreen"] = false;
  60. engineParameters_["LogLevel"] = LOG_DEBUG;
  61. FileSystem* filesystem = GetSubsystem<FileSystem>();
  62. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
  63. #ifdef ATOMIC_PLATFORM_OSX
  64. engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
  65. #endif
  66. #ifdef ATOMIC_DEV_BUILD
  67. engineParameters_["ResourcePrefixPath"] = "";
  68. String resourcePaths = env->GetCoreDataDir() + ";" + env->GetEditorDataDir();
  69. // for dev builds, add the compile editor scripts from artifacts
  70. resourcePaths += ";" + env->GetRootSourceDir() + "Artifacts/Build/Resources/EditorData/";
  71. engineParameters_["ResourcePaths"] = resourcePaths;
  72. #else
  73. #ifdef ATOMIC_PLATFORM_OSX
  74. engineParameters_["ResourcePrefixPath"] = "../Resources";
  75. #else
  76. engineParameters_["ResourcePrefixPath"] = filesystem->GetProgramDir() + "Resources";
  77. #endif
  78. engineParameters_["ResourcePaths"] = "CoreData;EditorData";
  79. #endif // ATOMIC_DEV_BUILD
  80. }
  81. void AEEditorApp::Stop()
  82. {
  83. AEEditorCommon::Stop();
  84. }
  85. void AEEditorApp::HandleExitRequested(StringHash eventType, VariantMap& eventData)
  86. {
  87. }
  88. void AEEditorApp::HandleJSError(StringHash eventType, VariantMap& eventData)
  89. {
  90. using namespace JSError;
  91. //String errName = eventData[P_ERRORNAME].GetString();
  92. String errMessage = eventData[P_ERRORMESSAGE].GetString();
  93. String errFilename = eventData[P_ERRORFILENAME].GetString();
  94. //String errStack = eventData[P_ERRORSTACK].GetString();
  95. int errLineNumber = vm_->GetRealLineNumber(errFilename, eventData[P_ERRORLINENUMBER].GetInt());
  96. String errorString = ToString("%s - %s - Line: %i", errFilename.CString(), errMessage.CString(), errLineNumber);
  97. ErrorExit(errorString);
  98. }
  99. }