-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
569 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
using Loader.scdb.Xml.Factions; | ||
using Newtonsoft.Json; | ||
using scdb.Xml.Entities; | ||
|
||
namespace Loader | ||
{ | ||
public class FactionLoader | ||
{ | ||
public string OutputFolder { get; set; } | ||
public string DataRoot { get; set; } | ||
|
||
public Dictionary<string, Faction> LoadFactions() | ||
{ | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "factions")); | ||
|
||
var output = new Dictionary<string, Faction>(); | ||
|
||
|
||
var path = Path.Combine(DataRoot, Path.Join("Data", "Libs", "Foundry", "Records", "factions")); | ||
|
||
foreach (var entityFilename in Directory.EnumerateFiles(path, "*.xml")) | ||
{ | ||
var faction = Parse<Faction>(entityFilename); | ||
output.Add(faction.__ref, faction); | ||
File.WriteAllText(Path.Combine(OutputFolder, "factions", $"{faction.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(faction)); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
T Parse<T>(string xmlFilename) where T : ClassBase | ||
{ | ||
string rootNodeName; | ||
using (var reader = XmlReader.Create(new StreamReader(xmlFilename))) | ||
{ | ||
reader.MoveToContent(); | ||
rootNodeName = reader.Name; | ||
} | ||
|
||
var split = rootNodeName.Split('.'); | ||
string className = split[split.Length - 1]; | ||
|
||
var xml = File.ReadAllText(xmlFilename); | ||
var doc = new XmlDocument(); | ||
doc.LoadXml(xml); | ||
|
||
var serialiser = new XmlSerializer(typeof(T), new XmlRootAttribute { ElementName = rootNodeName }); | ||
using (var stream = new XmlNodeReader(doc)) | ||
{ | ||
var entity = (T)serialiser.Deserialize(stream); | ||
entity.ClassName = className; | ||
return entity; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
using Newtonsoft.Json; | ||
using scdb.Xml.Entities; | ||
using scdb.Xml.Missionbroker; | ||
|
||
namespace Loader | ||
{ | ||
public class MissionLoader | ||
{ | ||
public string OutputFolder { get; set; } | ||
public string DataRoot { get; set; } | ||
public LocalisationService locService { get; set; } | ||
|
||
public Dictionary<string, MissionBrokerEntry> LoadMissions() | ||
{ | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "missions")); | ||
|
||
var output = new Dictionary<string, MissionBrokerEntry>(); | ||
|
||
|
||
var path = Path.Combine(DataRoot, Path.Join("Data", "Libs", "Foundry", "Records", "missionbroker")); | ||
|
||
foreach (var entityFilename in Directory.EnumerateFiles(path, "*.xml", SearchOption.AllDirectories)) | ||
{ | ||
var mission = Parse<MissionBrokerEntry>(entityFilename); | ||
AddTranslations(mission); | ||
output.Add(mission.__ref, mission); | ||
File.WriteAllText(Path.Combine(OutputFolder, "missions", $"{mission.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(mission)); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
T Parse<T>(string xmlFilename) where T : ClassBase | ||
{ | ||
string rootNodeName; | ||
using (var reader = XmlReader.Create(new StreamReader(xmlFilename))) | ||
{ | ||
reader.MoveToContent(); | ||
rootNodeName = reader.Name; | ||
} | ||
|
||
var split = rootNodeName.Split('.'); | ||
string className = split[split.Length - 1]; | ||
|
||
var xml = File.ReadAllText(xmlFilename); | ||
var doc = new XmlDocument(); | ||
doc.LoadXml(xml); | ||
|
||
var serialiser = new XmlSerializer(typeof(T), new XmlRootAttribute { ElementName = rootNodeName }); | ||
using (var stream = new XmlNodeReader(doc)) | ||
{ | ||
var entity = (T)serialiser.Deserialize(stream); | ||
entity.ClassName = className; | ||
return entity; | ||
} | ||
} | ||
|
||
private void AddTranslations(MissionBrokerEntry entity) | ||
{ | ||
entity.title = locService.GetText(entity.title, entity.title); | ||
entity.titleHUD = locService.GetText(entity.titleHUD, entity.titleHUD); | ||
entity.description = locService.GetText(entity.description, entity.description); | ||
entity.commsChannelName = locService.GetText(entity.commsChannelName, entity.commsChannelName); | ||
entity.missionGiver = locService.GetText(entity.missionGiver, entity.missionGiver); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
using Loader.scdb.Xml.Reputation; | ||
using Newtonsoft.Json; | ||
using scdb.Xml.Entities; | ||
|
||
namespace Loader | ||
{ | ||
public class RewardLoader | ||
{ | ||
public string OutputFolder { get; set; } | ||
public string DataRoot { get; set; } | ||
public LocalisationService locService { get; set; } | ||
|
||
public Dictionary<string, Scope> LoadScopes() | ||
{ | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "reputation", "scopes")); | ||
|
||
var output = new Dictionary<string, Scope>(); | ||
|
||
|
||
var path = Path.Combine(DataRoot, Path.Join("Data", "Libs", "Foundry", "Records", "reputation", "scopes")); | ||
|
||
foreach (var entityFilename in Directory.EnumerateFiles(path, "*.xml", SearchOption.AllDirectories)) | ||
{ | ||
var scope = Parse<Scope>(entityFilename); | ||
AddScopeTranslations(scope); | ||
output.Add(scope.__ref, scope); | ||
File.WriteAllText(Path.Combine(OutputFolder, "reputation", "scopes", $"{scope.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(scope)); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
public Dictionary<string, Standing> LoadStandings() | ||
{ | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "reputation", "standings")); | ||
|
||
var output = new Dictionary<string, Standing>(); | ||
|
||
|
||
var path = Path.Combine(DataRoot, Path.Join("Data", "Libs", "Foundry", "Records", "reputation", "standings")); | ||
|
||
foreach (var entityFilename in Directory.EnumerateFiles(path, "*.xml", SearchOption.AllDirectories)) | ||
{ | ||
var standing = Parse<Standing>(entityFilename); | ||
AddStandingTranslations(standing); | ||
output.Add(standing.__ref, standing); | ||
File.WriteAllText(Path.Combine(OutputFolder, "reputation", "standings", $"{standing.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(standing)); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
public void LoadRewards() | ||
{ | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "reputation", "rewards")); | ||
|
||
var path = Path.Combine(DataRoot, Path.Join("Data", "Libs", "Foundry", "Records", "reputation", "rewards")); | ||
|
||
foreach (var entityFilename in Directory.EnumerateFiles(Path.Join(path, "missionrewards_reputation"), "*.xml", SearchOption.AllDirectories)) | ||
{ | ||
var reward = Parse<SReputationRewardAmount>(entityFilename); | ||
File.WriteAllText(Path.Combine(OutputFolder, "reputation", "rewards", $"{reward.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(reward)); | ||
} | ||
|
||
foreach (var entityFilename in Directory.EnumerateFiles(Path.Join(path, "missionrewards_bonusuec"), "*.xml", SearchOption.AllDirectories)) | ||
{ | ||
var reward = Parse<SReputationMissionRewardBonusParams>(entityFilename); | ||
File.WriteAllText(Path.Combine(OutputFolder, "reputation", "rewards", $"{reward.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(reward)); | ||
} | ||
} | ||
|
||
T Parse<T>(string xmlFilename) where T : ClassBase | ||
{ | ||
string rootNodeName; | ||
using (var reader = XmlReader.Create(new StreamReader(xmlFilename))) | ||
{ | ||
reader.MoveToContent(); | ||
rootNodeName = reader.Name; | ||
} | ||
|
||
var split = rootNodeName.Split('.'); | ||
string className = split[split.Length - 1]; | ||
|
||
var xml = File.ReadAllText(xmlFilename); | ||
var doc = new XmlDocument(); | ||
doc.LoadXml(xml); | ||
|
||
var serialiser = new XmlSerializer(typeof(T), new XmlRootAttribute { ElementName = rootNodeName }); | ||
using (var stream = new XmlNodeReader(doc)) | ||
{ | ||
var entity = (T)serialiser.Deserialize(stream); | ||
entity.ClassName = className; | ||
return entity; | ||
} | ||
} | ||
|
||
private void AddScopeTranslations(Scope entity) | ||
{ | ||
entity.displayName = locService.GetText(entity.displayName, entity.displayName); | ||
entity.description = locService.GetText(entity.description, entity.description); | ||
} | ||
|
||
private void AddStandingTranslations(Standing entity) | ||
{ | ||
entity.displayName = locService.GetText(entity.displayName, entity.displayName); | ||
entity.perkDescription = locService.GetText(entity.perkDescription, entity.perkDescription); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Xml.Serialization; | ||
using scdb.Xml.Entities; | ||
|
||
namespace Loader.scdb.Xml.Factions; | ||
|
||
public class Faction : ClassBase | ||
{ | ||
[XmlAttribute] public string displayName; | ||
[XmlAttribute] public string description; | ||
[XmlAttribute] public string gameToken; | ||
[XmlAttribute] public string defaultReaction; | ||
|
||
public FriendlyFireReactionOverride[] friendlyFireReactionOverrides; | ||
public FactionRelationship[] factionRelationships; | ||
} | ||
|
||
public class FriendlyFireReactionOverride | ||
{ | ||
[XmlAttribute] public string reactionType; | ||
[XmlAttribute] public bool shouldAllowFriendlyFire; | ||
} | ||
|
||
public class FactionRelationship | ||
{ | ||
[XmlAttribute] public string faction; | ||
[XmlAttribute] public string reactionType; | ||
} |
Oops, something went wrong.