public Settings(string file, Arguments args) { SettingsFile = file; Sections = new Dictionary <string, object>() { { "Player", Player }, { "Game", Game }, { "Sound", Sound }, { "Graphics", Graphics }, { "Server", Server }, { "Debug", Debug }, { "Keys", Keys }, { "Irc", Irc } }; // Override fieldloader to ignore invalid entries var err1 = FieldLoader.UnknownFieldAction; var err2 = FieldLoader.InvalidValueAction; FieldLoader.UnknownFieldAction = (s, f) => { Console.WriteLine("Ignoring unknown field `{0}` on `{1}`".F(s, f.Name)); }; if (File.Exists(SettingsFile)) { var yaml = MiniYaml.DictFromFile(SettingsFile); foreach (var kv in Sections) { if (yaml.ContainsKey(kv.Key)) { LoadSectionYaml(yaml[kv.Key], kv.Value); } } } // Override with commandline args foreach (var kv in Sections) { foreach (var f in kv.Value.GetType().GetFields()) { if (args.Contains(kv.Key + "." + f.Name)) { FieldLoader.LoadField(kv.Value, f.Name, args.GetValue(kv.Key + "." + f.Name, "")); } } } FieldLoader.UnknownFieldAction = err1; FieldLoader.InvalidValueAction = err2; }
void LoadTerrainDefinitions() { var terrainDefinition = new Dictionary <string, TerrainTypeInfo>(); var yaml = MiniYaml.DictFromFile("defaults.yaml"); terrainDefinition = yaml["Terrain"].ToDictionary().Values.Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type); surface1.Icon = new Bitmap[terrainDefinition.Keys.Count]; terrainType = new TerrainTypeInfo[terrainDefinition.Keys.Count]; var title = this.Text; surface1.UpdateMouseTilePosition += (x, y, tileNr) => { this.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, newColor); } } 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 FormBuilder(string src, string tsize, bool autoExport, string outputDir) { InitializeComponent(); var terrainDefinition = new Dictionary <string, TerrainTypeInfo>(); var size = int.Parse(tsize); var yaml = MiniYaml.DictFromFile("defaults.yaml"); terrainDefinition = yaml["Terrain"].ToDictionary().Values.Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type); var i = 0; surface1.Icon = new Bitmap[terrainDefinition.Keys.Count]; TerrainType = new TerrainTypeInfo[terrainDefinition.Keys.Count]; var title = this.Text; surface1.UpdateMouseTilePosition += (x, y, tileNr) => { this.Text = "{0} - {1} ({2,3}, {3,3}) tileNr: {4,3}".F(title, txtTilesetName.Text, x, y, tileNr); }; surface1.Enabled = false; 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, newColor); } } 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; i++; terrainTypes.Items.Add(terrainTypeButton); } if (src.Length > 0) { srcfile = src; this.size = size; surface1.TileSize = size; surface1.Image = (Bitmap)Image.FromFile(src); surface1.TilesPerRow = surface1.Image.Size.Width / surface1.TileSize; surface1.Image.SetResolution(96, 96); // people keep being noobs about DPI, and GDI+ cares. surface1.TerrainTypes = new int[surface1.Image.Width / size, surface1.Image.Height / size]; /* all passable by default */ surface1.Templates = new List <Template>(); surface1.Size = surface1.Image.Size; surface1.Enabled = true; Load(); } else { CreateNewTileset(); } if (autoExport) { Export(outputDir); Application.Exit(); } }
public frmBuilder(string src, string tsize, bool AutoExport, string OutputDir) { InitializeComponent(); Dictionary <string, TerrainTypeInfo> DefTerrain = new Dictionary <string, TerrainTypeInfo>(); int size = int.Parse(tsize); var yaml = MiniYaml.DictFromFile("OpenRA.TilesetBuilder/defaults.yaml"); DefTerrain = yaml["Terrain"].NodesDict.Values.Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type); int i = 0; surface1.icon = new Bitmap[DefTerrain.Keys.Count]; TerrainType = new TerrainTypeInfo[DefTerrain.Keys.Count]; surface1.Enabled = false; foreach (var deftype in DefTerrain) { Bitmap icon = new Bitmap(16, 16); int x, y; // Loop through the images pixels to reset color. for (x = 0; x < icon.Width; x++) { for (y = 0; y < icon.Height; y++) { Color newColor = deftype.Value.Color; icon.SetPixel(x, y, newColor); } } surface1.icon[i] = icon; TerrainType[i] = deftype.Value; ToolStripButton TerrainTypeButton = new ToolStripButton(deftype.Key, icon, TerrainTypeSelectorClicked); TerrainTypeButton.ToolTipText = deftype.Key; TerrainTypeButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; TerrainTypeButton.Tag = i.ToString(); i++; tsTerrainTypes.Items.Add(TerrainTypeButton); } if (src.Length > 0) { srcfile = src; this.size = size; surface1.TileSize = size; surface1.Image = (Bitmap)Image.FromFile(src); surface1.Image.SetResolution(96, 96); // people keep being noobs about DPI, and GDI+ cares. surface1.TerrainTypes = new int[surface1.Image.Width / size, surface1.Image.Height / size]; /* all passable by default */ surface1.Templates = new List <Template>(); surface1.Size = surface1.Image.Size; surface1.Enabled = true; Load(); } else { CreateNewTileset(); } if (AutoExport) { Export(OutputDir); Application.Exit(); } }