/* eslint-disable functional/prefer-type-literal */ /* eslint-disable functional/no-method-signature */ /* eslint-disable functional/prefer-readonly-type */ /* eslint-disable functional/no-class */ declare namespace Godot { /** * The Engine configuration object */ type Config = { fileSizes: { [path: string]: number }; /** * Whether the unload the engine automatically after the instance is initialized. */ unloadAfterInit: boolean; /** * The HTML DOM Canvas object to use. * By default, the first canvas element in the document will be used is none is specified. */ canvas: HTMLCanvasElement; /** * The name of the WASM file without the extension. (Set by Godot Editor export process) */ executable: string; /** * An alternative name for the game pck to load. The executable name is used otherwise. */ mainPack: string; /** * Specify a language code to select the proper localization for the game. * The browser locale will be used if none is specified. * See complete list of [supported locales](https://docs.godotengine.org/en/stable/tutorials/i18n/locales.html#doc-locales). */ locale: string; /** * The canvas resize policy determines how the canvas should be resized by Godot. * - `0` means Godot won't do any resizing. This is useful if you want to control the canvas size from javascript code in your template. * - `1` means Godot will resize the canvas on start, and when changing window size via engine functions. * - `2` means Godot will adapt the canvas size to match the whole browser window. */ canvasResizePolicy: 0 | 1 | 2; /** * The arguments to be passed as command line arguments on startup. * See [command line tutorial](https://docs.godotengine.org/en/stable/tutorials/editor/command_line_tutorial.html#doc-command-line-tutorial). * Note: `startGame` will always add the `--main-pack` argument. */ args: string[]; /** * A callback function for handling Godot's OS.execute calls. * This is for example used in the Web Editor template to switch between project manager and editor, and for running the game. * * @param path The path that Godot's wants executed. * @param args The arguments of the "command" to execute. */ onExecute(path: string, args: string[]): void; /** * A callback function for being notified when the Godot instance quits. * **Note**: This function will not be called if the engine crashes or become unresponsive * @param status_code The status code returned by Godot on exit. */ onExit(status_code: number): void; /** * A callback function for displaying download progress. * The function is called once per frame while downloading files, so the usage of requestAnimationFrame() is not necessary. * If the callback function receives a total amount of bytes as 0, this means that it is impossible to calculate. Possible reasons include: * * - Files are delivered with server-side chunked compression * - Files are delivered with server-side compression on Chromium * - Not all file downloads have started yet (usually on servers without multi-threading) * * @param current The current amount of downloaded bytes so far. * @param total The total amount of bytes to be downloaded. */ onProgress(current: number, total: number): void; /** * A callback function for handling the standard output stream. This method should usually only be used in debug pages. * By default, `console.log()` is used. * @param args A variadic number of arguments to be printed. */ onPrint(...args: unknown[]): void; /** * A callback function for handling the standard error stream. This method should usually only be used in debug pages. * By default, `console.error()` is used. * @param args A variadic number of arguments to be printed as errors. */ onPrintError(...args: unknown[]): void; }; /** * The Engine class provides methods for loading and starting exported projects on the Web. * For default export settings, this is already part of the exported HTML page. * To understand practical use of the Engine class, see [Custom HTML page for Web export](https://docs.godotengine.org/en/stable/tutorials/platform/customizing_html5_shell.html#doc-customizing-html5-shell). */ interface EngineClass { new (initConfig?: Partial): Engine; /** * Load the engine from the specified base path. * @param basePath Base path of the engine to load. * @return A Promise that resolves once the engine is loaded. */ load(basePath: string): Promise; /** * Unload the engine to free memory. * This method will be called automatically depending on the configuration. * @see Config.unloadAfterInit */ unload(): void; /** * Check whether WebGL is available. Optionally, specify a particular version of WebGL to check for. * @param majorVersion The major WebGL version to check for */ isWebGLAvailable(majorVersion?: number): boolean; } interface Engine { config: Config; /** * Initialize the engine instance. Optionally, pass the base path to the engine to load it, if it hasn't been loaded yet. * @param basePath Base path of the engine to load. * @returns A Promise that resolves once the engine is loaded and initialized. * @see load() */ init(basePath: string): Promise; /** * Load a file so it is available in the instance's file system once it runs. Must be called before starting the instance. * If not provided, the path is derived from the URL of the loaded file. * * @param file The file to preload. * If a string the file will be loaded from that path. * If an ArrayBuffer or a view on one, the buffer will used as the content of the file. * @param path Path by which the file will be accessible. Required, if file is not a string. * @return A Promise that resolves once the file is loaded. */ preloadFile(file: string | ArrayBuffer, path?: string): Promise; /** * Start the engine instance using the given override configuration (if any). `startGame` can be used in typical cases instead. * This will initialize the instance if it is not initialized. For manual initialization, see `init`. The engine must be loaded beforehand. * Fails if a canvas cannot be found on the page, or not specified in the configuration. * * @param override An optional configuration override. * @return Promise that resolves once the engine started. */ start(override: Partial): Promise; /** * Start the game instance using the given configuration override (if any). * This will initialize the instance if it is not initialized. For manual initialization, see `init`. * This will load the engine if it is not loaded, and preload the main pck. * This method expects the initial config (or the override) to have both the `executable` and `mainPack` properties set (normally done by the editor during export). * @param override An optional configuration override. * @return Promise that resolves once the game started. */ startGame(override: Partial): Promise; /** * Create a file at the specified path with the passed as buffer in the instance's file system. * @param path The location where the file will be created. * @param buffer The content of the file. */ copyToFS(path: string, buffer: ArrayBuffer): void; /** * Request that the current instance quit. * This is akin the user pressing the close button in the window manager, and will have no effect if the engine has crashed, or is stuck in a loop. */ requestQuit(): void; } interface PreloaderClass { new (): Preloader; } interface Preloader { /** * contains the files loaded by that Preloader instance. * Push them to the Godot file system with something like: * ```js * preloader.preloadedFiles.forEach(file => { * engine.copyToFS(file.path, file.buffer) * }) * ``` * If you used `raw`, then the `buffer` property contains a `Blob` object. */ preloadedFiles: { path: string; buffer: ArrayBuffer | Blob }[]; /** * Calls a progress func for every tick. * If no total filesize was provided, then the progress will not be correctly calculated. * * Note that this isn't automatically called; You should request it at regular intervals. * The easiest way to do this is: * ```js * requestAnimationFrame(preloader.animateProgress); * ``` * the callback function will then be called on each frame. * @param callback the function to be called when progress is made */ setProgressFunc(callback: (loaded: number, total: number) => void): void; /** * Loads a file, returns a promise that is resolved when the file is loaded. * If the file fails, then the function will try to download again 4 times. * @param pathOrBuffer The path to the file * @param fileSize The size of the file. Must be provided for the callback to work * @param raw if true, the file's `Blob` will be returned rather than just the array buffer. Defaults to `false` */ loadPromise( pathOrBuffer: string | ArrayBuffer, fileSize: number, raw?: boolean ): void; /** * Loads a file, returns a promise that is resolved when the file is loaded. * Adds the file to the list of loaded files if successful. * @param pathOrBuffer The path to the file * @param destPath The destination path to write the file to. * @param fileSize The size of the file. Must be provided for the callback to work */ preload( pathOrBuffer: string | ArrayBuffer, destPath: string, fileSize: number ): void; } }