From 2e44f4653b030ee64b8c4813e3c8dd1dda1ba417 Mon Sep 17 00:00:00 2001 From: Bartosz Chyzy Date: Mon, 22 Apr 2019 22:11:56 +0200 Subject: [PATCH] MapEditor --- .gitattributes | 63 ++++++++++ .../App.config | 6 + .../App.xaml | 9 ++ .../App.xaml.cs | 17 +++ .../CzokoŚmieciarka.UserInterface.WPF.csproj | 98 +++++++++++++++ .../MainWindow.xaml | 15 +++ .../MainWindow.xaml.cs | 69 +++++++++++ .../Properties/AssemblyInfo.cs | 55 ++++++++ .../Properties/Resources.Designer.cs | 71 +++++++++++ .../Properties/Resources.resx | 117 ++++++++++++++++++ .../Properties/Settings.Designer.cs | 30 +++++ .../Properties/Settings.settings | 7 ++ Trunk/Helper Programs/MapEditor/MapEditor.sln | 25 ++++ .../MapEditor/MapEditor/App.config | 10 ++ .../MapEditor/MapEditor/Config.cs | 16 +++ .../Helpers/ColorToFieldTypeConverter.cs | 31 +++++ .../MapEditor/MapEditor/MapEditor.csproj | 59 +++++++++ .../MapEditor/MapEditor/Models/Enums.cs | 36 ++++++ .../MapEditor/MapEditor/Models/FieldInfo.cs | 22 ++++ .../MapEditor/MapEditor/Program.cs | 83 +++++++++++++ .../MapEditor/Properties/AssemblyInfo.cs | 36 ++++++ 21 files changed, 875 insertions(+) create mode 100644 .gitattributes create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/App.config create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/App.xaml create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/App.xaml.cs create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/CzokoŚmieciarka.UserInterface.WPF.csproj create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/MainWindow.xaml create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/MainWindow.xaml.cs create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/AssemblyInfo.cs create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Resources.Designer.cs create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Resources.resx create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Settings.Designer.cs create mode 100644 Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Settings.settings create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor.sln create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor/App.config create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor/Config.cs create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor/Helpers/ColorToFieldTypeConverter.cs create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor/MapEditor.csproj create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor/Models/Enums.cs create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor/Models/FieldInfo.cs create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor/Program.cs create mode 100644 Trunk/Helper Programs/MapEditor/MapEditor/Properties/AssemblyInfo.cs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.config b/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.xaml b/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.xaml new file mode 100644 index 0000000..af73171 --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.xaml.cs b/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.xaml.cs new file mode 100644 index 0000000..962c8ad --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace CzokoŚmieciarka.UserInterface.WPF +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/CzokoŚmieciarka.UserInterface.WPF.csproj b/Trunk/CzokoŚmieciarka.UserInterface.WPF/CzokoŚmieciarka.UserInterface.WPF.csproj new file mode 100644 index 0000000..7686ade --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/CzokoŚmieciarka.UserInterface.WPF.csproj @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {C510F713-91EC-465F-AD99-5BA051072E90} + WinExe + CzokoŚmieciarka.UserInterface.WPF + CzokoŚmieciarka.UserInterface.WPF + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + \ No newline at end of file diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/MainWindow.xaml b/Trunk/CzokoŚmieciarka.UserInterface.WPF/MainWindow.xaml new file mode 100644 index 0000000..c35e3e7 --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/MainWindow.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/MainWindow.xaml.cs b/Trunk/CzokoŚmieciarka.UserInterface.WPF/MainWindow.xaml.cs new file mode 100644 index 0000000..2bcebf0 --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/MainWindow.xaml.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace CzokoŚmieciarka.UserInterface.WPF +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + this._rows = 10; + this._columns = 15; + + GenerateGridBoard(); + PopulateGridBoard(); + } + + private int _rows; + private int _columns; + + private void GenerateGridBoard() + { + for (int row = 0; row < _rows; row++) + { + GridBoard.RowDefinitions.Add(new RowDefinition(){Height = new GridLength(70)}); + } + for (int column = 0; column < _columns; column++) + { + GridBoard.ColumnDefinitions.Add(new ColumnDefinition(){ Width = new GridLength(70) }); + } + } + + private void PopulateGridBoard() + { + var random = new Random(); + + for (int row = 0; row < _rows; row++) + { + for (int column = 0; column < _columns; column++) + { + byte red = (byte)random.Next(0, 255); + byte green = (byte)random.Next(0, 255); + byte blue = (byte)random.Next(0, 255); + var content = new StackPanel() { Background = new SolidColorBrush(Color.FromRgb(red, green, blue)) }; + + Grid.SetRow(content,row); + Grid.SetColumn(content,column); + + GridBoard.Children.Add(content); + } + } + } + } +} diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/AssemblyInfo.cs b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8b37cf3 --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CzokoŚmieciarka.UserInterface.WPF")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CzokoŚmieciarka.UserInterface.WPF")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Resources.Designer.cs b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Resources.Designer.cs new file mode 100644 index 0000000..66ea380 --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CzokoŚmieciarka.UserInterface.WPF.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CzokoŚmieciarka.UserInterface.WPF.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Resources.resx b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Settings.Designer.cs b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Settings.Designer.cs new file mode 100644 index 0000000..37c4033 --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CzokoŚmieciarka.UserInterface.WPF.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Settings.settings b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/Trunk/CzokoŚmieciarka.UserInterface.WPF/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Trunk/Helper Programs/MapEditor/MapEditor.sln b/Trunk/Helper Programs/MapEditor/MapEditor.sln new file mode 100644 index 0000000..59ab246 --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.572 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapEditor", "MapEditor\MapEditor.csproj", "{B04C4A92-1376-4D98-ADC1-A3799DEECF0F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B04C4A92-1376-4D98-ADC1-A3799DEECF0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B04C4A92-1376-4D98-ADC1-A3799DEECF0F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B04C4A92-1376-4D98-ADC1-A3799DEECF0F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B04C4A92-1376-4D98-ADC1-A3799DEECF0F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FD2A72E0-B6AB-4E11-AB7E-A40AF69F3E36} + EndGlobalSection +EndGlobal diff --git a/Trunk/Helper Programs/MapEditor/MapEditor/App.config b/Trunk/Helper Programs/MapEditor/MapEditor/App.config new file mode 100644 index 0000000..9133650 --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor/App.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Trunk/Helper Programs/MapEditor/MapEditor/Config.cs b/Trunk/Helper Programs/MapEditor/MapEditor/Config.cs new file mode 100644 index 0000000..38e26ac --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor/Config.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MapEditor +{ + public static class Config + { + public static string ImageFilePath => ConfigurationManager.AppSettings["imageFilePath"]; + + public static string OutputFilePath => ConfigurationManager.AppSettings["outputFilePath"]; + } +} diff --git a/Trunk/Helper Programs/MapEditor/MapEditor/Helpers/ColorToFieldTypeConverter.cs b/Trunk/Helper Programs/MapEditor/MapEditor/Helpers/ColorToFieldTypeConverter.cs new file mode 100644 index 0000000..7a880a6 --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor/Helpers/ColorToFieldTypeConverter.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MapEditor.Models; + +namespace MapEditor.Helpers +{ + public static class ColorToFieldTypeConverter + { + public static FieldType ConvertToFieldType(Color color) + { + if (color == Color.FromArgb(0, 255, 0)) + return FieldType.Grass; + + if (color == Color.FromArgb(0, 0, 0)) + return FieldType.Road; + + if (color == Color.FromArgb(255, 0, 0)) + return FieldType.House; + + if (color == Color.FromArgb(255,255,0)) + return FieldType.House; + + throw new NotImplementedException($"Conversion form {color.ToKnownColor()} has not been implemented."); + + } + } +} diff --git a/Trunk/Helper Programs/MapEditor/MapEditor/MapEditor.csproj b/Trunk/Helper Programs/MapEditor/MapEditor/MapEditor.csproj new file mode 100644 index 0000000..fccb96c --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor/MapEditor.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {B04C4A92-1376-4D98-ADC1-A3799DEECF0F} + Exe + MapEditor + MapEditor + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Trunk/Helper Programs/MapEditor/MapEditor/Models/Enums.cs b/Trunk/Helper Programs/MapEditor/MapEditor/Models/Enums.cs new file mode 100644 index 0000000..d3d5348 --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor/Models/Enums.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MapEditor.Models +{ + public enum FieldType + { + Grass = 0, + Road = 1, + House = 2, + Dump = 3 + } + + public static class EnumExtensions + { + public static string ToFriendlyString(this FieldType fieldType) + { + if (fieldType == FieldType.Grass) + return "Grass"; + + if (fieldType == FieldType.Road) + return "Road"; + + if (fieldType == FieldType.House) + return "House"; + + if (fieldType == FieldType.Dump) + return "Dump"; + + throw new NotImplementedException($"String conversion for enum with value '{fieldType.ToString()}' has not been implemented."); + } + } +} diff --git a/Trunk/Helper Programs/MapEditor/MapEditor/Models/FieldInfo.cs b/Trunk/Helper Programs/MapEditor/MapEditor/Models/FieldInfo.cs new file mode 100644 index 0000000..3336ad2 --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor/Models/FieldInfo.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MapEditor.Models +{ + public class FieldInfo + { + public FieldInfo(int x, int y, FieldType fieldType) + { + X = x; + Y = y; + FieldType = fieldType; + } + + public int X { get; } + public int Y { get; } + public FieldType FieldType { get; } + } +} diff --git a/Trunk/Helper Programs/MapEditor/MapEditor/Program.cs b/Trunk/Helper Programs/MapEditor/MapEditor/Program.cs new file mode 100644 index 0000000..58262a0 --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor/Program.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Net.Mime; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using MapEditor.Helpers; +using MapEditor.Models; + +namespace MapEditor +{ + class Program + { + static void Main(string[] args) + { + var bitmap = (Bitmap)Bitmap.FromFile(Config.ImageFilePath); + var fieldInfos = GetFieldInfos(bitmap); + + if(GenerateXML(fieldInfos)) + Console.WriteLine("Done."); + else + Console.WriteLine("Something gone wrong."); + + Console.ReadKey(); + } + + private static IEnumerable GetFieldInfos(Bitmap bitmap) + { + var width = bitmap.Width; + var height = bitmap.Height; + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + var color = bitmap.GetPixel(x, y); + var fieldType = ColorToFieldTypeConverter.ConvertToFieldType(color); + + yield return new FieldInfo(x,y,fieldType); + } + } + } + private static bool GenerateXML(IEnumerable fieldInfos) + { + try + { + using (var xmlWriter = XmlWriter.Create(Config.OutputFilePath)) + { + xmlWriter.WriteStartElement("Map"); + + xmlWriter.WriteElementString("Size",Math.Sqrt(fieldInfos.Count()).ToString()); + + xmlWriter.WriteStartElement("Objects"); + foreach (var fieldInfo in fieldInfos) + { + xmlWriter.WriteStartElement("Object"); + + xmlWriter.WriteElementString("Type",fieldInfo.FieldType.ToFriendlyString()); + + xmlWriter.WriteStartElement("Position"); + xmlWriter.WriteElementString("X",fieldInfo.X.ToString()); + xmlWriter.WriteElementString("Y",fieldInfo.Y.ToString()); + xmlWriter.WriteEndElement(); + + xmlWriter.WriteEndElement(); + } + xmlWriter.WriteEndElement(); + + xmlWriter.WriteEndElement(); + xmlWriter.Flush(); + } + + return true; + } + catch (Exception ex) + { + return false; + } + } + } +} diff --git a/Trunk/Helper Programs/MapEditor/MapEditor/Properties/AssemblyInfo.cs b/Trunk/Helper Programs/MapEditor/MapEditor/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1ed45b6 --- /dev/null +++ b/Trunk/Helper Programs/MapEditor/MapEditor/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MapEditor")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MapEditor")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b04c4a92-1376-4d98-adc1-a3799deecf0f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]