EditorWork.d.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. /// <reference path="Atomic.d.ts" />
  8. /// <reference path="Editor.d.ts" />
  9. declare module Editor.EditorEvents {
  10. export interface ModalErrorEvent {
  11. title: string;
  12. message: string;
  13. }
  14. export interface PlayerLogEvent {
  15. message: string;
  16. level: number;
  17. }
  18. export interface ActiveSceneEditorChangeEvent {
  19. sceneEditor: Editor.SceneEditor3D;
  20. }
  21. export interface SceneClosedEvent {
  22. scene: Atomic.Scene;
  23. }
  24. export interface ContentFolderChangedEvent {
  25. path: string;
  26. }
  27. export interface LoadProjectEvent {
  28. // The full path to the .atomic file
  29. path: string;
  30. }
  31. /**
  32. * Called once the resource has been saved
  33. * @type {String}
  34. */
  35. export interface SaveResourceEvent {
  36. // The full path to the resource to save / empty or undefined for current
  37. path: string;
  38. }
  39. export interface LoadResourceEvent {
  40. // The full path to the resource to load
  41. path: string;
  42. }
  43. export interface EditorFileEvent {
  44. filename: string;
  45. fileExt: string;
  46. editor: any;
  47. }
  48. export interface CodeLoadedEvent extends EditorFileEvent {
  49. code: string;
  50. }
  51. export interface CodeSavedEvent extends EditorFileEvent {
  52. code: string;
  53. }
  54. export interface EditorCloseResourceEvent {
  55. editor: Editor.ResourceEditor;
  56. navigateToAvailableResource: boolean;
  57. }
  58. export interface EditResourceEvent {
  59. // The full path to the resource to edit
  60. path: string;
  61. }
  62. /**
  63. * Called once the resource has been deleted
  64. * @type {String}
  65. */
  66. export interface DeleteResourceEvent {
  67. // The full path to the resource to edit
  68. path: string;
  69. }
  70. /**
  71. * Called once the resource has been renamed
  72. * @type {String}
  73. */
  74. export interface RenameResourceEvent {
  75. /**
  76. * Original path of the resource
  77. * @type {string}
  78. */
  79. path: string;
  80. /**
  81. * New path of the resource
  82. * @type {string}
  83. */
  84. newPath: string;
  85. /**
  86. * New base name of the resource (no path or extension)
  87. * @type {string}
  88. */
  89. newName?: string;
  90. // the asset being changed
  91. asset?: ToolCore.Asset;
  92. }
  93. export interface SceneEditStateChangeEvent {
  94. serializable: Atomic.Serializable;
  95. }
  96. }
  97. declare module Editor.Extensions {
  98. /**
  99. * Base interface for any editor services.
  100. */
  101. export interface EditorService {
  102. /**
  103. * Unique name of this service
  104. * @type {string}
  105. */
  106. name: string;
  107. /**
  108. * Description of this service
  109. * @type {string}
  110. */
  111. description: string;
  112. }
  113. interface EventDispatcher {
  114. /**
  115. * Send a custom event. This can be used by services to publish custom events
  116. * @param {string} eventType
  117. * @param {any} data
  118. */
  119. sendEvent(eventType: string, data: any);
  120. /**
  121. * Subscribe to an event and provide a callback. This can be used by services to subscribe to custom events
  122. * @param {string} eventType
  123. * @param {any} callback
  124. */
  125. subscribeToEvent(eventType, callback);
  126. }
  127. /**
  128. * Generic service locator of editor services that may be injected by either a plugin
  129. * or by the editor itself.
  130. */
  131. export interface ServiceLoader extends EventDispatcher {
  132. /**
  133. * Loads a service into a service registry
  134. * @param {EditorService} service
  135. */
  136. loadService(service: EditorService): void;
  137. }
  138. /**
  139. * Service registry interface for registering services
  140. */
  141. export interface ServiceRegistry<T extends EditorService> {
  142. registeredServices: T[];
  143. /**
  144. * Adds a service to the registered services list for this type of service
  145. * @param {T} service the service to register
  146. */
  147. register(service: T);
  148. /**
  149. * Removes a service from the registered services list for this type of service
  150. * @param {T} service the service to unregister
  151. */
  152. unregister(service: T);
  153. }
  154. }
  155. declare module Editor.Modal {
  156. export interface ExtensionWindow extends Atomic.UIWindow {
  157. hide();
  158. }
  159. }
  160. declare module Editor.HostExtensions {
  161. /**
  162. * Generic service locator of editor services that may be injected by either a plugin
  163. * or by the editor itself.
  164. */
  165. export interface HostServiceLocator extends Editor.Extensions.ServiceLoader {
  166. resourceServices: ResourceServiceRegistry;
  167. projectServices: ProjectServiceRegistry;
  168. uiServices: UIServiceRegistry;
  169. }
  170. export interface HostEditorService extends Editor.Extensions.EditorService {
  171. /**
  172. * Called by the service locator at load time
  173. */
  174. initialize(serviceLocator: Editor.Extensions.ServiceLoader);
  175. }
  176. export interface ResourceService extends Editor.Extensions.EditorService {
  177. save?(ev: EditorEvents.SaveResourceEvent);
  178. delete?(ev: EditorEvents.DeleteResourceEvent);
  179. rename?(ev: EditorEvents.RenameResourceEvent);
  180. }
  181. export interface ResourceServiceRegistry extends Editor.Extensions.ServiceRegistry<ResourceService> { }
  182. export interface ProjectService extends Editor.Extensions.EditorService {
  183. projectUnloaded?();
  184. projectLoaded?(ev: EditorEvents.LoadProjectEvent);
  185. playerStarted?();
  186. }
  187. export interface ProjectServiceRegistry extends Editor.Extensions.ServiceRegistry<ProjectService> { }
  188. export interface UIService extends Editor.Extensions.EditorService {
  189. menuItemClicked?(refId: string): boolean;
  190. }
  191. export interface UIServiceRegistry extends Editor.Extensions.ServiceRegistry<UIService> {
  192. createPluginMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
  193. removePluginMenuItemSource(id: string);
  194. showModalWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow;
  195. menuItemClicked(refId: string): boolean;
  196. }
  197. }
  198. /**
  199. * Interfaces for client extensions
  200. */
  201. declare module Editor.ClientExtensions {
  202. /**
  203. * Generic service locator of editor services that may be injected by either a plugin
  204. * or by the editor itself.
  205. */
  206. export interface ClientServiceLocator extends Editor.Extensions.ServiceLoader {
  207. getHostInterop(): HostInterop;
  208. }
  209. export interface ClientEditorService extends Editor.Extensions.EditorService {
  210. /**
  211. * Called by the service locator at load time
  212. */
  213. initialize(serviceLocator: ClientServiceLocator);
  214. }
  215. export interface WebViewService extends Editor.Extensions.EditorService {
  216. configureEditor?(ev: EditorEvents.EditorFileEvent);
  217. codeLoaded?(ev: EditorEvents.CodeLoadedEvent);
  218. save?(ev: EditorEvents.CodeSavedEvent);
  219. delete?(ev: EditorEvents.DeleteResourceEvent);
  220. rename?(ev: EditorEvents.RenameResourceEvent);
  221. projectUnloaded?();
  222. }
  223. export interface AtomicErrorMessage {
  224. error_code: number;
  225. error_message: string;
  226. }
  227. /**
  228. * Interface for functions that are available from the client web view to call on the host
  229. */
  230. export interface HostInterop {
  231. /**
  232. * Called from the host to notify the client what file to load
  233. * @param {string} codeUrl
  234. */
  235. loadCode(codeUrl: string);
  236. /**
  237. * Save the contents of the editor
  238. * @return {Promise}
  239. */
  240. saveCode(): PromiseLike<{}>;
  241. /**
  242. * Save the contents of a file as filename
  243. * @param {string} filename
  244. * @param {string} fileContents
  245. * @return {Promise}
  246. */
  247. saveFile(filename: string, fileContents: string): PromiseLike<{}>;
  248. /**
  249. * Queries the host for a particular resource and returns it in a promise
  250. * @param {string} codeUrl
  251. * @return {Promise}
  252. */
  253. getResource(codeUrl: string): PromiseLike<{}>;
  254. /**
  255. * Returns a file resource from the resources directory
  256. * @param {string} filename name and path of file under the project directory or a fully qualified file name
  257. * @return {Promise}
  258. */
  259. getFileResource(filename: string): PromiseLike<{}>;
  260. /**
  261. * Notify the host that the contents of the editor has changed
  262. */
  263. notifyEditorChange();
  264. }
  265. }