Skip to content
Merged
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
1 change: 1 addition & 0 deletions Dat/Loaders/WaterObjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Definitions.ObjectModels.Types;

namespace Dat.Loaders;

public abstract class WaterObjectLoader : IDatObjectLoader
{
public static class Constants
Expand Down
6 changes: 3 additions & 3 deletions Definitions/DTO/Comparers/DtoObjectDescriptorComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Definitions.DTO.Comparers;

public class DtoObjectDescriptorComparer : IEqualityComparer<DtoObjectDescriptor>
public class DtoObjectDescriptorComparer : IEqualityComparer<DtoObjectPostResponse>
{
public bool Equals(DtoObjectDescriptor? x, DtoObjectDescriptor? y)
public bool Equals(DtoObjectPostResponse? x, DtoObjectPostResponse? y)
{
if (x is null || y is null)
{
Expand All @@ -31,6 +31,6 @@ public bool Equals(DtoObjectDescriptor? x, DtoObjectDescriptor? y)
&& x.StringTable.Equals(y.StringTable);
}

public int GetHashCode([DisallowNull] DtoObjectDescriptor obj)
public int GetHashCode([DisallowNull] DtoObjectPostResponse obj)
=> obj.GetHashCode();
}
6 changes: 3 additions & 3 deletions Definitions/DTO/Comparers/DtoObjectMissingUploadComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Definitions.DTO.Comparers;

public class DtoObjectMissingUploadComparer : IEqualityComparer<DtoObjectMissingUpload>
public class DtoObjectMissingUploadComparer : IEqualityComparer<DtoObjectMissingPost>
{
public bool Equals(DtoObjectMissingUpload? x, DtoObjectMissingUpload? y)
public bool Equals(DtoObjectMissingPost? x, DtoObjectMissingPost? y)
{
if (x is null || y is null)
{
Expand All @@ -17,6 +17,6 @@ public bool Equals(DtoObjectMissingUpload? x, DtoObjectMissingUpload? y)
&& x.ObjectType == y.ObjectType;
}

public int GetHashCode([DisallowNull] DtoObjectMissingUpload obj)
public int GetHashCode([DisallowNull] DtoObjectMissingPost obj)
=> HashCode.Combine(obj.DatName, obj.DatChecksum, obj.ObjectType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Definitions.DTO;

public record DtoObjectMissingUpload(
public record DtoObjectMissingPost(
string DatName,
uint32_t DatChecksum,
ObjectType ObjectType);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Definitions.DTO;

public record DtoUploadDat(
public record DtoObjectPost(
string DatBytesAsBase64,
ulong xxHash3,
ObjectAvailability InitialAvailability,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Definitions.DTO;

public record DtoObjectDescriptor(
public record DtoObjectPostResponse(
UniqueObjectId Id,
string Name,
string DisplayName,
Expand Down
2 changes: 1 addition & 1 deletion Definitions/DTO/Mappers/DtoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Definitions.DTO.Mappers;

public static class DtoExtensions
{
public static DtoObjectDescriptor ToDtoDescriptor(this ExpandedTbl<TblObject, TblObjectPack> x /*, IDtoSubObject SubObject*/)
public static DtoObjectPostResponse ToDtoDescriptor(this ExpandedTbl<TblObject, TblObjectPack> x /*, IDtoSubObject SubObject*/)
=> new(
x!.Object.Id,
x!.Object.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Definitions.ObjectModels;

public class LocoObjectMetadata(string internalName)
public class ObjectMetadata(string internalName)
{
public UniqueObjectId UniqueObjectId { get; init; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;

namespace Definitions.ObjectModels.Objects.ScenarioText;

public class ScenarioTextObject : ILocoStruct
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
Expand Down
55 changes: 48 additions & 7 deletions Definitions/Web/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ public static async Task<IEnumerable<DtoObjectEntry>> GetObjectListAsync(HttpCli
null,
logger) ?? [];

public static async Task<DtoObjectDescriptor?> GetObjectAsync(HttpClient client, UniqueObjectId id, ILogger? logger = null)
=> await ClientHelpers.GetAsync<DtoObjectDescriptor>(
public static async Task<DtoObjectPostResponse?> GetObjectAsync(HttpClient client, UniqueObjectId id, ILogger? logger = null)
=> await ClientHelpers.GetAsync<DtoObjectPostResponse>(
client,
ApiVersion,
RoutesV2.Objects,
id,
logger);

public static async Task<DtoObjectPostResponse?> UpdateObjectAsync(HttpClient client, UniqueObjectId id, DtoObjectPostResponse request, ILogger? logger = null)
=> await ClientHelpers.PutAsync<DtoObjectPostResponse, DtoObjectPostResponse>(
client,
ApiVersion,
RoutesV2.Objects,
id,
request,
logger);

public static async Task<byte[]?> GetObjectFileAsync(HttpClient client, UniqueObjectId id, ILogger? logger = null)
=> await ClientHelpers.SendRequestAsync(
client,
Expand All @@ -32,26 +41,58 @@ public static async Task<IEnumerable<DtoObjectEntry>> GetObjectListAsync(HttpCli
ClientHelpers.ReadBinaryContentAsync,
logger) ?? default;

public static async Task<DtoObjectDescriptor?> UploadDatFileAsync(HttpClient client, string filename, byte[] datFileBytes, DateOnly creationDate, DateOnly modifiedDate, ILogger logger)
public static async Task<DtoObjectPostResponse?> UploadDatFileAsync(HttpClient client, string filename, byte[] datFileBytes, DateOnly creationDate, DateOnly modifiedDate, ILogger logger)
{
var xxHash3 = XxHash3.HashToUInt64(datFileBytes);
logger.Debug($"Posting {filename} to {client.BaseAddress?.OriginalString}{RoutesV2.Objects}");
var request = new DtoUploadDat(Convert.ToBase64String(datFileBytes), xxHash3, ObjectAvailability.Available, creationDate, modifiedDate);
return await ClientHelpers.PostAsync<DtoUploadDat, DtoObjectDescriptor>(
var request = new DtoObjectPost(Convert.ToBase64String(datFileBytes), xxHash3, ObjectAvailability.Available, creationDate, modifiedDate);
return await ClientHelpers.PostAsync<DtoObjectPost, DtoObjectPostResponse>(
client,
ApiVersion,
RoutesV2.Objects,
request);
}

public static async Task<DtoObjectMissingEntry?> AddMissingObjectAsync(HttpClient client, DtoObjectMissingUpload entry, ILogger? logger = null)
public static async Task<DtoObjectMissingEntry?> AddMissingObjectAsync(HttpClient client, DtoObjectMissingPost entry, ILogger? logger = null)
{
logger?.Debug($"Posting missing object {entry.DatName} with checksum {entry.DatChecksum} to {client.BaseAddress?.OriginalString}{RoutesV2.Objects}{RoutesV2.Missing}");
return await ClientHelpers.PostAsync<DtoObjectMissingUpload, DtoObjectMissingEntry>(
return await ClientHelpers.PostAsync<DtoObjectMissingPost, DtoObjectMissingEntry>(
client,
ApiVersion,
RoutesV2.Objects + RoutesV2.Missing,
entry,
logger);
}

public static async Task<IEnumerable<DtoLicenceEntry>> GetLicencesAsync(HttpClient client, ILogger? logger = null)
=> await ClientHelpers.GetAsync<IEnumerable<DtoLicenceEntry>>(
client,
ApiVersion,
RoutesV2.Licences,
null,
logger) ?? [];

public static async Task<IEnumerable<DtoAuthorEntry>> GetAuthorsAsync(HttpClient client, ILogger? logger = null)
=> await ClientHelpers.GetAsync<IEnumerable<DtoAuthorEntry>>(
client,
ApiVersion,
RoutesV2.Authors,
null,
logger) ?? [];

public static async Task<IEnumerable<DtoTagEntry>> GetTagsAsync(HttpClient client, ILogger? logger = null)
=> await ClientHelpers.GetAsync<IEnumerable<DtoTagEntry>>(
client,
ApiVersion,
RoutesV2.Tags,
null,
logger) ?? [];

public static async Task<IEnumerable<DtoItemPackEntry>> GetObjectPacksAsync(HttpClient client, ILogger? logger = null)
=> await ClientHelpers.GetAsync<IEnumerable<DtoItemPackEntry>>(
client,
ApiVersion,
RoutesV2.ObjectPacks,
null,
logger) ?? [];
}
9 changes: 1 addition & 8 deletions Gui/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:domt="using:Definitions.ObjectModels.Types"
xmlns:vm="using:Gui.ViewModels"
xmlns:vi="using:Gui.Views"
xmlns:oldt="using:Dat.Types"
xmlns:log="using:Common.Logging"
xmlns:cnv="using:Gui.Converters"
xmlns:pgc="clr-namespace:Avalonia.PropertyGrid.Controls;assembly=Avalonia.PropertyGrid"
Expand Down Expand Up @@ -97,12 +96,6 @@
<DataTemplate DataType="domt:ObjectModelHeader">
<pgc:PropertyGrid DataContext="{Binding}" IsCategoryVisible="False" />
</DataTemplate>
<!--<DataTemplate DataType="oldt:S5Header">
<pgc:PropertyGrid x:Name="propertyGrid_S5Header" DataContext="{Binding}" IsCategoryVisible="False" />
</DataTemplate>
<DataTemplate DataType="oldt:ObjectHeader">
<pgc:PropertyGrid x:Name="propertyGrid_ObjectHeader" DataContext="{Binding}" IsCategoryVisible="False" />
</DataTemplate>-->
<DataTemplate DataType="vm:SCV5ViewModel">
<vi:SCV5View />
</DataTemplate>
Expand All @@ -112,7 +105,7 @@
<DataTemplate DataType="vm:Graphics.ImageTableViewModel">
<vi:ImageTableView />
</DataTemplate>
<DataTemplate DataType="vm:LocoObjectMetadataViewModel">
<DataTemplate DataType="vm:ObjectMetadataViewModel">
<vi:MetadataView />
</DataTemplate>
<DataTemplate DataType="vm:ObjectEditorViewModel">
Expand Down
2 changes: 1 addition & 1 deletion Gui/Converters/EnumToMaterialIconConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class EnumToMaterialIconConverter : IValueConverter
static readonly Dictionary<string, string> MiscMappings = new()
{
{ nameof(ObjectIndexEntry), "ViewList" },
{ nameof(LocoObjectMetadata), "ViewListOutline" },
{ nameof(ObjectMetadata), "ViewListOutline" },
};

static readonly Dictionary<ObjectType, string> ObjectMapping = new()
Expand Down
2 changes: 1 addition & 1 deletion Gui/Models/LocoUIObjectModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace Gui.Models;
public class LocoUIObjectModel
{
public LocoObject? LocoObject { get; set; }
public LocoObjectMetadata? Metadata { get; set; }
public ObjectMetadata? Metadata { get; set; }
public DatHeaderInfo? DatInfo { get; set; }
}
10 changes: 5 additions & 5 deletions Gui/Models/ObjectEditorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ObjectEditorModel : IDisposable

public ObjectIndex? ObjectIndexOnline { get; set; }

public Dictionary<UniqueObjectId, DtoObjectDescriptor> OnlineCache { get; } = [];
public Dictionary<UniqueObjectId, DtoObjectPostResponse> OnlineCache { get; } = [];

public PaletteMap PaletteMap { get; set; }

Expand Down Expand Up @@ -197,7 +197,7 @@ bool TryLoadOnlineFile(FileSystemItem filesystemItem, out LocoUIObjectModel? loc

DatHeaderInfo? fileInfo = null;
LocoObject? locoObject = null;
LocoObjectMetadata? metadata = null;
ObjectMetadata? metadata = null;
//List<Image<Rgba32>> images = [];

if (filesystemItem.Id == null)
Expand Down Expand Up @@ -304,7 +304,7 @@ bool TryLoadOnlineFile(FileSystemItem filesystemItem, out LocoUIObjectModel? loc
fileInfo = new DatHeaderInfo(fakeS5Header, ObjectHeader.NullHeader);
}

metadata = new LocoObjectMetadata(cachedLocoObjDto.Name)
metadata = new ObjectMetadata(cachedLocoObjDto.Name)
{
UniqueObjectId = cachedLocoObjDto.Id,
Description = cachedLocoObjDto.Description,
Expand Down Expand Up @@ -342,7 +342,7 @@ bool TryLoadLocalFile(FileSystemItem filesystemItem, out LocoUIObjectModel? loco

DatHeaderInfo? fileInfo = null;
LocoObject? locoObject = null;
LocoObjectMetadata? metadata = null;
ObjectMetadata? metadata = null;

var filename = File.Exists(filesystemItem.FileName)
? filesystemItem.FileName
Expand All @@ -351,7 +351,7 @@ bool TryLoadLocalFile(FileSystemItem filesystemItem, out LocoUIObjectModel? loco
var obj = SawyerStreamReader.LoadFullObject(filename, logger: Logger);
fileInfo = obj.DatFileInfo;
locoObject = obj.LocoObject;
metadata = new LocoObjectMetadata("<unknown>")
metadata = new ObjectMetadata("<unknown>")
{
CreatedDate = filesystemItem.CreatedDate?.ToDateTimeOffset(),
ModifiedDate = filesystemItem.ModifiedDate?.ToDateTimeOffset(),
Expand Down
21 changes: 18 additions & 3 deletions Gui/ObjectServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,30 @@ public ObjectServiceClient(EditorSettings settings, ILogger logger)
public async Task<IEnumerable<DtoObjectEntry>> GetObjectListAsync()
=> await Client.GetObjectListAsync(WebClient, Logger);

public async Task<DtoObjectDescriptor?> GetObjectAsync(UniqueObjectId id)
public async Task<DtoObjectPostResponse?> GetObjectAsync(UniqueObjectId id)
=> await Client.GetObjectAsync(WebClient, id, Logger);

public async Task<DtoObjectPostResponse?> UpdateObjectAsync(UniqueObjectId id, DtoObjectPostResponse request)
=> await Client.UpdateObjectAsync(WebClient, id, request, Logger);

public async Task<byte[]?> GetObjectFileAsync(UniqueObjectId id)
=> await Client.GetObjectFileAsync(WebClient, id, Logger);

public async Task<DtoObjectDescriptor?> UploadDatFileAsync(string filename, byte[] datFileBytes, DateOnly creationDate, DateOnly modifiedDate)
public async Task<DtoObjectPostResponse?> UploadDatFileAsync(string filename, byte[] datFileBytes, DateOnly creationDate, DateOnly modifiedDate)
=> await Client.UploadDatFileAsync(WebClient, filename, datFileBytes, creationDate, modifiedDate, Logger);

public async Task<DtoObjectMissingEntry?> AddMissingObjectAsync(DtoObjectMissingUpload entry)
public async Task<DtoObjectMissingEntry?> AddMissingObjectAsync(DtoObjectMissingPost entry)
=> await Client.AddMissingObjectAsync(WebClient, entry, Logger);

public async Task<IEnumerable<DtoLicenceEntry>> GetLicencesAsync()
=> await Client.GetLicencesAsync(WebClient, Logger);

public async Task<IEnumerable<DtoAuthorEntry>> GetAuthorsAsync()
=> await Client.GetAuthorsAsync(WebClient, Logger);

public async Task<IEnumerable<DtoTagEntry>> GetTagsAsync()
=> await Client.GetTagsAsync(WebClient, Logger);

public async Task<IEnumerable<DtoItemPackEntry>> GetObjectPacksAsync()
=> await Client.GetObjectPacksAsync(WebClient, Logger);
}
2 changes: 1 addition & 1 deletion Gui/ViewModels/FolderTreeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public DesignerFolderTreeViewModel()
var availableFilterCategories = new List<FilterTypeViewModel>
{
new() { Type = typeof(ObjectIndexEntry), DisplayName = "Index data", IconName = nameof(ObjectIndexEntry) },
new() { Type = typeof (LocoObjectMetadata), DisplayName = "Metadata", IconName = nameof(LocoObjectMetadata) }
new() { Type = typeof (ObjectMetadata), DisplayName = "Metadata", IconName = nameof(ObjectMetadata) }
};

//Filters.Add(new FilterViewModel(availableFilterCategories, RemoveFilter));
Expand Down
10 changes: 0 additions & 10 deletions Gui/ViewModels/LocoObjectMetadataViewModel.cs

This file was deleted.

Loading