diff --git a/GameBundle.sln b/GameBundle.sln index ef64607..7329623 100644 --- a/GameBundle.sln +++ b/GameBundle.sln @@ -2,6 +2,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameBundle", "GameBundle\GameBundle.csproj", "{18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{6FD8768A-7F59-4815-BF41-33DA9ACDB81A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +14,9 @@ Global {18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Debug|Any CPU.Build.0 = Debug|Any CPU {18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Release|Any CPU.ActiveCfg = Release|Any CPU {18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Release|Any CPU.Build.0 = Release|Any CPU + {6FD8768A-7F59-4815-BF41-33DA9ACDB81A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FD8768A-7F59-4815-BF41-33DA9ACDB81A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FD8768A-7F59-4815-BF41-33DA9ACDB81A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6FD8768A-7F59-4815-BF41-33DA9ACDB81A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/GameBundle/GameBundle.csproj b/GameBundle/GameBundle.csproj index ae39d8c..efe86b2 100644 --- a/GameBundle/GameBundle.csproj +++ b/GameBundle/GameBundle.csproj @@ -3,7 +3,20 @@ Exe netcoreapp3.1 - Contentless.nuspec + + Ellpeck + A tool to package MonoGame and other .NET Core applications into several distributable formats + monogame mono xna netcore dotnet publish bundle tool library + https://github.com/Ellpeck/GameBundle + https://github.com/Ellpeck/GameBundle + https://github.com/Ellpeck/GameBundle/blob/master/LICENSE + true + gamebundle + 0.0.1 + + + + diff --git a/GameBundle/GameBundle.nuspec b/GameBundle/GameBundle.nuspec deleted file mode 100644 index 00d032c..0000000 --- a/GameBundle/GameBundle.nuspec +++ /dev/null @@ -1,20 +0,0 @@ - - - - GameBundle - 0.0.1 - Ellpeck - A tool to package MonoGame and other .NET Core applications into several distributable formats - monogame mono xna netcore dotnet publish bundle tool library - https://github.com/Ellpeck/GameBundle - https://github.com/Ellpeck/GameBundle/blob/master/LICENSE - - README.md - - - - - - - - \ No newline at end of file diff --git a/GameBundle/GameBundle.targets b/GameBundle/GameBundle.targets deleted file mode 100644 index b4cc581..0000000 --- a/GameBundle/GameBundle.targets +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/GameBundle/Options.cs b/GameBundle/Options.cs new file mode 100644 index 0000000..ab3fdf0 --- /dev/null +++ b/GameBundle/Options.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using CommandLine; + +namespace GameBundle { + public class Options { + + [Option('s', "source", Required = true, HelpText = "The location of the .csproj file that should be built and bundled")] + public string SourceFile { get; set; } + [Option('o', "output", Required = true, HelpText = "The location of the directory that the bundles should be stored in")] + public string OutputDirectory { get; set; } + [Option('v', "verbose", Default = false)] + public bool Verbose { get; set; } + + [Option('w', "win", Default = true, HelpText = "Bundle for windows")] + public bool BundleWindows { get; set; } + [Option('l', "linux", Default = true, HelpText = "Bundle for linux")] + public bool BundleLinux { get; set; } + [Option('m', "mac", Default = true, HelpText = "Bundle for mac")] + public bool BundleMac { get; set; } + + [Option('e', "exclude", Default = new[] {"openal", "oal", "sdl2", "SDL2"}, HelpText = "Files like unmanaged libraries that should not be moved to the /Lib folder")] + public string[] ExcludedFiles { get; set; } + [Option("32bit", Default = false, HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")] + public bool Publish32Bit { get; set; } + [Option("trim", Default = true, HelpText = "If the application should be trimmed when being published")] + public bool Trim { get; set; } + + } +} \ No newline at end of file diff --git a/GameBundle/Program.cs b/GameBundle/Program.cs index f32375e..ab770ac 100644 --- a/GameBundle/Program.cs +++ b/GameBundle/Program.cs @@ -1,7 +1,64 @@ -namespace GameBundle { +using System; +using System.Diagnostics; +using System.IO; +using System.Text.RegularExpressions; +using CommandLine; + +namespace GameBundle { internal static class Program { - private static void Main(string[] args) { + private static int Main(string[] args) { + return Parser.Default.ParseArguments(args).MapResult(Run, _ => -1); + } + + private static int Run(Options options) { + if (RunProcess(options, "dotnet", "tool install nulastudio.ncbeauty -g") < 0) + return -1; + + var proj = new FileInfo(options.SourceFile); + if (!proj.Exists) { + Console.WriteLine("Project file not found at " + proj.FullName); + return -1; + } + if (options.Verbose) + Console.WriteLine("Found project file at " + proj.FullName); + + var bundleDir = new DirectoryInfo(Path.Combine(options.OutputDirectory, "Bundled")); + if (!bundleDir.Exists) + bundleDir.Create(); + + if (options.BundleWindows) + Publish(options, proj, $"{bundleDir}/win", options.Publish32Bit ? "win-x86" : "win-x64"); + if (options.BundleLinux) + Publish(options, proj, $"{bundleDir}/linux", "linux-x64"); + if (options.BundleMac) + Publish(options, proj, $"{bundleDir}/mac", "osx-x64"); + + return 0; + } + + private static void Publish(Options options, FileInfo proj, string path, string rid) { + RunProcess(options, "dotnet", $"publish {proj.FullName} -o {path} -r {rid} /p:PublishTrimmed={options.Trim}"); + + // Run beauty + var excludes = string.Empty; + if (options.ExcludedFiles.Length > 0) + excludes = "excludes=" + string.Join(";", options.ExcludedFiles); + var log = options.Verbose ? "Detail" : "Error"; + RunProcess(options, "ncbeauty", $"--loglevel={log} --force=True {path} Lib {excludes}"); + + // Remove the beauty file since it's just a marker + var beautyFile = new FileInfo(Path.Combine(path, "NetCoreBeauty")); + if (beautyFile.Exists) + beautyFile.Delete(); + } + + private static int RunProcess(Options options, string program, string args) { + if (options.Verbose) + Console.WriteLine($"$ {program} {args}"); + var process = Process.Start(program, args); + process.WaitForExit(); + return process.ExitCode; } } diff --git a/GameBundle/_._ b/GameBundle/_._ deleted file mode 100644 index e69de29..0000000 diff --git a/Test/Bundle.bat b/Test/Bundle.bat new file mode 100644 index 0000000..2b52fb1 --- /dev/null +++ b/Test/Bundle.bat @@ -0,0 +1 @@ +"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -s Test.csproj -o bin -v \ No newline at end of file diff --git a/Test/Content/Content.mgcb b/Test/Content/Content.mgcb new file mode 100644 index 0000000..e33afed --- /dev/null +++ b/Test/Content/Content.mgcb @@ -0,0 +1,63 @@ + +#----------------------------- Global Properties ----------------------------# + +/outputDir:bin +/intermediateDir:obj +/platform:DesktopGL +/config: +/profile:Reach +/compress:False + +#-------------------------------- References --------------------------------# + + +#---------------------------------- Content ---------------------------------# + +#begin Textures/Anim.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/Anim.png + +#begin Textures/AutoTiling.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/AutoTiling.png + +#begin Textures/Test.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/Test.png + +#begin Textures/Tree.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/Tree.png + diff --git a/Test/Content/Textures/Anim.png b/Test/Content/Textures/Anim.png new file mode 100644 index 0000000..d4ddb1e Binary files /dev/null and b/Test/Content/Textures/Anim.png differ diff --git a/Test/Content/Textures/AutoTiling.png b/Test/Content/Textures/AutoTiling.png new file mode 100644 index 0000000..5496de7 Binary files /dev/null and b/Test/Content/Textures/AutoTiling.png differ diff --git a/Test/Content/Textures/Test.png b/Test/Content/Textures/Test.png new file mode 100644 index 0000000..7d88c33 Binary files /dev/null and b/Test/Content/Textures/Test.png differ diff --git a/Test/Content/Textures/Tree.png b/Test/Content/Textures/Tree.png new file mode 100644 index 0000000..2d29e39 Binary files /dev/null and b/Test/Content/Textures/Tree.png differ diff --git a/Test/GameImpl.cs b/Test/GameImpl.cs new file mode 100644 index 0000000..0e9f419 --- /dev/null +++ b/Test/GameImpl.cs @@ -0,0 +1,13 @@ +using MLEM.Startup; + +namespace Test { + public class GameImpl : MlemGame { + + public static GameImpl Instance { get; private set; } + + public GameImpl() { + Instance = this; + } + + } +} \ No newline at end of file diff --git a/Test/Program.cs b/Test/Program.cs new file mode 100644 index 0000000..d9ed80f --- /dev/null +++ b/Test/Program.cs @@ -0,0 +1,14 @@ +using Microsoft.Xna.Framework; +using MLEM.Misc; + +namespace Test { + public static class Program { + + public static void Main() { + TextInputWrapper.Current = new TextInputWrapper.DesktopGl((w, c) => w.TextInput += c); + using var game = new GameImpl(); + game.Run(); + } + + } +} \ No newline at end of file diff --git a/Test/Test.csproj b/Test/Test.csproj new file mode 100644 index 0000000..4acd8d7 --- /dev/null +++ b/Test/Test.csproj @@ -0,0 +1,21 @@ + + + + Exe + netcoreapp3.0 + false + false + + + + + + + + + + + + + + \ No newline at end of file