Editor.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. import EditorUI = require("ui/EditorUI");
  8. import UIEvents = require("ui/UIEvents");
  9. import PlayMode = require("ui/playmode/PlayMode");
  10. import EditorLicense = require("./EditorLicense");
  11. import EditorEvents = require("./EditorEvents");
  12. import Preferences = require("./Preferences");
  13. class Editor extends Atomic.ScriptObject {
  14. project: ToolCore.Project;
  15. editorLicense: EditorLicense;
  16. playMode: PlayMode;
  17. static instance: Editor;
  18. constructor() {
  19. super();
  20. // limit the framerate to limit CPU usage
  21. Atomic.getEngine().maxFps = 60;
  22. Editor.instance = this;
  23. this.initUI();
  24. this.editorLicense = new EditorLicense();
  25. Preferences.getInstance().read();
  26. EditorUI.initialize();
  27. this.playMode = new PlayMode();
  28. Atomic.getResourceCache().autoReloadResources = true;
  29. this.subscribeToEvent(EditorEvents.LoadProject, (data) => this.handleEditorLoadProject(data));
  30. this.subscribeToEvent(EditorEvents.CloseProject, (data) => this.handleEditorCloseProject(data));
  31. this.subscribeToEvent("ProjectUnloaded", (data) => {
  32. Atomic.graphics.windowTitle = "AtomicEditor";
  33. this.handleProjectUnloaded(data)
  34. });
  35. this.subscribeToEvent(EditorEvents.Quit, (data) => this.handleEditorEventQuit(data));
  36. this.subscribeToEvent("ExitRequested", (data) => this.handleExitRequested(data));
  37. this.subscribeToEvent("ProjectLoaded", (data) => {
  38. Atomic.graphics.windowTitle = "AtomicEditor - " + data.projectPath;
  39. Preferences.getInstance().registerRecentProject(data.projectPath);
  40. });
  41. this.parseArguments();
  42. }
  43. initUI() {
  44. var ui = Atomic.ui;
  45. ui.loadSkin("AtomicEditor/resources/default_skin/skin.tb.txt", "AtomicEditor/editor/skin/skin.tb.txt");
  46. ui.addFont("AtomicEditor/resources/vera.ttf", "Vera");
  47. ui.addFont("AtomicEditor/resources/MesloLGS-Regular.ttf", "Monaco");
  48. ui.setDefaultFont("Vera", 12);
  49. }
  50. handleEditorLoadProject(event: EditorEvents.LoadProjectEvent): boolean {
  51. var system = ToolCore.getToolSystem();
  52. if (system.project) {
  53. this.sendEvent(UIEvents.MessageModalEvent,
  54. { type: "error", title: "Project already loaded", message: "Project already loaded" });
  55. return false;
  56. }
  57. return system.loadProject(event.path);
  58. }
  59. handleEditorCloseProject(event) {
  60. var system = ToolCore.getToolSystem();
  61. if (system.project) {
  62. system.closeProject();
  63. }
  64. }
  65. handleProjectUnloaded(event) {
  66. this.sendEvent(EditorEvents.ActiveSceneChange, { scene: null });
  67. }
  68. parseArguments() {
  69. var args = Atomic.getArguments();
  70. var idx = 0;
  71. while (idx < args.length) {
  72. if (args[idx] == "--project") {
  73. this.sendEvent(EditorEvents.LoadProject, { path: args[idx + 1] });
  74. }
  75. idx++;
  76. }
  77. }
  78. // event handling
  79. handleExitRequested(data) {
  80. Preferences.getInstance().write();
  81. EditorUI.shutdown();
  82. }
  83. handleEditorEventQuit(data) {
  84. this.sendEvent("ExitRequested");
  85. }
  86. }
  87. export = Editor;