Skip to content

Commit

Permalink
支持多开, 不同存档
Browse files Browse the repository at this point in the history
  • Loading branch information
LorisYounger committed Oct 10, 2023
1 parent 931fd47 commit 1f3bd42
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 233 deletions.
8 changes: 8 additions & 0 deletions VPet-Simulator.Windows.Interface/IMainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ namespace VPet_Simulator.Windows.Interface
/// </summary>
public interface IMainWindow
{
/// <summary>
/// 存档前缀, 用于多开游戏, 为空时使用默认存档, 不为空时前缀的前缀一般为'-'
/// </summary>
string PrefixSave { get; }
/// <summary>
/// 启动参数
/// </summary>
LPS_D Args { get; }
/// <summary>
/// 是否为Steam用户
/// </summary>
Expand Down
11 changes: 9 additions & 2 deletions VPet-Simulator.Windows/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public App() : base()
#endif
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
public static string[] Args { get; set; }

protected override void OnStartup(StartupEventArgs e)
{
Args = e.Args;
}

private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
Expand All @@ -23,14 +29,15 @@ private void App_DispatcherUnhandledException(object sender, System.Windows.Thre
var expt = e.Exception.ToString();
if (expt.Contains("value") && expt.Contains("Panuon.WPF.UI.Internal.Utils") && expt.Contains("NaN"))
{
MessageBox.Show("由于修改游戏数据导致数据溢出,存档可能会出错\n开发者提醒您请不要使用过于超模的MOD".Translate());
MessageBox.Show("由于修改游戏数据导致数据溢出,存档可能会出错\n开发者提醒您请不要使用过于超模的MOD".Translate());
return;
}
else if (expt.Contains("System.IO.FileNotFoundException") && expt.Contains("cache"))
{
MessageBox.Show("缓存被其他软件删除,游戏无法继续运行\n请重启游戏重新生成缓存".Translate());
return;
}else if (expt.Contains("0x80070008"))
}
else if (expt.Contains("0x80070008"))
{
MessageBox.Show("游戏内存不足,请修改设置中渲染分辨率以便降低内存使用".Translate());
}
Expand Down
21 changes: 12 additions & 9 deletions VPet-Simulator.Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public partial class MainWindow : IMainWindow
{
public readonly string ModPath = Environment.CurrentDirectory + @"\mod";
public bool IsSteamUser { get; }
public LPS_D Args { get; }
public string PrefixSave { get; } = "";
public Setting Set { get; set; }
public List<PetLoader> Pets { get; set; } = new List<PetLoader>();
public List<CoreMOD> CoreMODs = new List<CoreMOD>();
Expand Down Expand Up @@ -186,16 +188,16 @@ public void Save()
//timecount = DateTime.Now;
}
Set.StartRecordLastPoint = new Point(Dispatcher.Invoke(() => Left), Dispatcher.Invoke(() => Top));
File.WriteAllText(ExtensionValue.BaseDirectory + @"\Setting.lps", Set.ToString());
File.WriteAllText(ExtensionValue.BaseDirectory + @$"\Setting{PrefixSave}.lps", Set.ToString());

if (!Directory.Exists(ExtensionValue.BaseDirectory + @"\Saves"))
Directory.CreateDirectory(ExtensionValue.BaseDirectory + @"\Saves");

if (Core != null && Core.Save != null)
{
var ds = new List<string>(Directory.GetFiles(ExtensionValue.BaseDirectory + @"\Saves", "*.lps")).FindAll(x => x.Contains('_')).OrderBy(x =>
var ds = new List<string>(Directory.GetFiles(ExtensionValue.BaseDirectory + @"\Saves", $"Save{PrefixSave}_*.lps")).OrderBy(x =>
{
if (int.TryParse(x.Split('_')[1].Split('.')[0], out int i))
if (int.TryParse(x.Split('_').Last().Split('.')[0], out int i))
return i;
return 0;
}).ToList();
Expand All @@ -204,16 +206,17 @@ public void Save()
File.Delete(ds[0]);
ds.RemoveAt(0);
}
if (File.Exists(ExtensionValue.BaseDirectory + $"\\Saves\\Save_{st}.lps"))
File.Delete(ExtensionValue.BaseDirectory + $"\\Saves\\Save_{st}.lps");
if (File.Exists(ExtensionValue.BaseDirectory + $"\\Saves\\Save{PrefixSave}_{st}.lps"))
File.Delete(ExtensionValue.BaseDirectory + $"\\Saves\\Save{PrefixSave}_{st}.lps");

File.WriteAllText(ExtensionValue.BaseDirectory + $"\\Saves\\Save_{st}.lps", GameSavesData.ToLPS().ToString());

if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.bkp"))
File.Delete(ExtensionValue.BaseDirectory + @"\Save.bkp");
File.WriteAllText(ExtensionValue.BaseDirectory + $"\\Saves\\Save{PrefixSave}_{st}.lps", GameSavesData.ToLPS().ToString());

if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.lps"))
{
if (File.Exists(ExtensionValue.BaseDirectory + @"\Save.bkp"))
File.Delete(ExtensionValue.BaseDirectory + @"\Save.bkp");
File.Move(ExtensionValue.BaseDirectory + @"\Save.lps", ExtensionValue.BaseDirectory + @"\Save.bkp");
}

}
}
Expand Down
17 changes: 9 additions & 8 deletions VPet-Simulator.Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public MainWindow()

//存档前缀
if (Args.ContainsLine("prefix"))
PrefixSave = '_' + Args["prefix"].Info;
PrefixSave = '-' + Args["prefix"].Info;

#if X64
PNGAnimation.MaxLoadNumber = 50;
Expand Down Expand Up @@ -296,16 +296,17 @@ public void LoadLatestSave(string petname)
{
if (Directory.Exists(ExtensionValue.BaseDirectory + @"\Saves"))
{
var ds = new List<string>(Directory.GetFiles(ExtensionValue.BaseDirectory + @"\Saves", "*.lps")).FindAll(x => x.Contains('_')).OrderBy(x =>
{
if (int.TryParse(x.Split('_')[1].Split('.')[0], out int i))
return i;
return 0;
}).ToList();
var ds = new List<string>(Directory.GetFiles(ExtensionValue.BaseDirectory + @"\Saves", $@"Save{PrefixSave}_*.lps"))
.OrderBy(x =>
{
if (int.TryParse(x.Split('_').Last().Split('.')[0], out int i))
return i;
return 0;
}).ToList();

if (ds.Count != 0)
{
int.TryParse(ds.Last().Split('_')[1].Split('.')[0], out int lastid);
int.TryParse(ds.Last().Split('_').Last().Split('.')[0], out int lastid);
if (Set.SaveTimes < lastid)
{
Set.SaveTimes = lastid;
Expand Down
8 changes: 8 additions & 0 deletions VPet-Simulator.Windows/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"VPet-Simulator.Windows": {
"commandName": "Project",
"commandLineArgs": "prefix#test:|"
}
}
}
2 changes: 1 addition & 1 deletion VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pu="https://opensource.panuon.com/wpf-ui" xmlns:local="clr-namespace:VPet_Simulator.Windows"
mc:Ignorable="d" Title="{ll:Str 更好买}" Height="550" Width="800" FontSize="14"
mc:Ignorable="d" Height="550" Width="800" FontSize="14"
WindowStartupLocation="CenterScreen" Background="#E0F6FF" pu:WindowXCaption.Height="45"
pu:WindowXCaption.Background="{DynamicResource DARKPrimary}" pu:WindowXCaption.Foreground="#FFFFFF"
pu:WindowXCaption.Buttons="Close" Icon="/Res/BetterBuy.png"
Expand Down
1 change: 1 addition & 0 deletions VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public winBetterBuy(MainWindow mw)
{
InitializeComponent();
this.mw = mw;
Title = "更好买".Translate() + ' ' + mw.PrefixSave;
LsbSortRule.SelectedIndex = mw.Set["betterbuy"].GetInt("lastorder");
LsbSortAsc.SelectedIndex = mw.Set["betterbuy"].GetBool("lastasc") ? 0 : 1;
AllowChange = true;
Expand Down
Loading

0 comments on commit 1f3bd42

Please sign in to comment.