@bscotch/gamemaker-project 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE.md +29 -0
  2. package/README.md +138 -2
  3. package/dist/asset.d.ts +114 -0
  4. package/dist/asset.d.ts.map +1 -0
  5. package/dist/asset.js +259 -0
  6. package/dist/asset.js.map +1 -0
  7. package/dist/discovery.d.ts +25 -0
  8. package/dist/discovery.d.ts.map +1 -0
  9. package/dist/discovery.js +33 -0
  10. package/dist/discovery.js.map +1 -0
  11. package/dist/import.d.ts +90 -0
  12. package/dist/import.d.ts.map +1 -0
  13. package/dist/import.js +197 -0
  14. package/dist/import.js.map +1 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +10 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/objectEvents.d.ts +36 -0
  20. package/dist/objectEvents.d.ts.map +1 -0
  21. package/dist/objectEvents.js +140 -0
  22. package/dist/objectEvents.js.map +1 -0
  23. package/dist/project.d.ts +187 -0
  24. package/dist/project.d.ts.map +1 -0
  25. package/dist/project.js +732 -0
  26. package/dist/project.js.map +1 -0
  27. package/dist/project.state.d.ts +220 -0
  28. package/dist/project.state.d.ts.map +1 -0
  29. package/dist/project.state.js +718 -0
  30. package/dist/project.state.js.map +1 -0
  31. package/dist/refs.d.ts +20 -0
  32. package/dist/refs.d.ts.map +1 -0
  33. package/dist/refs.js +53 -0
  34. package/dist/refs.js.map +1 -0
  35. package/dist/shaderDefaults.d.ts +3 -0
  36. package/dist/shaderDefaults.d.ts.map +1 -0
  37. package/dist/shaderDefaults.js +32 -0
  38. package/dist/shaderDefaults.js.map +1 -0
  39. package/dist/spine.d.ts +20 -0
  40. package/dist/spine.d.ts.map +1 -0
  41. package/dist/spine.js +47 -0
  42. package/dist/spine.js.map +1 -0
  43. package/dist/spine.types.d.ts +89 -0
  44. package/dist/spine.types.d.ts.map +1 -0
  45. package/dist/spine.types.js +2 -0
  46. package/dist/spine.types.js.map +1 -0
  47. package/dist/transaction.d.ts +91 -0
  48. package/dist/transaction.d.ts.map +1 -0
  49. package/dist/transaction.js +203 -0
  50. package/dist/transaction.js.map +1 -0
  51. package/dist/util.d.ts +56 -0
  52. package/dist/util.d.ts.map +1 -0
  53. package/dist/util.js +163 -0
  54. package/dist/util.js.map +1 -0
  55. package/package.json +45 -3
@@ -0,0 +1,187 @@
1
+ import { type YyData, type YyRoom } from '@bscotch/yy';
2
+ import { type Asset, type AssetKind, type AssetRef } from './asset.ts';
3
+ import { type ObjectEvent } from './objectEvents.ts';
4
+ import { ProjectState, type GameMakerProjectOptions } from './project.state.ts';
5
+ import type { ProjectTransaction } from './transaction.ts';
6
+ export interface DeleteAssetResult {
7
+ /**
8
+ * Assets that still reference the deleted asset in a way that couldn't be
9
+ * cleaned up automatically (e.g. a tileset using a deleted sprite).
10
+ */
11
+ danglingReferences: string[];
12
+ }
13
+ /**
14
+ * A GameMaker project: its assets, folders, and settings, kept in sync with
15
+ * the files on disk.
16
+ *
17
+ * - **Disk is the source of truth.** Every change is made in a transaction
18
+ * that re-reads the files it changes, so external changes (GameMaker, git)
19
+ * are never overwritten with stale data.
20
+ * - **Changes are serialized.** Changes made through this class, and the
21
+ * processing of external changes, happen one at a time, in order.
22
+ * - **Changes are observable.** Use {@link on} to listen for assets being
23
+ * added, removed or changed — whether by this class or by something else.
24
+ *
25
+ * This class knows nothing about GML semantics. Updating code that refers to
26
+ * a renamed asset is the job of a higher layer.
27
+ */
28
+ export declare class GameMakerProject extends ProjectState {
29
+ /**
30
+ * Load a project.
31
+ * @param yypPathOrDir The path to the yyp file, or to the folder containing it.
32
+ */
33
+ static open(yypPathOrDir: string, options?: GameMakerProjectOptions): Promise<GameMakerProject>;
34
+ /**
35
+ * Set the GameMaker IDE version listed in the yyp. (The IDE overwrites
36
+ * this with its own version when it saves the project.)
37
+ */
38
+ setIdeVersion(version: string): Promise<void>;
39
+ /**
40
+ * Make the yyp's "Included Files" list match the files in the `datafiles`
41
+ * folder. Existing entries (and their settings) are kept.
42
+ */
43
+ syncIncludedFiles(): Promise<void>;
44
+ /**
45
+ * Create a folder in the asset tree (and any missing parent folders).
46
+ * Returns its POSIX path.
47
+ */
48
+ createFolder(folder: string | string[]): Promise<string>;
49
+ /** Delete a folder and its subfolders. They must not contain any assets. */
50
+ deleteFolder(folder: string | string[]): Promise<void>;
51
+ /**
52
+ * Rename or move a folder, along with its subfolders and assets. If the
53
+ * new folder already exists, the folders are merged.
54
+ */
55
+ renameFolder(from: string | string[], to: string | string[]): Promise<{
56
+ movedFolders: string[];
57
+ movedAssets: Asset[];
58
+ }>;
59
+ /** Move an asset to a folder (created if it doesn't exist) */
60
+ moveAsset(asset: AssetRef, folder: string | string[]): Promise<void>;
61
+ /**
62
+ * Create a script.
63
+ * @param assetPath The asset-tree path, ending with the script's name: `my/folder/scr_name`
64
+ */
65
+ createScript(assetPath: string, content?: string): Promise<Asset<'scripts'>>;
66
+ /**
67
+ * Create an object, with a Create event.
68
+ * @param assetPath The asset-tree path, ending with the object's name.
69
+ */
70
+ createObject(assetPath: string, options?: {
71
+ parent?: AssetRef<'objects'>;
72
+ sprite?: AssetRef<'sprites'>;
73
+ }): Promise<Asset<'objects'>>;
74
+ /**
75
+ * Create a sprite from a PNG image, with its origin in the middle.
76
+ * @param assetPath The asset-tree path, ending with the sprite's name.
77
+ */
78
+ createSprite(assetPath: string, fromImage: string): Promise<Asset<'sprites'>>;
79
+ /**
80
+ * Create a sound from an audio file. Defaults from the Stitch config's
81
+ * `newSoundRules` are applied.
82
+ * @param assetPath The asset-tree path, ending with the sound's name.
83
+ */
84
+ createSound(assetPath: string, fromFile: string): Promise<Asset<'sounds'>>;
85
+ /**
86
+ * Create an empty room, and add it to the end of the room order.
87
+ * @param assetPath The asset-tree path, ending with the room's name.
88
+ */
89
+ createRoom(assetPath: string): Promise<Asset<'rooms'>>;
90
+ /**
91
+ * Create a shader with GameMaker's default pass-through source.
92
+ * @param assetPath The asset-tree path, ending with the shader's name.
93
+ */
94
+ createShader(assetPath: string): Promise<Asset<'shaders'>>;
95
+ /**
96
+ * Add an asset whose files already exist in the project folder (e.g. written
97
+ * by a sprite importer) to the yyp, and put it in a folder. Its yy file must
98
+ * be at the standard location: `<kind>/<name>/<name>.yy`.
99
+ * @param assetPath The asset-tree path, ending with the asset's name.
100
+ */
101
+ adoptAsset<K extends AssetKind>(kind: K, assetPath: string): Promise<Asset<K>>;
102
+ /**
103
+ * Create a copy of an asset.
104
+ * @param newAssetPath The asset-tree path for the copy, ending with its
105
+ * name. If there's no folder, the copy goes in the source's folder.
106
+ */
107
+ duplicateAsset<K extends AssetKind>(source: AssetRef<K>, newAssetPath: string): Promise<Asset<K>>;
108
+ /**
109
+ * Rename an asset, updating every reference to it in the project's yy
110
+ * files (parent objects, object sprites, room instances, collision events,
111
+ * the room order, ...).
112
+ *
113
+ * GML code is not updated: that's the job of a code-aware layer.
114
+ *
115
+ * The asset is replaced by a new {@link Asset}, which is returned.
116
+ */
117
+ renameAsset<K extends AssetKind>(from: AssetRef<K>, to: string): Promise<Asset<K>>;
118
+ /**
119
+ * Delete an asset and its files.
120
+ *
121
+ * References to it are cleaned up where that's safe: object parents and
122
+ * sprites are unset, collision events with it are removed, its instances
123
+ * are removed from rooms, and it is removed from the room order. Any
124
+ * remaining references are reported.
125
+ */
126
+ deleteAsset(ref: AssetRef): Promise<DeleteAssetResult>;
127
+ /** Set (or unset) an object's parent */
128
+ setObjectParent(object: AssetRef<'objects'>, parent: AssetRef<'objects'> | undefined): Promise<void>;
129
+ /** Set (or unset) an object's sprite */
130
+ setObjectSprite(object: AssetRef<'objects'>, sprite: AssetRef<'sprites'> | undefined): Promise<void>;
131
+ /**
132
+ * Add an event to an object, creating its GML file if needed. Returns the
133
+ * path to the event's GML file.
134
+ * @param event The event, or its file name (`Step_0`) or label (`Step`).
135
+ */
136
+ createObjectEvent(object: AssetRef<'objects'>, event: ObjectEvent | string): Promise<string>;
137
+ /** Remove an event from an object, deleting its GML file */
138
+ deleteObjectEvent(object: AssetRef<'objects'>, event: ObjectEvent | string): Promise<void>;
139
+ /**
140
+ * Add an instance of an object to a room, at the end of the creation
141
+ * order. Returns the new instance's ID.
142
+ * @param options.layer The instance layer to add it to (default: the first one, created if needed)
143
+ */
144
+ addRoomInstance(room: AssetRef<'rooms'>, object: AssetRef<'objects'>, options?: {
145
+ x?: number;
146
+ y?: number;
147
+ layer?: string;
148
+ }): Promise<string>;
149
+ /** Remove an instance from a room (and its creation code, if any) */
150
+ removeRoomInstance(room: AssetRef<'rooms'>, instanceId: string): Promise<void>;
151
+ /** Set a room's instance creation order. Must list every instance exactly once. */
152
+ reorderRoomInstances(room: AssetRef<'rooms'>, instanceIds: string[]): Promise<void>;
153
+ /** Add PNG images as new frames at the end of a (non-Spine) sprite */
154
+ addSpriteFrames(sprite: AssetRef<'sprites'>, images: string[]): Promise<void>;
155
+ /** Delete frames from a (non-Spine) sprite, along with their images */
156
+ deleteSpriteFrames(sprite: AssetRef<'sprites'>, frameIds: string[]): Promise<void>;
157
+ /**
158
+ * Set the order of a (non-Spine) sprite's frames. Frames not listed are
159
+ * deleted, along with their images.
160
+ */
161
+ reorderSpriteFrames(sprite: AssetRef<'sprites'>, frameIds: string[]): Promise<void>;
162
+ /**
163
+ * Change an asset's yy data, in a transaction. `change` gets the data as
164
+ * read fresh from disk, and mutates it.
165
+ */
166
+ updateYy<K extends AssetKind>(asset: Asset<K>, change: (yy: YyData<K>) => void): Promise<void>;
167
+ protected requireSpriteForFrames(sprite: AssetRef<'sprites'>): Asset<"sprites">;
168
+ /** Split an asset-tree path into the asset name and its folder */
169
+ protected parseNewAssetPath(assetPath: string): {
170
+ name: string;
171
+ folder: string[];
172
+ };
173
+ /** Throw if the name is taken (checking disk, not just memory) */
174
+ protected assertNameAvailable(tx: ProjectTransaction, name: string, kind: AssetKind): Promise<void>;
175
+ /**
176
+ * Create a new asset: `build` writes any extra files and returns the yy
177
+ * data, which is then written and added to the yyp.
178
+ */
179
+ protected createAsset<K extends AssetKind>(kind: K, name: string, build: (tx: ProjectTransaction, dir: string) => Promise<unknown>): Promise<Asset<K>>;
180
+ protected deleteInstanceCreationCode(tx: ProjectTransaction, room: Asset, instanceId: string): Promise<void>;
181
+ /**
182
+ * Give a room's instances new IDs (instance IDs must be unique across the
183
+ * project), renaming their creation-code files to match.
184
+ */
185
+ protected renewRoomInstanceIds(tx: ProjectTransaction, room: YyRoom, dir: string): Promise<void>;
186
+ }
187
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAKA,OAAO,EASL,KAAK,MAAM,EAGX,KAAK,MAAM,EAGZ,MAAM,aAAa,CAAC;AAIrB,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,QAAQ,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAGhF,OAAO,KAAK,EAAa,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAgBtE,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;IAChD;;;OAGG;WACU,IAAI,CACf,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,gBAAgB,CAAC;IAW5B;;;OAGG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUnD;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBxC;;;OAGG;IACG,YAAY,CAAC,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