void IUtilityCommand.Run(Utility utility, string[] args) { Png png; using (var pngStream = File.OpenRead(args[1])) png = new Png(pngStream); var yaml = MiniYaml.FromFile(Path.ChangeExtension(args[1], "yaml")); var frameSizeField = yaml.Where(y => y.Key == "FrameSize").Select(y => y.Value.Value).FirstOrDefault(); if (frameSizeField != null) { var frameSize = FieldLoader.GetValue<Size>("FrameSize", frameSizeField); var frameAmountField = yaml.Where(y => y.Key == "FrameAmount").Select(y => y.Value.Value).FirstOrDefault(); if (frameAmountField != null) { var frameAmount = FieldLoader.GetValue<int>("FrameAmount", frameAmountField); if (frameAmount > (png.Width / frameSize.Width) * (png.Height / frameSize.Height)) throw new InvalidDataException(".png file is too small for given FrameSize and FrameAmount."); } } foreach (var node in yaml) png.EmbeddedData[node.Key] = node.Value.Value; png.Save(args[1]); }
NewsItem[] ParseNews(string path) { if (!File.Exists(path)) { return(null); } try { return(MiniYaml.FromFile(path).Select(node => { var nodesDict = node.Value.ToDictionary(); return new NewsItem { Title = nodesDict["Title"].Value, Author = nodesDict["Author"].Value, DateTime = FieldLoader.GetValue <DateTime>("DateTime", node.Key), Content = nodesDict["Content"].Value }; }).ToArray()); } catch (Exception ex) { SetNewsStatus("Failed to parse news: {0}".F(ex.Message)); } return(null); }
public void Run(Action <string> emitError, Action <string> emitWarning) { foreach (var filename in Game.ModData.Manifest.ChromeLayout) { CheckInner(MiniYaml.FromFile(filename), filename, emitError); } }
public static void Initialize(string[] sequenceFiles) { cursors = new Dictionary <string, CursorSequence>(); var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal)); int[] ShadowIndex = { }; if (sequences.NodesDict.ContainsKey("ShadowIndex")) { Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); int.TryParse(sequences.NodesDict["ShadowIndex"].Value, out ShadowIndex[ShadowIndex.Length - 1]); } Palette = new HardwarePalette(); foreach (var p in sequences.NodesDict["Palettes"].Nodes) { Palette.AddPalette(p.Key, new Palette(FileSystem.Open(p.Value.Value), ShadowIndex), false); } foreach (var s in sequences.NodesDict["Cursors"].Nodes) { LoadSequencesForCursor(s.Key, s.Value); } Palette.Initialize(); }
public CursorProvider(ModData modData) { var sequenceFiles = modData.Manifest.Cursors; cursors = new Dictionary <string, CursorSequence>(); palettes = new Cache <string, PaletteReference>(CreatePaletteReference); var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal)); var shadowIndex = new int[] { }; var nodesDict = sequences.ToDictionary(); if (nodesDict.ContainsKey("ShadowIndex")) { Array.Resize(ref shadowIndex, shadowIndex.Length + 1); Exts.TryParseIntegerInvariant(nodesDict["ShadowIndex"].Value, out shadowIndex[shadowIndex.Length - 1]); } palette = new HardwarePalette(); foreach (var p in nodesDict["Palettes"].Nodes) { palette.AddPalette(p.Key, new ImmutablePalette(GlobalFileSystem.Open(p.Value.Value), shadowIndex), false); } var spriteLoader = new SpriteLoader(new string[0], new SheetBuilder(SheetType.Indexed)); foreach (var s in nodesDict["Cursors"].Nodes) { LoadSequencesForCursor(spriteLoader, s.Key, s.Value); } spriteLoader.SheetBuilder.Current.ReleaseBuffer(); palette.Initialize(); }
public void Run(ModData modData, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; Game.ModData.ModFiles.LoadFromManifest(Game.ModData.Manifest); Game.ModData.SpriteSequenceLoader.OnMissingSpriteError = s => Console.WriteLine("\t" + s); foreach (var t in Game.ModData.Manifest.TileSets) { var ts = new TileSet(Game.ModData, t); Console.WriteLine("Tileset: " + ts.Name); var sc = new SpriteCache(modData.SpriteLoaders, new SheetBuilder(SheetType.Indexed)); var sequenceFiles = modData.Manifest.Sequences; var partial = sequenceFiles .Select(s => MiniYaml.FromFile(s)) .Aggregate(MiniYaml.MergePartial); var nodes = MiniYaml.ApplyRemovals(partial); foreach (var n in nodes) { Game.ModData.SpriteSequenceLoader.ParseSequences(Game.ModData, ts, sc, n); } } }
public static void Initialize(params string[] chromeFiles) { collections = new Dictionary <string, Collection>(); cachedSheets = new Dictionary <string, Sheet>(); cachedSprites = new Dictionary <string, Dictionary <string, Sprite> >(); if (chromeFiles.Length == 0) { chromeFiles = storedChromeFiles; if (chromeFiles == null || chromeFiles.Length == 0) { return; } } else { storedChromeFiles = chromeFiles; } var chrome = chromeFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal); foreach (var c in chrome) { LoadCollection(c.Key, c.Value); } }
Sequences Load(List <MiniYamlNode> sequenceNodes) { var sequenceFiles = modData.Manifest.Sequences; var nodes = sequenceFiles .Select(s => MiniYaml.FromFile(s)) .Aggregate(sequenceNodes, MiniYaml.MergeLiberal); var items = new Dictionary <string, UnitSequences>(); foreach (var n in nodes) { // Work around the loop closure issue in older versions of C# var node = n; var key = node.Value.ToLines(node.Key).JoinWith("|"); UnitSequences t; if (sequenceCache.TryGetValue(key, out t)) { items.Add(node.Key, t); } else { t = Exts.Lazy(() => modData.SpriteSequenceLoader.ParseSequences(modData, tileSet, SpriteCache, node)); sequenceCache.Add(key, t); items.Add(node.Key, t); } } return(new ReadOnlyDictionary <string, UnitSequences>(items)); }
void IUtilityCommand.Run(Utility utility, string[] args) { // HACK: The engine code assumes that Game.modData is set. var modData = Game.ModData = utility.ModData; var types = modData.ObjectCreator.GetTypes(); var translatableFields = types.SelectMany(t => t.GetFields()) .Where(f => f.HasAttribute <TranslateAttribute>()).Distinct(); foreach (var filename in modData.Manifest.ChromeLayout) { string name; OpenRA.FileSystem.IReadOnlyPackage package; modData.ModFiles.TryGetPackageContaining(filename, out package, out name); name = package.Name + "/" + name; Console.WriteLine("# {0}:", name); var yaml = MiniYaml.FromFile(name, false); FromChromeLayout(ref yaml, null, translatableFields.Select(t => t.Name).Distinct(), null); using (var file = new StreamWriter(name)) file.WriteLine(yaml.WriteToString()); } // TODO: Properties can also be translated. }
void IUtilityCommand.Run(Utility utility, string[] args) { // HACK: This could eventually be merged into the Png class (add a Write method), however this requires complex png writing algorythms. var rs = File.OpenRead(args[1]); var ws = new MemoryStream(); using (var bw = new BinaryWriter(ws)) { bw.Write(rs.ReadBytes(8)); var crc32 = new Crc32(); for (;;) { var length = IPAddress.NetworkToHostOrder(rs.ReadInt32()); var type = Encoding.UTF8.GetString(rs.ReadBytes(4)); var content = rs.ReadBytes(length); var crc = rs.ReadUInt32(); switch (type) { case "tEXt": break; case "IEND": rs.Close(); foreach (var node in MiniYaml.FromFile(Path.ChangeExtension(args[1], "yaml"))) { bw.Write(IPAddress.NetworkToHostOrder(node.Key.Length + 1 + node.Value.Value.Length)); bw.Write("tEXt".ToCharArray()); bw.Write(node.Key.ToCharArray()); bw.Write((byte)0x00); bw.Write(node.Value.Value.ToCharArray()); crc32.Reset(); crc32.Update(Encoding.ASCII.GetBytes("tEXt")); crc32.Update(Encoding.ASCII.GetBytes(node.Key + (char)0x00 + node.Value.Value)); bw.Write((uint)IPAddress.NetworkToHostOrder((int)crc32.Value)); } bw.Write(0); bw.Write(type.ToCharArray()); bw.Write(crc); File.WriteAllBytes(args[1], ws.ToArray()); ws.Close(); return; default: bw.Write(IPAddress.NetworkToHostOrder(length)); bw.Write(type.ToCharArray()); bw.Write(content); bw.Write(crc); break; } } } }
public static void UpgradeMod(string[] args) { var mod = args[1]; var engineDate = Exts.ParseIntegerInvariant(args[2]); Game.modData = new ModData(mod); Game.modData.MapCache.LoadMaps(); Console.WriteLine("Processing Rules:"); foreach (var filename in Game.modData.Manifest.Rules) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeActorRules(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.WriteLine(yaml.WriteToString()); } Console.WriteLine("Processing Weapons:"); foreach (var filename in Game.modData.Manifest.Weapons) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeWeaponRules(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.WriteLine(yaml.WriteToString()); } Console.WriteLine("Processing Tilesets:"); foreach (var filename in Game.modData.Manifest.TileSets) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeTileset(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.WriteLine(yaml.WriteToString()); } Console.WriteLine("Processing Maps:"); var maps = Game.modData.MapCache .Where(m => m.Status == MapStatus.Available) .Select(m => m.Map); foreach (var map in maps) { Console.WriteLine("\t" + map.Path); UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0); UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0); map.Save(map.Path); } }
public Manifest(Mod mod) : base() { this.yamlFilePath = Path.Combine(mod.ModsDirectoryPath, mod.ModId, "mod.yaml"); this.yamlNodes = MiniYaml.FromFile(this.yamlFilePath, false); this.Children.Add(new Packages(this.yamlNodes.FirstOrDefault(x => x.Key == NodeNames.PackagesNodeName)?.Value)); var pathResolver = new SimplePathResolver(this, mod.ModsDirectoryPath, mod.WorkingDirectoryPath); this.Children.Add(new RuleSetCollection(this.yamlNodes.FirstOrDefault(x => x.Key == NodeNames.RulesNodeName)?.Value, pathResolver)); this.Children.Add(new WeaponSetCollection(this.yamlNodes.FirstOrDefault(x => x.Key == NodeNames.WeaponsNodeName)?.Value, pathResolver)); }
public static void Initialize(string[] sequenceFiles, List <MiniYamlNode> sequenceNodes) { units = new Dictionary <string, Dictionary <string, Sequence> >(); var sequences = sequenceFiles .Select(s => MiniYaml.FromFile(s)) .Aggregate(sequenceNodes, MiniYaml.MergeLiberal); foreach (var s in sequences) { LoadSequencesForUnit(s.Key, s.Value); } }
public static void Initialize(IEnumerable <string> chromeFiles) { collections = new Dictionary <string, Collection>(); cachedSheets = new Dictionary <string, Sheet>(); cachedSprites = new Dictionary <string, Dictionary <string, Sprite> >(); var chrome = chromeFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal); foreach (var c in chrome) { LoadCollection(c.Key, c.Value); } }
public static void Initialize(IEnumerable <string> yaml) { data = new Dictionary <string, string>(); var metrics = yaml.Select(y => MiniYaml.FromFile(y)) .Aggregate(MiniYaml.MergeLiberal); foreach (var m in metrics) { foreach (var n in m.Value.Nodes) { data[n.Key] = n.Value.Value; } } }
void IUtilityCommand.Run(Utility utility, string[] args) { Png png; using (var pngStream = File.OpenRead(args[1])) png = new Png(pngStream); foreach (var node in MiniYaml.FromFile(Path.ChangeExtension(args[1], "yaml"))) { png.EmbeddedData[node.Key] = node.Value.Value; } png.Save(args[1]); }
public static void Initialize(string[] voxelFiles, List <MiniYamlNode> voxelNodes) { units = new Dictionary <string, Dictionary <string, Voxel> >(); var sequences = voxelFiles .Select(s => MiniYaml.FromFile(s)) .Aggregate(voxelNodes, MiniYaml.MergeLiberal); foreach (var s in sequences) { LoadVoxelsForUnit(s.Key, s.Value); } Game.modData.VoxelLoader.RefreshBuffer(); }
public static void Initialize(string[] sequenceFiles) { cursors = new Dictionary <string, CursorSequence>(); var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal)); foreach (var s in sequences.NodesDict["Palettes"].Nodes) { Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), true)); } foreach (var s in sequences.NodesDict["Cursors"].Nodes) { LoadSequencesForCursor(s.Key, s.Value); } }
void LoadTerrainDefinitions() { var terrainDefinition = new Dictionary <string, TerrainTypeInfo>(); var yaml = MiniYaml.FromFile("defaults.yaml").FirstOrDefault(y => y.Key == "Terrain").Value.Nodes; terrainDefinition = yaml.Select(n => new TerrainTypeInfo(n.Value)).ToDictionary(t => t.Type); surface1.Icon = new Bitmap[terrainDefinition.Keys.Count]; terrainType = new TerrainTypeInfo[terrainDefinition.Keys.Count]; templates = new Dictionary <ushort, TerrainTemplateInfo>(); var title = this.Text; surface1.UpdateMouseTilePosition += (x, y, tileNr) => { Text = "{0} - {1} ({2,3}, {3,3}) tileNr: {4,3}".F(title, txtTilesetName.Text, x, y, tileNr); }; surface1.Enabled = false; var i = 0; foreach (var deftype in terrainDefinition) { var icon = new Bitmap(16, 16); // Loop through the images pixels to reset color. for (var x = 0; x < icon.Width; x++) { for (var y = 0; y < icon.Height; y++) { var newColor = deftype.Value.Color; icon.SetPixel(x, y, Color.FromArgb(newColor.ToArgb())); } } surface1.Icon[i] = icon; terrainType[i] = deftype.Value; var terrainTypeButton = new ToolStripButton(deftype.Key, icon, TerrainTypeSelectorClicked); terrainTypeButton.ToolTipText = deftype.Key; terrainTypeButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; terrainTypeButton.Tag = i.ToString(); terrainTypeButton.ImageAlign = ContentAlignment.MiddleLeft; terrainTypes.Items.Add(terrainTypeButton); i++; } }
public void Run(Action <string> emitError, Action <string> emitWarning) { var sequences = Game.modData.Manifest.Sequences .Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal); foreach (var actorInfo in Rules.Info) { foreach (var renderInfo in actorInfo.Value.Traits.WithInterface <RenderSimpleInfo>()) { var image = renderInfo.Image ?? actorInfo.Value.Name; if (!sequences.Any(s => s.Key == image.ToLower()) && !actorInfo.Value.Name.Contains("^")) { emitWarning("Sprite image {0} from actor {1} has no sequence definition.".F(image, actorInfo.Value.Name)); } } } }
public WeaponSet(MiniYamlNode yamlNode, IPathResolver pathResolver) : base() { this.parentYamlNode = yamlNode; this.pathResolver = pathResolver; if (yamlNode != null) { var actualPath = pathResolver.ResolvePath(yamlNode.Key); this.yamlFilePath = actualPath; this.Name = yamlNode.Key; this.yamlNodes = MiniYaml.FromFile(actualPath, false); foreach (var node in this.yamlNodes) { if (!string.IsNullOrEmpty(node.Key)) { this.Children.Add(new Weapon(node)); } } } }
public CursorProvider(ModData modData) { var sequenceFiles = modData.Manifest.Cursors; var partial = sequenceFiles .Select(s => MiniYaml.FromFile(s)) .Aggregate(MiniYaml.MergePartial); var sequences = new MiniYaml(null, MiniYaml.ApplyRemovals(partial)); var shadowIndex = new int[] { }; var nodesDict = sequences.ToDictionary(); if (nodesDict.ContainsKey("ShadowIndex")) { Array.Resize(ref shadowIndex, shadowIndex.Length + 1); Exts.TryParseIntegerInvariant(nodesDict["ShadowIndex"].Value, out shadowIndex[shadowIndex.Length - 1]); } var palettes = new Dictionary <string, ImmutablePalette>(); foreach (var p in nodesDict["Palettes"].Nodes) { palettes.Add(p.Key, new ImmutablePalette(modData.ModFiles.Open(p.Value.Value), shadowIndex)); } Palettes = palettes.AsReadOnly(); var frameCache = new FrameCache(modData.SpriteLoaders); var cursors = new Dictionary <string, CursorSequence>(); foreach (var s in nodesDict["Cursors"].Nodes) { foreach (var sequence in s.Value.Nodes) { cursors.Add(sequence.Key, new CursorSequence(frameCache, sequence.Key, s.Key, s.Value.Value, sequence.Value)); } } Cursors = cursors.AsReadOnly(); }
public void Run(ModData modData, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; var types = Game.ModData.ObjectCreator.GetTypes(); var translatableFields = types.SelectMany(t => t.GetFields()) .Where(f => f.HasAttribute <TranslateAttribute>()).Distinct(); foreach (var filename in modData.Manifest.ChromeLayout) { Console.WriteLine("# {0}:", filename); var yaml = MiniYaml.FromFile(filename); FromChromeLayout(ref yaml, null, translatableFields.Select(t => t.Name).Distinct(), null); using (var file = new StreamWriter(filename)) file.WriteLine(yaml.WriteToString()); } // TODO: Properties can also be translated. }
public static void FromMod(string[] args) { var mod = args[1]; Game.modData = new ModData(mod); Game.modData.RulesetCache.LoadDefaultRules(); var types = Game.modData.ObjectCreator.GetTypes(); var translatableFields = types.SelectMany(t => t.GetFields()) .Where(f => f.HasAttribute <TranslateAttribute>()).Distinct(); foreach (var filename in Game.modData.Manifest.ChromeLayout) { Console.WriteLine("# {0}:", filename); var yaml = MiniYaml.FromFile(filename); ExtractLanguageStrings.FromChromeLayout(ref yaml, null, translatableFields.Select(t => t.Name).Distinct(), null); using (var file = new StreamWriter(filename)) file.WriteLine(yaml.WriteToString()); } // TODO: Properties can also be translated. }
public static void Initialize(string[] sequenceFiles) { cursors = new Dictionary <string, CursorSequence>(); var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal)); int[] ShadowIndex = { }; if (sequences.NodesDict.ContainsKey("ShadowIndex")) { Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value); } foreach (var s in sequences.NodesDict["Palettes"].Nodes) { Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex)); } foreach (var s in sequences.NodesDict["Cursors"].Nodes) { LoadSequencesForCursor(s.Key, s.Value); } }
IReadOnlyDictionary <string, Lazy <IReadOnlyDictionary <string, Sequence> > > Load(List <MiniYamlNode> sequenceNodes) { var sequenceFiles = modData.Manifest.Sequences; var nodes = sequenceFiles .Select(s => MiniYaml.FromFile(s)) .Aggregate(sequenceNodes, MiniYaml.MergeLiberal); var items = new Dictionary <string, Lazy <IReadOnlyDictionary <string, Sequence> > >(); foreach (var n in nodes) { // Work around the loop closure issue in older versions of C# var node = n; var key = node.Value.ToLines(node.Key).JoinWith("|"); Lazy <IReadOnlyDictionary <string, Sequence> > t; if (sequenceCache.TryGetValue(key, out t)) { items.Add(node.Key, t); } else { t = Exts.Lazy(() => (IReadOnlyDictionary <string, Sequence>) new ReadOnlyDictionary <string, Sequence>( node.Value.NodesDict.ToDictionary(x => x.Key, x => { using (new Support.PerfTimer("new Sequence(\"{0}\")".F(node.Key), 20)) return(new Sequence(spriteLoader.Value, node.Key, x.Key, x.Value)); }))); sequenceCache.Add(key, t); items.Add(node.Key, t); } } return(new ReadOnlyDictionary <string, Lazy <IReadOnlyDictionary <string, Sequence> > >(items)); }
public void Run(Utility utility, string[] args) { Console.WriteLine("Starting importing the translated strings"); //Get translated strings from LOCALIZATIONNAME.yaml string customFontPath = null; if (args.Length == 4) { customFontPath = args[3]; } string localizationName = args[1]; var modData = utility.ModData; string localizationFile = string.Format("languages\\{0}.yaml", localizationName); var stream = modData.ModFiles.Open(localizationFile); var nodes = MiniYaml.FromStream(stream); if (nodes[0].Value.Nodes[0].Key != localizationName) { Console.WriteLine("Invalid localization file!"); return; } var rulesLocalizationNode = nodes[0].Value.Nodes[0].Value.Nodes.Where(o => o.Key == "Rules").FirstOrDefault(); var chromeLayoutsLocalizationNode = nodes[0].Value.Nodes[0].Value.Nodes.Where(o => o.Key == "ChromeLayouts").FirstOrDefault(); var worldRulesLocalizationNode = nodes[0].Value.Nodes[0].Value.Nodes.Where(o => o.Key == "World").FirstOrDefault(); var modContentLocalizationNode = nodes[0].Value.Nodes[0].Value.Nodes.Where(o => o.Key == "ModContent").FirstOrDefault(); //Get the original mod install dir string modID = modData.Manifest.Id; string modFolder = null; if (stream is FileStream) { var fs = stream as FileStream; if (fs.Name.Contains(localizationFile)) { int idx = fs.Name.IndexOf(localizationFile); modFolder = fs.Name.Substring(0, idx); } } //Copy all the original mod files to the new mod which id is defined by NEWMODID parameter string newModID = args[2]; if (!string.IsNullOrEmpty(modFolder)) { DirectoryInfo di = new DirectoryInfo(modFolder); DirectoryInfo modRootDir = di.Parent; string newModFullPath = Path.Combine(modRootDir.FullName, newModID); if (Directory.Exists(newModFullPath)) { Directory.Delete(newModFullPath, true); } Directory.CreateDirectory(newModFullPath); foreach (var fileSystemInfo in di.EnumerateFileSystemInfos()) { if (fileSystemInfo.Attributes == FileAttributes.Directory) { DirectoryCopy(fileSystemInfo.FullName, Path.Combine(newModFullPath, fileSystemInfo.Name), true); } else { File.Copy(fileSystemInfo.FullName, Path.Combine(newModFullPath, fileSystemInfo.Name)); } } string lightFont = null; string normalFont = null; string boldFont = null; if (!string.IsNullOrEmpty(customFontPath)) { string currentDir = Environment.CurrentDirectory; DirectoryInfo d = new DirectoryInfo(currentDir); string fontSettingFilePath = Path.Combine(d.Parent.FullName, customFontPath); Console.WriteLine(fontSettingFilePath); if (File.Exists(fontSettingFilePath)) { var fontSettingFile = MiniYaml.FromFile(fontSettingFilePath); if (fontSettingFile[0].Value.Nodes.Count == 2) { normalFont = Path.Combine(Path.GetDirectoryName(fontSettingFilePath), fontSettingFile[0].Value.Nodes[0].Value.Value); boldFont = Path.Combine(Path.GetDirectoryName(fontSettingFilePath), fontSettingFile[0].Value.Nodes[1].Value.Value); } else { Console.WriteLine("Error: Invalid font setting file!"); } } else { Console.WriteLine("Error: Specific font path can't be found!"); } } //------------------------------------------------------ // Modify all the yaml files using the original mod id //------------------------------------------------------ List <string> mapFolders = new List <string>(); List <string> ruleFilePathes = new List <string>(); List <string> chromeLayoutFilePathes = new List <string>(); Dictionary <string, string> externalMods = new Dictionary <string, string>(); //Modify mod.yaml file string newModYaml = Path.Combine(newModFullPath, "mod.yaml"); var modYamlNodes = MiniYaml.FromFile(newModYaml); foreach (var modYamlNode in modYamlNodes) { if (modYamlNode.Key == "Metadata") { var modYamlMetadataTitleNode = modYamlNode.Value.Nodes.Where(o => o.Key == "Title").FirstOrDefault(); if (modYamlMetadataTitleNode != null) { localizationName = localizationName.Replace(localizationName.Substring(0, 1), localizationName.Substring(0, 1).ToUpper()); modYamlMetadataTitleNode.Value.Value += string.Format(" ({0} Version)", localizationName); } } else if (modYamlNode.Key == "Packages") { foreach (var subYamlNode in modYamlNode.Value.Nodes) { if (subYamlNode.Key == string.Format("${0}", modID)) { subYamlNode.Key = string.Format("${0}", newModID); subYamlNode.Value.Value = newModID; } else if (subYamlNode.Key.StartsWith(string.Format("{0}|", modID))) { string oldKey = string.Format("{0}|", modID); subYamlNode.Key = subYamlNode.Key.Replace( oldKey, string.Format("{0}|", newModID) ); } else if (subYamlNode.Key.StartsWith("~")) { if (subYamlNode.Key.Substring(1).StartsWith("^")) { subYamlNode.Key = "~^" + ReplacePathWithNewModID(subYamlNode.Key.Substring(2), modID, newModID); } } else if (!subYamlNode.Key.StartsWith("~") && !string.IsNullOrEmpty(subYamlNode.Value.Value)) { //This is an external mod Console.WriteLine(Platform.ResolvePath(subYamlNode.Key)); externalMods.Add(subYamlNode.Value.Value, Platform.ResolvePath(subYamlNode.Key)); } } } else if (modYamlNode.Key == "Rules" || modYamlNode.Key == "Sequences" || modYamlNode.Key == "ModelSequences" || modYamlNode.Key == "Cursors" || modYamlNode.Key == "Chrome" || modYamlNode.Key == "Assemblies" || modYamlNode.Key == "ChromeLayout" || modYamlNode.Key == "Hotkeys" || modYamlNode.Key == "Weapons" || modYamlNode.Key == "Voices" || modYamlNode.Key == "Notifications" || modYamlNode.Key == "TileSets" || modYamlNode.Key == "Music" || modYamlNode.Key == "Translations" || modYamlNode.Key == "ChromeMetrics" || modYamlNode.Key == "Missions") { foreach (var subYamlNode in modYamlNode.Value.Nodes) { if (subYamlNode.Key.StartsWith(string.Format("{0}|", modID))) { string oldKey = string.Format("{0}|", modID); subYamlNode.Key = subYamlNode.Key.Replace( oldKey, string.Format("{0}|", newModID) ); if (modYamlNode.Key == "Rules") { ruleFilePathes.Add(Path.Combine(newModFullPath, subYamlNode.Key.Split('|')[1])); } else if (modYamlNode.Key == "ChromeLayout") { chromeLayoutFilePathes.Add(Path.Combine(newModFullPath, subYamlNode.Key.Split('|')[1])); } } else { string[] tokens = subYamlNode.Key.Split('|'); if (tokens.Length == 2) { if (externalMods.ContainsKey(tokens[0]) && (modYamlNode.Key == "Rules" || modYamlNode.Key == "ChromeLayout")) { //Copy the external mod files string filePath = Path.Combine(externalMods[tokens[0]], tokens[1]); string newFilePath = Path.Combine(newModFullPath, tokens[0], tokens[1]); string newFileDir = Path.GetDirectoryName(newFilePath); if (!Directory.Exists(newFileDir)) { Directory.CreateDirectory(newFileDir); } if (!File.Exists(newFilePath)) { File.Copy(filePath, newFilePath); } string relativePath = ConvertToRelativeCurrentPath(newFilePath, newModFullPath); subYamlNode.Key = string.Format("{0}|{1}", newModID, relativePath); if (modYamlNode.Key == "Rules") { ruleFilePathes.Add(newFilePath); } else if (modYamlNode.Key == "ChromeLayout") { chromeLayoutFilePathes.Add(newFilePath); } } } } } } else if (modYamlNode.Key == "MapFolders") { foreach (var subYamlNode in modYamlNode.Value.Nodes) { if (subYamlNode.Key.StartsWith(string.Format("{0}|", modID))) { string oldKey = string.Format("{0}|", modID); subYamlNode.Key = subYamlNode.Key.Replace( oldKey, string.Format("{0}|", newModID) ); string[] tokens = subYamlNode.Key.Split('|'); //Relative map folder mapFolders.Add(Path.Combine(newModFullPath, tokens[1])); } else if (subYamlNode.Key.StartsWith("~")) //optional map folder { string temp = subYamlNode.Key.Substring(1); if (temp.StartsWith("^")) { string[] pathBlocks = temp.Substring(1).Split('/'); int idx = 0; string pathAfterModified = string.Empty; foreach (var pathBlock in pathBlocks) { if (pathBlock == modID) { pathBlocks[idx] = newModID; } pathAfterModified = Path.Combine(pathAfterModified, pathBlocks[idx]); idx++; } temp = "^" + pathAfterModified.Replace("\\", "/"); string fullPath = Platform.ResolvePath(temp); mapFolders.Add(fullPath); subYamlNode.Key = "~" + temp; } } } } else if (modYamlNode.Key == "LoadScreen") { foreach (var subYamlNode in modYamlNode.Value.Nodes) { if (subYamlNode.Value.Value.StartsWith(string.Format("{0}|", modID))) { string oldKey = string.Format("{0}|", modID); subYamlNode.Value.Value = subYamlNode.Value.Value.Replace( oldKey, string.Format("{0}|", newModID) ); } } } else if (modYamlNode.Key == "Fonts") { foreach (var subYamlNode in modYamlNode.Value.Nodes) { foreach (var sNode in subYamlNode.Value.Nodes) { if (sNode.Key == "Font") { if (sNode.Value.Value.StartsWith(string.Format("{0}|", modID))) { string oldKey = string.Format("{0}|", modID); sNode.Value.Value = sNode.Value.Value.Replace( oldKey, string.Format("{0}|", newModID) ); } if ((subYamlNode.Key == "Tiny" || subYamlNode.Key == "Small" || subYamlNode.Key == "Regular" || subYamlNode.Key == "Title")) { string targetNormalFontFile = Path.Combine(newModFullPath, Path.GetFileName(normalFont)); if (File.Exists(normalFont) && !File.Exists(targetNormalFontFile)) { File.Copy(normalFont, targetNormalFontFile); } sNode.Value.Value = string.Format("{0}|{1}", newModID, Path.GetFileName(normalFont)); } else if (subYamlNode.Key == "TinyBold" || subYamlNode.Key == "Bold" || subYamlNode.Key == "MediumBold" || subYamlNode.Key == "BigBold") { string targetBoldFontFile = Path.Combine(newModFullPath, Path.GetFileName(boldFont)); if (File.Exists(boldFont) && !File.Exists(targetBoldFontFile)) { File.Copy(boldFont, targetBoldFontFile); } sNode.Value.Value = string.Format("{0}|{1}", newModID, Path.GetFileName(boldFont)); } } } } } else if (modYamlNode.Key == "ModContent") { foreach (var subYamlNode in modYamlNode.Value.Nodes) { if (subYamlNode.Key == "InstallPromptMessage") { //Translate if (modContentLocalizationNode != null) { var installPromptLocalization = modContentLocalizationNode.Value.Nodes.Where(o => o.Key == "InstallPromptMessage").FirstOrDefault(); if (installPromptLocalization != null) { subYamlNode.Value.Value = installPromptLocalization.Value.Value; } } } else if (subYamlNode.Key == "HeaderMessage") { //Translate if (modContentLocalizationNode != null) { var headerMessageLocalization = modContentLocalizationNode.Value.Nodes.Where(o => o.Key == "HeaderMessage").FirstOrDefault(); if (headerMessageLocalization != null) { subYamlNode.Value.Value = headerMessageLocalization.Value.Value; } } } else if (subYamlNode.Key == "Packages") { foreach (var sNode in subYamlNode.Value.Nodes) { //Translate if (modContentLocalizationNode != null) { var packageLocalization = modContentLocalizationNode.Value.Nodes.Where(o => o.Key == "Packages").FirstOrDefault(); if (packageLocalization != null) { var subPackageLocalizationNode = packageLocalization.Value.Nodes.Where(o => o.Key == sNode.Key).FirstOrDefault(); if (subPackageLocalizationNode != null) { sNode.Value.Value = subPackageLocalizationNode.Value.Value; } } } foreach (var sn in sNode.Value.Nodes) { if (sn.Key == "TestFiles") { string[] contentFilePathes = sn.Value.Value.Split(','); int idx = 0; StringBuilder builder = new StringBuilder(); foreach (var contentFilePath in contentFilePathes) { string path = null; var contentFilePathTemp = contentFilePath.Trim(); if (contentFilePathTemp.StartsWith("^")) { path = contentFilePathTemp.Substring(1); } else { path = contentFilePathTemp; } contentFilePathes[idx] = "^" + ReplacePathWithNewModID(path, modID, newModID); builder.Append(contentFilePathes[idx] + ","); idx++; } sn.Value.Value = builder.ToString(); } } } } else if (subYamlNode.Key == "Sources") { foreach (var sNode in subYamlNode.Value.Nodes) { if (sNode.Key.StartsWith(string.Format("{0}|", modID))) { string oldKey = string.Format("{0}|", modID); sNode.Key = sNode.Key.Replace( oldKey, string.Format("{0}|", newModID) ); } } } } } } modYamlNodes.WriteToFile(newModYaml); //Modify all maps foreach (var mapFolder in mapFolders) { DirectoryInfo mapDir = new DirectoryInfo(mapFolder); if (!mapDir.Exists) { continue; } foreach (var directory in mapDir.EnumerateDirectories()) { if (File.Exists(Path.Combine(directory.FullName, "map.bin")) && File.Exists(Path.Combine(directory.FullName, "map.yaml")) && File.Exists(Path.Combine(directory.FullName, "map.png"))) { string mapYamlPath = Path.Combine(directory.FullName, "map.yaml"); var mapYamlFile = MiniYaml.FromFile(mapYamlPath); foreach (var node in mapYamlFile) { if (node.Key == "RequiresMod") { node.Value.Value = newModID; break; } } mapYamlFile.WriteToFile(mapYamlPath); } } } //Translate Rules file foreach (var ruleFilePath in ruleFilePathes) { var ruleYamlFile = MiniYaml.FromFile(ruleFilePath); foreach (var node in ruleYamlFile) { if (rulesLocalizationNode != null && node.Key != "^BaseWorld") { var actorLocalizationNode = rulesLocalizationNode.Value.Nodes.Where(o => o.Key == node.Key).FirstOrDefault(); var toolTipTraitNode = node.Value.Nodes.Where(o => o.Key == "Tooltip").FirstOrDefault(); if (toolTipTraitNode != null && actorLocalizationNode != null) { toolTipTraitNode.Value.Nodes[0].Value.Value = actorLocalizationNode.Value.Value; } } else if (node.Key == "^BaseWorld") //Translate Factions { if (worldRulesLocalizationNode != null) { foreach (var worldChildNode in node.Value.Nodes) { var factionLocalizationNode = worldRulesLocalizationNode.Value.Nodes.Where(o => o.Key == worldChildNode.Key).FirstOrDefault(); if (factionLocalizationNode != null) { foreach (var valueNode in worldChildNode.Value.Nodes) { var valueLocalizationNode = factionLocalizationNode.Value.Nodes.Where(o => o.Key == valueNode.Key).FirstOrDefault(); if (valueLocalizationNode != null) { valueNode.Value.Value = valueLocalizationNode.Value.Value; } } } } } } } ruleYamlFile.WriteToFile(ruleFilePath); } //Translate Chrome Layouts foreach (var chromeLayoutFilePath in chromeLayoutFilePathes) { var chromeLayoutFile = MiniYaml.FromFile(chromeLayoutFilePath); foreach (var chromeNode in chromeLayoutFile) { var chromeLocalizationNode = chromeLayoutsLocalizationNode.Value.Nodes.Where(o => o.Key == chromeNode.Key).FirstOrDefault(); if (chromeLocalizationNode != null) { translateChrome(chromeNode, chromeLocalizationNode); } } chromeLayoutFile.WriteToFile(chromeLayoutFilePath); } } Console.WriteLine("Import task has already finished!"); }
public void Run(ModData modData, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; Game.ModData.MapCache.LoadMaps(); var engineDate = Exts.ParseIntegerInvariant(args[1]); Console.WriteLine("Processing Rules:"); foreach (var filename in Game.ModData.Manifest.Rules) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeRules.UpgradeActorRules(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.Write(yaml.WriteToString()); } Console.WriteLine("Processing Weapons:"); foreach (var filename in Game.ModData.Manifest.Weapons) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeRules.UpgradeWeaponRules(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.Write(yaml.WriteToString()); } Console.WriteLine("Processing Tilesets:"); foreach (var filename in Game.ModData.Manifest.TileSets) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeRules.UpgradeTileset(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.Write(yaml.WriteToString()); } Console.WriteLine("Processing Cursors:"); foreach (var filename in Game.ModData.Manifest.Cursors) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeRules.UpgradeCursors(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.Write(yaml.WriteToString()); } Console.WriteLine("Processing Chrome Metrics:"); foreach (var filename in Game.ModData.Manifest.ChromeMetrics) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeRules.UpgradeChromeMetrics(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.Write(yaml.WriteToString()); } Console.WriteLine("Processing Chrome Layout:"); foreach (var filename in Game.ModData.Manifest.ChromeLayout) { Console.WriteLine("\t" + filename); var yaml = MiniYaml.FromFile(filename); UpgradeRules.UpgradeChromeLayout(engineDate, ref yaml, null, 0); using (var file = new StreamWriter(filename)) file.Write(yaml.WriteToString()); } Console.WriteLine("Processing Maps:"); var maps = Game.ModData.MapCache .Where(m => m.Status == MapStatus.Available) .Select(m => m.Map); foreach (var map in maps) { Console.WriteLine("\t" + map.Path); UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0); UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0); UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0); UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0); map.Save(map.Path); } }