From b3ce0e118a78e75131b4ad6f8618a69938f6333d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 9 Apr 2020 18:06:01 +0200 Subject: [PATCH] part 1 finished --- GameBundle.sln | 6 +++ GameBundle/GameBundle.csproj | 15 ++++++- GameBundle/GameBundle.nuspec | 20 --------- GameBundle/GameBundle.targets | 5 --- GameBundle/Options.cs | 29 ++++++++++++ GameBundle/Program.cs | 61 +++++++++++++++++++++++++- GameBundle/_._ | 0 Test/Bundle.bat | 1 + Test/Content/Content.mgcb | 63 +++++++++++++++++++++++++++ Test/Content/Textures/Anim.png | Bin 0 -> 710 bytes Test/Content/Textures/AutoTiling.png | Bin 0 -> 604 bytes Test/Content/Textures/Test.png | Bin 0 -> 896 bytes Test/Content/Textures/Tree.png | Bin 0 -> 248 bytes Test/GameImpl.cs | 13 ++++++ Test/Program.cs | 14 ++++++ Test/Test.csproj | 21 +++++++++ 16 files changed, 220 insertions(+), 28 deletions(-) delete mode 100644 GameBundle/GameBundle.nuspec delete mode 100644 GameBundle/GameBundle.targets create mode 100644 GameBundle/Options.cs delete mode 100644 GameBundle/_._ create mode 100644 Test/Bundle.bat create mode 100644 Test/Content/Content.mgcb create mode 100644 Test/Content/Textures/Anim.png create mode 100644 Test/Content/Textures/AutoTiling.png create mode 100644 Test/Content/Textures/Test.png create mode 100644 Test/Content/Textures/Tree.png create mode 100644 Test/GameImpl.cs create mode 100644 Test/Program.cs create mode 100644 Test/Test.csproj 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 0000000000000000000000000000000000000000..d4ddb1ee6eb8e769cdafb929793b9e801205bbed GIT binary patch literal 710 zcmV;%0y+JOP)Px%fJsC_R9J=WSHEl9P!Rqkgh5yj*NY8rRl!h*@nE_nlt2k|G1)rw&&U|a5IiTe zOUEpM4kmVkllPsnXkxk&N25V_uwFHdOb%^ir^d#GD2<_r;(c`|md#4|F?~{c& zr00<9*tnl10D#fYnFRy>vjW}E61a{H0J!@;we)xZ;2dWBqWmeRVXs5Hezp59l|&S5 z5(QiN<`u~CW-J%b|NIF6@ci}LOe}-OgDwG}JW_fNNzWlsuyc8iH+@9GCh0l3xz#O6 zDQP_DB94Dx*y}(_nR1j;Qanu%PZRhr>KPsY#)B>ZVD6{xGM*+@JWWzQ3=05iwHn27 z4Bz)30^%4^6hR1qFbu6)twyfvLI|OFAq1i*LKuc>qei1adYrxy?@_5#5CnnZY);5m zUYqu1JVP(g1l!mrRlv=~3Hqn+k$5cxL0~0bOWBxDyjF^z(6-_kY`eKQ$rQl(CbXU5 z008A`lZqvu%=Mr0%j}F|$)|F)nc`D@yq*JC&jDi&0KjN8vhw&Rp97UjCDrG88!nmy zUp}_gdf4lb5JKfK!FvcHQs0_2e=M}KcMSlzy=q(KYLmW=zp5(d?+!bA*SNiETlK92 zVqf-Q8vtA$Zvp_SFW*>ZJVTEKu)2qr`If6q)!)UEpPNUw>;CIGU}8N79s>TM9&k9J zepQugcGqq!{d;kCd literal 0 HcmV?d00001 diff --git a/Test/Content/Textures/AutoTiling.png b/Test/Content/Textures/AutoTiling.png new file mode 100644 index 0000000000000000000000000000000000000000..5496de78aeab0b65c3992ee5b4c7d09410603430 GIT binary patch literal 604 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRSjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc4Ie#S978JN-rjJ`5^)q^xG+!RjLVDz4SFpu z_a$cPHKfP{6io_fbHI2`5BB8PS zmrMQnUlP9j`=6)pcFayr-g{s6ZSCog-}Zieb9lLa`sIr*N7(+}zWd^bNq=_C^Uyy9 z-_zynEq9m-^Ut5}`^$a(^>dG_^Y48tDq`Gw@6d9it!8iaC3t?{oIgi4y-2I^YSz1t z=jPh15BZ~YYpb`2S8V&!Q%oyb!t1S0>4g?4X*TYK)a(_C zn5Wa=;dSTF>64jT{aaseJMlHL@3ZZJJ+tMdw`JVl|L=vL+v6Nl@y9n-9Bo_MryVzY zhyBsy!{Wso>pCCL*#H04qqNDd%{O!I`6Jio63VoCYw=pMeJje|Cde0TPP1cve0lvm zwuwE5#pR3sY%gnz{<-zSJIPm?AKpC@s9*fLj(KhMm*qV7BsfaSW-L z^Y)f+-em`gV;|Gi-mx!mDH7L-n2Q`RiHxr*Gc8dF{I6Y1>v8&5-k+^lyrJX{Eu1lMfgE|8wX>E^Pg?ZefjT;{P8XAIPX<@p!@ZI z?i!xWH{Zko`Rf^f@zu>*mS;3`#>teVTc7KvrK<7#$T16^mYTLy&}I83j+|?Z3!4un ztc;m;`$mkP$B@%D|y=T1sIzHffj^V8FBUqeG*`tQ6j{e1lPUyX@M ziu;aOZWoDI$(JSk!MD_RuS#g>)BVbx*P%X*Ot$X{7+(q(r(h+CG{eN12aLK6-6n8fM^8KROqgORj zJJ#AQ6aAu``Rw(Ly;JY)m(SVpwfokFx2Xk=DSKU3zWm$6w0r$_O@}0r8|-yl9k(+2 zJzICwi1+SfOOW1SU&C~SN9^{2zYpcvj`D@g2&fGFkdW@aR)(W5tpi__nzDMyzMWx%{fyrSbdgwQSUPWLj^3w;{uLZGn2hcU9L& zuSut#Jv&>ov1HTrf7Y+X*`kBelUmZ5dJT<|SZbHSK-)VqyVl6$KIeI% mvbkb>x0!(HpBkXTtDf<7+3ek`Ro+{G%=2{hb6Mw<&;$Ur(3j)@ literal 0 HcmV?d00001 diff --git a/Test/Content/Textures/Tree.png b/Test/Content/Textures/Tree.png new file mode 100644 index 0000000000000000000000000000000000000000..2d29e3992bc9005a4cd0f7f25ba1d2983c5dc049 GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp^96&6S?)pbHp0UHx3vIVCg!0B?#)bpQYW literal 0 HcmV?d00001 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