update
This commit is contained in:
parent
00e8bcc038
commit
4d1403958f
@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace ArtemisFgTools
|
namespace ArtemisFgTools
|
||||||
@ -40,7 +41,7 @@ namespace ArtemisFgTools
|
|||||||
return HashCode.Combine(ChName, Size, File, Face);
|
return HashCode.Combine(ChName, Size, File, Face);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static HashSet<FgRecord> FetchFgObjectsFromScript(string path)
|
public static HashSet<FgRecord> FetchFgRecordsFromScript(string path)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
throw new DirectoryNotFoundException("The path does not exist.");
|
throw new DirectoryNotFoundException("The path does not exist.");
|
||||||
@ -77,6 +78,81 @@ namespace ArtemisFgTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HashSet<FgRecord> FetchFgObjectsDirect(string path)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
throw new DirectoryNotFoundException("The path does not exist.");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HashSet<FgRecord> fgRecords = [];
|
||||||
|
//获取path文件夹下所有文件夹(不含子文件夹)
|
||||||
|
string[] charaDirs = Directory.GetDirectories(path);
|
||||||
|
foreach (string charaDir in charaDirs)
|
||||||
|
{
|
||||||
|
string chName = Path.GetFileName(charaDir);
|
||||||
|
string[] sizeDirs = Directory.GetDirectories(charaDir);
|
||||||
|
foreach (string sizeDir in sizeDirs)
|
||||||
|
{
|
||||||
|
string size = Path.GetFileName(sizeDir);
|
||||||
|
string[] files = Directory.GetFiles(sizeDir, "*.png");
|
||||||
|
Dictionary<string, List<string>> baseFiles = new Dictionary<string, List<string>>();
|
||||||
|
Dictionary<string, List<string>> faceFiles = new Dictionary<string, List<string>>();
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileNameWithoutExtension(file);
|
||||||
|
if (fileName.StartsWith(chName)) //base
|
||||||
|
{
|
||||||
|
string[] parts = fileName.Split('_');
|
||||||
|
if (parts.Length < 2)
|
||||||
|
throw new Exception("Not supported character name format.");
|
||||||
|
string category = parts[1][2].ToString();
|
||||||
|
if (!baseFiles.TryGetValue(category, out List<string>? value))
|
||||||
|
{
|
||||||
|
value = ([]);
|
||||||
|
baseFiles[category] = value;
|
||||||
|
}
|
||||||
|
value.Add(fileName);
|
||||||
|
}
|
||||||
|
else //face
|
||||||
|
{
|
||||||
|
string category = fileName[0].ToString();
|
||||||
|
if (!faceFiles.TryGetValue(category, out List<string>? value))
|
||||||
|
{
|
||||||
|
value = ([]);
|
||||||
|
faceFiles[category] = value;
|
||||||
|
}
|
||||||
|
value.Add(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
foreach (var baseEntry in baseFiles)
|
||||||
|
{
|
||||||
|
string baseCategory = baseEntry.Key; // 获取 base 文件的类别
|
||||||
|
var baseFileNames = baseEntry.Value; // 获取对应的 base 文件名列表
|
||||||
|
// 检查是否存在相同类别的 face 文件
|
||||||
|
if (faceFiles.TryGetValue(baseCategory, out List<string>? faceFileNames))
|
||||||
|
{
|
||||||
|
foreach (var baseFile in baseFileNames)
|
||||||
|
{
|
||||||
|
foreach (var faceFile in faceFileNames)
|
||||||
|
{
|
||||||
|
FgRecord fgRecord = new()
|
||||||
|
{
|
||||||
|
ChName = chName,
|
||||||
|
Size = size,
|
||||||
|
File = baseFile,
|
||||||
|
Face = faceFile
|
||||||
|
};
|
||||||
|
fgRecords.Add(fgRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fgRecords;
|
||||||
|
}
|
||||||
|
}
|
||||||
public static FgRecord? ParseScriptFGLine(string input)
|
public static FgRecord? ParseScriptFGLine(string input)
|
||||||
{
|
{
|
||||||
FgRecord fgRecord = new();
|
FgRecord fgRecord = new();
|
||||||
|
@ -15,6 +15,22 @@ namespace ArtemisFgTools
|
|||||||
else
|
else
|
||||||
Console.WriteLine("Invalid arguments, Please check the usage via -h");
|
Console.WriteLine("Invalid arguments, Please check the usage via -h");
|
||||||
}
|
}
|
||||||
|
else if(args.Length == 4)
|
||||||
|
{
|
||||||
|
//暴力合成
|
||||||
|
if (args[0] != "-c" || args[2] != "-o")
|
||||||
|
Console.WriteLine("Invalid arguments, Please check the usage via -h");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(args[3]))
|
||||||
|
Directory.CreateDirectory(args[3]);
|
||||||
|
if (!Directory.Exists(args[1]))
|
||||||
|
Console.WriteLine("Invalid fg path");
|
||||||
|
else
|
||||||
|
PreProcess3(args[1], args[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
else if (args.Length != 6)
|
else if (args.Length != 6)
|
||||||
Console.WriteLine("Invalid arguments, Please check the usage via -h");
|
Console.WriteLine("Invalid arguments, Please check the usage via -h");
|
||||||
else if (args[0] != "-c" || !(args[2] == "-s" || args[2] == "-t") || args[4] != "-o")
|
else if (args[0] != "-c" || !(args[2] == "-s" || args[2] == "-t") || args[4] != "-o")
|
||||||
@ -45,9 +61,18 @@ namespace ArtemisFgTools
|
|||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void PreProcess3(string fgImagePath, string savePath)
|
||||||
|
{
|
||||||
|
//直接暴力处理,只认定底和脸
|
||||||
|
HashSet<FgRecord> fgRecords = FetchFgObjectsDirect(fgImagePath);
|
||||||
|
if (fgRecords.Count == 0)
|
||||||
|
throw new Exception("No valid fg object found.");
|
||||||
|
Process2(fgImagePath, savePath, fgRecords);
|
||||||
|
}
|
||||||
|
|
||||||
private static void PreProcess2(string fgImagePath, string savePath, string scriptPath)
|
private static void PreProcess2(string fgImagePath, string savePath, string scriptPath)
|
||||||
{
|
{
|
||||||
HashSet<FgRecord> fgRecords = FetchFgObjectsFromScript(scriptPath);
|
HashSet<FgRecord> fgRecords = FetchFgRecordsFromScript(scriptPath);
|
||||||
if (fgRecords.Count == 0)
|
if (fgRecords.Count == 0)
|
||||||
throw new Exception("No valid fg object found.");
|
throw new Exception("No valid fg object found.");
|
||||||
//重新写个,我也懒得将FgRecord转FgObject了
|
//重新写个,我也懒得将FgRecord转FgObject了
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"ArtemisFgTools": {
|
"ArtemisFgTools": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "-c\r\nG:\\x221.local\\1\\lab\\fg\r\n-s\r\nG:\\x221.local\\1\\lab\\script\r\n-o\r\nG:\\x221.local\\1\\lab\\output"
|
"commandLineArgs": "-c\r\nG:\\x221.local\\1\\lab\\fg\r\n-o\r\nG:\\x221.local\\1\\lab\\output"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user