EditorWork.d.ts 9.6 KB

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