@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.
- package/LICENSE.md +29 -0
- package/README.md +138 -2
- package/dist/asset.d.ts +114 -0
- package/dist/asset.d.ts.map +1 -0
- package/dist/asset.js +259 -0
- package/dist/asset.js.map +1 -0
- package/dist/discovery.d.ts +25 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +33 -0
- package/dist/discovery.js.map +1 -0
- package/dist/import.d.ts +90 -0
- package/dist/import.d.ts.map +1 -0
- package/dist/import.js +197 -0
- package/dist/import.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/objectEvents.d.ts +36 -0
- package/dist/objectEvents.d.ts.map +1 -0
- package/dist/objectEvents.js +140 -0
- package/dist/objectEvents.js.map +1 -0
- package/dist/project.d.ts +187 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +732 -0
- package/dist/project.js.map +1 -0
- package/dist/project.state.d.ts +220 -0
- package/dist/project.state.d.ts.map +1 -0
- package/dist/project.state.js +718 -0
- package/dist/project.state.js.map +1 -0
- package/dist/refs.d.ts +20 -0
- package/dist/refs.d.ts.map +1 -0
- package/dist/refs.js +53 -0
- package/dist/refs.js.map +1 -0
- package/dist/shaderDefaults.d.ts +3 -0
- package/dist/shaderDefaults.d.ts.map +1 -0
- package/dist/shaderDefaults.js +32 -0
- package/dist/shaderDefaults.js.map +1 -0
- package/dist/spine.d.ts +20 -0
- package/dist/spine.d.ts.map +1 -0
- package/dist/spine.js +47 -0
- package/dist/spine.js.map +1 -0
- package/dist/spine.types.d.ts +89 -0
- package/dist/spine.types.d.ts.map +1 -0
- package/dist/spine.types.js +2 -0
- package/dist/spine.types.js.map +1 -0
- package/dist/transaction.d.ts +91 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +203 -0
- package/dist/transaction.js.map +1 -0
- package/dist/util.d.ts +56 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +163 -0
- package/dist/util.js.map +1 -0
- package/package.json +45 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# License for the Stitch Monorepo
|
|
2
|
+
|
|
3
|
+
License information for the content of this git repository. The various packages in this repo are developed by [Butterscotch Shenanigans](https://www.bscotch.net) ("Bscotch").
|
|
4
|
+
|
|
5
|
+
## License files
|
|
6
|
+
|
|
7
|
+
Whenever a `LICENSE` file is found in a folder, or a license is specified by a `package.json` or similar manifest file, that license takes precedence for all files in that folder and its subfolders.
|
|
8
|
+
|
|
9
|
+
This is the root-most `LICENSE` file, and therefore dictates the default licensing in this repository.
|
|
10
|
+
|
|
11
|
+
## Stitch name and logo
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
Stitch™ and its logo are trademarks of Bscotch. Bscotch reserves all rights to Stitch and its logo.
|
|
16
|
+
|
|
17
|
+
Stitch Logo ©2022 by Bscotch. All rights reserved.
|
|
18
|
+
|
|
19
|
+
## Other code and content
|
|
20
|
+
|
|
21
|
+
Everything found in this project, except for the Stitch name and logo as described above or unless otherwise specified by a more proximal LICENSE file, falls under the MIT license (https://opensource.org/license/mit/):
|
|
22
|
+
|
|
23
|
+
Copyright 2023 Butterscotch Shenanigans
|
|
24
|
+
|
|
25
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
26
|
+
|
|
27
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,139 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bscotch/gamemaker-project
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read and safely change GameMaker projects: assets, folders, and settings, in their yyp/yy files.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { GameMakerProject } from '@bscotch/gamemaker-project';
|
|
8
|
+
|
|
9
|
+
const project = await GameMakerProject.open('path/to/project');
|
|
10
|
+
|
|
11
|
+
project.on('assetAdded', (asset) => console.log('Added', asset.name));
|
|
12
|
+
const stopWatching = project.watch();
|
|
13
|
+
|
|
14
|
+
const player = await project.createObject('Objects/o_player', {
|
|
15
|
+
sprite: 'sp_player',
|
|
16
|
+
});
|
|
17
|
+
await project.createObjectEvent(player, 'Step');
|
|
18
|
+
await project.renameAsset(player, 'o_hero');
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What it does (and doesn't)
|
|
22
|
+
|
|
23
|
+
This package only knows about project *files*. Each asset is its yy data plus the files in its folder. It knows nothing about GML semantics, so it doesn't parse code, track symbols, or rewrite code references when an asset is renamed. A higher layer composes this package with GML analysis to do that.
|
|
24
|
+
|
|
25
|
+
## Guarantees
|
|
26
|
+
|
|
27
|
+
- **Disk is the source of truth.** Every change runs in a transaction that re-reads the yyp and the yy files it touches before changing them. Changes made by GameMaker, git or other tools in the meantime are kept, never overwritten with stale data.
|
|
28
|
+
- **Changes are serialized.** Transactions, and the processing of external changes, run one at a time, in order. Before a transaction runs, pending external changes are processed.
|
|
29
|
+
- **The yyp never points to missing files.** yy files are written before the yyp. Old files are deleted only after the yyp no longer lists them. If a transaction throws, what can be undone is undone.
|
|
30
|
+
- **Git operations are waited out.** While `.git/index.lock` exists (e.g. during a pull or checkout), the project waits before reading changes or writing files (`gitLockTimeoutMs`, 10s by default).
|
|
31
|
+
- **Events reflect real changes.** On a change notification, the project compares disk with memory and emits events only for real differences. Its own writes are recognized and don't cause duplicate events. Unchanged rewrites cause no events at all.
|
|
32
|
+
- **Writes are minimal.** Files whose content wouldn't change are not rewritten.
|
|
33
|
+
|
|
34
|
+
## Keeping up with external changes
|
|
35
|
+
|
|
36
|
+
The project has to be told when files change. Either:
|
|
37
|
+
- call `project.watch()`, which uses Node's recursive file watcher; or
|
|
38
|
+
- forward an editor's file-watcher events with `project.notifyChanged(paths)`.
|
|
39
|
+
|
|
40
|
+
Changes are collected for a moment (`changeDebounceMs`) and then processed together.
|
|
41
|
+
|
|
42
|
+
`project.reconcile()` checks everything against disk. `project.idle()` resolves once everything pending has been processed.
|
|
43
|
+
|
|
44
|
+
Events:
|
|
45
|
+
|
|
46
|
+
| Event | When |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `assetAdded` / `assetRemoved` | An asset was added to or removed from the yyp (a rename is a remove plus an add). |
|
|
49
|
+
| `assetChanged` | An asset's yy file changed, it gained or lost GML files, or other files in its folder changed (e.g. sprite frames). |
|
|
50
|
+
| `gmlChanged` | An existing GML file's content changed. |
|
|
51
|
+
| `yypChanged` | Something in the yyp besides its resources changed (folders, configs, included files, ...). |
|
|
52
|
+
| `configChanged` | `stitch.config.json` changed. |
|
|
53
|
+
| `includedFilesChanged` | Files in `datafiles/` changed. See `syncIncludedFiles()`. |
|
|
54
|
+
| `error` | Something couldn't be read. Half-written files are retried a few times. |
|
|
55
|
+
|
|
56
|
+
An `Asset` keeps its identity (`===`) while its data changes. Treat `asset.yy` and `project.yyp` as read-only, and change them through the project's methods.
|
|
57
|
+
|
|
58
|
+
## API overview
|
|
59
|
+
|
|
60
|
+
**Queries:**
|
|
61
|
+
- `assets`, `listAssets(kind?)`, `getAsset(name)`, `requireAsset(name, kind?)`, `getAssetByPath(file)`
|
|
62
|
+
- `getParent`, `getAncestors`, `getChildren` (objects)
|
|
63
|
+
- `listAssetsInFolder`
|
|
64
|
+
- `folders`, `configs`, `includedFiles`, `audioGroups`, `textureGroups`, `ideVersion`, `config`, `getWindowsName()`
|
|
65
|
+
|
|
66
|
+
**Per asset:**
|
|
67
|
+
- `gmlFiles` (only the files GameMaker uses: a script's file, an object's event files, a room's creation code), `orphanedGmlFiles`
|
|
68
|
+
- `folder`, `isInFolder()`
|
|
69
|
+
- Objects: `parentName`, `spriteName`, `listEvents()`, `getEventFile()`
|
|
70
|
+
- Rooms: `roomInstances`, `roomCreationCodeFile`
|
|
71
|
+
- Sprites: `frameIds`, `framePaths`, `isSpineSprite`, `spinePaths`
|
|
72
|
+
- Sounds: `soundFile`; shaders: `shaderPaths`
|
|
73
|
+
|
|
74
|
+
**Changes:**
|
|
75
|
+
- Create: `createScript`, `createObject`, `createSprite`, `createSound`, `createRoom`, `createShader`, `duplicateAsset`
|
|
76
|
+
- `renameAsset`, `deleteAsset`, `moveAsset`
|
|
77
|
+
- Folders: `createFolder`, `renameFolder`, `deleteFolder`
|
|
78
|
+
- Objects: `setObjectParent`, `setObjectSprite`, `createObjectEvent`, `deleteObjectEvent`
|
|
79
|
+
- Rooms: `addRoomInstance`, `removeRoomInstance`, `reorderRoomInstances`
|
|
80
|
+
- Sprites: `addSpriteFrames`, `deleteSpriteFrames`, `reorderSpriteFrames`
|
|
81
|
+
- Settings: `setIdeVersion`, `syncIncludedFiles`
|
|
82
|
+
- Anything else: `transaction(async (tx) => ...)`, using `tx.yyp()`, `tx.yy(asset)`, `tx.stageYy()`, `tx.writeFile()`, and so on.
|
|
83
|
+
|
|
84
|
+
**Importing** from another project: `importAssets(source, target, options)`, or `planImport` for a dry run. Dependencies found in yy files are handled here. Code dependencies can be passed in through `options.dependencies`.
|
|
85
|
+
|
|
86
|
+
**Other:**
|
|
87
|
+
- Object event helpers: `getEvent`, `getEventFromFilename`, `getEventFromLabel`, `objectEvents`
|
|
88
|
+
- Spine helpers: `readSpineJson`, `summarizeSpine`
|
|
89
|
+
|
|
90
|
+
## Differences from `@bscotch/gml-parser` v2
|
|
91
|
+
|
|
92
|
+
This package replaces the file-handling half of the `Project`/`Asset` classes in v2 of `@bscotch/gml-parser`. Where the old behavior was wrong, it was fixed rather than reproduced:
|
|
93
|
+
|
|
94
|
+
- **No hidden writes.**
|
|
95
|
+
- Setting a property never writes a file in the background; every change is an explicit, awaitable method.
|
|
96
|
+
- Imports no longer write a log file into the project. Problems are reported as structured `ImportError`s.
|
|
97
|
+
- **Assets that were deleted externally are removed** when the yyp changes. The old `reloadYyp` only ever added assets.
|
|
98
|
+
- **GML files are the ones GameMaker uses:**
|
|
99
|
+
- An object's event files come from its yy's event list, rather than from every `.gml` file in its folder. Leftover files are listed in `orphanedGmlFiles`.
|
|
100
|
+
- Room and instance creation code is included.
|
|
101
|
+
- **Renames update every reference in the project's yy files.** References are always `{name, path}` objects, so collision events (and their files), room instances, the room order, tilesets, sequences and so on are all found. The yyp entry is updated in place, and case-only renames work.
|
|
102
|
+
- **Deletes clean up references:**
|
|
103
|
+
- room instances (and their creation code);
|
|
104
|
+
- collision events (and their files);
|
|
105
|
+
- parent and sprite references;
|
|
106
|
+
- the room order.
|
|
107
|
+
|
|
108
|
+
Any references that remain are reported.
|
|
109
|
+
- **Duplicates:**
|
|
110
|
+
- A duplicated room gets new instance IDs, since instance IDs must be unique across the project, and is added to the room order.
|
|
111
|
+
- Duplicates keep their source's folder unless a new one is given.
|
|
112
|
+
- **Object events:**
|
|
113
|
+
- All 16 user events and 12 alarms are listed. The old table only had User Event 0.
|
|
114
|
+
- Any event type (keyboard, gesture, etc.) can be created from its file name.
|
|
115
|
+
- **Rooms:** instance layers nested inside layer folders are included.
|
|
116
|
+
- **New assets:**
|
|
117
|
+
- Assets can be created at the root of the asset tree.
|
|
118
|
+
- New GML files are empty.
|
|
119
|
+
- Sprites get a true middle-centre origin.
|
|
120
|
+
- **Yyp entries:** new entries are appended. `@bscotch/yy` sorts the yyp the same way GameMaker does, so the old random insertion (to avoid git conflicts) isn't needed.
|
|
121
|
+
|
|
122
|
+
## Testing
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
pnpm test
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The tests copy the sample projects in `../parser/samples` into temporary folders. The sync tests cover:
|
|
129
|
+
- external changes;
|
|
130
|
+
- half-written files;
|
|
131
|
+
- git locks;
|
|
132
|
+
- the project ignoring its own writes;
|
|
133
|
+
- not losing external changes made while the project's state was stale.
|
|
134
|
+
|
|
135
|
+
To benchmark loading a real project:
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
node scripts/bench-load.ts path/to/project
|
|
139
|
+
```
|
package/dist/asset.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { YyData, YyResourceType, YyRoom, YyRoomInstanceLayer, YypResourceId } from '@bscotch/yy';
|
|
2
|
+
import { type ObjectEvent } from './objectEvents.ts';
|
|
3
|
+
export type AssetKind = YyResourceType;
|
|
4
|
+
/** A reference to an asset: the asset itself, or its name (case-insensitive) */
|
|
5
|
+
export type AssetRef<K extends AssetKind = AssetKind> = Asset<K> | string;
|
|
6
|
+
export interface ObjectEventFile {
|
|
7
|
+
event: ObjectEvent;
|
|
8
|
+
/** Absolute path to the event's GML file */
|
|
9
|
+
file: string;
|
|
10
|
+
}
|
|
11
|
+
export interface RoomInstanceInfo {
|
|
12
|
+
/** The instance's unique name (e.g. `inst_1A2B3C4D`) */
|
|
13
|
+
instanceId: string;
|
|
14
|
+
objectName: string;
|
|
15
|
+
layerName: string;
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
/** The path to the instance's creation code, if it has any */
|
|
19
|
+
creationCodeFile?: string;
|
|
20
|
+
}
|
|
21
|
+
/** @internal Everything needed to construct an {@link Asset} */
|
|
22
|
+
export interface AssetInit<K extends AssetKind> {
|
|
23
|
+
kind: K;
|
|
24
|
+
id: YypResourceId;
|
|
25
|
+
yyPath: string;
|
|
26
|
+
yy: YyData<K>;
|
|
27
|
+
yyHash: string;
|
|
28
|
+
/** The names of the files in the asset's directory */
|
|
29
|
+
dirEntries: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A GameMaker asset ("resource"): its yy data and the files that belong to it.
|
|
33
|
+
*
|
|
34
|
+
* An `Asset` is a read-only view of what is on disk. To change an asset, use
|
|
35
|
+
* the methods on {@link GameMakerProject}, which write to disk and then update
|
|
36
|
+
* the `Asset` (emitting events). Do not mutate {@link yy} directly.
|
|
37
|
+
*
|
|
38
|
+
* An asset keeps the same identity (`===`) for its whole life, even as its
|
|
39
|
+
* data changes. Renaming an asset replaces it with a new one.
|
|
40
|
+
*/
|
|
41
|
+
export declare class Asset<K extends AssetKind = AssetKind> {
|
|
42
|
+
readonly kind: K;
|
|
43
|
+
/** The yyp resource id, e.g. `{name: 'obj_player', path: 'objects/obj_player/obj_player.yy'}` */
|
|
44
|
+
readonly id: Readonly<YypResourceId>;
|
|
45
|
+
/** Absolute path to the asset's yy file */
|
|
46
|
+
readonly yyPath: string;
|
|
47
|
+
protected _yy: YyData<K>;
|
|
48
|
+
protected _yyHash: string;
|
|
49
|
+
protected _gmlFiles: string[];
|
|
50
|
+
protected _orphanedGmlFiles: string[];
|
|
51
|
+
/** @internal Use the project's methods to get assets */
|
|
52
|
+
constructor(init: AssetInit<K>);
|
|
53
|
+
/** @internal Replace the asset's data with what is now on disk */
|
|
54
|
+
update(init: Pick<AssetInit<K>, 'yy' | 'yyHash' | 'dirEntries'>): void;
|
|
55
|
+
/** @internal Recompute which GML files belong to this asset */
|
|
56
|
+
updateGmlFiles(dirEntries: string[]): void;
|
|
57
|
+
/** @internal A hash of the yy file's content, for change detection */
|
|
58
|
+
get yyHash(): string;
|
|
59
|
+
/** The asset's yy data, as read from disk. Do not mutate! */
|
|
60
|
+
get yy(): YyData<K>;
|
|
61
|
+
get name(): string;
|
|
62
|
+
/** Absolute path to the asset's directory */
|
|
63
|
+
get dir(): string;
|
|
64
|
+
/** The asset's folder in the IDE's asset tree, in POSIX form (`my/folder`) */
|
|
65
|
+
get folder(): string;
|
|
66
|
+
/** Whether this asset is in the given folder, or one of its subfolders */
|
|
67
|
+
isInFolder(folder: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Absolute paths to the GML files that belong to this asset: a script's
|
|
70
|
+
* file, an object's event files (Create first, then in event order), or a
|
|
71
|
+
* room's creation code files. Only files GameMaker would use are included.
|
|
72
|
+
*/
|
|
73
|
+
get gmlFiles(): readonly string[];
|
|
74
|
+
/**
|
|
75
|
+
* GML files in the asset's directory that GameMaker would ignore (e.g. the
|
|
76
|
+
* file for an event that has been removed from the object).
|
|
77
|
+
*/
|
|
78
|
+
get orphanedGmlFiles(): readonly string[];
|
|
79
|
+
isKind<T extends AssetKind>(kind: T): this is Asset<T>;
|
|
80
|
+
/** For objects, the name of the parent object */
|
|
81
|
+
get parentName(): string | undefined;
|
|
82
|
+
/** For objects, the name of the sprite */
|
|
83
|
+
get spriteName(): string | undefined;
|
|
84
|
+
/** For objects, the events listed in the yy file, with their file names */
|
|
85
|
+
listEvents(): ObjectEventFile[];
|
|
86
|
+
/** For objects, the GML file for an event, by file name (e.g. `Step_0`) */
|
|
87
|
+
getEventFile(eventName: string): string | undefined;
|
|
88
|
+
/** For rooms, the object instances, in creation order */
|
|
89
|
+
get roomInstances(): RoomInstanceInfo[];
|
|
90
|
+
/** For rooms, the path to the room's creation code, if it has any */
|
|
91
|
+
get roomCreationCodeFile(): string | undefined;
|
|
92
|
+
get isSpineSprite(): boolean;
|
|
93
|
+
/** For sprites, the frame IDs, in order */
|
|
94
|
+
get frameIds(): string[];
|
|
95
|
+
/** For non-Spine sprites, the frame image paths, in order */
|
|
96
|
+
get framePaths(): string[];
|
|
97
|
+
/** For Spine sprites, the paths to the Spine files */
|
|
98
|
+
get spinePaths(): {
|
|
99
|
+
json: string;
|
|
100
|
+
atlas: string;
|
|
101
|
+
} | undefined;
|
|
102
|
+
/** For sounds, the path to the audio file */
|
|
103
|
+
get soundFile(): string | undefined;
|
|
104
|
+
/** For shaders, the paths to the shader source files */
|
|
105
|
+
get shaderPaths(): {
|
|
106
|
+
vertex: string;
|
|
107
|
+
fragment: string;
|
|
108
|
+
} | undefined;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* List a room's instance layers, including those nested in layer folders.
|
|
112
|
+
*/
|
|
113
|
+
export declare function instanceLayers(room: YyRoom): YyRoomInstanceLayer[];
|
|
114
|
+
//# sourceMappingURL=asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../src/asset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EAEN,cAAc,EACd,MAAM,EACN,mBAAmB,EAGnB,aAAa,EACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG/D,MAAM,MAAM,SAAS,GAAG,cAAc,CAAC;AAEvC,gFAAgF;AAChF,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAE1E,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,8DAA8D;IAC9D,gBAAgB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,MAAM,GAAG,mBAAmB,EAAE,CAclE"}
|
package/dist/asset.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { getEvent } from "./objectEvents.js";
|
|
3
|
+
import { folderPathToPosix, key } from "./util.js";
|
|
4
|
+
/**
|
|
5
|
+
* A GameMaker asset ("resource"): its yy data and the files that belong to it.
|
|
6
|
+
*
|
|
7
|
+
* An `Asset` is a read-only view of what is on disk. To change an asset, use
|
|
8
|
+
* the methods on {@link GameMakerProject}, which write to disk and then update
|
|
9
|
+
* the `Asset` (emitting events). Do not mutate {@link yy} directly.
|
|
10
|
+
*
|
|
11
|
+
* An asset keeps the same identity (`===`) for its whole life, even as its
|
|
12
|
+
* data changes. Renaming an asset replaces it with a new one.
|
|
13
|
+
*/
|
|
14
|
+
export class Asset {
|
|
15
|
+
kind;
|
|
16
|
+
/** The yyp resource id, e.g. `{name: 'obj_player', path: 'objects/obj_player/obj_player.yy'}` */
|
|
17
|
+
id;
|
|
18
|
+
/** Absolute path to the asset's yy file */
|
|
19
|
+
yyPath;
|
|
20
|
+
_yy;
|
|
21
|
+
_yyHash;
|
|
22
|
+
_gmlFiles = [];
|
|
23
|
+
_orphanedGmlFiles = [];
|
|
24
|
+
/** @internal Use the project's methods to get assets */
|
|
25
|
+
constructor(init) {
|
|
26
|
+
this.kind = init.kind;
|
|
27
|
+
this.id = Object.freeze({ ...init.id });
|
|
28
|
+
this.yyPath = init.yyPath;
|
|
29
|
+
this.update(init);
|
|
30
|
+
}
|
|
31
|
+
/** @internal Replace the asset's data with what is now on disk */
|
|
32
|
+
update(init) {
|
|
33
|
+
this._yy = init.yy;
|
|
34
|
+
this._yyHash = init.yyHash;
|
|
35
|
+
this.updateGmlFiles(init.dirEntries);
|
|
36
|
+
}
|
|
37
|
+
/** @internal Recompute which GML files belong to this asset */
|
|
38
|
+
updateGmlFiles(dirEntries) {
|
|
39
|
+
const gml = dirEntries.filter((e) => e.toLowerCase().endsWith('.gml'));
|
|
40
|
+
const files = [];
|
|
41
|
+
if (this.kind === 'scripts') {
|
|
42
|
+
const match = gml.find((e) => e === `${this.name}.gml`) ||
|
|
43
|
+
gml.find((e) => key(e) === key(`${this.name}.gml`));
|
|
44
|
+
if (match)
|
|
45
|
+
files.push(match);
|
|
46
|
+
}
|
|
47
|
+
else if (this.kind === 'objects') {
|
|
48
|
+
for (const { event } of this.listEvents()) {
|
|
49
|
+
const match = gml.find((e) => e === `${event.name}.gml`) ||
|
|
50
|
+
gml.find((e) => key(e) === key(`${event.name}.gml`));
|
|
51
|
+
if (match)
|
|
52
|
+
files.push(match);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (this.kind === 'rooms') {
|
|
56
|
+
// Room creation code, then instance creation code (in creation order)
|
|
57
|
+
const wanted = [
|
|
58
|
+
this.roomCreationCodeFile,
|
|
59
|
+
...this.roomInstances.map((i) => i.creationCodeFile),
|
|
60
|
+
];
|
|
61
|
+
for (const file of wanted) {
|
|
62
|
+
if (!file)
|
|
63
|
+
continue;
|
|
64
|
+
const name = path.basename(file);
|
|
65
|
+
const match = gml.find((e) => e === name) || gml.find((e) => key(e) === key(name));
|
|
66
|
+
if (match)
|
|
67
|
+
files.push(match);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const used = new Set(files);
|
|
71
|
+
this._gmlFiles = files.map((f) => path.join(this.dir, f));
|
|
72
|
+
this._orphanedGmlFiles = gml
|
|
73
|
+
.filter((f) => !used.has(f))
|
|
74
|
+
.map((f) => path.join(this.dir, f));
|
|
75
|
+
}
|
|
76
|
+
/** @internal A hash of the yy file's content, for change detection */
|
|
77
|
+
get yyHash() {
|
|
78
|
+
return this._yyHash;
|
|
79
|
+
}
|
|
80
|
+
/** The asset's yy data, as read from disk. Do not mutate! */
|
|
81
|
+
get yy() {
|
|
82
|
+
return this._yy;
|
|
83
|
+
}
|
|
84
|
+
get name() {
|
|
85
|
+
return this.id.name;
|
|
86
|
+
}
|
|
87
|
+
/** Absolute path to the asset's directory */
|
|
88
|
+
get dir() {
|
|
89
|
+
return path.dirname(this.yyPath);
|
|
90
|
+
}
|
|
91
|
+
/** The asset's folder in the IDE's asset tree, in POSIX form (`my/folder`) */
|
|
92
|
+
get folder() {
|
|
93
|
+
const parent = this._yy.parent;
|
|
94
|
+
// Assets at the root have the project as their parent
|
|
95
|
+
if (!parent?.path || parent.path.toLowerCase().endsWith('.yyp'))
|
|
96
|
+
return '';
|
|
97
|
+
return folderPathToPosix(parent.path);
|
|
98
|
+
}
|
|
99
|
+
/** Whether this asset is in the given folder, or one of its subfolders */
|
|
100
|
+
isInFolder(folder) {
|
|
101
|
+
folder = key(folderPathToPosix(folder));
|
|
102
|
+
const current = key(this.folder);
|
|
103
|
+
return current === folder || current.startsWith(`${folder}/`);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Absolute paths to the GML files that belong to this asset: a script's
|
|
107
|
+
* file, an object's event files (Create first, then in event order), or a
|
|
108
|
+
* room's creation code files. Only files GameMaker would use are included.
|
|
109
|
+
*/
|
|
110
|
+
get gmlFiles() {
|
|
111
|
+
return this._gmlFiles;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* GML files in the asset's directory that GameMaker would ignore (e.g. the
|
|
115
|
+
* file for an event that has been removed from the object).
|
|
116
|
+
*/
|
|
117
|
+
get orphanedGmlFiles() {
|
|
118
|
+
return this._orphanedGmlFiles;
|
|
119
|
+
}
|
|
120
|
+
isKind(kind) {
|
|
121
|
+
return this.kind === kind;
|
|
122
|
+
}
|
|
123
|
+
// --- Objects ---
|
|
124
|
+
/** For objects, the name of the parent object */
|
|
125
|
+
get parentName() {
|
|
126
|
+
if (!this.isKind('objects'))
|
|
127
|
+
return undefined;
|
|
128
|
+
return this._yy.parentObjectId?.name || undefined;
|
|
129
|
+
}
|
|
130
|
+
/** For objects, the name of the sprite */
|
|
131
|
+
get spriteName() {
|
|
132
|
+
if (!this.isKind('objects'))
|
|
133
|
+
return undefined;
|
|
134
|
+
return this._yy.spriteId?.name || undefined;
|
|
135
|
+
}
|
|
136
|
+
/** For objects, the events listed in the yy file, with their file names */
|
|
137
|
+
listEvents() {
|
|
138
|
+
if (!this.isKind('objects'))
|
|
139
|
+
return [];
|
|
140
|
+
const events = [];
|
|
141
|
+
for (const entry of this._yy.eventList || []) {
|
|
142
|
+
const event = getEvent(entry.eventType, entry.eventNum, entry.collisionObjectId?.name);
|
|
143
|
+
if (!event)
|
|
144
|
+
continue;
|
|
145
|
+
events.push({ event, file: path.join(this.dir, `${event.name}.gml`) });
|
|
146
|
+
}
|
|
147
|
+
// Create first, then in a stable order
|
|
148
|
+
return events.sort((a, b) => {
|
|
149
|
+
const aCreate = a.event.eventType === 0 ? 0 : 1;
|
|
150
|
+
const bCreate = b.event.eventType === 0 ? 0 : 1;
|
|
151
|
+
return (aCreate - bCreate ||
|
|
152
|
+
a.event.eventType - b.event.eventType ||
|
|
153
|
+
a.event.eventNum - b.event.eventNum ||
|
|
154
|
+
a.event.name.localeCompare(b.event.name));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/** For objects, the GML file for an event, by file name (e.g. `Step_0`) */
|
|
158
|
+
getEventFile(eventName) {
|
|
159
|
+
eventName = key(eventName.replace(/\.gml$/i, ''));
|
|
160
|
+
return this._gmlFiles.find((f) => key(path.basename(f, path.extname(f))) === eventName);
|
|
161
|
+
}
|
|
162
|
+
// --- Rooms ---
|
|
163
|
+
/** For rooms, the object instances, in creation order */
|
|
164
|
+
get roomInstances() {
|
|
165
|
+
if (!this.isKind('rooms'))
|
|
166
|
+
return [];
|
|
167
|
+
const yy = this._yy;
|
|
168
|
+
const instances = new Map();
|
|
169
|
+
for (const layer of instanceLayers(yy)) {
|
|
170
|
+
for (const instance of layer.instances || []) {
|
|
171
|
+
instances.set(instance.name, {
|
|
172
|
+
instanceId: instance.name,
|
|
173
|
+
objectName: instance.objectId.name,
|
|
174
|
+
layerName: layer.name,
|
|
175
|
+
x: instance.x,
|
|
176
|
+
y: instance.y,
|
|
177
|
+
creationCodeFile: instance.hasCreationCode
|
|
178
|
+
? path.join(this.dir, `InstanceCreationCode_${instance.name}.gml`)
|
|
179
|
+
: undefined,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const ordered = [];
|
|
184
|
+
for (const { name } of yy.instanceCreationOrder || []) {
|
|
185
|
+
const instance = instances.get(name);
|
|
186
|
+
if (instance)
|
|
187
|
+
ordered.push(instance);
|
|
188
|
+
}
|
|
189
|
+
return ordered;
|
|
190
|
+
}
|
|
191
|
+
/** For rooms, the path to the room's creation code, if it has any */
|
|
192
|
+
get roomCreationCodeFile() {
|
|
193
|
+
if (!this.isKind('rooms'))
|
|
194
|
+
return undefined;
|
|
195
|
+
const file = this._yy.creationCodeFile;
|
|
196
|
+
return file ? path.join(this.dir, path.basename(file)) : undefined;
|
|
197
|
+
}
|
|
198
|
+
// --- Sprites ---
|
|
199
|
+
get isSpineSprite() {
|
|
200
|
+
return this.isKind('sprites') && this._yy.type === 2;
|
|
201
|
+
}
|
|
202
|
+
/** For sprites, the frame IDs, in order */
|
|
203
|
+
get frameIds() {
|
|
204
|
+
if (!this.isKind('sprites'))
|
|
205
|
+
return [];
|
|
206
|
+
return (this._yy.frames || []).map((f) => f.name);
|
|
207
|
+
}
|
|
208
|
+
/** For non-Spine sprites, the frame image paths, in order */
|
|
209
|
+
get framePaths() {
|
|
210
|
+
if (this.isSpineSprite)
|
|
211
|
+
return [];
|
|
212
|
+
return this.frameIds.map((id) => path.join(this.dir, `${id}.png`));
|
|
213
|
+
}
|
|
214
|
+
/** For Spine sprites, the paths to the Spine files */
|
|
215
|
+
get spinePaths() {
|
|
216
|
+
const frameId = this.isSpineSprite ? this.frameIds[0] : undefined;
|
|
217
|
+
if (!frameId)
|
|
218
|
+
return undefined;
|
|
219
|
+
return {
|
|
220
|
+
json: path.join(this.dir, `${frameId}.json`),
|
|
221
|
+
atlas: path.join(this.dir, `${frameId}.atlas`),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
// --- Sounds & Shaders ---
|
|
225
|
+
/** For sounds, the path to the audio file */
|
|
226
|
+
get soundFile() {
|
|
227
|
+
if (!this.isKind('sounds'))
|
|
228
|
+
return undefined;
|
|
229
|
+
const file = this._yy.soundFile;
|
|
230
|
+
return file ? path.join(this.dir, file) : undefined;
|
|
231
|
+
}
|
|
232
|
+
/** For shaders, the paths to the shader source files */
|
|
233
|
+
get shaderPaths() {
|
|
234
|
+
if (!this.isKind('shaders'))
|
|
235
|
+
return undefined;
|
|
236
|
+
const base = this.yyPath.replace(/\.yy$/i, '');
|
|
237
|
+
return { vertex: `${base}.vsh`, fragment: `${base}.fsh` };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* List a room's instance layers, including those nested in layer folders.
|
|
242
|
+
*/
|
|
243
|
+
export function instanceLayers(room) {
|
|
244
|
+
const found = [];
|
|
245
|
+
const visit = (layers) => {
|
|
246
|
+
for (const layer of layers || []) {
|
|
247
|
+
if (!layer || typeof layer !== 'object')
|
|
248
|
+
continue;
|
|
249
|
+
const l = layer;
|
|
250
|
+
if (l.resourceType === 'GMRInstanceLayer') {
|
|
251
|
+
found.push(layer);
|
|
252
|
+
}
|
|
253
|
+
visit(l.layers);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
visit(room.layers);
|
|
257
|
+
return found;
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.js","sourceRoot":"","sources":["../src/asset.ts"],"names":[],"mappings":"AAUA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAoB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAmCnD;;;;;;;;;GASG;AACH,MAAM,OAAO,KAAK;I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AAC;YACD,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type YypKind =
|
|
2
|
+
/** A project that isn't inside another project's folder */
|
|
3
|
+
'project'
|
|
4
|
+
/** A prefab, stored in a project's `prefabs/` folder */
|
|
5
|
+
| 'prefab'
|
|
6
|
+
/** Any other `.yyp` inside another project's folder (e.g. a copy, or test data) */
|
|
7
|
+
| 'nested';
|
|
8
|
+
export interface ClassifiedYyp {
|
|
9
|
+
/** The path, as given */
|
|
10
|
+
path: string;
|
|
11
|
+
kind: YypKind;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Classify `.yyp` files found by searching (e.g. a workspace), so that only
|
|
15
|
+
* real projects are offered to the user:
|
|
16
|
+
* - A `.yyp` in a subfolder of a `prefabs` folder is a prefab. GameMaker
|
|
17
|
+
* stores prefabs in the `prefabs/` folder of the projects that use them.
|
|
18
|
+
* - Any other `.yyp` inside the folder of another `.yyp` is nested.
|
|
19
|
+
* - Everything else is a project.
|
|
20
|
+
*
|
|
21
|
+
* Projects don't have to be at the root of the searched folder: a project in
|
|
22
|
+
* a subfolder of a repository is still a project.
|
|
23
|
+
*/
|
|
24
|
+
export declare function classifyYypPaths(paths: readonly string[]): ClassifiedYyp[];
|
|
25
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,OAAO;AACjB,2DAA2D;AACzD,SAAS;AACX,wDAAwD;GACtD,QAAQ;AACV,mFAAmF;GACjF,QAAQ,CAAC;AAEb,MAAM,WAAW,aAAa;IAC5B,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,EAAE,CAmB1E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telling real projects apart from other `.yyp` files found by a search.
|
|
3
|
+
*/
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
/**
|
|
6
|
+
* Classify `.yyp` files found by searching (e.g. a workspace), so that only
|
|
7
|
+
* real projects are offered to the user:
|
|
8
|
+
* - A `.yyp` in a subfolder of a `prefabs` folder is a prefab. GameMaker
|
|
9
|
+
* stores prefabs in the `prefabs/` folder of the projects that use them.
|
|
10
|
+
* - Any other `.yyp` inside the folder of another `.yyp` is nested.
|
|
11
|
+
* - Everything else is a project.
|
|
12
|
+
*
|
|
13
|
+
* Projects don't have to be at the root of the searched folder: a project in
|
|
14
|
+
* a subfolder of a repository is still a project.
|
|
15
|
+
*/
|
|
16
|
+
export function classifyYypPaths(paths) {
|
|
17
|
+
const normalize = (p) => path.resolve(p).split(path.sep).join('/').toLowerCase();
|
|
18
|
+
const dirs = paths.map((p) => path.posix.dirname(normalize(p)));
|
|
19
|
+
return paths.map((original, i) => {
|
|
20
|
+
const dir = dirs[i];
|
|
21
|
+
const segments = dir.split('/');
|
|
22
|
+
const isInsideAnother = dirs.some((other, j) => j !== i && other !== dir && dir.startsWith(`${other}/`));
|
|
23
|
+
// GameMaker's layout is `prefabs/<name>/<name>.yyp`
|
|
24
|
+
const inPrefabsFolder = segments.at(-2) === 'prefabs';
|
|
25
|
+
const kind = inPrefabsFolder
|
|
26
|
+
? 'prefab'
|
|
27
|
+
: isInsideAnother
|
|
28
|
+
? 'nested'
|
|
29
|
+
: 'project';
|
|
30
|
+
return { path: original, kind };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @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