feat: Add --skin and --hide-slot CLI arguments

This commit is contained in:
jhq223
2025-10-15 03:35:15 +08:00
parent f5684a50dc
commit e4d655012b

View File

@@ -10,13 +10,15 @@ namespace SpineViewerCLI
public class CLI public class CLI
{ {
const string USAGE = @" const string USAGE = @"
usage: SpineViewerCLI.exe [--skel PATH] [--atlas PATH] [--output PATH] [--animation STR] [--pma] [--fps INT] [--loop] [--crf INT] [--width INT] [--height INT] [--centerx INT] [--centery INT] [--zoom FLOAT] [--speed FLOAT] [--color HEX] [--quiet] usage: SpineViewerCLI.exe [--skel PATH] [--atlas PATH] [--output PATH] [--animation STR] [--skin STR] [--hide-slot STR] [--pma] [--fps INT] [--loop] [--crf INT] [--width INT] [--height INT] [--centerx INT] [--centery INT] [--zoom FLOAT] [--speed FLOAT] [--color HEX] [--quiet]
options: options:
--skel PATH Path to the .skel file --skel PATH Path to the .skel file
--atlas PATH Path to the .atlas file, default searches in the skel file directory --atlas PATH Path to the .atlas file, default searches in the skel file directory
--output PATH Output file path --output PATH Output file path
--animation STR Animation name --animation STR Animation name
--skin STR Skin name to apply. Can be used multiple times to stack skins.
--hide-slot STR Slot name to hide. Can be used multiple times.
--pma Use premultiplied alpha, default false --pma Use premultiplied alpha, default false
--fps INT Frames per second, default 24 --fps INT Frames per second, default 24
--loop Whether to loop the animation, default false --loop Whether to loop the animation, default false
@@ -37,6 +39,8 @@ options:
string? atlasPath = null; string? atlasPath = null;
string? output = null; string? output = null;
string? animation = null; string? animation = null;
var skins = new List<string>();
var hideSlots = new List<string>();
bool pma = false; bool pma = false;
uint fps = 24; uint fps = 24;
bool loop = false; bool loop = false;
@@ -70,6 +74,12 @@ options:
case "--animation": case "--animation":
animation = args[++i]; animation = args[++i];
break; break;
case "--skin":
skins.Add(args[++i]);
break;
case "--hide-slot":
hideSlots.Add(args[++i]);
break;
case "--pma": case "--pma":
pma = true; pma = true;
break; break;
@@ -133,6 +143,24 @@ options:
var sp = new SpineObject(skelPath, atlasPath); var sp = new SpineObject(skelPath, atlasPath);
sp.UsePma = pma; sp.UsePma = pma;
foreach (var skinName in skins)
{
if (!sp.SetSkinStatus(skinName, true))
{
var availableSkins = string.Join(", ", sp.Data.Skins.Select(s => s.Name));
Console.Error.WriteLine($"Error: Skin '{skinName}' not found. Available skins: {availableSkins}");
Environment.Exit(2);
}
}
foreach (var slotName in hideSlots)
{
if (!sp.SetSlotVisible(slotName, false))
{
if (!quiet) Console.WriteLine($"Warning: Slot '{slotName}' not found, cannot hide.");
}
}
if (string.IsNullOrEmpty(animation)) if (string.IsNullOrEmpty(animation))
{ {
var availableAnimations = string.Join(", ", sp.Data.Animations); var availableAnimations = string.Join(", ", sp.Data.Animations);