From 6960aadcc3355c7b84e3fe77a0f0c4890f9f1304 Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Tue, 19 Sep 2023 11:22:58 +0000 Subject: [PATCH] fix set Jumpee name (and init move tutorial) --- src/Controllers/Common/ContentController.cs | 24 ++++++++++++--- src/Program.cs | 1 + src/Resources/displaynames.xml | 33 +++++++++++++++++++++ src/Schema/DisplayNames.cs | 15 ++++++++++ src/Services/DisplayNamesService.cs | 19 ++++++++++++ src/sodoff.csproj | 4 +++ 6 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/Resources/displaynames.xml create mode 100644 src/Schema/DisplayNames.cs create mode 100644 src/Services/DisplayNamesService.cs diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index e249c31..9876073 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -20,10 +20,11 @@ public class ContentController : Controller { private AchievementService achievementService; private InventoryService inventoryService; private GameDataService gameDataService; + private DisplayNamesService displayNamesService; private Random random = new Random(); private readonly IOptions config; - public ContentController(DBContext ctx, KeyValueService keyValueService, ItemService itemService, MissionService missionService, RoomService roomService, AchievementService achievementService, InventoryService inventoryService, GameDataService gameDataService, IOptions config) { + public ContentController(DBContext ctx, KeyValueService keyValueService, ItemService itemService, MissionService missionService, RoomService roomService, AchievementService achievementService, InventoryService inventoryService, GameDataService gameDataService, DisplayNamesService displayNamesService, IOptions config) { this.ctx = ctx; this.keyValueService = keyValueService; this.itemService = itemService; @@ -32,6 +33,7 @@ public class ContentController : Controller { this.achievementService = achievementService; this.inventoryService = inventoryService; this.gameDataService = gameDataService; + this.displayNamesService = displayNamesService; this.config = config; } @@ -352,11 +354,13 @@ public class ContentController : Controller { } [HttpPost] - //[Produces("application/xml")] + [Produces("application/xml")] [Route("ContentWebService.asmx/GetAvatar")] // used by World Of Jumpstart [VikingSession(UseLock=false)] public IActionResult GetAvatar(Viking viking) { - return Ok(viking.AvatarSerialized); + AvatarData avatarData = XmlUtil.DeserializeXml(viking.AvatarSerialized); + avatarData.Id = viking.Id; + return Ok(avatarData); } [HttpPost] @@ -1281,7 +1285,19 @@ public class ContentController : Controller { [Route("ContentWebService.asmx/GetDisplayNamesByCategoryID")] // used by Math Blaster public IActionResult GetDisplayNames() { // TODO: This is a placeholder - return Ok(" 1 Aaliyah 1 2 Abby 2 3 Adrian 3 11 Karen 2 12 Luna 2 13 Tori 2 "); + return Ok(XmlUtil.ReadResourceXmlString("displaynames")); + } + + [HttpPost] + //[Produces("application/xml")] + [Route("ContentWebService.asmx/SetDisplayName")] // used by World Of Jumpstart + [VikingSession] + public IActionResult SetProduct(Viking viking, [FromForm] int firstNameID, [FromForm] int secondNameID, [FromForm] int thirdNameID) { + AvatarData avatarData = XmlUtil.DeserializeXml(viking.AvatarSerialized); + avatarData.DisplayName = displayNamesService.GetName(firstNameID, secondNameID, thirdNameID); + viking.AvatarSerialized = XmlUtil.SerializeXml(avatarData); + ctx.SaveChanges(); + return Ok(); } [HttpPost] diff --git a/src/Program.cs b/src/Program.cs index a6ce21c..e637dac 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -26,6 +26,7 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/src/Resources/displaynames.xml b/src/Resources/displaynames.xml new file mode 100644 index 0000000..9cdd32c --- /dev/null +++ b/src/Resources/displaynames.xml @@ -0,0 +1,33 @@ + + + + 1 + Aaliyah + 1 + + + 2 + Abby + 2 + + + 3 + Adrian + 3 + + + 11 + Karen + 2 + + + 12 + Luna + 2 + + + 13 + Tori + 2 + + diff --git a/src/Schema/DisplayNames.cs b/src/Schema/DisplayNames.cs new file mode 100644 index 0000000..50c123e --- /dev/null +++ b/src/Schema/DisplayNames.cs @@ -0,0 +1,15 @@ +using System.Xml.Serialization; + +namespace sodoff.Schema; + +[Serializable] +[XmlRoot(ElementName = "DisplayNames", Namespace = "")] +public class DisplayNameList : List { +} +public class DisplayName { + [XmlElement("ID")] + public int Id; + + [XmlElement("Name")] + public string Name; +} diff --git a/src/Services/DisplayNamesService.cs b/src/Services/DisplayNamesService.cs new file mode 100644 index 0000000..ef963bb --- /dev/null +++ b/src/Services/DisplayNamesService.cs @@ -0,0 +1,19 @@ +using sodoff.Schema; +using sodoff.Util; + +namespace sodoff.Services; + +public class DisplayNamesService { + Dictionary displayNames = new(); + + public DisplayNamesService(ItemService itemService) { + DisplayNameList displayNamesList = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("displaynames")); + foreach (var n in displayNamesList) { + displayNames.Add(n.Id, n.Name); + } + } + + public string GetName(int firstNameID, int secondNameID, int thirdNameID) { + return displayNames[firstNameID] + " " + displayNames[secondNameID] + displayNames[thirdNameID]; + } +} diff --git a/src/sodoff.csproj b/src/sodoff.csproj index c9d3f97..5c4fc66 100644 --- a/src/sodoff.csproj +++ b/src/sodoff.csproj @@ -41,6 +41,7 @@ + @@ -80,6 +81,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest