AEEditorApp.cpp 4.8 KB

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