mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Add import of .atch files into metadata.
This commit is contained in:
parent
2be5bd0611
commit
93e184c9a5
2 changed files with 66 additions and 4 deletions
|
|
@ -1,11 +1,14 @@
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
|
using Dalamud.Interface.ImGuiNotification;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using OtterGui;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
using OtterGui.Services;
|
using OtterGui.Services;
|
||||||
using OtterGui.Text;
|
using OtterGui.Text;
|
||||||
using OtterGui.Widgets;
|
using OtterGui.Widgets;
|
||||||
using Penumbra.Collections.Cache;
|
using Penumbra.Collections.Cache;
|
||||||
|
using Penumbra.GameData.Data;
|
||||||
using Penumbra.GameData.Enums;
|
using Penumbra.GameData.Enums;
|
||||||
using Penumbra.GameData.Files;
|
using Penumbra.GameData.Files;
|
||||||
using Penumbra.GameData.Files.AtchStructs;
|
using Penumbra.GameData.Files.AtchStructs;
|
||||||
|
|
@ -13,6 +16,7 @@ using Penumbra.Meta;
|
||||||
using Penumbra.Meta.Manipulations;
|
using Penumbra.Meta.Manipulations;
|
||||||
using Penumbra.Mods.Editor;
|
using Penumbra.Mods.Editor;
|
||||||
using Penumbra.UI.Classes;
|
using Penumbra.UI.Classes;
|
||||||
|
using Notification = OtterGui.Classes.Notification;
|
||||||
|
|
||||||
namespace Penumbra.UI.AdvancedWindow.Meta;
|
namespace Penumbra.UI.AdvancedWindow.Meta;
|
||||||
|
|
||||||
|
|
@ -27,9 +31,9 @@ public sealed class AtchMetaDrawer : MetaDrawer<AtchIdentifier, AtchEntry>, ISer
|
||||||
public override float ColumnHeight
|
public override float ColumnHeight
|
||||||
=> 2 * ImUtf8.FrameHeightSpacing;
|
=> 2 * ImUtf8.FrameHeightSpacing;
|
||||||
|
|
||||||
private AtchFile? _currentBaseAtchFile;
|
private AtchFile? _currentBaseAtchFile;
|
||||||
private AtchPoint? _currentBaseAtchPoint;
|
private AtchPoint? _currentBaseAtchPoint;
|
||||||
private AtchPointCombo _combo;
|
private readonly AtchPointCombo _combo;
|
||||||
|
|
||||||
public AtchMetaDrawer(ModMetaEditor editor, MetaFileManager metaFiles)
|
public AtchMetaDrawer(ModMetaEditor editor, MetaFileManager metaFiles)
|
||||||
: base(editor, metaFiles)
|
: base(editor, metaFiles)
|
||||||
|
|
@ -44,6 +48,41 @@ public sealed class AtchMetaDrawer : MetaDrawer<AtchIdentifier, AtchEntry>, ISer
|
||||||
=> obj.ToName();
|
=> obj.ToName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ImportFile(string filePath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (filePath.Length == 0 || !File.Exists(filePath))
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
|
||||||
|
var gr = GamePaths.ParseRaceCode(filePath);
|
||||||
|
if (gr is GenderRace.Unknown)
|
||||||
|
throw new Exception($"Could not identify race code from path {filePath}.");
|
||||||
|
var text = File.ReadAllBytes(filePath);
|
||||||
|
var file = new AtchFile(text);
|
||||||
|
foreach (var point in file.Points)
|
||||||
|
{
|
||||||
|
foreach (var (entry, index) in point.Entries.WithIndex())
|
||||||
|
{
|
||||||
|
var identifier = new AtchIdentifier(point.Type, gr, (ushort) index);
|
||||||
|
var defaultValue = AtchCache.GetDefault(MetaFiles, identifier);
|
||||||
|
if (defaultValue == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (defaultValue.Value.Equals(entry))
|
||||||
|
Editor.Changes |= Editor.Remove(identifier);
|
||||||
|
else
|
||||||
|
Editor.Changes |= Editor.TryAdd(identifier, entry) || Editor.Update(identifier, entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Penumbra.Messager.AddMessage(new Notification(ex, "Unable to import .atch file.", "Could not import .atch file:",
|
||||||
|
NotificationType.Warning));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void DrawNew()
|
protected override void DrawNew()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ using OtterGui;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
using OtterGui.Text;
|
using OtterGui.Text;
|
||||||
using Penumbra.Api.Api;
|
using Penumbra.Api.Api;
|
||||||
|
using Penumbra.GameData.Data;
|
||||||
|
using Penumbra.GameData.Enums;
|
||||||
using Penumbra.Meta.Manipulations;
|
using Penumbra.Meta.Manipulations;
|
||||||
using Penumbra.UI.AdvancedWindow.Meta;
|
using Penumbra.UI.AdvancedWindow.Meta;
|
||||||
using Penumbra.UI.Classes;
|
using Penumbra.UI.Classes;
|
||||||
|
|
@ -43,8 +45,10 @@ public partial class ModEditWindow
|
||||||
if (ImUtf8.Button("Write as TexTools Files"u8))
|
if (ImUtf8.Button("Write as TexTools Files"u8))
|
||||||
_metaFileManager.WriteAllTexToolsMeta(Mod!);
|
_metaFileManager.WriteAllTexToolsMeta(Mod!);
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (ImUtf8.ButtonEx("Remove All Default-Values", "Delete any entries from all lists that set the value to its default value."u8))
|
if (ImUtf8.ButtonEx("Remove All Default-Values"u8, "Delete any entries from all lists that set the value to its default value."u8))
|
||||||
_editor.MetaEditor.DeleteDefaultValues();
|
_editor.MetaEditor.DeleteDefaultValues();
|
||||||
|
ImGui.SameLine();
|
||||||
|
DrawAtchDragDrop();
|
||||||
|
|
||||||
using var child = ImRaii.Child("##meta", -Vector2.One, true);
|
using var child = ImRaii.Child("##meta", -Vector2.One, true);
|
||||||
if (!child)
|
if (!child)
|
||||||
|
|
@ -60,6 +64,25 @@ public partial class ModEditWindow
|
||||||
DrawEditHeader(MetaManipulationType.GlobalEqp);
|
DrawEditHeader(MetaManipulationType.GlobalEqp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DrawAtchDragDrop()
|
||||||
|
{
|
||||||
|
_dragDropManager.CreateImGuiSource("atchDrag", f => f.Extensions.Contains(".atch"), f =>
|
||||||
|
{
|
||||||
|
var gr = GamePaths.ParseRaceCode(f.Files.FirstOrDefault() ?? string.Empty);
|
||||||
|
if (gr is GenderRace.Unknown)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ImUtf8.Text($"Dragging .atch for {gr.ToName()}...");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
ImUtf8.ButtonEx("Import .atch"u8,
|
||||||
|
_dragDropManager.IsDragging ? ""u8 : "Drag a .atch file containinig its race code in the path here to import its values."u8,
|
||||||
|
default,
|
||||||
|
!_dragDropManager.IsDragging);
|
||||||
|
if (_dragDropManager.CreateImGuiTarget("atchDrag", out var files, out _) && files.FirstOrDefault() is { } file)
|
||||||
|
_metaDrawers.Atch.ImportFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawEditHeader(MetaManipulationType type)
|
private void DrawEditHeader(MetaManipulationType type)
|
||||||
{
|
{
|
||||||
var drawer = _metaDrawers.Get(type);
|
var drawer = _metaDrawers.Get(type);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue