@bscotch/stitch
Version:
Stitch: The GameMaker Studio 2 Asset Pipeline Development Kit.
77 lines • 3.66 kB
JavaScript
import { Gms2Sound } from './components/resources/Gms2Sound.js';
import { Gms2Sprite } from './components/resources/Gms2Sprite.js';
/** Add a texture group assignment if it doesn't already exist. */
export async function addTextureGroupAssignment(project, folder, textureGroupName) {
await project.config.addTextureGroupAssignment(folder, textureGroupName);
await setTextureGroupsUsingConfig(project);
return project;
}
/**
* Ensure that the texture groups used in the config all exist, and
* that sprites are properly assigned to them. (This must generally be re-run
* on configuration upate, since cannot handle inheritance with singleton updates.)
*/
async function setTextureGroupsUsingConfig(project) {
for (const textureGroupName of await project.config.getTextureGroupsWithAssignedFolders()) {
project.addTextureGroup(textureGroupName);
}
// Ensure sprites are assigned to correct config texture groups.
// This can be done by iterating backwards over the assignments,
// since they get sorted by specificity (lowest first) and we only
// want the most specific ones (those that match LAST unless reverse-sorted).
const folders = (await project.config.getFoldersWithAssignedTextureGroups()).reverse();
const alreadyAssigned = new Set();
const textureGroupAssignments = await project.config.getTextureGroupAssignments();
for (const folder of folders) {
project.resources
.filterByClassAndFolder(Gms2Sprite, folder)
.forEach((sprite) => {
if (alreadyAssigned.has(sprite)) {
// Then should already have been assigned with the highest specificity possible.
return;
}
sprite.textureGroup = textureGroupAssignments[folder];
alreadyAssigned.add(sprite);
});
}
return project;
}
/** Add a texture group assignment if it doesn't already exist. */
export async function addAudioGroupAssignment(project, folder, audioGroupName) {
await project.config.addAudioGroupAssignment(folder, audioGroupName);
await setAudioGroupsUsingConfig(project);
return project;
}
/**
* Ensure that the Sound assets have their Audio Groups correctly
* assigned based on the config file. (This must generally be re-run
* on configuration upate, since cannot handle inheritance with singleton updates.)
*/
async function setAudioGroupsUsingConfig(project) {
for (const audioGroupName of await project.config.getAudioGroupsWithAssignedFolders()) {
project.addAudioGroup(audioGroupName);
}
// Ensure sounds are assigned to correct config audio groups
// This can be done by iterating backwards over the assignments,
// since they get sorted by specificity (lowest first) and we only
// want the most specific ones (those that match LAST unless reverse-sorted).
const folders = (await project.config.getFoldersWithAssignedAudioGroups()).reverse();
const alreadyAssigned = new Set();
const audioGroupAssignments = await project.config.getAudioGroupAssignments();
for (const folder of folders) {
project.resources
.filterByClassAndFolder(Gms2Sound, folder)
.forEach((sound) => {
if (alreadyAssigned.has(sound)) {
return;
}
sound.audioGroup = audioGroupAssignments[folder];
alreadyAssigned.add(sound);
});
}
return project;
}
export async function ensureResourceGroupAssignments(project) {
return await setAudioGroupsUsingConfig(await setTextureGroupsUsingConfig(project));
}
//# sourceMappingURL=StitchProject.groups.js.map