This commit is contained in:
Hakoyu 2023-09-15 01:02:02 +08:00
parent d4349147d6
commit 72a5843875
9 changed files with 107 additions and 41 deletions

View File

@ -21,7 +21,7 @@ public static class Extensions
return ((FileStream)image.StreamSource).Name;
}
public static void CloseString(this ImageSource source)
public static void CloseStream(this ImageSource source)
{
if (source is BitmapImage image)
{

View File

@ -27,7 +27,7 @@ public class ModLoader
/// </summary>
public ulong ItemID { get; }
public string Intro { get; }
public DirectoryInfo Path { get; }
public DirectoryInfo ModPath { get; }
public int GameVer { get; }
public int Ver { get; }
public HashSet<string> Tag { get; } = new();
@ -38,19 +38,18 @@ public class ModLoader
public List<LowText> LowTexts { get; } = new();
public List<ClickText> ClickTexts { get; } = new();
public List<SelectText> SelectTexts { get; } = new();
public Dictionary<string, GraphCore> MultiGraphs { get; } = new();
public Dictionary<string, I18nModInfoModel> I18nDatas { get; } = new();
public Dictionary<string, Dictionary<string, string>> OtherI18nDatas { get; } = new();
public ModLoader(DirectoryInfo directory)
public ModLoader(DirectoryInfo path)
{
try
{
Path = directory;
LpsDocument modlps = new LpsDocument(
File.ReadAllText(directory.FullName + @"\info.lps")
);
ModPath = path;
LpsDocument modlps = new LpsDocument(File.ReadAllText(path.FullName + @"\info.lps"));
Name = modlps.FindLine("vupmod").Info;
Intro = modlps.FindLine("intro").Info;
GameVer = modlps.FindSub("gamever").InfoToInt;
@ -80,7 +79,7 @@ public class ModLoader
I18nDatas.Add(line.Info, i18nData);
}
DirectoryInfo? langDirectory = null;
foreach (DirectoryInfo di in Path.EnumerateDirectories())
foreach (DirectoryInfo di in path.EnumerateDirectories())
{
switch (di.Name.ToLower())
{
@ -93,7 +92,16 @@ public class ModLoader
if (lps.First().Name.ToLower() == "pet")
{
var name = lps.First().Info;
Pets.Add(new PetLoader(lps, di));
var pet = new PetLoader(lps, di);
Pets.Add(pet);
// 此方法会导致 LoadImageToStream 无法使用
//var graphCore = new GraphCore(0);
//foreach (var p in pet.path)
// PetLoader.LoadGraph(graphCore, di, p);
//MultiGraphs.Add(pet.Name, graphCore);
//var p = mw.Pets.FirstOrDefault(x => x.Id == name);
//if (p == null)
// mw.Pets.Add(new PetLoader(lps, di));
@ -113,7 +121,7 @@ public class ModLoader
foreach (ILine li in tmp)
{
var food = LPSConvert.DeserializeObject<Food>(li);
var imagePath = $"{Path.FullName}\\image\\food\\{food.Name}.png";
var imagePath = $"{path.FullName}\\image\\food\\{food.Name}.png";
if (File.Exists(imagePath))
food.Image = imagePath;
Foods.Add(food);
@ -208,7 +216,7 @@ public class ModLoader
public void WriteFile()
{
var lps = new LpsDocument(File.ReadAllText(Path.FullName + @"\info.lps"));
var lps = new LpsDocument(File.ReadAllText(ModPath.FullName + @"\info.lps"));
lps.FindLine("vupmod").Info = Name;
lps.FindLine("intro").Info = Intro;
lps.FindSub("gamever").InfoToInt = GameVer;
@ -216,6 +224,6 @@ public class ModLoader
lps.FindSub("author").Info = Author;
lps.FindorAddLine("authorid").InfoToInt64 = AuthorID;
lps.FindorAddLine("itemid").info = ItemID.ToString();
File.WriteAllText(Path.FullName + @"\info.lps", lps.ToString());
File.WriteAllText(ModPath.FullName + @"\info.lps", lps.ToString());
}
}

View File

@ -10,4 +10,5 @@ public static class ModMakerInfo
{
public const string BaseDirectory = nameof(ModMaker);
public const string HistoryFile = $"{BaseDirectory}\\history.lps";
public const string InfoFile = "info.lps";
}

View File

@ -2,15 +2,36 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using VPet_Simulator.Core;
using static VPet_Simulator.Core.GraphInfo;
namespace VPet.ModMaker.Models.ModModel;
public class AnimeModel
{
public ObservableValue<ImageModel> CurrentImageModel { get; } = new();
public ObservableCollection<ImageModel> ImageModels { get; } = new();
public ObservableValue<string> Id { get; } = new();
public ObservableValue<GraphInfo.AnimatType> AnimeType { get; } = new();
public ObservableCollection<ObservableCollection<ImageModel>> MultiHappyImageModels = new();
public ObservableCollection<ObservableCollection<ImageModel>> MultiNomalImageModels = new();
public ObservableCollection<ObservableCollection<ImageModel>> MultiPoorConditionImageModels =
new();
public ObservableCollection<ObservableCollection<ImageModel>> MultiIllImageModels = new();
public AnimeModel() { }
public AnimeModel(string name, AnimatType animatType, IList<IGraph> graphList)
{
Id.Value = name;
AnimeType.Value = animatType;
foreach (IGraph graph in graphList)
{
//if(graph.)
}
}
}

View File

@ -9,6 +9,7 @@ using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using VPet_Simulator.Windows.Interface;
@ -50,13 +51,15 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
public ModInfoModel(ModLoader loader)
: this()
{
SourcePath.Value = loader.Path.FullName;
SourcePath.Value = loader.ModPath.FullName;
Id.Value = loader.Name;
DescriptionId.Value = loader.Intro;
Author.Value = loader.Author;
GameVersion.Value = loader.GameVer.ToString();
ModVersion.Value = loader.Ver.ToString();
var imagePath = Path.Combine(loader.Path.FullName, "icon.png");
var imagePath = Path.Combine(loader.ModPath.FullName, "icon.png");
Thread.Sleep(1000);
GC.Collect();
if (File.Exists(imagePath))
Image.Value = Utils.LoadImageToStream(imagePath);
foreach (var food in loader.Foods)
@ -243,7 +246,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
new Line("pet", pet.Id.Value)
{
new Sub("intor", pet.DescriptionId.Value),
new Sub("path", pet.Id.Value),
new Sub("ModPath", pet.Id.Value),
new Sub("petname", pet.PetNameId.Value)
}
);

View File

@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using VPet.ModMaker.Models.ModModel;
using VPet_Simulator.Core;
namespace VPet.ModMaker.Models;
@ -24,6 +25,10 @@ public class PetModel : I18nModel<I18nPetInfoModel>
public ObservableCollection<MoveModel> Moves { get; } = new();
public ObservableValue<AnimeModel> CurrentAnime { get; } = new();
public Dictionary<GraphInfo.GraphType, ObservableCollection<AnimeModel>> Animes { get; } =
new();
public PetModel()
{
PetNameId.Value = $"{Id.Value}_{nameof(PetNameId)}";
@ -112,6 +117,20 @@ public class PetModel : I18nModel<I18nPetInfoModel>
Moves.Add(new(move));
}
public void LoadAnime(GraphCore core)
{
foreach (var info in core.GraphsName)
{
var list = new ObservableCollection<AnimeModel>();
foreach (var name in info.Value)
{
foreach (var graph in core.GraphsList[name])
list.Add(new AnimeModel(name, graph.Key, graph.Value));
}
Animes.Add(info.Key, list);
}
}
public void Close() { }
}

View File

@ -15,8 +15,14 @@ public static class Utils
{
BitmapImage bitmapImage = new();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new StreamReader(imagePath).BaseStream;
bitmapImage.EndInit();
try
{
bitmapImage.StreamSource = new StreamReader(imagePath).BaseStream;
}
finally
{
bitmapImage.EndInit();
}
return bitmapImage;
}
@ -29,11 +35,17 @@ public static class Utils
{
BitmapImage bitmapImage = new();
bitmapImage.BeginInit();
var ms = new MemoryStream();
using var sr = new StreamReader(imagePath);
sr.BaseStream.CopyTo(ms);
bitmapImage.StreamSource = ms;
bitmapImage.EndInit();
try
{
var ms = new MemoryStream();
using var sr = new StreamReader(imagePath);
sr.BaseStream.CopyTo(ms);
bitmapImage.StreamSource = ms;
}
finally
{
bitmapImage.EndInit();
}
return bitmapImage;
}

View File

@ -14,6 +14,8 @@ public class AnimeEditWindowVM
{
public AnimeModel OldAnime { get; set; }
public ObservableValue<AnimeModel> Anime { get; } = new(new());
public ObservableValue<ImageModel> CurrentImageModel { get; } = new();
#region Command
public ObservableCommand PlayCommand { get; } = new();
public ObservableCommand PauseCommand { get; } = new();
@ -24,14 +26,14 @@ public class AnimeEditWindowVM
public AnimeEditWindowVM()
{
foreach (
var file in Directory.EnumerateFiles(
@"C:\Users\HKW\Desktop\TestPicture\0000_core\pet\vup\Default\Happy\1"
)
)
{
Anime.Value.ImageModels.Add(new(Utils.LoadImageToMemoryStream(file)));
}
//foreach (
// var file in Directory.EnumerateFiles(
// @"C:\Users\HKW\Desktop\TestPicture\0000_core\pet\vup\Default\Happy\1"
// )
//)
//{
// Anime.Value.MultiImageModels.Add(new(Utils.LoadImageToMemoryStream(file)));
//}
_playerTask = new(Play);
PlayCommand.ExecuteEvent += PlayCommand_ExecuteEvent;
PauseCommand.ExecuteEvent += PauseCommand_ExecuteEvent;
@ -49,13 +51,13 @@ public class AnimeEditWindowVM
private void Play()
{
while (_pause is false)
{
foreach (var model in Anime.Value.ImageModels)
{
Anime.Value.CurrentImageModel.Value = model;
Task.Delay(model.Duration.Value).Wait();
}
}
//while (_pause is false)
//{
// foreach (var model in Anime.Value.ImageModels)
// {
// Anime.Value.CurrentImageModel.Value = model;
// Task.Delay(model.Duration.Value).Wait();
// }
//}
}
}

View File

@ -36,7 +36,7 @@ public partial class ModMakerWindow : Window
{
InitializeComponent();
DataContext = new ModMakerWindowVM(this);
new AnimeEditWindow().Show();
//new AnimeEditWindow().Show();
}
private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)