1/**
2 * Tiled can be extended with the use of JavaScript.
3 *
4 * Scripts can be used to implement {@link tiled.registerMapFormat | custom map formats},
5 * {@link tiled.registerAction | custom actions} and {@link tiled.registerTool | new tools}.
6 * Scripts can also {@link Signal | automate actions based on signals}.
7 *
8 * See the [Tiled Manual](https://doc.mapeditor.org/en/stable/reference/scripting) for more information on writing or installing extensions.
9 *
10 * ### Type Definitions
11 *
12 * TypeScript type definitions for this API are available by installing the
13 * [`@mapeditor/tiled-api`](https://www.npmjs.com/package/@mapeditor/tiled-api)
14 * package, which allows you to write scripts using TypeScript and can provide
15 * auto-completion in your editor (also when using plain JavaScript).
16 */
17
18/**
19 * The file path of the current file being evaluated. Only available during
20 * initial evaluation of the file and not when later functions in that file
21 * get called. If you need it there, copy the value to local scope.
22 */
23// declare const __filename: string; // collides with nodejs types
24
25/**
26 * {@link Qt.rect} can be used to create a rectangle.
27 */
28interface rect {
29  /**
30   * X coordinate of the rectangle.
31   */
32  x: number;
33
34  /**
35   * Y coordinate of the rectangle.
36   */
37  y: number;
38
39  /**
40   * Width of the rectangle.
41   */
42  width: number;
43
44  /**
45   * Height of the rectangle.
46   */
47  height: number;
48}
49
50interface region {
51  /**
52   * Bounding rectangle of the region.
53   */
54  readonly boundingRect: rect;
55}
56
57/**
58 * {@link Qt.point} can be used to create a point object.
59 */
60interface point {
61  /**
62   * X coordinate of the point.
63   */
64  x: number;
65
66  /**
67   * Y coordinate of the point.
68   */
69  y: number;
70}
71
72/**
73 * {@link Qt.size} can be used to create a size object.
74 */
75interface size {
76  /**
77   * Width.
78   */
79  width: number;
80
81  /**
82   * Height.
83   */
84  height: number;
85}
86
87/**
88 * A polygon is not strictly a custom type. It is an array of objects that each
89 * have an ``x`` and ``y`` property, representing the points of the polygon.
90 *
91 * To modify the polygon of a {@link MapObject}, change or set up the
92 * polygon array and then assign it to {@link MapObject.polygon}.
93 */
94type Polygon = point[];
95
96/**
97 * The value of a property of type 'object', which refers to a
98 * {@link MapObject} by its ID. Generally only used as a fallback when an
99 * object property cannot be resolved to an actual object. Can be created with
100 * {@link tiled.objectRef}.
101 */
102interface ObjectRef {
103  /**
104   * The ID of the referenced object.
105   */
106  id: number;
107}
108
109interface MenuAction {
110  /**
111   * ID of a registered action that the menu item will represent.
112   */
113  action: string;
114
115  /**
116   * ID of the action before which this menu item should be added
117   * (optional).
118   */
119  before?: string;
120}
121
122interface MenuSeparator {
123  /**
124   * Set to `true` if this item is a menu separator (optional).
125   */
126  separator: boolean;
127}
128
129type Menu = MenuAction|MenuSeparator
130
131/**
132 * Used as the value for custom 'file' properties. Can be created with
133 * {@link tiled.filePath}.
134 */
135interface FilePath {
136  /**
137   * The URL of the file.
138   */
139  url: string;
140}
141
142/**
143 * An object representing an event.
144 *
145 * Functions can be connected to the signal object, after which they will get
146 * called when the signal is emitted. The {@link tiled} module provides several
147 * useful signals, like {@link tiled.assetAboutToBeSaved}.
148 *
149 * Properties usually will have related signals which can be used to detect
150 * changes to that property, but most of those are currently not implemented.
151 *
152 * To connect to a signal, call its {@link Signal.connect | connect} function and
153 * pass in a function object. In the following example, newly created maps
154 * automatically get their first tile layer removed:
155 *
156 * ```js
157 * tiled.assetCreated.connect(function(asset) {
158 *     if (asset.layerCount > 0) {
159 *         asset.removeLayerAt(0)
160 *         tiled.log("assetCreated: Removed automatically added tile layer.")
161 *     }
162 * })
163 * ```
164 *
165 * In some cases it will be necessary to later disconnect the function from
166 * the signal again. This can be done by defining the function separately
167 * and passing it into the {@link Signal.disconnect | disconnect} function:
168 *
169 * ```js
170 * function onAssetCreated(asset) {
171 *     // Do something...
172 * }
173 *
174 * tiled.assetCreated.connect(onAssetCreated)
175 * // ...
176 * tiled.assetCreated.disconnect(onAssetCreated)
177 * ```
178 */
179interface Signal<Arg> {
180  connect(callback: (arg: Arg) => void): void;
181  disconnect(callback: (arg: Arg) => void): void;
182}
183
184/**
185 * A global object with useful enums and functions from Qt.
186 *
187 * Only a small subset of available members in the `Qt` object are documented here.
188 * See the [Qt QML Type reference](https://doc.qt.io/qt-5/qml-qtqml-qt.html) for the full documentation
189 * (keep in mind, that the QtQuick module is not currently loaded).
190 */
191declare namespace Qt {
192  export function point(x: number, y: number): point;
193  export function rect(
194    x: number,
195    y: number,
196    width: number,
197    height: number
198  ): rect;
199  export function size(width: number, height: number): size;
200
201  /**
202   * Alignment is given by a set of flags.
203   * To align to the top while horizontally centering, the value can be set to `Qt.AlignTop | Qt.AlignHCenter`.
204   */
205  type Alignment = number;
206
207  const AlignLeft: Alignment;
208  const AlignRight: Alignment;
209  const AlignVCenter: Alignment;
210  const AlignHCenter: Alignment;
211  const AlignJustify: Alignment;
212  const AlignTop: Alignment;
213  const AlignBottom: Alignment;
214  const AlignCenter: Alignment;
215}
216
217/**
218 * The `TextFile` object is used to read and write files in text mode.
219 *
220 * When using {@link TextFile.WriteOnly}, you need to call {@link commit} when you’re
221 * done writing otherwise the operation will be aborted without effect.
222 *
223 * To read and write files in binary mode, use {@link BinaryFile} instead.
224 */
225declare class TextFile {
226  static readonly ReadOnly: unique symbol;
227  static readonly WriteOnly: unique symbol;
228  static readonly ReadWrite: unique symbol;
229  static readonly Append: unique symbol;
230
231  /**
232   * The path of the file.
233   */
234  public readonly filePath: string;
235
236  /**
237   * True if no more data can be read.
238   */
239  public readonly atEof: boolean;
240
241  /**
242   * The text codec.
243   */
244  public codec: string;
245
246  /**
247   * Opens a text file in the given mode.
248   */
249  constructor(filePath: string, mode?: typeof TextFile.ReadOnly | typeof TextFile.WriteOnly | typeof TextFile.ReadWrite | typeof TextFile.Append);
250
251  /**
252   * Reads one line of text from the file and returns it. The returned string does not contain the
253   * newline characters.
254   */
255  public readLine(): string;
256
257  /**
258   * Reads all data from the file and returns it.
259   */
260  public readAll(): string;
261
262  /**
263   * Truncates the file, that is, gives it the size of zero, removing all content.
264   */
265  public truncate(): void;
266
267  /**
268   * Writes a string to the file.
269   */
270  public write(text: string): void;
271
272  /**
273   * Writes a string to the file and appends a newline character.
274   */
275  public writeLine(text: string): void;
276
277  /**
278    * Commits all written text to disk and closes the file. Should be called when writing to files in WriteOnly mode. Failing to call this function will result in cancelling the operation, unless safe writing to files is disabled.
279    */
280  public commit(): void;
281
282  /**
283    * Closes the file. It is recommended to always call this function as soon as you are finished with the file.
284    */
285  public close(): void;
286}
287
288/**
289 * The `BinaryFile` object is used to read and write files in binary mode.
290 *
291 * When using {@link BinaryFile.WriteOnly}, you need to call {@link commit} when you’re
292 * done writing otherwise the operation will be aborted without effect.
293 *
294 * To read and write files in text mode, use {@link TextFile} instead.
295 */
296declare class BinaryFile {
297  static readonly ReadOnly: unique symbol;
298  static readonly WriteOnly: unique symbol;
299  static readonly ReadWrite: unique symbol;
300
301  /**
302   * The path of the file.
303   */
304  public readonly filePath: string;
305  /**
306   * True if no more data can be read.
307   */
308  public readonly atEof: boolean;
309  /**
310   * The size of the file (in bytes).
311   */
312  public size: number;
313  /**
314   * The position that data is written to or read from.
315   */
316  public pos: number;
317
318  /**
319   * Opens a binary file in the given mode.
320   */
321  constructor(filePath: string, mode?: typeof BinaryFile.ReadOnly | typeof BinaryFile.WriteOnly | typeof BinaryFile.ReadWrite);
322
323  /**
324   * Sets the file size (in bytes). If `size` is larger than the file currently is, the new bytes
325   * will be set to 0; if `size` is smaller, the file is truncated.
326   */
327  public resize(size: number): void;
328
329  /**
330   * Sets the current position to `pos`.
331   */
332  public seek(pos: number): void;
333
334  /**
335   * Reads at most `size` bytes of data from the file and returns it as an `ArrayBuffer`.
336   */
337  public read(size: number): ArrayBuffer;
338
339  /**
340   * Reads all data from the file and returns it as an `ArrayBuffer`.
341   */
342  public readAll(): ArrayBuffer;
343
344  /**
345   * Writes data into the file at the current position.
346   */
347  public write(data: ArrayBuffer): void;
348
349  /**
350   * Commits all written data to disk and closes the file. Should be called when writing to files
351   * in WriteOnly mode. Failing to call this function will result in cancelling the operation,
352   * unless safe writing to files is disabled.
353   */
354  public commit(): void;
355
356  /**
357   * Closes the file. It is recommended to always call this function as soon as you are finished
358   * with the file.
359   */
360  public close(): void;
361}
362
363/**
364 * An action that was registered with {@link tiled.registerAction}.
365 *
366 * This class is used to change the properties of the action.
367 * It can be added to a menu using {@link tiled.extendMenu}.
368 */
369interface Action {
370  /**
371   * The ID this action was registered with.
372   */
373  readonly id: string;
374
375  /**
376   * The text used when the action is part of a menu.
377   */
378  text: string;
379
380  /**
381   * Whether the action is checked.
382   */
383  checked: boolean;
384
385  /**
386   * Whether the action can be checked.
387   */
388  checkable: boolean;
389
390  /**
391   * Whether the action is enabled.
392   */
393  enabled: boolean;
394
395  /**
396   * File name of an icon.
397   */
398  icon: string;
399
400  /**
401   * Whether the action should show an icon
402   * in a menu.
403   */
404  iconVisibleInMenu: boolean;
405
406  /**
407   * The shortcut (can be assigned a string like "Ctrl+K").
408   */
409  shortcut: string;
410
411  /**
412   * Whether the action is visible.
413   */
414  visible: boolean;
415
416  /**
417   * Triggers the action.
418   */
419  trigger(): void;
420
421  /**
422   * Changes the checked state to its opposite state.
423   */
424  toggle(): void;
425}
426
427/**
428 * The "ObjectGroup" is a type of layer that can contain objects. It will
429 * henceforth be referred to as a layer.
430 */
431declare class ObjectGroup extends Layer {
432  /**
433   * Array of all objects on this layer.
434   */
435  readonly objects : MapObject[]
436
437  /**
438   * Number of objects on this layer.
439   */
440  readonly objectCount : number
441
442  /**
443   * Color of shape and point objects on this layer (when not set by object type).
444   */
445  color : color
446
447  /**
448   * Constructs a new object layer, which can be added to a TileMap.
449   */
450  constructor(name? : string)
451
452  /**
453   * Returns a reference to the object at the given index. When the object is removed, the reference turns into a standalone copy of the object.
454   */
455  objectAt(index : number) : MapObject
456
457  /**
458   * Removes the object at the given index.
459   */
460  removeObjectAt(index : number) : void
461
462  /**
463   * Removes the given object from this layer. The object reference turns into a standalone copy of the object.
464   */
465  removeObject(object : MapObject) : void
466
467  /**
468   * Inserts the object at the given index. The object can’t already be part of a layer.
469   */
470  insertObjectAt(index : number, object : MapObject) : void
471
472  /**
473   * Adds the given object to the layer. The object can’t already be part of a layer.
474   */
475  addObject(object : MapObject) : void
476
477}
478
479type TiledObjectPropertyValue = number | string | boolean | ObjectRef | FilePath | MapObject | undefined
480
481interface TiledObjectProperties {
482  [name:string]:TiledObjectPropertyValue
483}
484
485/**
486 * The base of most data types in Tiled. Provides the ability to associate
487 * custom properties with the data.
488 */
489declare class TiledObject {
490  /**
491   * The asset this object is part of, or `null`.
492   */
493  readonly asset: Asset;
494
495  /**
496   * Whether the object is read-only.
497   */
498  readonly readOnly: boolean;
499
500  /**
501   * Returns the value of the custom property with the given name, or
502   * `undefined` if no such property is set on the object. Does not
503   * include inherited values (see {@link resolvedProperty}).
504   *
505   * `file` properties are returned as {@link FilePath}.
506   *
507   * `object` properties are returned as {@link MapObject} when possible,
508   * or {@link ObjectRef} when the object could not be found.
509   */
510  property(name: string): TiledObjectPropertyValue;
511
512  /**
513   * Sets the value of the custom property with the given name. Supported
514   * types are `bool`, `number`, `string`, {@link FilePath},
515   * {@link ObjectRef} and {@link MapObject}.
516   *
517   * When setting a `number`, the property type will be set to either
518   * `int` or `float`, depending on whether it is a whole number.
519   *
520   * @note Support for setting `color` properties is currently missing.
521   */
522  setProperty(name: string, value: TiledObjectPropertyValue): void;
523
524  /**
525   * Returns all custom properties set on this object.
526   *
527   * Modifications to the properties will not affect the original object.
528   * Does not include inherited values (see {@link resolvedProperties}).
529   */
530  properties(): TiledObjectProperties;
531
532  /**
533   * Replaces all currently set custom properties with a new set of
534   * properties.
535   */
536  setProperties(properties: TiledObjectProperties): void;
537
538  /**
539   * Removes the custom property with the given name.
540   */
541  removeProperty(name: string): void;
542
543  /**
544   * Returns the value of the custom property with the given name, or
545   * `undefined` if no such property is set. Includes values inherited
546   * from object types, templates and tiles where applicable.
547   */
548  resolvedProperty(name: string): TiledObjectPropertyValue;
549
550  /**
551   * Returns all custom properties set on this object. Modifications to
552   * the properties will not affect the original object. Includes values
553   * inherited from object types, templates and tiles where applicable.
554   */
555  resolvedProperties(): TiledObjectProperties;
556}
557
558
559interface Font {
560  /**
561   * The font family.
562   */
563  family : string
564
565  /**
566   * Font size in pixels.
567   */
568  pixelSize : number
569
570  /**
571   * Whether the font is bold.
572   */
573  bold : boolean
574
575  /**
576   * Whether the font is italic.
577   */
578  italic : boolean
579
580  /**
581   * Whether the text is underlined.
582   */
583  underline : boolean
584
585  /**
586   * Whether the text is striked through.
587   */
588  strikeOut : boolean
589
590  /**
591   * Whether to use kerning when rendering the text.
592   */
593  kerning : boolean
594}
595
596declare class MapObject extends TiledObject {
597  static readonly Rectangle: unique symbol
598  static readonly Polygon: unique symbol
599  static readonly Polyline: unique symbol
600  static readonly Ellipse: unique symbol
601  static readonly Text: unique symbol
602  static readonly Point: unique symbol
603
604  /**
605   * Unique (map-wide) ID of the object.
606   */
607  readonly id: number;
608
609  /**
610   * Shape of the object.
611   */
612  shape: typeof MapObject.Rectangle | typeof MapObject.Polygon | typeof MapObject.Polyline | typeof MapObject.Ellipse | typeof MapObject.Text | typeof MapObject.Point
613
614  /**
615   * Name of the object.
616   */
617  name: string;
618
619  /**
620   * Type of the object.
621   */
622  type: string;
623
624  /**
625   * X coordinate of the object in pixels.
626   */
627  x: number;
628
629  /**
630   * Y coordinate of the object in pixels.
631   */
632  y: number;
633
634  /**
635   * Position of the object in pixels.
636   */
637  pos: point;
638
639  /**
640   * Width of the object in pixels.
641   */
642  width: number;
643
644  /**
645   * Height of the object in pixels.
646   */
647  height: number;
648
649  /**
650   * Size of the object in pixels.
651   */
652  size: size;
653
654  /**
655   * Rotation of the object in degrees clockwise.
656   */
657  rotation: number;
658
659  /**
660   *
661   */
662  visible: boolean;
663
664  /**
665   * Polygon of the object.
666   */
667  polygon: Polygon;
668
669  /**
670   * The text of a text object.
671   */
672  text: string;
673
674  /**
675   * The font of a text object.
676   */
677  font: Font;
678
679  /**
680   * The alignment of a text object.
681   */
682  textAlignment: Qt.Alignment;
683
684  /**
685   * Whether the text of a text object wraps based on the width of the object.
686   */
687  wordWrap: boolean;
688
689  /**
690   * Color of a text object.
691   */
692  textColor: color;
693
694  /**
695   * Tile of the object.
696   */
697  tile: Tile;
698
699  /**
700   * Whether the tile is flipped horizontally.
701   */
702  tileFlippedHorizontally: boolean;
703
704  /**
705   * Whether the tile is flipped vertically.
706   */
707  tileFlippedVertically: boolean;
708
709  /**
710   * Whether the object is selected.
711   */
712  selected: boolean;
713
714  /**
715   * Layer this object is part of (or `null` in case of a standalone
716   * object).
717   */
718  layer: ObjectGroup;
719
720  /**
721   * Map this object is part of (or `null` in case of a
722   * standalone object).
723   */
724  readonly map: TileMap;
725
726  /**
727   * Constructs a new map object, which can be added to an {@link ObjectGroup}.
728   */
729  constructor(name? : string)
730}
731
732/**
733 * Represents any top-level data type that can be saved to a file.
734 *
735 * Currently either a {@link TileMap} or a {@link Tileset}.
736 *
737 * For assets that are loaded in the editor, all modifications and
738 * modifications to their contained parts create undo commands. This
739 * includes both modifying functions that are called as well as simply
740 * assigning to a writable property.
741 */
742declare class Asset extends TiledObject {
743  /**
744   * File name of the asset.
745   */
746  readonly fileName: string;
747
748  /**
749   * Whether the asset was modified after it was saved or loaded.
750   */
751  readonly modified: boolean;
752
753  /**
754   * Whether the asset is a {@link TileMap}.
755   */
756  readonly isTileMap: boolean;
757
758  /**
759   * Whether the asset is a {@link Tileset}.
760   */
761  readonly isTileset: boolean;
762
763  /**
764   * Creates a single undo command that wraps all changes applied to this
765   * asset by the given callback. Recommended to avoid spamming the undo
766   * stack with small steps that the user does not care about.
767   *
768   * Example function that changes visibility of multiple layers in one
769   * step:
770   *
771   * ```js
772   * tileMap.macro((visible ? "Show" : "Hide") + " Selected Layers", function() {
773   *     tileMap.selectedLayers.forEach(function(layer) {
774   *         layer.visible = visible
775   *     })
776   * })
777   * ```
778   *
779   * The returned value is whatever the callback function returned.
780   */
781  macro<T>(text: string, callback: () => T): T;
782
783  /**
784   * Undoes the last applied change.
785   *
786   * @note The undo system is only enabled for assets loaded in the editor!
787   */
788  undo(): void;
789
790  /**
791   * Redoes the last change that was undone.
792   *
793   * @note The undo system is only enabled for assets loaded in the editor!
794   */
795  redo(): void;
796}
797
798/**
799 * Common functionality for file format readers and writers.
800 *
801 * @since 1.4
802 */
803interface FileFormat {
804  /**
805   * Whether this format supports reading files.
806   */
807  readonly canRead: boolean;
808
809  /**
810   * Whether this format supports writing files.
811   */
812  readonly canWrite: boolean;
813
814  /**
815   * Returns whether the given file is readable by this format.
816   */
817  supportsFile(fileName: string): boolean;
818}
819
820/**
821 * An object that can read or write map files.
822 *
823 * Implementations of this interface are returned from {@link tiled.mapFormat} and {@link tiled.mapFormatForFile}.
824 *
825 * @since 1.4
826 */
827interface MapFormat extends FileFormat {
828  /**
829   * Reads the given file as a map.
830   *
831   * This function will throw an error if reading is not supported.
832   */
833  read(fileName : string) : TileMap
834
835  /**
836   * Writes the given map to a file.
837   *
838   * This function will throw an error if writing is not supported.
839   *
840   * If there is an error writing the file, it will return a description of the error; otherwise, it will return "".
841   */
842  write(map : TileMap, fileName : string) : string
843}
844
845/**
846 * An object that can read or write tileset files.
847 *
848 * Implementations of this interface are returned from {@link tiled.tilesetFormat} and {@link tiled.tilesetFormatForFile}.
849 *
850 * @since 1.4
851 */
852interface TilesetFormat extends FileFormat {
853  /**
854   * Reads the given file as a tileset.
855   *
856   * This function will throw an error if reading is not supported.
857   */
858  read(fileName : string) : Tileset
859
860  /**
861   * Writes the given tileset to a file.
862   *
863   * This function will throw an error if writing is not supported.
864   *
865   * If there is an error writing the file, it will return a description of the error; otherwise, it will return "".
866   */
867  write(tileset : Tileset, fileName : string) : string
868}
869
870/**
871 * Offers various operations on file paths, such as turning absolute paths
872 * into relative ones, splitting a path into its components, and so on.
873 */
874interface FileInfo {  // TODO: namespace instead of interface?
875  /**
876   * Returns the file name of `filePath` up to (but not including) the
877   * first '.' character.
878   */
879  baseName(filePath: string): string;
880
881  /**
882   * Returns a canonicalized `filePath`, i.e. an absolute path without
883   * symbolic links or redundant "." or ".." elements. On Windows,
884   * drive substitutions are also resolved.
885   *
886   * It is recommended to use `canonicalPath` in only those cases where
887   * canonical paths are really necessary. In most cases, `cleanPath`
888   * should be enough.
889   */
890  canonicalPath(filePath: string): string;
891
892  /**
893   * Returns `filePath` without redundant separators and with resolved
894   * occurrences of `.` and `..` components. For
895   * instance, `/usr/local//../bin/` becomes `/usr/bin`.
896   */
897  cleanPath(filePath: string): string;
898
899  /**
900   * Returns the file name of `filePath` up to (but not including) the
901   * last `.` character.
902   */
903  completeBaseName(filePath: string): string;
904
905  /**
906   * Returns the file suffix of `filePath` from (but not including) the
907   * last `.` character.
908   */
909  completeSuffix(filePath: string): string;
910
911  /**
912   * Returns the last component of `filePath`, that is, everything after
913   * the last `/` character.
914   */
915  fileName(filePath: string): string;
916
917  /**
918   * On Windows, returns `filePath` with all `\` characters replaced
919   * by `/`. On other operating systems, it returns the input
920   * unmodified.
921   */
922  fromNativeSeparators(filePath: string): string;
923
924  /**
925   * Returns true if `filePath` is an absolute path and false
926   * if it is a relative one.
927   */
928  isAbsolutePath(filePath: string): boolean;
929
930  /**
931   * Concatenates the given paths using the `/` character.
932   */
933  joinPaths(...paths:string[]) : string;
934
935  /**
936   * Returns the part of `filePath` that is not the file name, that is,
937   * everything up to (but not including) the last `/` character. If
938   * `filePath` is just a file name, then `.` is returned. If
939   * `filePath` ends with a `/` character, then the file name is
940   * assumed to be empty for the purpose of the above definition.
941   */
942  path(filePath: string): string;
943
944  /**
945   * Returns the path to `filePath` relative to the directory `dirPath`.
946   * If necessary, `..` components are inserted.
947   */
948  relativePath(dirPath: string, filePath: string): string;
949
950  /**
951   * Returns the file suffix of `filePath` from (but not including) the
952   * first `.` character.
953   */
954  suffix(filePath: string): string;
955
956  /**
957   * On Windows, returns `filePath` with all `/` characters replaced by
958   * `\`. On other operating systems, it returns the input unmodified.
959   */
960  toNativeSeparators(filePath: string): string;
961}
962
963/**
964 * A layer that groups several other layers.
965 */
966declare class GroupLayer extends Layer {
967  /**
968   * Number of child layers the group layer has.
969   */
970  readonly layerCount: number;
971
972  /**
973   * Constructs a new group layer.
974   */
975  constructor(name? : string)
976
977  /**
978   * Returns a reference to the child layer at the given index.
979   */
980  layerAt(index: number): Layer;
981
982  /**
983   * Removes the child layer at the given index. When a reference to the
984   * layer still exists and this group layer isn't already standalone,
985   * that reference becomes a standalone copy of the layer.
986   */
987  removeLayerAt(index: number): void
988
989  /**
990   * Removes the given layer from the group. If this group wasn't
991   * standalone, the reference to the layer becomes a standalone copy.
992   */
993  removeLayer(layer: Layer): void;
994
995  /**
996   * Inserts the layer at the given index. The layer can't already be
997   * part of a map.
998   *
999   * When adding a {@link TileLayer} to a map, the layer's width and height
1000   * are automatically initialized to the size of the map (since Tiled 1.4.2).
1001   */
1002  insertLayerAt(index: number, layer: Layer): void;
1003
1004  /**
1005   * Adds the layer to the group, above all existing layers. The layer
1006   * can't already be part of a map.
1007   *
1008   * When adding a {@link TileLayer} to a map, the layer's width and height
1009   * are automatically initialized to the size of the map (since Tiled 1.4.2).
1010   */
1011  addLayer(layer: Layer): void;
1012}
1013
1014/**
1015 * Can be used to create, load, save and modify images. Also useful when
1016 * writing an importer, where the image can be set on a tileset or its
1017 * tiles ({@link Tileset.loadFromImage} and {@link Tile.setImage}).
1018 *
1019 * @since 1.5
1020 */
1021declare class Image {
1022  static readonly Format_Invalid: unique symbol
1023  static readonly Format_Mono: unique symbol
1024  static readonly Format_MonoLSB: unique symbol
1025  static readonly Format_Indexed8: unique symbol
1026  static readonly Format_RGB32: unique symbol
1027  static readonly Format_ARGB32: unique symbol
1028  static readonly Format_ARGB32_Premultiplied: unique symbol
1029  static readonly Format_RGB16: unique symbol
1030  static readonly Format_ARGB8565_Premultiplied: unique symbol
1031  static readonly Format_RGB666: unique symbol
1032  static readonly Format_ARGB6666_Premultiplied: unique symbol
1033  static readonly Format_RGB555: unique symbol
1034  static readonly Format_ARGB8555_Premultiplied: unique symbol
1035  static readonly Format_RGB888: unique symbol
1036  static readonly Format_RGB444: unique symbol
1037  static readonly Format_ARGB4444_Premultiplied: unique symbol
1038  static readonly Format_RGBX8888: unique symbol
1039  static readonly Format_RGBA8888: unique symbol
1040  static readonly Format_RGBA8888_Premultiplied: unique symbol
1041  static readonly Format_BGR30: unique symbol
1042  static readonly Format_A2BGR30_Premultiplied: unique symbol
1043  static readonly Format_RGB30: unique symbol
1044  static readonly Format_A2RGB30_Premultiplied: unique symbol
1045  static readonly Format_Alpha8: unique symbol
1046  static readonly Format_Grayscale8: unique symbol
1047  static readonly Format_RGBX64: unique symbol
1048  static readonly Format_RGBA64: unique symbol
1049  static readonly Format_RGBA64_Premultiplied: unique symbol
1050  static readonly Format_Grayscale16: unique symbol
1051  static readonly Format_BGR888: unique symbol
1052
1053  static readonly IgnoreAspectRatio: unique symbol
1054  static readonly KeepAspectRatio: unique symbol
1055  static readonly KeepAspectRatioByExpanding: unique symbol
1056
1057  static readonly FastTransformation: unique symbol
1058  static readonly SmoothTransformation: unique symbol
1059
1060  /**
1061   * Width of the image in pixels.
1062   */
1063  readonly width: number;
1064
1065  /**
1066   * Height of the image in pixels.
1067   */
1068  readonly height: number;
1069
1070  /**
1071   * Number of bits used to store a single pixel.
1072   */
1073  readonly depth: number;
1074
1075  /**
1076   * Size of the image in pixels.
1077   */
1078  readonly size: size;
1079
1080  /**
1081   * Format of the image. The format is defined by one of the `Image.Format_` values.
1082   */
1083  readonly format: number;
1084
1085  /**
1086   * Constructs an empty image.
1087   */
1088  constructor();
1089
1090  /**
1091   * Constructs an image of the given size using the given format. The format is defined by one of the `Image.Format_` values.
1092   */
1093  constructor(width: number, height: number, format: number);
1094
1095  /**
1096   * Constructs an image from the given data, interpreting it in the
1097   * specified format and size. The format is defined by one of the `Image.Format_` values.
1098   */
1099  constructor(
1100    data: ArrayBuffer,
1101    width: number,
1102    height: number,
1103    format: number
1104    );
1105
1106  /**
1107   * Constructs an image from the given data, interpreting it in the
1108   * specified format and size. The `bytesPerLine` argument
1109   * specifies the stride and can be useful for referencing a sub-image.
1110   * The format is defined by one of the `Image.Format_` values.
1111   */
1112  constructor(
1113    data: ArrayBuffer,
1114    width: number,
1115    height: number,
1116    bytesPerLine: number,
1117    format: number
1118    );
1119
1120  /**
1121   * Construct an image by loading it from the given file name. When no
1122   * format is given it will be auto-detected (can be "bmp", "png",
1123   * etc.).
1124   */
1125  constructor(fileName: string, format?: string);
1126
1127  /**
1128   * Returns the 32-bit color value.
1129   */
1130  pixel(x: number, y: number): number;
1131
1132  /**
1133   * Returns the color at the given position as string like "#rrggbb".
1134   */
1135  pixelColor(x: number, y: number): string;
1136
1137  /**
1138   * Sets the color at the specified location to the given 32-bit color
1139   * value or color table index.
1140   */
1141  setPixel(x: number, y: number, index_or_rgb: number): void;
1142
1143  /**
1144   * Sets the color at the specified location to the given color by
1145   * string (supports values like "#rrggbb").
1146   */
1147  setPixelColor(x: number, y: number, color: string): void;
1148
1149  /**
1150   * Fills the image with the given 32-bit color value or color table
1151   * index.
1152   */
1153  fill(index_or_rgb: number): void;
1154
1155  /**
1156   * Fills the image with the given color by string (supports values like
1157   * "#rrggbb").
1158   */
1159  fill(color: string): void;
1160
1161  /**
1162   * Loads the image from the given file name. When no format is given it
1163   * will be auto-detected (can be "bmp", "png", etc.).
1164   */
1165  load(fileName: string, format?: string): void;
1166
1167  /**
1168   * Loads the image from the given data interpreted with the given
1169   * format (can be "bmp", "png", etc.).
1170   */
1171  loadFromData(data: ArrayBuffer, format: string): void;
1172
1173  /**
1174   * Saves the image to the given file.
1175   *
1176   * When no format is given it will be auto-detected based on the file extension.
1177   */
1178  save(fileName : string, format? : string, quality? : number) : boolean
1179
1180  /**
1181   * Saves the image to an ArrayBuffer in the given format (can be "bmp", png", etc.).
1182   */
1183  saveToData(format : string, quality? : number) : ArrayBuffer
1184
1185  /**
1186   * Returns the 32-bit color value at the given index in the color
1187   * table.
1188   */
1189  color(index: number): number;
1190
1191  /**
1192   * Returns the color table as an array of 32-bit color values.
1193   */
1194  colorTable(): number[];
1195
1196  /**
1197   * Sets the color at the given index in the color table to a given
1198   * 32-bit color value.
1199   */
1200  setColor(index: number, rgb: number): void;
1201
1202  /**
1203   * Sets the color at the given index in the color table to a color by
1204   * string (supports values like "#rrggbb").
1205   */
1206  setColor(index: number, color: string) : void;
1207
1208  /**
1209   * Sets the color table given by an array of either 32-bit color values
1210    or strings (supports values like "#rrggbb").
1211   */
1212  setColorTable(colors: number[] | string[]): void;
1213
1214  /**
1215   * Copies the given rectangle to a new image object.
1216   */
1217  copy(x: number, y: number, width: number, height: number) : Image;
1218
1219  /**
1220   * Returns a scaled copy of this image. Default `aspectRatioMode`
1221   * behavior is to ignore the aspect ratio. Default `mode` is a fast
1222   * transformation.
1223   */
1224  scaled(width: number, height: number,
1225         aspectRatioMode?: typeof Image.IgnoreAspectRatio  | typeof Image.KeepAspectRatio  | typeof Image.KeepAspectRatioByExpanding,
1226         transformationMode?: typeof Image.FastTransformation  | typeof Image.SmoothTransformation): Image;
1227
1228  /**
1229   * Returns a mirrored copy of this image.
1230   */
1231  mirrored(horizontal: boolean, vertical: boolean) : Image;
1232}
1233
1234declare class ImageLayer extends Layer {
1235  /**
1236   * Color used as transparent color when rendering the image.
1237   */
1238  transparentColor: number;
1239
1240  /**
1241   * Reference to the image rendered by this layer.
1242   */
1243  imageSource: string;
1244
1245  /**
1246   * Constructs a new image layer.
1247   */
1248  constructor(name? : string);
1249
1250  /**
1251   * Sets the image for this layer to the given image, optionally also
1252   * setting the source of the image.
1253   *
1254   * @warning This function has no undo!
1255   */
1256  loadFromImage(image: Image, source?: string) : void;
1257}
1258
1259/**
1260 * The interface that should be implemented for objects passed to {@link tiled.registerMapFormat}.
1261 */
1262interface ScriptedMapFormat {
1263  /**
1264   * Name of the format as shown in the file dialog.
1265   */
1266  readonly name: string;
1267
1268  /**
1269   * The file extension used by the format.
1270   */
1271  readonly extension: string;
1272
1273  /**
1274   * A function that reads a map from the given file. Can use
1275   * {@link TextFile} or {@link BinaryFile} to read the file.
1276   */
1277  read?(fileName: string): TileMap;
1278
1279  /**
1280   * A function that writes a map to the given
1281   * file. Can use {@link TextFile} or {@link BinaryFile} to write the file. * When a non-empty string is returned, it is shown as error message.
1282   */
1283  write?(map: TileMap, fileName: string): string | undefined;
1284
1285  /**
1286   * A function that returns the list of files that will
1287   * be written when exporting the given map (optional).
1288   */
1289  outputFiles?(map: TileMap, fileName: string): string[];
1290}
1291
1292interface MapEditor {
1293  /**
1294   * Get or set the currently used tile brush.
1295   */
1296  currentBrush : TileMap
1297
1298  /**
1299   * Access the current map view.
1300   */
1301  readonly currentMapView : MapView
1302
1303  /**
1304   * Access the Tilesets view
1305   */
1306  readonly tilesetsView: TilesetsView
1307}
1308
1309interface TilesetsView {
1310  /**
1311   * Access or change the currently displayed tileset
1312   */
1313  currentTileset: Tileset
1314  /**
1315   * A list of the tiles that are selected in the current tileset.
1316   */
1317  selectedTiles: Tile[]
1318}
1319
1320interface frame {
1321  /**
1322   * The local tile ID used to represent the frame.
1323   */
1324  tileId : number
1325
1326  /**
1327   * Duration of the frame in milliseconds.
1328   */
1329  duration : number
1330}
1331
1332declare class Tile extends TiledObject {
1333  static readonly FlippedHorizontally: 0x01
1334  static readonly FlippedVertically: 0x02
1335  static readonly FlippedAntiDiagonally: 0x04
1336  static readonly RotatedHexagonal120: 0x08
1337
1338  /**
1339   * ID of this tile within its tileset.
1340   */
1341  readonly id : number
1342
1343  /**
1344   * Width of the tile in pixels.
1345   */
1346  readonly width : number
1347
1348  /**
1349   * Height of the tile in pixels.
1350   */
1351  readonly height : number
1352
1353  /**
1354   * Size of the tile in pixels.
1355   */
1356  readonly size : size
1357
1358  /**
1359   * Type of the tile.
1360   */
1361  type : string
1362
1363  /**
1364   * File name of the tile image (when the tile is part of an image collection tileset).
1365   */
1366  imageFileName : string
1367
1368  /**
1369   * Probability that the tile gets chosen relative to other tiles.
1370   */
1371  probability : number
1372
1373  /**
1374   * The ObjectGroup associated with the tile in case collision shapes were defined. Returns null if no collision shapes were defined for this tile.
1375   */
1376  objectGroup : ObjectGroup
1377
1378  /**
1379   * This tile’s animation as an array of frames.
1380   */
1381  frames : frame[]
1382
1383  /**
1384   * Indicates whether this tile is animated.
1385   */
1386  readonly animated : boolean
1387
1388  /**
1389   * The tileset of the tile.
1390   */
1391  readonly tileset : Tileset
1392
1393  /**
1394   * Sets the image of this tile.
1395   *
1396   * @warning This function has no undo and does not affect the saved tileset!
1397   */
1398  setImage(image : Image) : void
1399}
1400
1401declare class Layer extends TiledObject {
1402  /**
1403   * Unique (map-wide) ID of the layer
1404   *
1405   * @since 1.5
1406   */
1407  readonly id: number;
1408
1409  /**
1410   * Name of the layer.
1411   */
1412  name: string;
1413
1414  /**
1415   * Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque).
1416   */
1417  opacity: any;
1418
1419  /**
1420   * Whether the layer is visible (affects child layer visibility for group layers).
1421   */
1422  visible: boolean;
1423
1424  /**
1425   * Whether the layer is locked (affects whether child layers are locked for group layers).
1426   */
1427  locked: boolean;
1428
1429  /**
1430   * Offset in pixels that is applied when this layer is rendered.
1431   */
1432  offset: point;
1433
1434  /**
1435   * Map that this layer is part of (or `null` in case of a standalone layer).
1436   */
1437  map: TileMap;
1438
1439  /**
1440   * Whether the layer is selected.
1441   */
1442  selected: boolean;
1443
1444  /**
1445   * Whether this layer is a {@link TileLayer}.
1446   */
1447  readonly isTileLayer: boolean;
1448
1449  /**
1450   * Whether this layer is an {@link ObjectGroup}.
1451   */
1452  readonly isObjectLayer: boolean;
1453
1454  /**
1455   * Whether this layer is a {@link GroupLayer}.
1456   */
1457  readonly isGroupLayer: boolean;
1458
1459  /**
1460   * Whether this layer is an {@link ImageLayer}.
1461   */
1462  readonly isImageLayer: boolean;
1463}
1464
1465interface SelectedArea {
1466  /**
1467   * Bounding rectangle of the selected area.
1468   */
1469  readonly boundingRect: rect;
1470
1471  /**
1472   * Returns the selected region.
1473   */
1474  get() : region
1475
1476  /**
1477   * Sets the selected area to the given rectangle.
1478   */
1479  set(rect : rect) : void
1480
1481  /**
1482   * Sets the selected area to the given region.
1483   */
1484  set(region : region) : void
1485
1486  /**
1487   * Adds the given rectangle to the selected area.
1488   */
1489  add(rect : rect) : void
1490
1491  /**
1492   * Adds the given region to the selected area.
1493   */
1494  add(region : region) : void
1495
1496  /**
1497   * Subtracts the given rectangle from the selected area.
1498   */
1499  subtract(rect : rect) : void
1500
1501  /**
1502   * Subtracts the given region from the selected area.
1503   */
1504  subtract(region : region) : void
1505
1506  /**
1507   * Sets the selected area to the intersection of the current selected area and the given rectangle.
1508   */
1509  intersect(rect : rect) : void
1510
1511  /**
1512   * Sets the selected area to the intersection of the current selected area and the given region.
1513   */
1514  intersect(region : region) : void
1515}
1516
1517declare class TileMap extends Asset {
1518  static readonly Unknown: unique symbol
1519  static readonly Orthogonal: unique symbol
1520  static readonly Isometric: unique symbol
1521  static readonly Staggered: unique symbol
1522  static readonly Hexagonal: unique symbol
1523
1524  static readonly XML: unique symbol
1525  static readonly Base64: unique symbol
1526  static readonly Base64Gzip: unique symbol
1527  static readonly Base64Zlib: unique symbol
1528  static readonly Base64Zstandard: unique symbol
1529  static readonly CSV: unique symbol
1530
1531  static readonly RightDown: unique symbol
1532  static readonly RightUp: unique symbol
1533  static readonly LeftDown: unique symbol
1534  static readonly LeftUp: unique symbol
1535
1536  static readonly StaggerX: unique symbol
1537  static readonly StaggerY: unique symbol
1538
1539  static readonly StaggerOdd: unique symbol
1540  static readonly StaggerEven: unique symbol
1541
1542
1543  /**
1544   * Width of the map in tiles (only relevant for non-infinite maps).
1545   */
1546  width : number
1547
1548  /**
1549   * Height of the map in tiles (only relevant for non-infinite maps).
1550   */
1551  height : number
1552
1553  /**
1554   * Size of the map in tiles (only relevant for non-infinite maps).
1555   */
1556  readonly size : size
1557
1558  /**
1559   * Tile width (used by tile layers).
1560   */
1561  tileWidth : number
1562
1563  /**
1564   * Tile height (used by tile layers).
1565   */
1566  tileHeight : number
1567
1568  /**
1569   * Whether this map is infinite.
1570   */
1571  infinite : boolean
1572
1573  /**
1574   * Length of the side of a hexagonal tile (used by tile layers on hexagonal maps).
1575   */
1576  hexSideLength : number
1577
1578  /**
1579   * For staggered and hexagonal maps, determines which axis (X or Y) is staggered.
1580   */
1581  staggerAxis : typeof TileMap.StaggerX | typeof TileMap.StaggerY
1582
1583  /**
1584   * General map orientation
1585   */
1586  orientation : typeof TileMap.Orthogonal | typeof TileMap.Isometric | typeof TileMap.Staggered | typeof TileMap.Hexagonal | typeof TileMap.Unknown
1587
1588  /**
1589   * Tile rendering order (only implemented for orthogonal maps)
1590   */
1591  renderOrder : typeof TileMap.RightDown | typeof TileMap.RightUp | typeof TileMap.LeftDown | typeof TileMap.LeftUp
1592
1593  /**
1594   * For staggered and hexagonal maps, determines whether the even or odd indexes along the staggered axis are shifted.
1595   */
1596  staggerIndex : typeof TileMap.StaggerOdd | typeof TileMap.StaggerEven
1597
1598  /**
1599   * Background color of the map.
1600   */
1601  backgroundColor : color
1602
1603  /**
1604   * The format in which the layer data is stored, taken into account by TMX, JSON and Lua map formats.
1605   */
1606  layerDataFormat : typeof TileMap.XML | typeof TileMap.Base64 | typeof TileMap.Base64Gzip | typeof TileMap.Base64Zlib | typeof TileMap.Base64Zstandard | typeof TileMap.CSV
1607
1608  /**
1609   * Number of top-level layers the map has.
1610   */
1611  readonly layerCount : number
1612
1613  /**
1614   * The list of tilesets referenced by this map. To determine which tilesets are actually used, call usedTilesets().
1615   */
1616  tilesets : Tileset[]
1617
1618  /**
1619   * The selected area of tiles.
1620   */
1621  selectedArea : SelectedArea
1622
1623  /**
1624   * The current layer.
1625   */
1626  currentLayer : Layer
1627
1628  /**
1629   * Selected layers.
1630   */
1631  selectedLayers : Layer[]
1632
1633  /**
1634   * Selected objects.
1635   */
1636  selectedObjects : MapObject[]
1637
1638  /**
1639   * Constructs a new map.
1640   */
1641  constructor();
1642
1643  /**
1644   * Applies [Automapping](https://doc.mapeditor.org/en/stable/manual/automapping/) using the given rules file, or using the default rules file is none is given.
1645   *
1646   * This operation can only be applied to maps loaded from a file.
1647   */
1648  public autoMap(rulesFule?: string): void;
1649
1650  /**
1651   * Applies [Automapping](https://doc.mapeditor.org/en/stable/manual/automapping/) in the given region using the given rules file, or using the default rules file is none is given.
1652   *
1653   * This operation can only be applied to maps loaded from a file.
1654   */
1655  public autoMap(region: region | rect, rulesFile?: string): void;
1656
1657  /**
1658   * Sets the size of the map in tiles. This does not affect the contents of the map.
1659   *
1660   * See also {@link resize}.
1661   */
1662  public setSize(width: number, height: number): void;
1663
1664  /**
1665   * Sets the tile size of the map in pixels. This affects the rendering of all tile layers.
1666   */
1667  public setTileSize(width: number, height: number): void;
1668
1669  /**
1670   * Returns a reference to the top-level layer at the given index. When the layer gets removed from the map, the reference changes to a standalone copy of the layer.
1671   */
1672  public layerAt(index: number): Layer;
1673
1674  /**
1675   * Removes the top-level layer at the given index. When a reference to the layer still exists, that reference becomes a standalone copy of the layer.
1676   */
1677  public removeLayerAt(index: number): void;
1678
1679  /**
1680   * Removes the given layer from the map. The reference to the layer becomes a standalone copy.
1681   */
1682  public removeLayer(layer: Layer): void;
1683
1684  /**
1685   * Inserts the layer at the given index. The layer can’t already be part of a map.
1686   */
1687  public insertLayerAt(index: number, layer: Layer): void;
1688
1689  /**
1690   * Adds the layer to the map, above all existing layers. The layer can’t already be part of a map.
1691   */
1692  public addLayer(layer: Layer): void;
1693
1694  /**
1695   * Adds the given tileset to the list of tilesets referenced by this map. Returns true if the tileset was added, or false if the tileset was already referenced by this map.
1696   */
1697  public addTileset(tileset: Tileset): boolean;
1698
1699  /**
1700   * Replaces all occurrences of oldTileset with newTileset. Returns true on success, or false when either the old tileset was not referenced by the map, or when the new tileset was already referenced by the map.
1701   */
1702  public replaceTileset(oldTileset: Tileset, newTileset: Tileset): boolean;
1703
1704  /**
1705   * Removes the given tileset from the list of tilesets referenced by this map. Returns true on success, or false when the given tileset was not referenced by this map or when the tileset was still in use by a tile layer or tile object.
1706   */
1707  public removeTileset(tileset: Tileset): boolean;
1708
1709  /**
1710   * Returns the list of tilesets actually used by this map. This is generally a subset of the tilesets referenced by the map (the TileMap.tilesets property).
1711   */
1712  public usedTilesets(): Tileset[];
1713
1714  /**
1715   * Merges the tile layers in the given map with this one. If only a single tile layer exists in the given map, it will be merged with the currentLayer.
1716   *
1717   * This operation can currently only be applied to maps loaded from a file.
1718   *
1719   * If `canJoin` is true, the operation joins with the previous one on the undo stack when possible. Useful for reducing the amount of undo commands.
1720   */
1721  public merge(map: TileMap, canJoin?: boolean): void;
1722
1723  /**
1724   * Resizes the map to the given size, optionally applying an offset (in tiles).
1725   *
1726   * This operation can currently only be applied to maps loaded from a file.
1727   *
1728   * See also {@link setSize}.
1729   */
1730  public resize(size: size, offset?: point, removeObjects?: boolean): void;
1731
1732  /**
1733   * Converts the given position from screen to tile coordinates.
1734   */
1735  public screenToTile(x: number, y: number): point;
1736
1737  /**
1738   * Converts the given position from screen to tile coordinates.
1739   */
1740  public screenToTile(position: point): point;
1741
1742  /**
1743   * Converts the given position from tile to screen coordinates.
1744   */
1745  public tileToScreen(x: number, y: number): point;
1746
1747  /**
1748   * Converts the given position from tile to screen coordinates.
1749   */
1750  public tileToScreen(position: point): point;
1751
1752  /**
1753   * Converts the given position from screen to pixel coordinates.
1754   */
1755  public screenToPixel(x: number, y: number): point;
1756
1757  /**
1758   * Converts the given position from screen to pixel coordinates.
1759   */
1760  public screenToPixel(position: point): point;
1761
1762  /**
1763   * Converts the given position from pixel to screen coordinates.
1764   */
1765  public pixelToScreen(x: number, y: number): point;
1766
1767  /**
1768   * Converts the given position from pixel to screen coordinates.
1769   */
1770  public pixelToScreen(position: point): point;
1771
1772  /**
1773   * Converts the given position from pixel to tile coordinates.
1774   */
1775  public pixelToTile(x: number, y: number): point;
1776
1777  /**
1778   * Converts the given position from pixel to tile coordinates.
1779   */
1780  public pixelToTile(position: point): point;
1781
1782  /**
1783   * Converts the given position from tile to pixel coordinates.
1784   */
1785  public tileToPixel(x: number, y: number): point;
1786
1787  /**
1788   * Converts the given position from tile to pixel coordinates.
1789   */
1790  public tileToPixel(position: point): point;
1791}
1792
1793/**
1794 * A cell on a {@link TileLayer}.
1795 */
1796interface cell {
1797  /**
1798   * The local tile ID of the tile, or -1 if the cell is empty.
1799   */
1800  tileId : number
1801
1802  /**
1803   * Whether the cell is empty.
1804   */
1805  empty : boolean
1806
1807  /**
1808   * Whether the tile is flipped horizontally.
1809   */
1810  flippedHorizontally : boolean
1811
1812  /**
1813   * Whether the tile is flipped vertically.
1814   */
1815  flippedVertically : boolean
1816
1817  /**
1818   * Whether the tile is flipped anti-diagonally.
1819   */
1820  flippedAntiDiagonally : boolean
1821
1822  /**
1823   * Whether the tile is rotated by 120 degrees (for hexagonal maps, the anti-diagonal flip is interpreted as a 60-degree rotation).
1824   */
1825  rotatedHexagonal120 : boolean
1826}
1827
1828/**
1829 * A tile layer.
1830 *
1831 * Note that while tile layers have a size, the size is generally ignored on
1832 * infinite maps. Even for fixed size maps, nothing in the scripting API stops you
1833 * from changing the layer outside of its boundaries and changing the size of the
1834 * layer has no effect on its contents. If you want to change the size while
1835 * affecting the contents, use the {@link resize} function.
1836 */
1837declare class TileLayer extends Layer {
1838  /**
1839   * Width of the layer in tiles (only relevant for non-infinite maps).
1840   */
1841  width : number
1842
1843  /**
1844   * Height of the layer in tiles (only relevant for non-infinite maps).
1845   */
1846  height : number
1847
1848  /**
1849   * Size of the layer in tiles (only relevant for non-infinite maps).
1850   */
1851  size : size
1852
1853  /**
1854   * Constructs a new tile layer, which can be added to a {@link TileMap}.
1855   */
1856  constructor(name? : string)
1857
1858  /**
1859   * Returns the region of the layer that is covered with tiles.
1860   */
1861  region() : region
1862
1863  /**
1864   * Resizes the layer, erasing the part of the contents that falls outside of the layer’s new size.
1865   * The offset parameter can be used to shift the contents by a certain distance in tiles before applying the resize.
1866   */
1867  resize(size : size, offset : point) : void
1868
1869  /**
1870   * Returns the value of the cell at the given position. Can be used to query the flags and the tile ID, but does not currently allow getting a tile reference (see {@link tileAt}).
1871   */
1872  cellAt(x : number, y : number) : cell
1873
1874  /**
1875   * Returns the flags used for the tile at the given position.
1876   */
1877  flagsAt(x : number, y : number) : number
1878
1879  /**
1880   * Returns the tile used at the given position, or null for empty spaces.
1881   */
1882  tileAt(x : number, y : number) : Tile | null
1883
1884  /**
1885   * Returns an object that enables making modifications to the tile layer.
1886   */
1887  edit() : TileLayerEdit
1888}
1889
1890/**
1891 * This object enables modifying the tiles on a tile layer. Tile layers can't be
1892 * modified directly for reasons of efficiency. The {@link apply}
1893 * function needs to be called when you're done making changes.
1894 *
1895 * An instance of this object is created by calling {@link TileLayer.edit}.
1896 */
1897interface TileLayerEdit {
1898  /**
1899   * The target layer of this edit object.
1900   */
1901  readonly target : TileLayer
1902
1903  /**
1904   * Whether applied edits are mergeable with previous edits. Starts out as false and is automatically set to true by {@link apply}.
1905   */
1906  mergeable : boolean
1907
1908  /**
1909   * Sets the tile at the given location, optionally specifying tile flags.
1910   */
1911  setTile(x : number, y : number, tile : Tile , flags? : number) : void
1912
1913  /**
1914   * Applies all changes made through this object. This object can be reused to make further changes.
1915   */
1916  apply() : void
1917}
1918
1919/**
1920 * @since 1.5
1921 */
1922declare class WangSet {
1923  static readonly Edge: unique symbol;
1924  static readonly Corner: unique symbol;
1925  static readonly Mixed: unique symbol;
1926
1927  /**
1928   * Name of the Wang set.
1929   */
1930  name : string
1931
1932  /**
1933   * Type of the Wang set.
1934   */
1935  type : typeof WangSet.Edge | typeof WangSet.Corner | typeof WangSet.Mixed;
1936
1937  /**
1938   * The tile used to represent the Wang set.
1939   */
1940  imageTile : Tile
1941
1942  /**
1943   * The number of colors used by this Wang set.
1944   */
1945  colorCount : number
1946
1947  /**
1948   * The tileset to which this Wang set belongs.
1949   */
1950  readonly tileset : Tileset
1951
1952  /**
1953   * Returns the current Wang ID associated with the given tile.
1954   *
1955   * The Wang ID is given by an array of 8 numbers, indicating the colors associated with each index in the following order: [Top, TopRight, Right, BottomRight, Bottom, BottomLeft, Left, TopLeft].
1956   * A value of 0 indicates that no color is associated with a given index.
1957   */
1958  public wangId(tile : Tile) : number[]
1959
1960  /**
1961   * Sets the Wang ID associated with the given tile.
1962   *
1963   * The Wang ID is given by an array of 8 numbers, indicating the colors associated with each index in the following order: [Top, TopRight, Right, BottomRight, Bottom, BottomLeft, Left, TopLeft].
1964   * A value of 0 indicates that no color is associated with a given index.
1965   *
1966   * Make sure the Wang set color count is set before calling this function, because it will raise an error when the Wang ID refers to non-existing colors.
1967   */
1968  public setWangId(tile : Tile, wangId : number[]) : void
1969}
1970
1971interface color {}
1972
1973declare class Tileset extends Asset {
1974  static readonly Unspecified: unique symbol
1975  static readonly TopLeft: unique symbol
1976  static readonly Top: unique symbol
1977  static readonly TopRight: unique symbol
1978  static readonly Left: unique symbol
1979  static readonly Center: unique symbol
1980  static readonly Right: unique symbol
1981  static readonly BottomLeft: unique symbol
1982  static readonly Bottom: unique symbol
1983  static readonly BottomRight: unique symbol
1984
1985  static readonly Orthogonal: unique symbol
1986  static readonly Isometric: unique symbol
1987
1988  /**
1989   * Name of the tileset.
1990   */
1991  name : string
1992
1993  /**
1994   * The file name of the image used by this tileset. Empty in case of image collection tilesets.
1995   */
1996  image : string
1997
1998  /**
1999   * Array of all tiles in this tileset. Note that the index of a tile in this array does not always match with its ID.
2000   */
2001  readonly tiles : Tile[]
2002
2003  /**
2004   * Array of all Wang sets in this tileset.
2005   */
2006  readonly wangSets : WangSet[]
2007
2008  /**
2009   * The number of tiles in this tileset.
2010   */
2011  tileCount : number
2012
2013  /**
2014   * The ID of the next tile that would be added to this tileset. All existing tiles have IDs that are lower than this ID.
2015   */
2016  nextTileId : number
2017
2018  /**
2019   * Tile width for tiles in this tileset in pixels.
2020   */
2021  tileWidth : number
2022
2023  /**
2024   * Tile Height for tiles in this tileset in pixels.
2025   */
2026  tileHeight : number
2027
2028  /**
2029   * Tile size for tiles in this tileset in pixels.
2030   */
2031  tileSize : size
2032
2033  /**
2034   * Width of the tileset image in pixels.
2035   */
2036  readonly imageWidth : number
2037
2038  /**
2039   * Height of the tileset image in pixels.
2040   */
2041  readonly imageHeight : number
2042
2043  /**
2044   * Size of the tileset image in pixels.
2045   */
2046  readonly imageSize : size
2047
2048  /**
2049   * Spacing between tiles in this tileset in pixels.
2050   */
2051  readonly tileSpacing : number
2052
2053  /**
2054   * Margin around the tileset in pixels (only used at the top and left sides of the tileset image).
2055   */
2056  readonly margin : number
2057
2058  /**
2059   * The alignment to use for tile objects (when Unspecified, uses Bottom alignment on isometric maps and BottomLeft alignment for all other maps).
2060   */
2061  objectAlignment : typeof Tileset.Unspecified | typeof Tileset.TopLeft | typeof Tileset.Top | typeof Tileset.TopRight | typeof Tileset.Left | typeof Tileset.Center | typeof Tileset.Right | typeof Tileset.BottomLeft | typeof Tileset.Bottom | typeof Tileset.BottomRight
2062
2063  /**
2064   * Offset in pixels that is applied when tiles from this tileset are rendered.
2065   */
2066  tileOffset : point
2067
2068  /**
2069   * The orientation of this tileset (used when rendering overlays and in the tile collision editor).
2070   */
2071  orientation : typeof Tileset.Orthogonal | typeof Tileset.Isometric
2072
2073  /**
2074   * Background color for this tileset in the Tilesets view.
2075   */
2076  backgroundColor : color
2077
2078  /**
2079   * Whether this tileset is a collection of images (same as checking whether image is an empty string).
2080   */
2081  readonly isCollection : boolean
2082
2083  /**
2084   * Selected tiles (in the tileset editor).
2085   */
2086  selectedTiles : Tile[]
2087
2088  /**
2089   * Constructs a new Tileset.
2090   */
2091  constructor(name? : string)
2092
2093  /**
2094   * Returns a reference to the tile with the given ID. Raises an error if no such tile exists. When the tile gets removed from the tileset, the reference changes to a standalone copy of the tile.
2095   *
2096   * Note that the tiles in a tileset are only guaranteed to have consecutive IDs for tileset-image based tilesets. For image collection tilesets there will be gaps when tiles have been removed from the tileset.
2097   */
2098  public tile(id : number) : Tile
2099
2100  /**
2101   * Sets the tile size for this tileset. If an image has been specified as well, the tileset will be (re)loaded. Can’t be used on image collection tilesets.
2102   */
2103  public setTileSize(width : number, height : number) : void
2104
2105  /**
2106   * Creates the tiles in this tileset by cutting them out of the given image, using the current tile size, tile spacing and margin parameters. These values should be set before calling this function.
2107   *
2108   * Optionally sets the source file of the image. This may be useful, but be careful since Tiled will try to reload the tileset from that source when the tileset parameters are changed.
2109   *
2110   * @warning This function has no undo!
2111   */
2112  public loadFromImage(image : Image, source?: string) : void
2113
2114  /**
2115   * Adds a new tile to this tileset and returns it. Only works for image collection tilesets.
2116   */
2117  public addTile() : Tile
2118
2119  /**
2120   * Removes the given tiles from this tileset. Only works for image collection tilesets.
2121   */
2122  public removeTiles(tiles : Tile[]) : void
2123
2124  /**
2125   * Add a new Wang set to this tileset with the given name and type.
2126   */
2127  public addWangSet(name : string, type : number) : WangSet
2128
2129  /**
2130   * Removes the given Wang set from this tileset.
2131   */
2132  public removeWangSet(wangSet : WangSet) : void
2133}
2134
2135/**
2136 * The interface that should be implemented for objects passed to {@link tiled.registerTilesetFormat}.
2137 */
2138interface ScriptedTilesetFormat {
2139  /**
2140   * Name of the format as shown in the file dialog.
2141   */
2142  readonly name: string;
2143
2144  /**
2145   * The file extension used by the format.
2146   */
2147  readonly extension: string;
2148
2149  /**
2150   * A function that reads a tileset from the given file.
2151   *
2152   * Can use {@link TextFile} or {@link BinaryFile} to read the file.
2153   */
2154  read?(fileName: string): Tileset;
2155
2156  /**
2157   * A function that writes a tileset to the given file.
2158   *
2159   * Can use {@link TextFile} or {@link BinaryFile} to write the file.
2160   * When a non-empty string is returned, it is shown as error message.
2161   */
2162  write?(tileset: Tileset, fileName: string) : string | undefined;
2163}
2164
2165/**
2166 * The view displaying the map.
2167 */
2168interface MapView {
2169  /**
2170   * The scale of the view.
2171   */
2172  scale : number
2173
2174  /**
2175   * The center of the view.
2176   */
2177  center : point
2178
2179  /**
2180   * Centers the view at the given location in screen coordinates. Same as assigning to the center property.
2181   */
2182  centerOn(x : number, y : number) : void
2183}
2184
2185interface TileCollisionEditor {
2186  /**
2187   * Selected objects.
2188   */
2189  selectedObjects : MapObject[]
2190
2191  /**
2192   * The map view used by the Collision Editor.
2193   */
2194  view : MapView
2195
2196  /**
2197   * Focuses the given object in the collision editor view and makes sure its
2198   * visible in its objects list. Does not automatically select the object.
2199   */
2200  focusObject(object : MapObject) : void
2201}
2202
2203interface TilesetEditor {
2204  /**
2205   * Access the collision editor within the tileset editor.
2206   */
2207  collisionEditor : TileCollisionEditor
2208}
2209
2210interface Tool {
2211  /**
2212   * Name of the tool as shown on the tool bar.
2213   */
2214  name: string;
2215
2216  /**
2217   * File name of an icon. If set, the icon is shown on the tool bar and the name becomes the tool tip.
2218   */
2219  icon: string;
2220
2221  /**
2222   * Currently active tile map.
2223   */
2224  map: TileMap;
2225
2226  /**
2227   * The last clicked tile for the active map. See also the {@link MapEditor.currentBrush} property.
2228   */
2229  selectedTile: any;
2230
2231  /**
2232   * Get or set the preview for tile layer edits.
2233   */
2234  preview: TileMap;
2235
2236  /**
2237   * Mouse cursor position in tile coordinates.
2238   */
2239  tilePosition: point;
2240
2241  /**
2242   * Text shown in the status bar while the tool is active.
2243   */
2244  statusInfo: string;
2245
2246  /**
2247   * Whether this tool is enabled.
2248   */
2249  enabled: boolean;
2250
2251  /**
2252   * Called when the tool was activated.
2253   */
2254  activated(): void;
2255
2256  /**
2257   * Called when the tool was deactivated.
2258   */
2259  deactivated(): void;
2260
2261  /**
2262   * Called when a key was pressed while the tool was active.
2263   */
2264  keyPressed(key:string, modifiers:any): void;
2265
2266  /**
2267   * Called when the mouse entered the map view.
2268   */
2269  mouseEntered(): void;
2270
2271  /**
2272   * Called when the mouse left the map view.
2273   */
2274  mouseLeft(): void;
2275
2276  /**
2277   * Called when the mouse position in the map scene changed.
2278   */
2279  mouseMoved(x: number, y: number, modifiers:any): void;
2280
2281  /**
2282   * Called when a mouse button was pressed.
2283   */
2284  mousePressed(button:any, x: number, y: number, modifiers:any): void;
2285
2286  /**
2287   * Called when a mouse button was released.
2288   */
2289  mouseReleased(button:any, x: number, y: number, modifiers:any): void;
2290
2291  /**
2292   * Called when a mouse button was double-clicked.
2293   */
2294  mouseDoubleClicked(button:any, x: number, y: number, modifiers:any): void;
2295
2296  /**
2297   * Called when the active modifier keys changed.
2298   */
2299  modifiersChanged(modifiers:any): void;
2300
2301  /**
2302   * Called when the language was changed.
2303   */
2304  languageChanged(): void;
2305
2306  /**
2307   * Called when the active map was changed.
2308   */
2309  mapChanged(oldMap: TileMap, newMap: TileMap): void;
2310
2311  /**
2312   * Called when the hovered tile position changed.
2313   */
2314  tilePositionChanged(): void;
2315
2316  /**
2317   * Called when the hovered tile position changed.
2318   *
2319   * Used to override the default updating of the status bar text.
2320   */
2321  updateStatusInfo(): void;
2322
2323  /**
2324   * Called when the map or the current layer changed.
2325   */
2326  updateEnabledState(): void;
2327}
2328
2329/**
2330 * The ``tiled`` module is the main entry point and provides properties,
2331 * functions and signals which are documented below.
2332 */
2333declare namespace tiled {
2334  /**
2335   * Currently used version of Tiled.
2336   */
2337  export const version: string;
2338
2339  /**
2340   * Operating system. One of `windows`, `macos`, `linux` or
2341   * `unix` (for any other UNIX-like system).
2342   */
2343  export const platform: string;
2344
2345  /**
2346   * Processor architecture. One of `x64`, `x86` or `unknown`.
2347   */
2348  export const arch: string;
2349
2350  /**
2351   * Available actions for {@link trigger | tiled.trigger()}.
2352   */
2353  export const actions: string[];
2354
2355  /**
2356   * Available menus for {@link extendMenu | tiled.extendMenu()}.
2357   */
2358  export const menus: string[];
2359
2360  /**
2361   * urrently selected asset, or `null` if no file is open.
2362   * Can be assigned any open asset in order to change the active asset.
2363   */
2364  export let activeAsset: Asset;
2365
2366  /**
2367   * List of currently opened {@link Asset | assets}.
2368   */
2369  export const openAssets: Asset[];
2370
2371  /**
2372   * List of supported tileset format names. Use {@link tilesetFormat}
2373   * to get the corresponding format object to read and write files.
2374   *
2375   * @since 1.4
2376   */
2377  export const tilesetFormats: string[];
2378
2379  /**
2380   * List of supported map format names. Use {@link mapFormat} to get
2381   * the corresponding format object to read and write files.
2382   *
2383   * @since 1.4
2384   */
2385  export const mapFormats: string[];
2386
2387  /**
2388   * Access the editor used when editing maps.
2389   */
2390  export const mapEditor: MapEditor;
2391
2392  /**
2393   * Access the editor used when editing tilesets.
2394   */
2395  export const tilesetEditor: TilesetEditor;
2396
2397  /**
2398   * This function can be used to trigger any registered action. This
2399   * includes most actions you would normally trigger through the menu or
2400   * by using their shortcut.
2401   *
2402   * Use the {@link actions | tiled.actions} property to get a list
2403   * of all available actions.
2404   *
2405   * Actions that are checkable will toggle when triggered.
2406   */
2407  export function trigger(action: string): void;
2408
2409  /**
2410   * Executes the first custom command with the given name, as if it was
2411   * triggered manually. Works also with commands that are not currently
2412   * enabled.
2413   *
2414   * Raises a script error if the command is not found.
2415   *
2416   * For more control over the executed binary, use {@link Process} instead.
2417   */
2418  export function executeCommand(name: string, inTerminal: boolean): void;
2419
2420  /**
2421   * Requests to open the asset with the given file name. Returns a
2422   * reference to the opened asset, or `null` in case there was a
2423   * problem.
2424   */
2425  export function open(fileName: string): Asset | null;
2426
2427  /**
2428   * Closes the given asset without checking for unsaved changes (to
2429   * confirm the loss of any unsaved changes, set {@link activeAsset} and
2430   * trigger the "Close" action instead).
2431   */
2432  export function close(asset: Asset): boolean;
2433
2434  /**
2435   * Reloads the given asset from disk, without checking for unsaved
2436   * changes. This invalidates the previous script reference to the
2437   * asset, hence the new reference is returned for convenience. Returns
2438   * `null` if reloading failed.
2439   */
2440  export function reload(asset: Asset): Asset | null;
2441
2442  /**
2443   * Shows a modal warning dialog to the user with the given text and
2444   * optional title.
2445   */
2446  export function alert(text: string, title?: string): void;
2447
2448  /**
2449   * Shows a yes/no dialog to the user with the given text and optional
2450    title. Returns `true` or `false`.
2451   */
2452  export function confirm(text: string, title?: string): boolean;
2453
2454  /**
2455   * Shows a dialog that asks the user to enter some text, along with the
2456   * given label and optional title. The optional `text` parameter
2457   * provides the initial value of the text. Returns the entered text.
2458   */
2459  export function prompt(label: string, text?: string, title?: string): string;
2460
2461  /**
2462   * Outputs the given text in the Console window as regular text.
2463   */
2464  export function log(text: string): void;
2465
2466  /**
2467   * Outputs the given text in the Console window as warning message and
2468   * creates an issue in the Issues window.
2469   *
2470   * When the issue is activated (with double-click or Enter key) the
2471   * given callback function is invoked.
2472   */
2473  export function warn(text: string, activated: () => void): void;
2474
2475  /**
2476   * Outputs the given text in the Console window as error message and
2477   * creates an issue in the Issues window.
2478   *
2479   * When the issue is activated (with double-click or Enter key) the
2480   * given callback function is invoked.
2481   */
2482  export function error(text: string, activated: () => void): void;
2483
2484  /**
2485   * Extends the menu with the given ID. Supports both a list of items or
2486   * a single item. Available menu IDs can be obtained using the
2487   * {@link tiled.menus} property.
2488   *
2489   * If a menu item does not include a `before` property, the value is
2490   * inherited from the previous item. When this property is not set at
2491   * all, the items are appended to the end of the menu.
2492   *
2493   * Example that adds a custom action to the "Edit" menu, before the
2494   * "Select All" action and separated by a separator:
2495   *
2496   * ```js
2497   * tiled.extendMenu("Edit", [
2498   *     { action: "CustomAction", before: "SelectAll" },
2499   *     { separator: true }
2500   * ]);
2501   * ```
2502   *
2503   * The "CustomAction" will need to have been registered before using
2504   * {@link registerAction | tiled.registerAction()}.
2505   */
2506  export function extendMenu(
2507    shortName: string,
2508    menu: Menu[]
2509  ): void;
2510
2511  /**
2512   * Registers a new action with the given `id` and `callback` (which is
2513   * called when the action is triggered). The returned action object can
2514   * be used to set (and update) various properties of the action.
2515   *
2516   * The shortcut will currently only work when the action is added to a
2517   * menu using {@link extendMenu | tiled.extendMenu()}.
2518   *
2519   * @example
2520   * ```js
2521   * var action = tiled.registerAction("CustomAction", function(action) {
2522   *     tiled.log(action.text + " was " + (action.checked ? "checked" : "unchecked"))
2523   * })
2524   *
2525   * action.text = "My Custom Action"
2526   * action.checkable = true
2527   * action.shortcut = "Ctrl+K"
2528   * ```
2529   */
2530  export function registerAction(
2531    id: string,
2532    callback: (action: Action) => void
2533  ): Action;
2534
2535  /**
2536   * Registers a custom tool that will become available on the Tools tool
2537   * bar of the Map Editor.
2538   *
2539   * If a tool is already registered with the same `shortName` the
2540   * existing tool is replaced.
2541   *
2542   * @example
2543   * Here is an example tool that places a rectangle each time the mouse
2544   * has moved by 32 pixels:
2545   *
2546   * ```js
2547   * var tool = tiled.registerTool("PlaceRectangles", {
2548   *     name: "Place Rectangles",
2549   *
2550   *     mouseMoved: function(x, y, modifiers) {
2551   *         if (!this.pressed)
2552   *             return
2553   *
2554   *         var dx = Math.abs(this.x - x)
2555   *         var dy = Math.abs(this.y - y)
2556   *
2557   *         this.distance += Math.sqrt(dx*dx + dy*dy)
2558   *         this.x = x
2559   *         this.y = y
2560   *
2561   *         if (this.distance > 32) {
2562   *             var objectLayer = this.map.currentLayer
2563   *
2564   *             if (objectLayer && objectLayer.isObjectLayer) {
2565   *                 var object = new MapObject(++this.counter)
2566   *                 object.x = Math.min(this.lastX, x)
2567   *                 object.y = Math.min(this.lastY, y)
2568   *                 object.width = Math.abs(this.lastX - x)
2569   *                 object.height = Math.abs(this.lastY - y)
2570   *                 objectLayer.addObject(object)
2571   *             }
2572   *
2573   *             this.distance = 0
2574   *             this.lastX = x
2575   *             this.lastY = y
2576   *         }
2577   *     },
2578   *
2579   *     mousePressed: function(button, x, y, modifiers) {
2580   *         this.pressed = true
2581   *         this.x = x
2582   *         this.y = y
2583   *         this.distance = 0
2584   *         this.counter = 0
2585   *         this.lastX = x
2586   *         this.lastY = y
2587   *     },
2588   *
2589   *     mouseReleased: function(button, x, y, modifiers) {
2590   *         this.pressed = false
2591   *     },
2592   * })
2593   * ```
2594   */
2595  export function registerTool(shortName: string, tool: Tool): Tool;
2596
2597  /**
2598   * Returns the tileset format object with the given name, or
2599    `undefined` if no object was found. See the
2600    {@link tilesetFormats} property for more info.
2601   */
2602  export function tilesetFormat(shortName: string): TilesetFormat;
2603
2604  /**
2605   * Returns the tileset format object that can read the given file, or
2606    `undefined` if no object was found.
2607   */
2608  export function tilesetFormatForFile(fileName: string): TilesetFormat;
2609
2610  /**
2611   * Returns the map format object with the given name, or
2612   * `undefined` if no object was found. See the
2613   * {@link mapFormats} property for more info.
2614   */
2615  export function mapFormat(shortName: string): MapFormat;
2616
2617  /**
2618   * Returns the map format object that can read the given file, or
2619   * `undefined` if no object was found.
2620   */
2621  export function mapFormatForFile(fileName: string): MapFormat;
2622
2623  /**
2624   * Creates a {@link FilePath} object with the given URL.
2625   */
2626  export function filePath(path: string): FilePath;
2627
2628  /**
2629   * Creates an {@link ObjectRef} object with the given ID.
2630   */
2631  export function objectRef(id: number): ObjectRef;
2632
2633  /**
2634   * Registers a new map format that can then be used to open and/or save
2635   * maps in that format.
2636   *
2637   * If a map format is already registered with the same `shortName`, the
2638   * existing format is replaced. The short name can also be used to
2639   * specify the format when using `--export-map` on the command-line, in
2640   * case the file extension is ambiguous or a different one should be
2641   * used.
2642   *
2643   * @example
2644   * Example that produces a simple JSON representation of a map:
2645   * ```js
2646   * var customMapFormat = {
2647   *     name: "Custom map format",
2648   *     extension: "custom",
2649   *
2650   *     write: function(map, fileName) {
2651   *         var m = {
2652   *             width: map.width,
2653   *             height: map.height,
2654   *             layers: []
2655   *         };
2656   *
2657   *         for (var i = 0; i < map.layerCount; ++i) {
2658   *             var layer = map.layerAt(i);
2659   *             if (layer.isTileLayer) {
2660   *                 var rows = [];
2661   *                 for (y = 0; y < layer.height; ++y) {
2662   *                     var row = [];
2663   *                     for (x = 0; x < layer.width; ++x)
2664   *                         row.push(layer.cellAt(x, y).tileId);
2665   *                     rows.push(row);
2666   *                 }
2667   *                 m.layers.push(rows);
2668   *             }
2669   *         }
2670   *
2671   *         var file = new TextFile(fileName, TextFile.WriteOnly);
2672   *         file.write(JSON.stringify(m));
2673   *         file.commit();
2674   *     },
2675   * }
2676   *
2677   * tiled.registerMapFormat("custom", customMapFormat)
2678   * ```
2679   */
2680  export function registerMapFormat(
2681    shortName: string,
2682    mapFormat: ScriptedMapFormat
2683  ): void;
2684
2685  /**
2686   * Like {@link registerMapFormat}, but registers a custom tileset
2687   * format instead.
2688   */
2689  export function registerTilesetFormat(
2690    shortName: string,
2691    tilesetFormat: ScriptedTilesetFormat
2692  ): void;
2693
2694  /**
2695   * A new asset has been created.
2696   */
2697  export const assetCreated: Signal<Asset>;
2698
2699  /**
2700   * An asset has been opened.
2701   */
2702  export const assetOpened: Signal<Asset>;
2703
2704  /**
2705   * An asset is about to be saved. Can be used to make last-minute
2706   * changes.
2707   */
2708  export const assetAboutToBeSaved: Signal<Asset>;
2709
2710  /**
2711   * An asset has been saved.
2712   */
2713  export const assetSaved: Signal<Asset>;
2714
2715  /**
2716   * An asset is about to be closed.
2717   */
2718  export const assetAboutToBeClosed: Signal<Asset>;
2719
2720  /**
2721   * The currently active asset has changed.
2722   */
2723  export const activeAssetChanged: Signal<Asset>;
2724}
2725
2726/**
2727 * The Process class allows you to start processes, track their output, and so on.
2728 *
2729 * @since 1.5
2730 */
2731declare class Process {
2732  /**
2733   * The directory the process will be started in. This only has an effect if set before the process is started.
2734   */
2735  workingDirectory : string
2736
2737  /**
2738   * True if there is no more data to be read from the process output, otherwise false.
2739   */
2740  readonly atEnd : boolean
2741
2742  /**
2743   * The exit code of the process. This is needed for retrieving the exit code from processes started via start(), rather than exec().
2744   */
2745  readonly exitCode : number
2746
2747  /**
2748   * Sets the text codec to codec. The codec is used for reading and writing from and to the process, respectively. Common codecs are supported, for example: “UTF-8”, “UTF-16”, and “ISO 8859-1”.
2749   */
2750  codec: string
2751
2752  /**
2753   * Allocates and returns a new Process object.
2754   */
2755  constructor()
2756
2757  /**
2758   * Frees the resources associated with the process. It is recommended to always call this function as soon as you are finished with the process.
2759   */
2760  close() : void
2761
2762  /**
2763   * Schedules the stdin channel of process to be closed. The channel will close once all data has been written to the process. After calling this function, any attempts to write to the process will do nothing.
2764   */
2765  closeWriteChannel() : void
2766
2767  /**
2768   * Executes the program at filePath with the given argument list and blocks until the process is finished. If an error occurs (for example, there is no executable file at filePath) and throwOnError is true (the default), then a JavaScript exception will be thrown. Otherwise, -1 will be returned in case of an error. The normal return code is the exit code of the process.
2769   */
2770  exec(filePath : string, arguments : string[] , throwOnError? : boolean) : number
2771
2772  /**
2773   * Returns the value of the variable varName in the process’ environment.
2774   */
2775  getEnv(name : string) : string
2776
2777  /**
2778   * Kills the process, causing it to exit immediately.
2779   */
2780  kill() : void
2781
2782  /**
2783   * Reads and returns one line of text from the process output, without the newline character(s).
2784   */
2785  readLine() : string
2786
2787  /**
2788   * Reads and returns all data from the process’ standard error channel.
2789   */
2790  readStdErr() : string
2791
2792  /**
2793   * Reads and returns all data from the process’ standard output channel.
2794   */
2795  readStdOut() : string
2796
2797  /**
2798   * Sets the value of variable varName to varValue in the process environment. This only has an effect if called before the process is started.
2799   */
2800  setEnv(varName : string, varValue : string) : string
2801
2802  /**
2803   * Starts the program at filePath with the given list of arguments. Returns true if the process could be started and false otherwise.
2804   *
2805   * Note: This call returns right after starting the process and should be used only if you need to interact with the process while it is running. Most of the time, you want to use exec() instead.
2806   */
2807  start(filePath : string, arguments : string[]) : boolean
2808
2809  /**
2810   * Tries to terminate the process. This is not guaranteed to make the process exit immediately; if you need that, use kill().
2811   */
2812  terminate() : void
2813
2814  /**
2815   * Blocks until the process has finished or timeout milliseconds have passed (default is 30000). Returns true if the process has finished and false if the operation has timed out. Calling this function only makes sense for processes started via start() (as opposed to exec()).
2816   */
2817  waitForFinished( msecs?:number ) : boolean
2818
2819  /**
2820   * Writes text into the process’ input channel.
2821   */
2822  write(text : string) : void
2823
2824  /**
2825   * Writes text, followed by a newline character, into the process’ input channel.
2826   */
2827  writeLine(text : string) : void
2828}
2829