From 81befb4cd88f364ac686d673de6392d399112bf2 Mon Sep 17 00:00:00 2001 From: LumaLivy Date: Mon, 8 Nov 2021 05:17:47 -0500 Subject: [PATCH] Support playcount migration and fix unexpected null reference for creator name --- ProjectLighthouse/Types/Levels/Slot.cs | 52 ++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/ProjectLighthouse/Types/Levels/Slot.cs b/ProjectLighthouse/Types/Levels/Slot.cs index 1057fa48..acbcade8 100644 --- a/ProjectLighthouse/Types/Levels/Slot.cs +++ b/ProjectLighthouse/Types/Levels/Slot.cs @@ -52,6 +52,12 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels [ForeignKey(nameof(CreatorId))] public User Creator { get; set; } + [NotMapped] + public string CreatorName + { + get => this.Creator?.Username; + } + /// /// The location of the level on the creator's earth /// @@ -109,7 +115,36 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels } [XmlIgnore] - public int Plays { get; set; } + [NotMapped] + public int Plays { get => this.PlaysLBP1 + this.PlaysLBP2 + this.PlaysLBP3; } + [XmlIgnore] + [NotMapped] + public int PlaysUnique { get => this.PlaysLBP1Unique + this.PlaysLBP2Unique + this.PlaysLBP3Unique; } + [XmlIgnore] + [NotMapped] + public int PlaysComplete { get => this.PlaysLBP1Complete + this.PlaysLBP2Complete + this.PlaysLBP3Complete; } + + [XmlIgnore] + public int PlaysLBP1 { get; set; } + [XmlIgnore] + public int PlaysLBP1Complete { get; set; } + [XmlIgnore] + public int PlaysLBP1Unique { get; set; } + + [XmlIgnore] + public int PlaysLBP2 { get; set; } + [XmlIgnore] + public int PlaysLBP2Complete { get; set; } + [XmlIgnore] + public int PlaysLBP2Unique { get; set; } + + [XmlIgnore] + public int PlaysLBP3 { get; set; } + [XmlIgnore] + public int PlaysLBP3Complete { get; set; } + [XmlIgnore] + public int PlaysLBP3Unique { get; set; } + public string SerializeResources() { @@ -121,7 +156,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels string slotData = LbpSerializer.StringElement("name", this.Name) + LbpSerializer.StringElement("id", this.SlotId) + LbpSerializer.StringElement("game", (int)this.GameVersion) + - LbpSerializer.StringElement("npHandle", this.Creator.Username) + + LbpSerializer.StringElement("npHandle", this.CreatorName) + LbpSerializer.StringElement("description", this.Description) + LbpSerializer.StringElement("icon", this.IconHash) + LbpSerializer.StringElement("rootLevel", this.RootLevel) + @@ -139,7 +174,18 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels LbpSerializer.StringElement("lastUpdated", this.LastUpdated) + LbpSerializer.StringElement("mmpick", this.TeamPick) + LbpSerializer.StringElement("heartCount", this.Hearts) + - LbpSerializer.StringElement("playCount", this.Plays); + LbpSerializer.StringElement("playCount", this.Plays) + + LbpSerializer.StringElement("uniquePlayCount", this.PlaysLBP2Unique) + // ??? good naming scheme lol + LbpSerializer.StringElement("completionCount", this.PlaysComplete) + + LbpSerializer.StringElement("lbp1PlayCount", this.PlaysLBP1) + + LbpSerializer.StringElement("lbp1CompletionCount", this.PlaysLBP1Complete) + + LbpSerializer.StringElement("lbp1UniquePlayCount", this.PlaysLBP1Unique) + + LbpSerializer.StringElement("lbp2PlayCount", this.PlaysLBP2) + + LbpSerializer.StringElement("lbp2CompletionCount", this.PlaysLBP2Complete) + + LbpSerializer.StringElement("lbp2UniquePlayCount", this.PlaysLBP2Unique) + // not actually used ingame, as per above comment + LbpSerializer.StringElement("lbp3PlayCount", this.PlaysLBP3) + + LbpSerializer.StringElement("lbp3CompletionCount", this.PlaysLBP3Complete) + + LbpSerializer.StringElement("lbp3UniquePlayCount", this.PlaysLBP3Unique); return LbpSerializer.TaggedStringElement("slot", slotData, "type", "user"); }