/// <summary> /// Will initalise optional values to sensible defaults. /// </summary> /// <param name="stellarisRoot"></param> /// <param name="outputRoot"></param> public TechTreeCreatorManager(string stellarisRoot, string outputRoot) { this.outputRoot = outputRoot; //Support UTF-8 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Language = STLLang.English; OutputDirectoryHelper = new OutputDirectoryHelper(outputRoot); // setup parser // Include extra pie! Especially for Piebadger. StellarisDirectoryHelper = new StellarisDirectoryHelper(stellarisRoot); CopyImages = true; }
public void Parse(IEnumerable <ParseTarget> parseTargets) { var techTreeGraphCreator = new TechTreeGraphCreator(Localisation, CWParser, StellarisDirectoryHelper, ModDirectoryHelpers); ModEntityData <Tech> techData = techTreeGraphCreator.CreateTechnologyGraph(); Log.Logger.Debug("Processed {entityCount} techs with {linkCount} Links", techData.EntityCount, techData.LinkCount); // process technolgoies first var techImageOutputDir = OutputDirectoryHelper.GetImagesPath(ParseTarget.Technologies.ImagesDirectory()); if (CopyImages) { CopyMainImages(techData.AllEntities, ParseTarget.Technologies.ImagesDirectory(), techImageOutputDir); // because the image copying only get the most recent version of the entity, make sure that the image flag is set on all // relevant for the vanilla graph display var currentTechs = techData.AllEntitiesByKey; techData.ApplyToChain((techs, links) => { foreach (var tech in techs.Values) { tech.IconFound = currentTechs[tech.Id].IconFound; } }); var techAreas = Enum.GetValues(typeof(TechArea)).Cast <TechArea>(); var areaDir = Path.Combine(techImageOutputDir, "areas"); // tech areas Directory.CreateDirectory(areaDir); foreach (var techArea in techAreas) { var inputPath = Path.Combine(StellarisDirectoryHelper.Icons, "resources", techArea.ToString().ToLowerInvariant() + "_research.dds"); // icon to be displayed on the 3 root nodes ImageOutput.TransformAndOutputImage( inputPath, Path.Combine(techImageOutputDir, techArea + "-root.png")); // area icon ImageOutput.TransformAndOutputImage( inputPath, Path.Combine(areaDir, techArea.ToString().ToLowerInvariant() + ".png")); } // tech categories CopyCategoryImages(techImageOutputDir); } // process dependant objects ObjectsDependantOnTechs dependants = null; var parseTargetsWithoutTechs = parseTargets.WithoutTechs().ToList(); if (parseTargetsWithoutTechs.Any()) { var dependantsGraphCreator = new DependantsGraphCreator(Localisation, CWParser, StellarisDirectoryHelper, ModDirectoryHelpers, techData); dependants = dependantsGraphCreator.CreateDependantGraph(parseTargetsWithoutTechs); if (CopyImages) { foreach (var parseTarget in parseTargetsWithoutTechs) { var imageOutputDir = OutputDirectoryHelper.GetImagesPath(parseTarget.ImagesDirectory()); var entityData = dependants.Get(parseTarget); CopyMainImages(entityData, parseTarget.ImagesDirectory(), imageOutputDir); } dependants.FixImages(); } } var visDataMarshaler = new VisDataMarshaler(localisation, OutputDirectoryHelper); IDictionary <string, VisData> techVisResults = visDataMarshaler.CreateTechVisData(techData, techImageOutputDir); ModEntityData <Tech> coreGameTech = techData.FindCoreGameData(); if (coreGameTech != null) { IDictionary <string, VisData> techVisData = visDataMarshaler.CreateTechVisData(coreGameTech, techImageOutputDir); techVisResults["Stellaris-No-Mods"] = techVisData[StellarisDirectoryHelper.StellarisCoreRootDirectory]; } else { Log.Logger.Warning("Could not find core game tech files to generate vanilla tree"); } VisData rootNotes = visDataMarshaler.CreateRootNotes(techData, techImageOutputDir); techVisResults["Tech-Root-Nodes"] = rootNotes; WriteVisData(techVisResults, true); if (dependants != null) { var dependantVisResults = visDataMarshaler.CreateGroupedVisDependantData(techVisResults, dependants, parseTargetsWithoutTechs); var coreDependantsOnly = dependants.CopyOnlyCore(); // also do a no-mods lookup var stellarisNoModsTechVisResult = techVisResults["Stellaris-No-Mods"]; IDictionary <string, VisData> visLookupData = stellarisNoModsTechVisResult != null ? new Dictionary <string, VisData>() { { "Stellaris-No-Mods", stellarisNoModsTechVisResult } } : techVisResults; var coreDependantData = visDataMarshaler.CreateGroupedVisDependantData(visLookupData, coreDependantsOnly, parseTargetsWithoutTechs); if (coreDependantData.ContainsKey(StellarisDirectoryHelper.StellarisCoreRootDirectory)) { dependantVisResults["Stellaris-No-Mods"] = coreDependantData[StellarisDirectoryHelper.StellarisCoreRootDirectory]; } else { Log.Logger.Warning("Could not find core game dependant files to generate vanilla tree"); } WriteVisData(dependantVisResults, false); } }
public TechsVisMarshaler(ILocalisationApiHelper localisationApi, OutputDirectoryHelper outputDirectoryHelper) { this.localisationApi = localisationApi; this.outputDirectoryHelper = outputDirectoryHelper; }