Fix level thumbs up and thumbs down being switched

This commit is contained in:
Slendy 2023-03-28 14:28:11 -05:00
commit 7c1d109157
No known key found for this signature in database
GPG key ID: 7288D68361B91428

View file

@ -1,4 +1,5 @@
using System; #nullable enable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
@ -8,7 +9,6 @@ using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Files; using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction; using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
using LBPUnion.ProjectLighthouse.Types.Entities.Level; using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@ -35,7 +35,7 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
public SerializationMode SerializationMode { get; set; } public SerializationMode SerializationMode { get; set; }
[XmlIgnore] [XmlIgnore]
public string[] Resources { get; set; } public string[]? Resources { get; set; }
[XmlElement("id")] [XmlElement("id")]
public int SlotId { get; set; } public int SlotId { get; set; }
@ -53,16 +53,19 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
public GameVersion GameVersion { get; set; } public GameVersion GameVersion { get; set; }
[XmlElement("name")] [XmlElement("name")]
public string Name { get; set; } public string Name { get; set; } = "";
[XmlElement("description")] [XmlElement("description")]
public string Description { get; set; } public string Description { get; set; } = "";
[XmlElement("rootLevel")] [XmlElement("rootLevel")]
public string RootLevel { get; set; } public string? RootLevel { get; set; }
[XmlElement("resource")]
public string[]? ResourceList { get; set; }
[XmlElement("icon")] [XmlElement("icon")]
public string IconHash { get; set; } public string IconHash { get; set; } = "";
[XmlElement("initiallyLocked")] [XmlElement("initiallyLocked")]
public bool InitiallyLocked { get; set; } public bool InitiallyLocked { get; set; }
@ -78,7 +81,7 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
[DefaultValue("")] [DefaultValue("")]
[XmlElement("background")] [XmlElement("background")]
public string BackgroundHash { get; set; } public string? BackgroundHash { get; set; }
[XmlElement("shareable")] [XmlElement("shareable")]
public int IsShareable { get; set; } public int IsShareable { get; set; }
@ -153,7 +156,7 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
[DefaultValue("")] [DefaultValue("")]
[XmlElement("tags")] [XmlElement("tags")]
public string Tags { get; set; } public string? Tags { get; set; }
public bool ShouldSerializeTags() => this.SerializationMode == SerializationMode.Full; public bool ShouldSerializeTags() => this.SerializationMode == SerializationMode.Full;
[DefaultValue("")] [DefaultValue("")]
@ -175,7 +178,7 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
[DefaultValue(null)] [DefaultValue(null)]
[XmlElement("yourReview")] [XmlElement("yourReview")]
public GameReview YourReview { get; set; } public GameReview? YourReview { get; set; }
public bool ShouldSerializeYourReview() => this.SerializationMode == SerializationMode.Full; public bool ShouldSerializeYourReview() => this.SerializationMode == SerializationMode.Full;
[XmlElement("reviewsEnabled")] [XmlElement("reviewsEnabled")]
@ -237,8 +240,8 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
var stats = await database.Slots var stats = await database.Slots
.Select(_ => new .Select(_ => new
{ {
ThumbsUp = database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == -1), ThumbsUp = database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == 1),
ThumbsDown = database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == 1), ThumbsDown = database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == -1),
ReviewCount = database.Reviews.Count(r => r.SlotId == this.SlotId), ReviewCount = database.Reviews.Count(r => r.SlotId == this.SlotId),
CommentCount = database.Comments.Count(c => c.TargetId == this.SlotId && c.Type == CommentType.Level), CommentCount = database.Comments.Count(c => c.TargetId == this.SlotId && c.Type == CommentType.Level),
PhotoCount = database.Photos.Count(p => p.SlotId == this.SlotId), PhotoCount = database.Photos.Count(p => p.SlotId == this.SlotId),
@ -269,7 +272,7 @@ public class GameUserSlot : SlotBase, INeedsPreparationForSerialization
if (this.SerializationMode == SerializationMode.Minimal) return; if (this.SerializationMode == SerializationMode.Minimal) return;
if (this.GameVersion == GameVersion.LittleBigPlanetVita) this.ResourcesSize = this.Resources.Sum(FileHelper.ResourceSize); if (this.GameVersion == GameVersion.LittleBigPlanetVita && this.Resources != null) this.ResourcesSize = this.Resources.Sum(FileHelper.ResourceSize);
#nullable enable #nullable enable
RatedLevelEntity? yourRating = await database.RatedLevels.FirstOrDefaultAsync(r => r.UserId == this.TargetUserId && r.SlotId == this.SlotId); RatedLevelEntity? yourRating = await database.RatedLevels.FirstOrDefaultAsync(r => r.UserId == this.TargetUserId && r.SlotId == this.SlotId);