diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index bfe965f..4dc3153 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -21,9 +21,8 @@ public class ContentController : Controller { private AchievementService achievementService; private InventoryService inventoryService; private GameDataService gameDataService; - private DisplayNamesService displayNamesService; + private XmlDataService xmlDataService; private NeighborhoodService neighborhoodService; - private WorldIdService worldIdService; private Random random = new Random(); private readonly IOptions config; @@ -37,9 +36,8 @@ public class ContentController : Controller { AchievementService achievementService, InventoryService inventoryService, GameDataService gameDataService, - DisplayNamesService displayNamesService, + XmlDataService xmlDataService, NeighborhoodService neighborhoodService, - WorldIdService worldIdService, IOptions config ) { this.ctx = ctx; @@ -51,9 +49,8 @@ public class ContentController : Controller { this.achievementService = achievementService; this.inventoryService = inventoryService; this.gameDataService = gameDataService; - this.displayNamesService = displayNamesService; + this.xmlDataService = xmlDataService; this.neighborhoodService = neighborhoodService; - this.worldIdService = worldIdService; this.config = config; } @@ -1599,7 +1596,7 @@ public class ContentController : Controller { [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); + avatarData.DisplayName = xmlDataService.GetDisplayName(firstNameID, secondNameID, thirdNameID); viking.AvatarSerialized = XmlUtil.SerializeXml(avatarData); ctx.SaveChanges(); return Ok(true); @@ -2172,7 +2169,7 @@ public class ContentController : Controller { [Produces("application/xml")] [Route("MissionWebService.asmx/GetWorldId")] // used by Math Blaster and WoJS Adventureland public IActionResult GetWorldId([FromForm] int gameId, [FromForm] string sceneName) { - return Ok(worldIdService.GetWorldID(sceneName)); + return Ok(xmlDataService.GetWorldID(sceneName)); } [HttpPost] diff --git a/src/Program.cs b/src/Program.cs index 91cbbaa..25462b4 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -28,9 +28,8 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); 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/Services/DisplayNamesService.cs b/src/Services/DisplayNamesService.cs deleted file mode 100644 index ea7cdf6..0000000 --- a/src/Services/DisplayNamesService.cs +++ /dev/null @@ -1,20 +0,0 @@ -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")); - displayNames.Add(0, ""); - 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/Services/WorldIdService.cs b/src/Services/WorldIdService.cs deleted file mode 100644 index c20bce0..0000000 --- a/src/Services/WorldIdService.cs +++ /dev/null @@ -1,25 +0,0 @@ -using sodoff.Schema; -using sodoff.Util; - -namespace sodoff.Services; - -public class WorldIdService { - Dictionary worlds_id = new(); - - public WorldIdService() - { - var worlds = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("worlds")); - foreach (var w in worlds) - { - worlds_id[w.Scene] = w.ID; - } - } - - public int GetWorldID(string mapName) - { - if (worlds_id.ContainsKey(mapName)) - return worlds_id[mapName]; - else - return 0; - } -} diff --git a/src/Services/XmlDataService.cs b/src/Services/XmlDataService.cs new file mode 100644 index 0000000..e5c169f --- /dev/null +++ b/src/Services/XmlDataService.cs @@ -0,0 +1,37 @@ +using sodoff.Schema; +using sodoff.Util; +using sodoff.Configuration; +using Microsoft.Extensions.Options; + +namespace sodoff.Services; + +public class XmlDataService { + Dictionary displayNames = new(); + Dictionary worlds_id = new(); + + public XmlDataService(IOptions config) { + if (!config.Value.LoadNonSoDData) + return; + + var displayNamesList = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("displaynames")); + displayNames.Add(0, ""); + foreach (var n in displayNamesList) { + displayNames.Add(n.Id, n.Name); + } + + var worlds = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("worlds")); + foreach (var w in worlds) { + worlds_id[w.Scene] = w.ID; + } + } + + public string GetDisplayName(int firstNameID, int secondNameID, int thirdNameID) { + return displayNames[firstNameID] + " " + displayNames[secondNameID] + displayNames[thirdNameID]; + } + + public int GetWorldID(string mapName) { + if (worlds_id.ContainsKey(mapName)) + return worlds_id[mapName]; + return 0; + } +}