From b28d999131a21ecf1b9259f45eb77daa64d5cda8 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 7 Dec 2014 17:28:01 +0000 Subject: [PATCH] Made SheetBuilder rely on global settings rather than global renderer. Additionally exposed an InitializeSettings method on game to initialize the global settings so that other classes can set up all the secret dependencies on the global settings required. --- OpenRA.Editor/Form1.cs | 16 ++++++++-------- OpenRA.Game/Game.cs | 7 ++++++- OpenRA.Game/Graphics/SheetBuilder.cs | 2 +- OpenRA.Lint/YamlChecker.cs | 4 +--- OpenRA.Utility/Program.cs | 1 + 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index c9834e1c8d..e68aac57e9 100644 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -46,6 +46,7 @@ namespace OpenRA.Editor miniMapBox.Image = null; currentMod = toolStripComboBox1.SelectedItem as string; + Game.InitializeSettings(Arguments.Empty); Game.modData = new ModData(currentMod); GlobalFileSystem.LoadFromManifest(Game.modData.Manifest); Program.Rules = Game.modData.RulesetCache.LoadDefaultRules(); @@ -203,10 +204,10 @@ namespace OpenRA.Editor Height = bitmap.Height / 2, SizeMode = PictureBoxSizeMode.StretchImage }; - + var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = t.Key }; ibox.Click += (_, e) => surface1.SetTool(new BrushTool(brushTemplate)); - + var template = t.Value; tilePalette.Controls.Add(ibox); tt.SetToolTip(ibox, "{1}:{0} ({2}x{3})".F(template.Image, template.Id, template.Size.X, template.Size.Y)); @@ -463,7 +464,7 @@ namespace OpenRA.Editor void ExportMinimap(object sender, EventArgs e) { using (var sfd = new SaveFileDialog() - { + { InitialDirectory = Path.Combine(Environment.CurrentDirectory, "maps"), DefaultExt = "*.png", Filter = "PNG Image (*.png)|*.png", @@ -471,9 +472,8 @@ namespace OpenRA.Editor FileName = Path.ChangeExtension(loadedMapName, ".png"), RestoreDirectory = true }) - - if (DialogResult.OK == sfd.ShowDialog()) - miniMapBox.Image.Save(sfd.FileName); + if (DialogResult.OK == sfd.ShowDialog()) + miniMapBox.Image.Save(sfd.FileName); } void ShowActorNamesClicked(object sender, EventArgs e) @@ -637,7 +637,7 @@ namespace OpenRA.Editor { ShowGridClicked(sender, e); } - + public int CalculateTotalResource() { var totalResource = 0; @@ -651,7 +651,7 @@ namespace OpenRA.Editor return totalResource; } - + int GetAdjecentCellsWith(int resourceType, int x, int y) { var sum = 0; diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 506ad986e6..1fbb6d8683 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -175,13 +175,18 @@ namespace OpenRA public static Modifiers GetModifierKeys() { return modifiers; } internal static void HandleModifierKeys(Modifiers mods) { modifiers = mods; } + public static void InitializeSettings(Arguments args) + { + Settings = new Settings(Platform.ResolvePath("^", "settings.yaml"), args); + } + internal static void Initialize(Arguments args) { Console.WriteLine("Platform is {0}", Platform.CurrentPlatform); AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly; - Settings = new Settings(Platform.ResolvePath("^", "settings.yaml"), args); + InitializeSettings(args); Log.AddChannel("perf", "perf.log"); Log.AddChannel("debug", "debug.log"); diff --git a/OpenRA.Game/Graphics/SheetBuilder.cs b/OpenRA.Game/Graphics/SheetBuilder.cs index e136654fcc..b79eb2d0cc 100644 --- a/OpenRA.Game/Graphics/SheetBuilder.cs +++ b/OpenRA.Game/Graphics/SheetBuilder.cs @@ -46,7 +46,7 @@ namespace OpenRA.Graphics } public SheetBuilder(SheetType t) - : this(t, Game.Renderer.SheetSize) { } + : this(t, Game.Settings.Graphics.SheetSize) { } public SheetBuilder(SheetType t, int sheetSize) : this(t, () => AllocateSheet(sheetSize)) { } diff --git a/OpenRA.Lint/YamlChecker.cs b/OpenRA.Lint/YamlChecker.cs index 11e70ae4e8..c8686378bb 100644 --- a/OpenRA.Lint/YamlChecker.cs +++ b/OpenRA.Lint/YamlChecker.cs @@ -55,9 +55,7 @@ namespace OpenRA.Lint FieldLoader.UnknownFieldAction = (s, f) => EmitError("FieldLoader: Missing field `{0}` on `{1}`".F(s, f.Name)); AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly; - Game.Renderer = new Graphics.Renderer( - new GraphicSettings() { Renderer = "Null", NumTempBuffers = 0, SheetSize = 0 }, - new ServerSettings()); + Game.InitializeSettings(Arguments.Empty); Game.modData = new ModData(mod); IEnumerable maps; diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 0a403c2ecc..8b79d8f580 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -38,6 +38,7 @@ namespace OpenRA.Utility return; } + Game.InitializeSettings(Arguments.Empty); var modData = new ModData(modName); args = args.Skip(1).ToArray(); var actions = new Dictionary>();