Costume subfolders
This commit is contained in:
parent
182216e711
commit
9fb4b3425e
|
@ -716,6 +716,13 @@ async function setSpriteSetCommand(_, folder) {
|
||||||
folder = '';
|
folder = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (folder.startsWith('/') || folder.startsWith('\\')) {
|
||||||
|
folder = folder.slice(1);
|
||||||
|
|
||||||
|
const currentLastMessage = getLastCharacterMessage();
|
||||||
|
folder = `${currentLastMessage.name}/${folder}`;
|
||||||
|
}
|
||||||
|
|
||||||
$("#expression_override").val(folder.trim());
|
$("#expression_override").val(folder.trim());
|
||||||
onClickExpressionOverrideButton();
|
onClickExpressionOverrideButton();
|
||||||
removeExpression();
|
removeExpression();
|
||||||
|
@ -1372,5 +1379,5 @@ function setExpressionOverrideHtml(forceClear = false) {
|
||||||
eventSource.on(event_types.MOVABLE_PANELS_RESET, updateVisualNovelModeDebounced);
|
eventSource.on(event_types.MOVABLE_PANELS_RESET, updateVisualNovelModeDebounced);
|
||||||
eventSource.on(event_types.GROUP_UPDATED, updateVisualNovelModeDebounced);
|
eventSource.on(event_types.GROUP_UPDATED, updateVisualNovelModeDebounced);
|
||||||
registerSlashCommand('sprite', setSpriteSlashCommand, ['emote'], '<span class="monospace">spriteId</span> – force sets the sprite for the current character', true, true);
|
registerSlashCommand('sprite', setSpriteSlashCommand, ['emote'], '<span class="monospace">spriteId</span> – force sets the sprite for the current character', true, true);
|
||||||
registerSlashCommand('spriteoverride', setSpriteSetCommand, ['costume'], '<span class="monospace">folder</span> – sets an override sprite folder for the current character. Empty value to reset to default.', true, true);
|
registerSlashCommand('spriteoverride', setSpriteSetCommand, ['costume'], '<span class="monospace">folder</span> – sets an override sprite folder for the current character. If the name starts with a slash or a backslash, selects a sub-folder in the character-named folder. Empty value to reset to default.', true, true);
|
||||||
})();
|
})();
|
||||||
|
|
33
server.js
33
server.js
|
@ -2941,13 +2941,42 @@ app.get('/discover_extensions', jsonParser, function (_, response) {
|
||||||
return response.send(extensions);
|
return response.send(extensions);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the path to the sprites folder for the provided character name
|
||||||
|
* @param {string} name - The name of the character
|
||||||
|
* @param {boolean} isSubfolder - Whether the name contains a subfolder
|
||||||
|
* @returns {string | null} The path to the sprites folder. Null if the name is invalid.
|
||||||
|
*/
|
||||||
|
function getSpritesPath(name, isSubfolder) {
|
||||||
|
if (isSubfolder) {
|
||||||
|
const nameParts = name.split('/');
|
||||||
|
const characterName = sanitize(nameParts[0]);
|
||||||
|
const subfolderName = sanitize(nameParts[1]);
|
||||||
|
|
||||||
|
if (!characterName || !subfolderName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.join(directories.characters, characterName, subfolderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
name = sanitize(name);
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.join(directories.characters, name);
|
||||||
|
}
|
||||||
|
|
||||||
app.get('/get_sprites', jsonParser, function (request, response) {
|
app.get('/get_sprites', jsonParser, function (request, response) {
|
||||||
const name = String(request.query.name);
|
const name = String(request.query.name);
|
||||||
const spritesPath = path.join(directories.characters, name);
|
const isSubfolder = name.includes('/');
|
||||||
|
const spritesPath = getSpritesPath(name, isSubfolder);
|
||||||
let sprites = [];
|
let sprites = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(spritesPath) && fs.statSync(spritesPath).isDirectory()) {
|
if (spritesPath && fs.existsSync(spritesPath) && fs.statSync(spritesPath).isDirectory()) {
|
||||||
sprites = fs.readdirSync(spritesPath)
|
sprites = fs.readdirSync(spritesPath)
|
||||||
.filter(file => {
|
.filter(file => {
|
||||||
const mimeType = mime.lookup(file);
|
const mimeType = mime.lookup(file);
|
||||||
|
|
Loading…
Reference in New Issue