Add user, ClientsConnected, and Location type

This commit is contained in:
jvyden 2021-10-06 02:19:50 -04:00
commit ceac914475
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 103 additions and 0 deletions

View file

@ -11,6 +11,12 @@ namespace ProjectLighthouse.Serialization {
public static string GetStringElement(string key, object value) => $"<{key}>{value}</{key}>";
public static string GetTaggedStringElement(KeyValuePair<string, object> pair, KeyValuePair<string, object> tagPair) =>
$"<{pair.Key} {tagPair.Key}=\"{tagPair.Value}\">{pair.Value}</{pair.Key}>";
public static string GetTaggedStringElement(string key, object value, string tagKey, object tagValue) =>
$"<{key} {tagKey}=\"{tagValue}\">{value}</{key}>";
public static string GetElements(params KeyValuePair<string, object>[] pairs) =>
pairs.Aggregate(string.Empty, (current, pair) => current + GetStringElement(pair));
}

View file

@ -0,0 +1,20 @@
using ProjectLighthouse.Serialization;
namespace ProjectLighthouse.Types {
public class ClientsConnected {
public bool Lbp1 { get; set; }
public bool Lbp2 { get; set; }
public bool LbpMe { get; set; }
public bool Lbp3Ps3 { get; set; }
public bool Lbp3Ps4 { get; set; }
public string Serialize() {
return LbpSerializer.GetStringElement("clientsConnected",
LbpSerializer.GetStringElement("lbp1", Lbp1) +
LbpSerializer.GetStringElement("lbp2", Lbp2) +
LbpSerializer.GetStringElement("lbpme", LbpMe) +
LbpSerializer.GetStringElement("lbp3ps3", Lbp3Ps3) +
LbpSerializer.GetStringElement("lbp3ps4", Lbp3Ps4));
}
}
}

View file

@ -0,0 +1,13 @@
using ProjectLighthouse.Serialization;
namespace ProjectLighthouse {
public class Location {
public int X;
public int Y;
public string Serialize() {
return LbpSerializer.GetStringElement("x", this.X) +
LbpSerializer.GetStringElement("Y", this.Y);
}
}
}

View file

@ -0,0 +1,64 @@
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types;
namespace ProjectLighthouse {
public class User {
public string Username { get; set; }
public string IconHash { get; set; }
public int Game { get; set; }
public int Lists { get; set; }
public static int ListsQuota = 20;
public int HeartCount { get; set; }
public string YayHash { get; set; }
public string BooHash { get; set; }
public string Biography { get; set; }
public int ReviewCount { get; set; }
public int CommentCount { get; set; }
public int PhotosByMeCount { get; set; }
public int PhotosWithMeCount { get; set; }
public bool CommentsEnabled { get; set; }
public Location Location { get; set; }
public string Pins { get; set; }
public int StaffChallengeGoldCount { get; set; }
public int StaffChallengeSilverCount { get; set; }
public int StaffChallengeBronzeCount { get; set; }
public ClientsConnected ClientsConnected;
#region Slots
public static int EntitledSlots = 20;
public int UsedSlots { get; set; }
public int FreeSlots => EntitledSlots - UsedSlots;
private static string[] slotTypes = {
"lbp1",
"lbp2",
"lbp3",
"crossControl"
};
private string SerializeSlots() {
string slots = string.Empty;
foreach(string slotType in slotTypes) {
slots += LbpSerializer.GetStringElement(slotType + "UsedSlots", UsedSlots);
slots += LbpSerializer.GetStringElement(slotType + "EntitledSlots", EntitledSlots);
// ReSharper disable once StringLiteralTypo
slots += LbpSerializer.GetStringElement(slotType + slotType == "crossControl" ? "PurchsedSlots" : "PurchasedSlots", 0);
slots += LbpSerializer.GetStringElement(slotType + "FreeSlots", FreeSlots);
}
return slots;
}
#endregion Slots
public string Serialize() {
string user = LbpSerializer.GetTaggedStringElement("npHandle", Username, "icon", IconHash) +
this.SerializeSlots() +
LbpSerializer.GetStringElement("game", Game);
return LbpSerializer.GetTaggedStringElement("user", user, "type", "user");
}
}
}