editorConfig.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 editor from "./editor";
  8. import serviceLocator from "../clientExtensions/ServiceLocator";
  9. import HostInterop from "../interop";
  10. const CONFIGURE_EDITOR_EVENT = "ConfigureEditor";
  11. const CODE_LOADED_NOTIFICATION = "CodeLoadedNotification";
  12. /**
  13. * Set the editor theme and configuration based upon the file extension
  14. * @param {string} fileExt
  15. */
  16. export function configure(fileExt: string, filename: string) {
  17. // set a default theme
  18. editor.setTheme("ace/theme/monokai");
  19. // set a default mode
  20. editor.session.setMode("ace/mode/javascript");
  21. // give the language extensions the opportunity to configure the editor based upon the file type
  22. serviceLocator.sendEvent(CONFIGURE_EDITOR_EVENT, {
  23. fileExt: fileExt,
  24. filename: filename,
  25. editor: editor
  26. });
  27. }
  28. /**
  29. * Loads a file of code into the editor and wires up the change events
  30. * @param {string} code
  31. * @param {string} filename
  32. * @param {string} fileExt
  33. */
  34. export function loadCodeIntoEditor(code: string, filename: string, fileExt: string) {
  35. editor.session.setValue(code);
  36. editor.gotoLine(0);
  37. editor.getSession().on("change", function(e) {
  38. HostInterop.getInstance().notifyEditorChange();
  39. });
  40. serviceLocator.sendEvent(CODE_LOADED_NOTIFICATION, {
  41. code: code,
  42. filename: filename,
  43. fileExt: fileExt,
  44. editor: editor
  45. });
  46. }