mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-11-27 01:56:53 -08:00
create XmlDataService
repleaced DisplayNamesService and WorldIdService
This commit is contained in:
parent
f8b26e468b
commit
4e9ef56a8a
@ -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<ApiServerConfig> config;
|
||||
|
||||
@ -37,9 +36,8 @@ public class ContentController : Controller {
|
||||
AchievementService achievementService,
|
||||
InventoryService inventoryService,
|
||||
GameDataService gameDataService,
|
||||
DisplayNamesService displayNamesService,
|
||||
XmlDataService xmlDataService,
|
||||
NeighborhoodService neighborhoodService,
|
||||
WorldIdService worldIdService,
|
||||
IOptions<ApiServerConfig> 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<AvatarData>(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]
|
||||
|
||||
@ -28,9 +28,8 @@ builder.Services.AddSingleton<MissionStoreSingleton>();
|
||||
builder.Services.AddSingleton<AchievementStoreSingleton>();
|
||||
builder.Services.AddSingleton<ItemService>();
|
||||
builder.Services.AddSingleton<StoreService>();
|
||||
builder.Services.AddSingleton<DisplayNamesService>();
|
||||
builder.Services.AddSingleton<XmlDataService>();
|
||||
builder.Services.AddSingleton<MMOConfigService>();
|
||||
builder.Services.AddSingleton<WorldIdService>();
|
||||
|
||||
builder.Services.AddScoped<KeyValueService>();
|
||||
builder.Services.AddScoped<MissionService>();
|
||||
|
||||
@ -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];
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
37
src/Services/XmlDataService.cs
Normal file
37
src/Services/XmlDataService.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user