EditorWork.d.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 EditorServiceExtension {
  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. /**
  114. * Base Service Event Listener. Attach descendents of these to an EditorServiceExtension
  115. * to hook service events
  116. */
  117. export interface ServiceEventListener extends EditorServiceExtension { }
  118. interface EventDispatcher {
  119. /**
  120. * Send a custom event. This can be used by services to publish custom events
  121. * @param {string} eventType
  122. * @param {any} data
  123. */
  124. sendEvent(eventType: string, data: any);
  125. /**
  126. * Subscribe to an event and provide a callback. This can be used by services to subscribe to custom events
  127. * @param {string} eventType
  128. * @param {any} callback
  129. */
  130. subscribeToEvent(eventType, callback);
  131. }
  132. /**
  133. * Generic service locator of editor services that may be injected by either a plugin
  134. * or by the editor itself.
  135. */
  136. export interface ServiceLoader extends EventDispatcher {
  137. /**
  138. * Loads a service into a service registry
  139. * @param {EditorService} service
  140. */
  141. loadService(service: EditorServiceExtension): void;
  142. }
  143. /**
  144. * Service registry interface for registering services
  145. */
  146. export interface ServicesProvider<T extends ServiceEventListener> {
  147. registeredServices: T[];
  148. /**
  149. * Adds a service to the registered services list for this type of service
  150. * @param {T} service the service to register
  151. */
  152. register(service: T);
  153. /**
  154. * Removes a service from the registered services list for this type of service
  155. * @param {T} service the service to unregister
  156. */
  157. unregister(service: T);
  158. }
  159. }
  160. declare module Editor.Modal {
  161. export interface ExtensionWindow extends Atomic.UIWindow {
  162. hide();
  163. }
  164. }
  165. declare module Editor.HostExtensions {
  166. /**
  167. * Generic service locator of editor services that may be injected by either a plugin
  168. * or by the editor itself.
  169. */
  170. export interface HostServiceLocator extends Editor.Extensions.ServiceLoader {
  171. resourceServices: ResourceServicesProvider;
  172. projectServices: ProjectServicesProvider;
  173. uiServices: UIServicesProvider;
  174. }
  175. export interface HostEditorService extends Editor.Extensions.EditorServiceExtension {
  176. /**
  177. * Called by the service locator at load time
  178. */
  179. initialize(serviceLocator: HostServiceLocator);
  180. }
  181. export interface ResourceServicesEventListener extends Editor.Extensions.ServiceEventListener {
  182. save?(ev: EditorEvents.SaveResourceEvent);
  183. delete?(ev: EditorEvents.DeleteResourceEvent);
  184. rename?(ev: EditorEvents.RenameResourceEvent);
  185. }
  186. export interface ResourceServicesProvider extends Editor.Extensions.ServicesProvider<ResourceServicesEventListener> { }
  187. export interface ProjectServicesEventListener extends Editor.Extensions.ServiceEventListener {
  188. projectUnloaded?();
  189. projectLoaded?(ev: EditorEvents.LoadProjectEvent);
  190. playerStarted?();
  191. }
  192. export interface ProjectServicesProvider extends Editor.Extensions.ServicesProvider<ProjectServicesEventListener> { }
  193. export interface UIServicesEventListener extends Editor.Extensions.ServiceEventListener {
  194. menuItemClicked?(refId: string): boolean;
  195. }
  196. export interface UIServicesProvider extends Editor.Extensions.ServicesProvider<UIServicesEventListener> {
  197. createPluginMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
  198. removePluginMenuItemSource(id: string);
  199. showModalWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow;
  200. }
  201. }
  202. /**
  203. * Interfaces for client extensions
  204. */
  205. declare module Editor.ClientExtensions {
  206. /**
  207. * Generic service locator of editor services that may be injected by either a plugin
  208. * or by the editor itself.
  209. */
  210. export interface ClientServiceLocator extends Editor.Extensions.ServiceLoader {
  211. getHostInterop(): HostInterop;
  212. }
  213. export interface ClientEditorService extends Editor.Extensions.EditorServiceExtension {
  214. /**
  215. * Called by the service locator at load time
  216. */
  217. initialize(serviceLocator: ClientServiceLocator);
  218. }
  219. export interface WebViewService extends Editor.Extensions.EditorServiceExtension {
  220. configureEditor?(ev: EditorEvents.EditorFileEvent);
  221. codeLoaded?(ev: EditorEvents.CodeLoadedEvent);
  222. save?(ev: EditorEvents.CodeSavedEvent);
  223. delete?(ev: EditorEvents.DeleteResourceEvent);
  224. rename?(ev: EditorEvents.RenameResourceEvent);
  225. projectUnloaded?();
  226. }
  227. export interface AtomicErrorMessage {
  228. error_code: number;
  229. error_message: string;
  230. }
  231. /**
  232. * Interface for functions that are available from the client web view to call on the host
  233. */
  234. export interface HostInterop {
  235. /**
  236. * Called from the host to notify the client what file to load
  237. * @param {string} codeUrl
  238. */
  239. loadCode(codeUrl: string);
  240. /**
  241. * Save the contents of the editor
  242. * @return {Promise}
  243. */
  244. saveCode(): PromiseLike<{}>;
  245. /**
  246. * Save the contents of a file as filename
  247. * @param {string} filename
  248. * @param {string} fileContents
  249. * @return {Promise}
  250. */
  251. saveFile(filename: string, fileContents: string): PromiseLike<{}>;
  252. /**
  253. * Queries the host for a particular resource and returns it in a promise
  254. * @param {string} codeUrl
  255. * @return {Promise}
  256. */
  257. getResource(codeUrl: string): PromiseLike<{}>;
  258. /**
  259. * Returns a file resource from the resources directory
  260. * @param {string} filename name and path of file under the project directory or a fully qualified file name
  261. * @return {Promise}
  262. */
  263. getFileResource(filename: string): PromiseLike<{}>;
  264. /**
  265. * Notify the host that the contents of the editor has changed
  266. */
  267. notifyEditorChange();
  268. }
  269. }