create XmlDataService

repleaced DisplayNamesService and WorldIdService
This commit is contained in:
Robert Paciorek 2025-10-19 12:29:26 +00:00
parent f8b26e468b
commit 4e9ef56a8a
5 changed files with 43 additions and 55 deletions

View File

@ -21,9 +21,8 @@ public class ContentController : Controller {
private AchievementService achievementService; private AchievementService achievementService;
private InventoryService inventoryService; private InventoryService inventoryService;
private GameDataService gameDataService; private GameDataService gameDataService;
private DisplayNamesService displayNamesService; private XmlDataService xmlDataService;
private NeighborhoodService neighborhoodService; private NeighborhoodService neighborhoodService;
private WorldIdService worldIdService;
private Random random = new Random(); private Random random = new Random();
private readonly IOptions<ApiServerConfig> config; private readonly IOptions<ApiServerConfig> config;
@ -37,9 +36,8 @@ public class ContentController : Controller {
AchievementService achievementService, AchievementService achievementService,
InventoryService inventoryService, InventoryService inventoryService,
GameDataService gameDataService, GameDataService gameDataService,
DisplayNamesService displayNamesService, XmlDataService xmlDataService,
NeighborhoodService neighborhoodService, NeighborhoodService neighborhoodService,
WorldIdService worldIdService,
IOptions<ApiServerConfig> config IOptions<ApiServerConfig> config
) { ) {
this.ctx = ctx; this.ctx = ctx;
@ -51,9 +49,8 @@ public class ContentController : Controller {
this.achievementService = achievementService; this.achievementService = achievementService;
this.inventoryService = inventoryService; this.inventoryService = inventoryService;
this.gameDataService = gameDataService; this.gameDataService = gameDataService;
this.displayNamesService = displayNamesService; this.xmlDataService = xmlDataService;
this.neighborhoodService = neighborhoodService; this.neighborhoodService = neighborhoodService;
this.worldIdService = worldIdService;
this.config = config; this.config = config;
} }
@ -1599,7 +1596,7 @@ public class ContentController : Controller {
[VikingSession] [VikingSession]
public IActionResult SetProduct(Viking viking, [FromForm] int firstNameID, [FromForm] int secondNameID, [FromForm] int thirdNameID) { public IActionResult SetProduct(Viking viking, [FromForm] int firstNameID, [FromForm] int secondNameID, [FromForm] int thirdNameID) {
AvatarData avatarData = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized); AvatarData avatarData = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized);
avatarData.DisplayName = displayNamesService.GetName(firstNameID, secondNameID, thirdNameID); avatarData.DisplayName = xmlDataService.GetDisplayName(firstNameID, secondNameID, thirdNameID);
viking.AvatarSerialized = XmlUtil.SerializeXml(avatarData); viking.AvatarSerialized = XmlUtil.SerializeXml(avatarData);
ctx.SaveChanges(); ctx.SaveChanges();
return Ok(true); return Ok(true);
@ -2172,7 +2169,7 @@ public class ContentController : Controller {
[Produces("application/xml")] [Produces("application/xml")]
[Route("MissionWebService.asmx/GetWorldId")] // used by Math Blaster and WoJS Adventureland [Route("MissionWebService.asmx/GetWorldId")] // used by Math Blaster and WoJS Adventureland
public IActionResult GetWorldId([FromForm] int gameId, [FromForm] string sceneName) { public IActionResult GetWorldId([FromForm] int gameId, [FromForm] string sceneName) {
return Ok(worldIdService.GetWorldID(sceneName)); return Ok(xmlDataService.GetWorldID(sceneName));
} }
[HttpPost] [HttpPost]

View File

@ -28,9 +28,8 @@ builder.Services.AddSingleton<MissionStoreSingleton>();
builder.Services.AddSingleton<AchievementStoreSingleton>(); builder.Services.AddSingleton<AchievementStoreSingleton>();
builder.Services.AddSingleton<ItemService>(); builder.Services.AddSingleton<ItemService>();
builder.Services.AddSingleton<StoreService>(); builder.Services.AddSingleton<StoreService>();
builder.Services.AddSingleton<DisplayNamesService>(); builder.Services.AddSingleton<XmlDataService>();
builder.Services.AddSingleton<MMOConfigService>(); builder.Services.AddSingleton<MMOConfigService>();
builder.Services.AddSingleton<WorldIdService>();
builder.Services.AddScoped<KeyValueService>(); builder.Services.AddScoped<KeyValueService>();
builder.Services.AddScoped<MissionService>(); builder.Services.AddScoped<MissionService>();

View File

@ -1,20 +0,0 @@
using sodoff.Schema;
using sodoff.Util;
namespace sodoff.Services;
public class DisplayNamesService {
Dictionary<int, string> displayNames = new();
public DisplayNamesService(ItemService itemService) {
DisplayNameList displayNamesList = XmlUtil.DeserializeXml<DisplayNameList>(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];
}
}

View File

@ -1,25 +0,0 @@
using sodoff.Schema;
using sodoff.Util;
namespace sodoff.Services;
public class WorldIdService {
Dictionary<string, int> worlds_id = new();
public WorldIdService()
{
var worlds = XmlUtil.DeserializeXml<World[]>(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;
}
}

View File

@ -0,0 +1,37 @@
using sodoff.Schema;
using sodoff.Util;
using sodoff.Configuration;
using Microsoft.Extensions.Options;
namespace sodoff.Services;
public class XmlDataService {
Dictionary<int, string> displayNames = new();
Dictionary<string, int> worlds_id = new();
public XmlDataService(IOptions<ApiServerConfig> config) {
if (!config.Value.LoadNonSoDData)
return;
var displayNamesList = XmlUtil.DeserializeXml<DisplayNameList>(XmlUtil.ReadResourceXmlString("displaynames"));
displayNames.Add(0, "");
foreach (var n in displayNamesList) {
displayNames.Add(n.Id, n.Name);
}
var worlds = XmlUtil.DeserializeXml<World[]>(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;
}
}