Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Individual Pose auto-save implementation #141

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Brio/Config/AutoSaveConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public class AutoSaveConfiguration
{
public bool AutoSaveSystemEnabled { get; set; } = true;

public bool AutoSaveIndividualPoses { get; set; } = true;

public int AutoSaveInterval { get; set; } = 60;
public int MaxAutoSaves { get; set; } = 8;

Expand Down
3 changes: 3 additions & 0 deletions Brio/Files/ActorFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ActorFile
{
public string Name { get; set; } = "";

public string FriendlyName { get; set; } = "Actor";

public required AnamnesisCharaFile AnamnesisCharaFile { get; set; }
public required PoseFile PoseFile { get; set; }

Expand All @@ -42,6 +44,7 @@ public static unsafe implicit operator ActorFile(ActorEntity actorEntity)
var actorFile = new ActorFile
{
Name = actorEntity.RawName,
FriendlyName = actorEntity.FriendlyName,
AnamnesisCharaFile = new ActorAppearanceExtended { Appearance = appearanceCapability.CurrentAppearance, ShaderParams = *appearanceCapability.Character.GetShaderParams() },
PoseFile = posingCapability.GeneratePoseFile(),
IsProp = actorEntity.IsProp,
Expand Down
54 changes: 41 additions & 13 deletions Brio/Game/Core/AutoSaveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Brio.Files;
using Brio.Game.GPose;
using Brio.Game.Scene;
using Brio.Resources;
using Brio.UI;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
Expand Down Expand Up @@ -80,10 +81,37 @@ private void AutoSave()

byte[] bytes = MessagePackSerializer.Serialize(scene);

var path = Path.Combine(AutoSaveFolder, $"autosave-{DateTime.Now:yyyy-MM-dd}-{DateTime.Now:hh-mm-ss}.brioautosave");
var path = Path.Combine(AutoSaveFolder, $"autosave-{DateTime.Now:yyyy-MM-dd}-{DateTime.Now:hh-mm-ss}");

Brio.Log.Verbose($"AutoSaving: {path}");

File.WriteAllBytes(path, bytes);
if(Directory.Exists(path) == false)
{
Directory.CreateDirectory(path);
}

File.WriteAllBytes(Path.Combine(path, "SceneAutoSave.brioautosave"), bytes);

if(ConfigurationService.Instance.Configuration.AutoSave.AutoSaveIndividualPoses)
{
var posespath = Path.Combine(path, "Poses");

if(Directory.Exists(posespath) == false)
{
Directory.CreateDirectory(posespath);
}

foreach(var actor in scene.Actors)
{

ResourceProvider.Instance.SaveFileDocument(Path.Combine(posespath, $"{actor.FriendlyName}.pose"), actor.PoseFile);

if(actor.HasChild && actor.Child?.PoseFile != null)
{
ResourceProvider.Instance.SaveFileDocument(Path.Combine(posespath, $"{actor.FriendlyName}-Companion.pose"), actor.Child.PoseFile);
}
}
}

Brio.Log.Verbose($"AutoSaved!");

Expand Down Expand Up @@ -143,22 +171,22 @@ public void CleanOldSaves()
{
try
{
var saveFiles = Directory.EnumerateFiles(AutoSaveFolder)
.Select(f => new FileInfo(f))
.OrderByDescending(f => f.LastWriteTime)
var saveFolders = Directory.EnumerateDirectories(AutoSaveFolder)
.Select(d => new DirectoryInfo(d))
.OrderByDescending(d => d.LastWriteTime)
.ToList();

if(saveFiles.Count > ConfigurationService.Instance.Configuration.AutoSave.MaxAutoSaves)
if(saveFolders.Count > ConfigurationService.Instance.Configuration.AutoSave.MaxAutoSaves)
{

}

// Keep the newest files and delete the rest
var filesToDelete = saveFiles.Skip(ConfigurationService.Instance.Configuration.AutoSave.MaxAutoSaves);
var foldersToDelete = saveFolders.Skip(ConfigurationService.Instance.Configuration.AutoSave.MaxAutoSaves);

foreach(var file in filesToDelete)
foreach(var folder in foldersToDelete)
{
file.Delete();
folder.Delete(true);
}
}
catch(Exception ex)
Expand All @@ -171,13 +199,13 @@ public void CleanAllSaves()
{
try
{
var saveFiles = Directory.EnumerateFiles(AutoSaveFolder)
.Select(f => new FileInfo(f))
var saveFolders = Directory.EnumerateDirectories(AutoSaveFolder)
.Select(d => new DirectoryInfo(d))
.ToList();

foreach(var file in saveFiles)
foreach(var folder in saveFolders)
{
file.Delete();
folder.Delete(true);
}
}
catch(Exception ex)
Expand Down
8 changes: 8 additions & 0 deletions Brio/UI/Windows/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ private void DrawImportScene()

using(ImRaii.Disabled(!enabled))
{

var individual = _configurationService.Configuration.AutoSave.AutoSaveIndividualPoses;
if(ImGui.Checkbox("Save Individual Poses", ref individual))
{
_configurationService.Configuration.AutoSave.AutoSaveIndividualPoses = individual;
_configurationService.ApplyChange();
}

var saveInterval = _configurationService.Configuration.AutoSave.AutoSaveInterval;
if(ImGui.SliderInt("Auto-Save Interval", ref saveInterval, 15, 500, "%d seconds"))
{
Expand Down