Skip to content

Commit

Permalink
feat: Add CLI commands for assigning texture and audio groups and their
Browse files Browse the repository at this point in the history
smoke tests.
  • Loading branch information
shichen85 authored and adam-coster committed Oct 1, 2020
1 parent 8462709 commit 6350afa
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 54 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,16 @@ To keep things stable and automatable, Stitch uses a configuration file (`stitch

## Using the CLI <a id="cli"></a>

<b style="color:red">⚠ NOT YET IMPLEMENTED ⚠</b>

+ ✅ import
+ ✅ modules --source-project=path --modules=m1,m2 --target-project=path
+ ✅ sounds --source-path=path --extensions=mp3,wave --target-project=path
+ ✅ files --source-path=dir/file --extensions=txt --target-project=path
+ assign
+ texture-groups --folder=sprites/myGroupOfSprites --group-name=name
+ audio-groups --folder=sound/myGroupOfSounds --group-name=name
+ ✅ modules --source-project=path --modules=m1,m2
+ ✅ sounds --source-path=path --extensions=mp3,wave
+ ✅ files --source-path=dir/file --extensions=txt
+ assign
+ texture-groups --folder=sprites/myGroupOfSprites --group-name=name
+ audio-groups --folder=sound/myGroupOfSounds --group-name=name
+ ✅ set
+ ✅ version --version
+ ✅ jsonify --dir --filepath
+ ✅ jsonify --path

## Core Features <a id="features"></a>

Expand Down
23 changes: 23 additions & 0 deletions src/cli/gms2-assign-audio-groups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env node
import commander, { CommanderStatic } from "commander";
import { oneline, undent } from "../lib/strings";
import {assignAudioGroups, AssignCliOptions} from './lib/assign';

const cli = commander;

cli.description(undent`
Assign all audios in a GMS IDE folder to a group.`)
.requiredOption("--folder <folder>", undent`
This is the folder name shown in the GMS IDE, not the folder name of the actual audio file.
For example, a audio called "snd_title" is shown in the "Sounds" folder in the IDE, whereas
the actual audio file might be at "project/sounds/snd_title/snd_title.yy".
`)
.requiredOption("--group-name <name>", oneline`
The name of the audio group. If it does not exist, it will be created.
`)
.option("--target-project-path <path>", oneline`
Path to the target Gamemaker Studio 2 project. If not set, will use the current directory.
`)
.parse(process.argv);

assignAudioGroups(cli as AssignCliOptions & CommanderStatic);
23 changes: 23 additions & 0 deletions src/cli/gms2-assign-texture-groups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env node
import commander, { CommanderStatic } from "commander";
import { oneline, undent } from "../lib/strings";
import {assignTextureGroups, AssignCliOptions} from './lib/assign';

const cli = commander;

cli.description(undent`
Assign all sprites in a GMS IDE folder to a group.`)
.requiredOption("--folder <folder>", undent`
This is the folder name shown in the GMS IDE, not the folder name of the actual sprite file.
For example, a sprite called "sp_title" is shown in the "Sprites" folder in the IDE, whereas
the actual sprite file might be at "project/sprites/sp_title/sp_title.yy".
`)
.requiredOption("--group-name <name>", oneline`
The name of the texture group. If it does not exist, it will be created.
`)
.option("--target-project-path <path>", oneline`
Path to the target Gamemaker Studio 2 project. If not set, will use the current directory.
`)
.parse(process.argv);

assignTextureGroups(cli as AssignCliOptions & CommanderStatic);
9 changes: 9 additions & 0 deletions src/cli/gms2-assign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node
import commander from "commander";
const cli = commander;

cli.description("Modify resource group assignments in Gamemaker Studio 2 projects.")
.command("texture-groups", "Modify texture group assignments.")
.command("audio-groups", "Modify audio group assignments.")
.parse(process.argv);

1 change: 1 addition & 0 deletions src/cli/gms2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cli.version(version, '-v, --version')
.description('Gamemaker Studio 2: Pipeline Development Kit CLI')
.command("import", "Import assets to Gamemaker Studio 2 projects.")
.command("set", "Modify metadata in Gamemaker Studio 2 projects.")
.command("assign", "Modify resource group assignments in Gamemaker Studio 2 projects.")
.command("jsonify", "Convert .yy and .yyp files into valid JSON.");

//Trim the input and filter out empty space inputs such as " "
Expand Down
36 changes: 36 additions & 0 deletions src/cli/lib/assign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import cli_assert from './cli-assert';
import { Gms2Project } from '../../lib/Gms2Project';

export type AssignCliOptions = {
folder: string,
groupName: string,
targetProjectPath?: string
}

function normalizeAssignOptions(options: AssignCliOptions){
let {targetProjectPath} = options;
if (targetProjectPath){
cli_assert.assertPathExists(targetProjectPath);
}
else{
targetProjectPath = process.cwd();
}

return {
folder: options.folder,
groupName: options.groupName,
targetProjectPath
};
}

export function assignTextureGroups (options: AssignCliOptions){
options = normalizeAssignOptions(options);
const targetProject = new Gms2Project(options.targetProjectPath);
targetProject.addTextureGroupAssignment(options.folder, options.groupName);
}

export function assignAudioGroups (options: AssignCliOptions){
options = normalizeAssignOptions(options);
const targetProject = new Gms2Project(options.targetProjectPath);
targetProject.addAudioGroupAssignment(options.folder, options.groupName);
}
94 changes: 49 additions & 45 deletions src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import importSounds from '../cli/lib/import-sounds';
import { ImportBaseOptions } from '../cli/lib/import-base-options';
import version, {VersionOptions} from '../cli/lib/version';
import importFiles from '../cli/lib/import-files';
import {assignAudioGroups, assignTextureGroups, AssignCliOptions} from '../cli/lib/assign';

process.env.GMS2PDK_DEV = 'true';

Expand Down Expand Up @@ -562,51 +563,54 @@ at it goooo ${interp2}
expect(()=>version(versionOptions), "Should succeed when version is valid").to.not.throw();
expect(project.versionOnPlatform("windows")).to.equal('100.5.6.11');
});
// it('can add a folder and texture to the "Textures" of the config file', function(){
// resetSandbox();
// const project = new Project(sandboxProjectYYPPath);
// const folder = "Sprites/testGroup";
// const subfolder = "Sprites/testGroup/testSubGroup";
// const texture = "TestTexture";
// const subTexture = "OtherTestTexture";
// const topLevelTextureID = project.getTextureByName(texture)?.id;
// const subTextureID = project.getTextureByName(subTexture)?.id;

// expect(topLevelTextureID).to.be.a("string");
// const thisView = project.getViewByPath(folder);
// expect(thisView).to.exist;
// const spritesInViewRecursive = thisView.getChildren("GMSprite", true) as Sprite[];
// expect(spritesInViewRecursive.length, "Should have found two sprites.").to.equal(2);
// for (const sprite of spritesInViewRecursive) {
// expect(sprite.rawDataFromYY.textureGroupId, "Sprite texture ID is not set to default.").to.not.equal(topLevelTextureID);
// }
// expect(function(){
// project.addFolderToTextureGroup("wrongFolder", "wrongTexture");
// }, "Should fail if wrong texture and folder.").to.throw;
// expect(function(){
// project.addFolderToTextureGroup(folder, "wrongTexture");
// }, "Should fail if wrong texture.").to.throw;
// expect(function(){
// project.addFolderToTextureGroup("wrongFolder", texture);
// }, "Should fail if wrong folder.").to.throw;
// project.addFolderToTextureGroup(folder, texture);
// for (const sprite of spritesInViewRecursive) {
// expect(sprite.rawDataFromYY.textureGroupId, "Sprite texture ID was not assigned as intended.").to.equal(topLevelTextureID);
// }
// project.removeFolderFromTextureGroups(folder);
// project.addFolderToTextureGroup(subfolder, subTexture);
// project.addFolderToTextureGroup(folder, texture);
// const spritesInParentView = thisView.getChildren("GMSprite", false) as Sprite[];
// const spritesInSubView = project.getViewByPath(subfolder).getChildren("GMSprite", true) as Sprite[];
// expect(spritesInParentView.length).to.be.greaterThan(0);
// expect(spritesInSubView.length).to.be.greaterThan(0);
// for (const sprite of spritesInParentView) {
// expect(sprite.rawDataFromYY.textureGroupId, "Sprite texture ID was not assigned as intended.").to.equal(topLevelTextureID);
// }
// for (const sprite of spritesInSubView) {
// expect(sprite.rawDataFromYY.textureGroupId, "Sprite texture ID was not assigned as intended.").to.equal(subTextureID);
// }
// });

it('Assign Texture Group command', function(){
let project = getResetProject();
let sprite = project.resources.sprites[0];
const newTextureGroupName = 'NewTextureGroup';
const assignTextureOptions: AssignCliOptions = {
folder: sprite.folder,
groupName: newTextureGroupName,
targetProjectPath: sandboxRoot
};
expect(()=>assignTextureGroups(assignTextureOptions), "Should succeed when the arguments are correct").to.not.throw();

project = new Gms2Project(sandboxProjectYYPPath);
sprite = project.resources.sprites[0];
// The new Texture page should exist
expect(project.textureGroups.findByField('name',newTextureGroupName),
'the new texture group should be added'
).to.exist;
// The Sprite should be properly reassigned
expect(sprite.textureGroup,
'sprite should be reassigned'
).to.equal(newTextureGroupName);
});

it('Assign Audio Group command', function(){
let project = getResetProject();
let sound = project.resources.sounds[0];
const newAudioGroupName = "NewAudioGroup";
const assignAudioOptions: AssignCliOptions = {
folder: sound.folder,
groupName: newAudioGroupName,
targetProjectPath: sandboxRoot
};
expect(sound.audioGroup,
'sound should not be in target audio group'
).to.not.equal(newAudioGroupName);
expect(()=>assignAudioGroups(assignAudioOptions), "Should succeed when the arguments are correct").to.not.throw();

project = new Gms2Project(sandboxProjectYYPPath);
sound = project.resources.sounds[0];
expect(project.audioGroups.findByField('name',newAudioGroupName),
'the new audio group should be added'
).to.exist;
// The Sprite should be properly reassigned
expect(sound.audioGroup,
'sound should be reassigned'
).to.equal(newAudioGroupName);
});
});

after(function () {
Expand Down

0 comments on commit 6350afa

Please sign in to comment.