Properly serialize slot resources

This commit is contained in:
Slendy 2023-03-28 15:19:25 -05:00
parent 795a6b9b6e
commit 3ebdc03951
No known key found for this signature in database
GPG key ID: 7288D68361B91428
2 changed files with 10 additions and 13 deletions

View file

@ -56,9 +56,9 @@ public class PublishController : ControllerBase
return this.BadRequest(); return this.BadRequest();
} }
if (slot.ResourceList?.Length == 0) slot.ResourceList = new[]{slot.RootLevel,}; if (slot.Resources?.Length == 0) slot.Resources = new[]{slot.RootLevel,};
if (slot.ResourceList == null) if (slot.Resources == null)
{ {
Logger.Warn("Rejecting level upload, resource list is null", LogArea.Publish); Logger.Warn("Rejecting level upload, resource list is null", LogArea.Publish);
return this.BadRequest(); return this.BadRequest();
@ -86,7 +86,7 @@ public class PublishController : ControllerBase
return this.Forbid(); return this.Forbid();
} }
HashSet<string> resources = new(slot.ResourceList) HashSet<string> resources = new(slot.Resources)
{ {
slot.IconHash, slot.IconHash,
}; };
@ -114,13 +114,13 @@ public class PublishController : ControllerBase
return this.BadRequest(); return this.BadRequest();
} }
if (slot.ResourceList?.Length == 0) if (slot.Resources?.Length == 0)
{ {
Logger.Warn("Rejecting level upload, resource list is null", LogArea.Publish); Logger.Warn("Rejecting level upload, resource list is null", LogArea.Publish);
return this.BadRequest(); return this.BadRequest();
} }
// Yes Rider, this isn't null // Yes Rider, this isn't null
Debug.Assert(slot.ResourceList != null, "slot.ResourceList != null"); Debug.Assert(slot.Resources != null, "slot.ResourceList != null");
if (string.IsNullOrWhiteSpace(slot.BackgroundHash)) if (string.IsNullOrWhiteSpace(slot.BackgroundHash))
{ {
@ -144,7 +144,7 @@ public class PublishController : ControllerBase
return this.BadRequest(); return this.BadRequest();
} }
if (slot.ResourceList.Any(resource => !FileHelper.ResourceExists(resource))) if (slot.Resources.Any(resource => !FileHelper.ResourceExists(resource)))
{ {
Logger.Warn("Rejecting level upload, missing resource(s)", LogArea.Publish); Logger.Warn("Rejecting level upload, missing resource(s)", LogArea.Publish);
return this.BadRequest(); return this.BadRequest();
@ -182,10 +182,10 @@ public class PublishController : ControllerBase
slot.AuthorLabels = LabelHelper.RemoveInvalidLabels(slot.AuthorLabels); slot.AuthorLabels = LabelHelper.RemoveInvalidLabels(slot.AuthorLabels);
if (!slot.ResourceList.Contains(slot.RootLevel)) if (!slot.Resources.Contains(slot.RootLevel))
slot.ResourceList = slot.ResourceList.Append(rootLevel.Hash).ToArray(); slot.Resources = slot.Resources.Append(rootLevel.Hash).ToArray();
string resourceCollection = string.Join(",", slot.ResourceList); string resourceCollection = string.Join(",", slot.Resources);
// Republish logic // Republish logic
if (slot.SlotId != 0) if (slot.SlotId != 0)

View file

@ -34,9 +34,6 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
[XmlIgnore] [XmlIgnore]
public SerializationMode SerializationMode { get; set; } public SerializationMode SerializationMode { get; set; }
[XmlIgnore]
public string[]? Resources { get; set; }
[XmlElement("id")] [XmlElement("id")]
public int SlotId { get; set; } public int SlotId { get; set; }
@ -62,7 +59,7 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
public string? RootLevel { get; set; } public string? RootLevel { get; set; }
[XmlElement("resource")] [XmlElement("resource")]
public string[]? ResourceList { get; set; } public string[]? Resources { get; set; }
[XmlElement("icon")] [XmlElement("icon")]
public string IconHash { get; set; } = ""; public string IconHash { get; set; } = "";