From 8b3bd76f9ebacc7490388fd35d2710fd50cd7f2b Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 7 Sep 2019 22:39:37 -0700 Subject: [PATCH 01/11] fixes for PascalCase --- project_name/DefaultScene.cs | 25 ++++++++++++------------- project_name/DemoComponent.cs | 10 +++++----- project_name/Game1.cs | 6 +++--- 3 files changed, 20 insertions(+), 21 deletions(-) mode change 100644 => 100755 project_name/DefaultScene.cs mode change 100644 => 100755 project_name/DemoComponent.cs mode change 100644 => 100755 project_name/Game1.cs diff --git a/project_name/DefaultScene.cs b/project_name/DefaultScene.cs old mode 100644 new mode 100755 index 3e19a9c..b57f723 --- a/project_name/DefaultScene.cs +++ b/project_name/DefaultScene.cs @@ -1,27 +1,26 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Nez; -using Nez.ImGuiTools; namespace project_name { - public class DefaultScene : Scene + public class DefaultScene : Scene { - public override void initialize() + public override void Initialize() { - setDesignResolution(Screen.width, Screen.height, Scene.SceneResolutionPolicy.None); + SetDesignResolution(Screen.Width, Screen.Height, Scene.SceneResolutionPolicy.None); - addRenderer(new DefaultRenderer()); + AddRenderer(new DefaultRenderer()); - createEntity("demo imgui draw commands") - .setPosition(new Vector2(150, 150)) - .addComponent() - .addComponent(new PrototypeSprite(20, 20)); + CreateEntity("demo imgui draw commands") + .SetPosition(new Vector2(150, 150)) + .AddComponent() + .AddComponent(new PrototypeSprite(20, 20)); - var logo = content.Load("nez-logo-black"); - createEntity("logo") - .setPosition(Screen.center) - .addComponent(new Nez.Sprites.Sprite(logo)); + var logo = Content.Load("nez-logo-black"); + CreateEntity("logo") + .SetPosition(Screen.Center) + .AddComponent(new Nez.Sprites.Sprite(logo)); } } } diff --git a/project_name/DemoComponent.cs b/project_name/DemoComponent.cs old mode 100644 new mode 100755 index cceb7c0..9f3e548 --- a/project_name/DemoComponent.cs +++ b/project_name/DemoComponent.cs @@ -8,19 +8,19 @@ namespace project_name { int _buttonClickCounter; - public override void onAddedToEntity() + public override void OnAddedToEntity() { // register with the ImGuiMangaer letting it know we want to render some IMGUI - Core.getGlobalManager().registerDrawCommand(imGuiDraw); + Core.GetGlobalManager().RegisterDrawCommand(ImGuiDraw); } - public override void onRemovedFromEntity() + public override void OnRemovedFromEntity() { // remove ourselves when we are removed from the Scene - Core.getGlobalManager().unregisterDrawCommand(imGuiDraw); + Core.GetGlobalManager().UnregisterDrawCommand(ImGuiDraw); } - void imGuiDraw() + void ImGuiDraw() { // do your actual drawing here ImGui.Begin("Your ImGui Window", ImGuiWindowFlags.AlwaysAutoResize); diff --git a/project_name/Game1.cs b/project_name/Game1.cs old mode 100644 new mode 100755 index 37a9350..fc9fa2d --- a/project_name/Game1.cs +++ b/project_name/Game1.cs @@ -16,11 +16,11 @@ namespace project_name System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out)); #endif - scene = new DefaultScene(); + Scene = new DefaultScene(); // optionally render Nez in an ImGui window var imGuiManager = new ImGuiManager(); - Core.registerGlobalManager(imGuiManager); + Core.RegisterGlobalManager(imGuiManager); } } -} \ No newline at end of file +} From dbf800af4d8563cd1b892b2d1a10a5e9af9d0b6b Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 7 Sep 2019 22:40:45 -0700 Subject: [PATCH 02/11] fix launch without build bbug --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index de33671..3844555 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -22,7 +22,7 @@ "name": "Launch Without Building", "type": "mono", "request": "launch", - "program": "${workspaceFolder}/Fook/bin/Debug/Fook.exe", + "program": "${workspaceFolder}/Fook/bin/Debug/project_name.exe", "cwd": "${workspaceFolder}", "osx":{ "env": { From d11f285680e9b569f68a1bd4fbd2b8e4cfe3f34b Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 7 Sep 2019 22:42:09 -0700 Subject: [PATCH 03/11] fix launch without build bug, this time for real --- .vscode/launch.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3844555..8a2fffb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -22,11 +22,11 @@ "name": "Launch Without Building", "type": "mono", "request": "launch", - "program": "${workspaceFolder}/Fook/bin/Debug/project_name.exe", + "program": "${workspaceFolder}/project_name/bin/Debug/project_name.exe", "cwd": "${workspaceFolder}", "osx":{ "env": { - "DYLD_LIBRARY_PATH": "${workspaceFolder}/Fook/bin/Debug/osx/" + "DYLD_LIBRARY_PATH": "${workspaceFolder}/project_name/bin/Debug/osx/" }, } }, From 94701480571f3036b39d6c77452304fc9cc23b45 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 16 Sep 2019 22:20:17 -0700 Subject: [PATCH 04/11] pixel art helper added and commented out --- project_name/Game1.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/project_name/Game1.cs b/project_name/Game1.cs index fc9fa2d..b6d1b00 100755 --- a/project_name/Game1.cs +++ b/project_name/Game1.cs @@ -12,6 +12,9 @@ namespace project_name { base.Initialize(); + // uncomment this line for scaled pixel art games + //Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); + #if DEBUG System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out)); #endif From 500f1e442023783af5c9759a6a7d5a037d26141a Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 19 Sep 2019 16:42:47 -0700 Subject: [PATCH 05/11] minor cleanup of Game --- project_name/Game1.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/project_name/Game1.cs b/project_name/Game1.cs index b6d1b00..869fe32 100755 --- a/project_name/Game1.cs +++ b/project_name/Game1.cs @@ -6,24 +6,29 @@ namespace project_name class Game1 : Core { public Game1() : base() - {} + { + // uncomment this line for scaled pixel art games + //Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); + } override protected void Initialize() { base.Initialize(); - // uncomment this line for scaled pixel art games - //Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); - #if DEBUG System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out)); #endif Scene = new DefaultScene(); - + // optionally render Nez in an ImGui window var imGuiManager = new ImGuiManager(); Core.RegisterGlobalManager(imGuiManager); + +#if DEBUG + // optionally load up ImGui DLL if not using the above setup so that its command gets loaded in the DebugConsole + //System.Reflection.Assembly.Load("Nez.ImGui") +#endif } } } From ab8debb952f29f76df0da59f5cb58343fc1a31a7 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 20 Sep 2019 22:25:59 -0700 Subject: [PATCH 06/11] new folder structure for content --- .../{Content-Goes-Here.txt => Atlases/.keep} | 0 project_name/Content/Audio/.keep | 0 project_name/Content/Fonts/.keep | 0 project_name/Content/Materials/.keep | 0 project_name/Content/Shaders/.keep | 0 project_name/Content/Textures/.keep | 0 project_name/Content/Tilemaps/.keep | 0 .../T4Templates/ContentPathGenerator.tt | 272 ++++++++++++------ 8 files changed, 182 insertions(+), 90 deletions(-) rename project_name/Content/{Content-Goes-Here.txt => Atlases/.keep} (100%) create mode 100644 project_name/Content/Audio/.keep create mode 100644 project_name/Content/Fonts/.keep create mode 100644 project_name/Content/Materials/.keep create mode 100644 project_name/Content/Shaders/.keep create mode 100644 project_name/Content/Textures/.keep create mode 100644 project_name/Content/Tilemaps/.keep mode change 100644 => 100755 project_name/T4Templates/ContentPathGenerator.tt diff --git a/project_name/Content/Content-Goes-Here.txt b/project_name/Content/Atlases/.keep similarity index 100% rename from project_name/Content/Content-Goes-Here.txt rename to project_name/Content/Atlases/.keep diff --git a/project_name/Content/Audio/.keep b/project_name/Content/Audio/.keep new file mode 100644 index 0000000..e69de29 diff --git a/project_name/Content/Fonts/.keep b/project_name/Content/Fonts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/project_name/Content/Materials/.keep b/project_name/Content/Materials/.keep new file mode 100644 index 0000000..e69de29 diff --git a/project_name/Content/Shaders/.keep b/project_name/Content/Shaders/.keep new file mode 100644 index 0000000..e69de29 diff --git a/project_name/Content/Textures/.keep b/project_name/Content/Textures/.keep new file mode 100644 index 0000000..e69de29 diff --git a/project_name/Content/Tilemaps/.keep b/project_name/Content/Tilemaps/.keep new file mode 100644 index 0000000..e69de29 diff --git a/project_name/T4Templates/ContentPathGenerator.tt b/project_name/T4Templates/ContentPathGenerator.tt old mode 100644 new mode 100755 index 9483dc2..1a2687d --- a/project_name/T4Templates/ContentPathGenerator.tt +++ b/project_name/T4Templates/ContentPathGenerator.tt @@ -8,48 +8,75 @@ <#@ import namespace="System.Globalization" #> <#@ import namespace="System.Text.RegularExpressions" #> -<# var sourceFolders = new string[] { "CompiledContent/bin/DesktopGL", "Content" }; #> - - namespace Nez { public static class Content { -<# - - // loop through all of our sourceFolders - foreach( var sourceFolder in sourceFolders ) - { - WriteLine( $"\t\t// folder: {sourceFolder}" ); - - // handle any files in the root sourceFolder - printContentFiles( sourceFolder, 2, sourceFolder ); - - // loop through all the directories in our sourceFolder - var directories = Directory.GetDirectories( sourceFolder ); - foreach( var dir in directories ) + public static class Nez { - var dirName = new DirectoryInfo( dir ).Name.ToLower(); - if( dirName == "bin" || dirName == "obj" || dirName == "content" ) - continue; - - // dont delve into directories that don't contan xnb files if this is the CompiledContent folder - if( !shouldTraverseSubfolders( dir ) ) - continue; - - // start off the recursive directory printing - printDirectoryClass( dir, 2, sourceFolder ); +<# PrintNezContent(); #> } - } -#> + + public static class Audio + { +<# PrintAudio(); #> + } + + public static class Fonts + { +<# PrintFonts(); #> + } + + public static class Materials + { +<# PrintMaterials(); #> + } + + public static class Particles + { +<# PrintParticles(); #> + } + + public static class Shaders + { +<# PrintShaders(); #> + } + + public static class Tilemaps + { +<# PrintTilemaps(); #> + } + + public static class Textures + { +<# PrintTextures(); #> + } + + public static class Atlases + { +<# PrintAtlases(); #> + } + + public static class Compiled + { +<# PrintCompiledContent(); #> + } + } } <#+ - // all the valid file extensions we should add to the output file - private string[] fileExtensionsToCopy = new string[] { ".xnb", ".png", ".ogg", ".wav", ".fxb" }; + // all the valid file extensions we should copy for each root folder + private string[] validAudioExtensions = new string[] { ".ogg", ".wav" }; + private string[] validFontExtensions = new string[] { ".fnt" }; + private string[] validMaterialExtensions = new string[] { ".mat" }; + private string[] validParticleExtensions = new string[] { ".pex" }; + private string[] validShaderExtensions = new string[] { ".fxb" }; + private string[] validTilemapExtensions = new string[] { ".tmx" }; + private string[] validTextureExtensions = new string[] { ".png", ".jpg" }; + private string[] validAtlasExtensions = new string[] { ".atlas" }; // C# reserved keywords private System.Collections.Generic.List keywords = new System.Collections.Generic.List @@ -61,105 +88,170 @@ namespace Nez "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while" }; - bool shouldTraverseSubfolders( string path ) + void PrintNezContent() { - if( !path.Contains( "/bin/" ) ) + PrintSpecialFolderAndSubfolders("../Nez/DefaultContent", new string[] { ".xnb", ".fxb" }, true); + } + + void PrintAudio() + { + PrintSpecialFolderAndSubfolders("Content/Audio", validAudioExtensions); + } + + void PrintFonts() + { + PrintSpecialFolderAndSubfolders("Content/Fonts", validFontExtensions); + } + + void PrintMaterials() + { + PrintSpecialFolderAndSubfolders("Content/Materials", validMaterialExtensions); + } + + void PrintParticles() + { + PrintSpecialFolderAndSubfolders("Content/Particles", validParticleExtensions); + } + + void PrintShaders() + { + PrintSpecialFolderAndSubfolders("Content/Shaders", validShaderExtensions); + } + + void PrintTextures() + { + PrintSpecialFolderAndSubfolders("Content/Textures", validTextureExtensions); + } + + void PrintAtlases() + { + PrintSpecialFolderAndSubfolders("Content/Atlases", validAtlasExtensions); + } + + void PrintTilemaps() + { + PrintSpecialFolderAndSubfolders("Content/Tilemaps", validTilemapExtensions); + } + + void PrintCompiledContent() + { + PrintSpecialFolderAndSubfolders("CompiledContent/bin/DesktopGL", new string[] { ".xnb" }, true); + } + + void PrintSpecialFolderAndSubfolders(string source, string[] validExtensions, bool isCompiledFolder = false) + { + var stripPath = isCompiledFolder ? source : ""; + PrintContentFiles(source, 3, stripPath, validExtensions); + + // loop through all the directories in our sourceFolder + foreach (var dir in Directory.GetDirectories(source)) { - return true; + var dirName = new DirectoryInfo(dir).Name.ToLower(); + PrintDirectoryClass(dir, 3, stripPath, validExtensions, isCompiledFolder); } - - return Directory.GetFiles( path, "*.xnb", SearchOption.AllDirectories ).Length > 0; } // recursively creates a class for each directory - void printDirectoryClass( string dir, int depth, string sourceFolder ) + void PrintDirectoryClass(string dir, int depth, string sourceFolder, string[] validFileExtensions, bool isCompiledFolder) { - var dirInfo = new DirectoryInfo( dir ); - var firstIndent = new string( ' ', depth * 4 ); - var className = generateClassName( dirInfo.Name, true ); - WriteLine( "{0}public static class {1}\n{2}{{", firstIndent, className, firstIndent ); + var dirInfo = new DirectoryInfo(dir); + var firstIndent = new string(' ', depth * 4); + var className = GenerateClassName(dirInfo.Name, true); + + if (!FolderHasContent(dir, validFileExtensions)) + return; + + // fix our class name if this is the FNAEffects folder + if (dir.Contains("Nez/DefaultContent") && className == "FNAEffects") + className = "Effects"; + WriteLine("{0}public static class {1}\n{2}{{", firstIndent, className, firstIndent); // handle subdirectories - foreach( var subdir in Directory.GetDirectories( dir ) ) - printDirectoryClass( subdir, depth + 1, sourceFolder ); + foreach (var subdir in Directory.GetDirectories(dir)) + PrintDirectoryClass(subdir, depth + 1, sourceFolder, validFileExtensions, isCompiledFolder); // handle files - printContentFiles( dir, depth + 1, sourceFolder ); + PrintContentFiles(dir, depth + 1, sourceFolder, validFileExtensions); - WriteLine( "{0}}}\n", firstIndent ); + WriteLine("{0}}}\n", firstIndent); } - // prints a const string for each file in the directory - void printContentFiles( string dir, int depth, string sourceFolder ) + void PrintContentFiles(string dir, int depth, string sourceFolder, string[] validFileExtensions) { - var firstIndent = new string( ' ', depth * 4 ); + var firstIndent = new string('\t', depth); - var files = Directory.EnumerateFiles( dir ) - .Where( s => Array.IndexOf( fileExtensionsToCopy, Path.GetExtension( s ) ) >= 0 ); - foreach( var file in files ) + var files = Directory.EnumerateFiles(dir) + .Where( s => Array.IndexOf(validFileExtensions, Path.GetExtension(s)) >= 0); + foreach (var file in files) { // clear out all of the path up to the sourceFolder so we get just the relative path to the Content folder - var finalPath = file.Substring( file.IndexOf( sourceFolder ) + sourceFolder.Length ); - var fileInfo = new FileInfo( file ); + var finalPath = file.Substring(file.IndexOf(sourceFolder) + sourceFolder.Length); + var fileInfo = new FileInfo(file); var fileName = fileInfo.Name; // clean the extension - foreach( var extension in fileExtensionsToCopy ) + foreach (var extension in validFileExtensions) + fileName = fileName.Replace(extension, string.Empty); + + var className = GenerateClassName(fileName, false); + + if (finalPath[0] == '/' || finalPath[0] == '\\') + finalPath = finalPath.Substring(1); + + // remove xnb extensions to avoid issues with loading + finalPath = finalPath.Replace(".xnb", string.Empty); + + // deal with built-in Nez content pathing + if (dir.Contains("Nez/DefaultContent")) { - fileName = fileName.Replace( extension, string.Empty ); + if (dir.Contains("FNAEffects")) + { + finalPath = finalPath.Replace("FNAEffects", "Effects"); + finalPath = "Content/Nez/" + finalPath; + } + else if(dir.Contains("Textures")) + { + finalPath = "Nez/" + finalPath; + } } - var className = generateClassName( fileName, false ); - - if( finalPath[0] == '/' || finalPath[0] == '\\' ) - finalPath = finalPath.Substring( 1 ); - // if file name is reserved insert a leading '@' - if( keywords.Contains( className ) ) + if (keywords.Contains(className)) className = className.Insert( 0, "@" ); - WriteLine( "{0}public const string {1} = @\"{2}\";", firstIndent, className, finalPath ); + WriteLine("{0}public const string {1} = @\"{2}\";", firstIndent, className, finalPath); } - if( files.Count() > 0 ) - { - WriteLine( "" ); - } + if (files.Count() > 0) + WriteLine(""); } - - string stripInvalidPathChars( string input ) - { - var invalidChars = Path.GetInvalidPathChars(); - return new string( input.Where( m => !invalidChars.Contains( m ) ).ToArray() ); - } - - - string stripInvalidFilenameChars( string input ) - { - var invalidChars = Path.GetInvalidFileNameChars(); - return new string( input.Where( m => !invalidChars.Contains( m ) ).ToArray() ); - } - - // attempts to generate a proper path name - string generateClassName( string className, bool uppercaseFirstChar ) + string GenerateClassName(string className, bool uppercaseFirstChar) { // handle upper or lower casing the first char in the className - if( uppercaseFirstChar && char.IsLower( className[0] ) ) - className = char.ToUpper( className[0] ) + className.Substring( 1 ); - else if( !uppercaseFirstChar && char.IsUpper( className[0] ) ) - className = char.ToLower( className[0] ) + className.Substring( 1 ); + if (uppercaseFirstChar && char.IsLower(className[0])) + className = char.ToUpper(className[0]) + className.Substring(1); + + className = className.Replace("-", "_"); // remove invalid characters - var regex = new Regex( @"[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Nl}\p{Mn}\p{Mc}\p{Cf}\p{Pc}\p{Lm}]" ); - className = regex.Replace( className, "" ); + var regex = new Regex(@"[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Nl}\p{Mn}\p{Mc}\p{Cf}\p{Pc}\p{Lm}]"); + className = regex.Replace(className, ""); // class name doesn't begin with a letter, insert an underscore - if( !char.IsLetter( className, 0 ) ) - className = className.Insert( 0, "_" ); + if (!char.IsLetter(className, 0)) + className = className.Insert(0, "_"); - return className.Replace( " ", string.Empty ); + return className.Replace(" ", string.Empty); + } + + // returns true if the folder or any subfolder has some content with a valid file extension + bool FolderHasContent(string dir, string[] validFileExtensions) + { + var files = Directory.EnumerateFiles(dir) + .Where( s => Array.IndexOf(validFileExtensions, Path.GetExtension(s)) >= 0); + return files.Count() > 0; } #> From f1b227884926d04cd165a9c004b067c9eaf64d1c Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 20 Sep 2019 22:26:15 -0700 Subject: [PATCH 07/11] new scene and game template --- project_name/DefaultScene.cs | 5 ++--- project_name/Game1.cs | 10 ++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/project_name/DefaultScene.cs b/project_name/DefaultScene.cs index b57f723..2e1f3e1 100755 --- a/project_name/DefaultScene.cs +++ b/project_name/DefaultScene.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Nez; +using Nez.Sprites; namespace project_name { @@ -10,8 +11,6 @@ namespace project_name { SetDesignResolution(Screen.Width, Screen.Height, Scene.SceneResolutionPolicy.None); - AddRenderer(new DefaultRenderer()); - CreateEntity("demo imgui draw commands") .SetPosition(new Vector2(150, 150)) .AddComponent() @@ -20,7 +19,7 @@ namespace project_name var logo = Content.Load("nez-logo-black"); CreateEntity("logo") .SetPosition(Screen.Center) - .AddComponent(new Nez.Sprites.Sprite(logo)); + .AddComponent(new SpriteRenderer(logo)); } } } diff --git a/project_name/Game1.cs b/project_name/Game1.cs index 869fe32..84800cf 100755 --- a/project_name/Game1.cs +++ b/project_name/Game1.cs @@ -8,24 +8,22 @@ namespace project_name public Game1() : base() { // uncomment this line for scaled pixel art games - //Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); + // System.Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); } override protected void Initialize() { base.Initialize(); - -#if DEBUG - System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out)); -#endif Scene = new DefaultScene(); +#if DEBUG + System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out)); + // optionally render Nez in an ImGui window var imGuiManager = new ImGuiManager(); Core.RegisterGlobalManager(imGuiManager); -#if DEBUG // optionally load up ImGui DLL if not using the above setup so that its command gets loaded in the DebugConsole //System.Reflection.Assembly.Load("Nez.ImGui") #endif From 6b0765a8a2d8fcdf1c4c5c5704d7562059bce179 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 20 Sep 2019 22:32:57 -0700 Subject: [PATCH 08/11] no more zlib --- README.md | 4 ++-- project_name/CompiledContent/Content.mgcb | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 581d540..2641f4e 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ Start new FNA projects with Nez quickly and easily with handy setup scripts, a v That's it! Now you're ready to build and run the base project. If you get missing DLL errors (pointing at SDL) when running in Visual Studio copy the FNA libs into your `/usr/local/lib` folder. With Visual Studio Code, `DYLD_LIBRARY_PATH` is set automatically so it won't run into the DLL not found error. Nez is setup as a submodule so you can update it in the normal fashion. -When developing, raw content (files not processed by the Pipeline tool) should be placed in the `Content` folder and anything that needs processing should go in the `CompiledContent` folder and added to the Pipeline tool. +When developing, raw content (files not processed by the Pipeline tool) should be placed in the `Content` folder's subfolders and anything that needs processing should go in the `CompiledContent` folder and added to the Pipeline tool. The setup process will also init a git repo for you with Nez added as a submodule. -If you want to see the output of `Debug.*` calls in the VS Code Debug Console, you have to install a listener by adding this somewhere in your code (Game1 by default has one for you): `System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out));` +If you want to see the output of `Debug.*` calls in the VS Code Debug Console, you have to install a listener by adding this somewhere in your code (Game1 by default has one for you): `System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(System.Console.Out));` Pixel art games should also uncomment a line in the Game1.cs file setting the `FNA_OPENGL_BACKBUFFER_SCALE_NEAREST` environment variable when using FNA. ## Build Tasks ## diff --git a/project_name/CompiledContent/Content.mgcb b/project_name/CompiledContent/Content.mgcb index 2194a6b..45c48e4 100644 --- a/project_name/CompiledContent/Content.mgcb +++ b/project_name/CompiledContent/Content.mgcb @@ -10,7 +10,6 @@ #-------------------------------- References --------------------------------# -/reference:../../Nez/Nez.PipelineImporter/bin/Debug/Ionic.ZLib.dll /reference:../../Nez/Nez.PipelineImporter/bin/Debug/Newtonsoft.Json.dll /reference:../../Nez/Nez.PipelineImporter/bin/Debug/Nez.PipelineImporter.dll /reference:../../Nez/Nez.PipelineImporter/bin/Debug/Nez.dll From 98ccbd2f66a4133e8c9165159bb1ab6f6371f0b9 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 20 Sep 2019 22:38:27 -0700 Subject: [PATCH 09/11] learning english --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2641f4e..fe8aa2d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Start new FNA projects with Nez quickly and easily with handy setup scripts, a v That's it! Now you're ready to build and run the base project. If you get missing DLL errors (pointing at SDL) when running in Visual Studio copy the FNA libs into your `/usr/local/lib` folder. With Visual Studio Code, `DYLD_LIBRARY_PATH` is set automatically so it won't run into the DLL not found error. Nez is setup as a submodule so you can update it in the normal fashion. -When developing, raw content (files not processed by the Pipeline tool) should be placed in the `Content` folder's subfolders and anything that needs processing should go in the `CompiledContent` folder and added to the Pipeline tool. +When developing, raw content (files not processed by the Pipeline tool) should be placed in the `Content` folders subfolders and anything that needs processing should go in the `CompiledContent` folder and added to the Pipeline tool. The setup process will also init a git repo for you with Nez added as a submodule. From e97423d34feef79032cef0eda3c23ce261d6f163 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 20 Sep 2019 23:03:36 -0700 Subject: [PATCH 10/11] windows support from PR 3 --- .vscode/launch.json | 26 ++++- .vscode/processT4Templates.ps1 | 27 +++++ .vscode/tasks.json | 53 +++++++-- README.md | 6 +- getFNA.ps1 | 181 +++++++++++++++++++++++++++++++ project_name.sln | 11 ++ project_name/project_name.csproj | 1 + 7 files changed, 287 insertions(+), 18 deletions(-) create mode 100644 .vscode/processT4Templates.ps1 create mode 100644 getFNA.ps1 diff --git a/.vscode/launch.json b/.vscode/launch.json index 8a2fffb..b26c771 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,8 +4,9 @@ "version": "0.2.0", "configurations": [ + { - "name": "Launch", + "name": "Launch (Mac)", "type": "mono", "request": "launch", "program": "${workspaceFolder}/project_name/bin/Debug/project_name.exe", @@ -14,12 +15,12 @@ "osx":{ "env": { "DYLD_LIBRARY_PATH": "${workspaceFolder}/project_name/bin/Debug/osx/" - }, + } } }, { - "name": "Launch Without Building", + "name": "Launch Without Building (Mac)", "type": "mono", "request": "launch", "program": "${workspaceFolder}/project_name/bin/Debug/project_name.exe", @@ -27,10 +28,27 @@ "osx":{ "env": { "DYLD_LIBRARY_PATH": "${workspaceFolder}/project_name/bin/Debug/osx/" - }, + } } }, + { + "name": "Launch (Windows)", + "type": "clr", + "request": "launch", + "program": "${workspaceFolder}/project_name/bin/Debug/project_name.exe", + "cwd": "${workspaceFolder}/project_name", + "preLaunchTask": "Build (Debug)" + }, + + { + "name": "Launch Without Building (Windows)", + "type": "clr", + "request": "launch", + "program": "${workspaceFolder}/project_name/bin/Debug/project_name.exe", + "cwd": "${workspaceFolder}" + }, + { "name": "Attach", "type": "mono", diff --git a/.vscode/processT4Templates.ps1 b/.vscode/processT4Templates.ps1 new file mode 100644 index 0000000..974975a --- /dev/null +++ b/.vscode/processT4Templates.ps1 @@ -0,0 +1,27 @@ +#!/bin/bash +# buildEffects +# Compiles all .fx files found in the project's Content directory. +# Intended for usage with VS Code Build Tasks tooling. +# You may need to change the path to fxc.exe depending on your installation. + +Write-Output "Starting T4 processing..." + +Set-Location $PSScriptRoot +Set-Location ..\project_name + +# create our output directory +if ((Test-Path("T4Templates\Output")) -eq 0) { New-Item -ItemType "directory" -Path "T4Templates\Output" } + +$files = Get-ChildItem ".\T4Templates\*" -Include *.tt + +foreach ($file in $files) +{ + $fileName = $file.BaseName + # Build the template + t4 -r System.dll -r mscorlib.dll -r netstandard.dll -r System.IO.FileSystem.dll -r System.Linq.dll -r System.Text.RegularExpressions -o "T4Templates\Output\${fileName}.cs" "T4Templates\${fileName}.tt" + + Write-Output "Built ${fileName}.cs from ${fileName}.tt" +} + + + diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bf8d65f..fdf992d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -16,7 +16,7 @@ // - clean, restore and rebuild Nez.FNA.sln (nuget restore Nez.FNA) "label": "Update, Restore and Rebuild Nez", "type": "shell", - "command": "git submodule foreach --recursive git pull && msbuild Nez/Nez.sln '/t:clean;restore;build' && msbuild Nez/Nez.FNA.sln '/t:clean;restore;build'", + "command": "git submodule foreach --recursive git pull && msbuild Nez/Nez.sln /t:clean /t:restore && msbuild Nez/Nez.FNA.sln /t:clean /t:restore", "group": "build", "problemMatcher": "$msCompile", "presentation": { @@ -32,7 +32,7 @@ { "label": "Clean Project", "type": "shell", - "command": "msbuild project_name /t:clean /p:configuration=Debug ; msbuild project_name /t:clean /p:configuration=Release", + "command": "msbuild project_name /t:clean /p:configuration=Debug && msbuild project_name /t:clean /p:configuration=Release", "group": "build", "problemMatcher": "$msCompile", }, @@ -42,8 +42,9 @@ "type": "shell", "command": "msbuild", "args": [ - "project_name", + "project_name.sln", "/p:configuration=Debug", + "/p:platform=Any CPU", "/t:build" ], "group": "build", @@ -56,8 +57,9 @@ "type": "shell", "command": "msbuild", "args": [ - "project_name", + "project_name.sln", "/p:configuration=Release", + "/p:platform=Any CPU", "/t:build" ], "group": "build", @@ -72,9 +74,9 @@ "command": "DYLD_LIBRARY_PATH=${workspaceFolder}/project_name/bin/Debug/osx/ mono ${workspaceFolder}/project_name/bin/Debug/project_name.exe" }, "windows":{ - "command": "cmd", + "command": "start", "args": [ - "/k", + "/wait", "${workspaceFolder}/project_name/bin/Debug/project_name.exe" ] }, @@ -90,9 +92,9 @@ "command": "DYLD_LIBRARY_PATH=${workspaceFolder}/project_name/bin/Release/osx/ mono ${workspaceFolder}/project_name/bin/Release/project_name.exe" }, "windows":{ - "command": "cmd", + "command": "start", "args": [ - "/k", + "/wait", "${workspaceFolder}/project_name/bin/Release/project_name.exe" ] }, @@ -108,7 +110,11 @@ "command": "${workspaceFolder}/.vscode/buildEffects.sh" }, "windows":{ - "command": "& ${workspaceFolder}/.vscode/buildEffects.ps1" + "command": "powershell", + "args": [ + "-File", + "${workspaceFolder}/.vscode/buildEffects.ps1" + ], }, "problemMatcher": "$msCompile" }, @@ -128,7 +134,16 @@ "label": "Force Build Content", "type": "shell", "group": "build", - "command": "mono /Applications/Pipeline.app/Contents/MonoBundle/MGCB.exe /@:Content.mgcb -r", + "osx": { + "command": "mono /Applications/Pipeline.app/Contents/MonoBundle/MGCB.exe /@:Content.mgcb -r", + }, + "windows": { + "command":"C:/Program Files (x86)/MSBuild/MonoGame/v3.0/Tools/MGCB.exe", + "args": [ + "/@:Content.mgcb", + "-r" + ] + }, "options": { "cwd": "${workspaceFolder}/project_name/CompiledContent" }, @@ -139,14 +154,28 @@ "label": "Open Pipeline Tool", "type": "shell", "group": "build", - "command": "export MONOGAME_PIPELINE_PROJECT=${workspaceFolder}/project_name/CompiledContent/Content.mgcb && /Applications/Pipeline.app/Contents/MacOS/Pipeline", + "osx": { + "command": "export MONOGAME_PIPELINE_PROJECT=${workspaceFolder}/project_name/CompiledContent/Content.mgcb && /Applications/Pipeline.app/Contents/MacOS/Pipeline" + }, + "windows": { + "command": "${workspaceFolder}/project_name/CompiledContent/Content.mgcb" + }, "problemMatcher": "$msCompile" }, { "label": "Process T4 Templates", "type": "shell", - "command": "${workspaceFolder}/.vscode/processT4Templates.sh", + "osx": { + "command": "${workspaceFolder}/.vscode/processT4Templates.sh" + }, + "windows": { + "command": "powershell", + "args": [ + "-File", + "${workspaceFolder}/.vscode/processT4Templates.ps1" + ] + }, "group": "build", "problemMatcher": "$msCompile", }, diff --git a/README.md b/README.md index fe8aa2d..b9f15d7 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,17 @@ Start new FNA projects with Nez quickly and easily with handy setup scripts, a v ## Prerequisites ## - [Visual Studio Code](https://code.visualstudio.com) or [Visual Studio](https://visualstudio.microsoft.com/) (recommended to use Visual Studio Code because it has some custom tasks but either will work fine) - - [Mono Debugger Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.mono-debug) (required for macOS debugging) +- [Mono Debugger Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.mono-debug) (required for macOS debugging) - [MonoGame](http://www.monogame.net/downloads/) (required for compiling content with the Pipeline tool) - (optional) [.NET Core](https://dotnet.microsoft.com/download) (required for compiling T4 templates) - (optional) [Microsoft DirectX SDK (June 2010)](https://www.microsoft.com/en-us/download/details.aspx?id=6812) (required for building effects, [you can use Wine to run this](https://github.com/AndrewRussellNet/FNA-Template#linuxmacos-installing-the-directx-sdk-on-wine)) +- (windows only) [7zip](https://www.7-zip.org) (if intending to use fnalibs, the filetype is unsupported for windows and requires 7zip to be installed to decompress/unzip) +- (windows only) [Build tools for Visua Studio](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16)(these build tools are required for all Visual Studio Code build tasks. if you intend to use the full Visual Studio, these are already included. be sure to include .NET Core Build Tools in the installation) ## Setup Instructions ## 1. Download and unzip the ZIP archive (don't clone the repo!) -2. Run `./getFNA.sh` (macOS) to download the latest Nez, FNA and fnalibs to the directory. You can run this script again if you want to update either FNA or the fnalibs at a later point. +2. Run `./getFNA.sh` (macOS) or `./getFNA.ps1` (windows) to download the latest Nez, FNA and fnalibs to the directory. You can run this script again if you want to update either FNA or the fnalibs at a later point. 3. Open the root folder that contains the .sln file in Visual Studio Code or the .sln file directly in Visual Studio. Note that only Visual Studio Code has an effect builder command. That's it! Now you're ready to build and run the base project. If you get missing DLL errors (pointing at SDL) when running in Visual Studio copy the FNA libs into your `/usr/local/lib` folder. With Visual Studio Code, `DYLD_LIBRARY_PATH` is set automatically so it won't run into the DLL not found error. Nez is setup as a submodule so you can update it in the normal fashion. diff --git a/getFNA.ps1 b/getFNA.ps1 new file mode 100644 index 0000000..162c762 --- /dev/null +++ b/getFNA.ps1 @@ -0,0 +1,181 @@ +#!/bin/bash +# Program: getFNA +# Author: Caleb Cornett (converted to powershell to work with windows) +# Usage: ./getFNA.sh +# Description: Quick and easy way to install a local copy of FNA and its native libraries. + +# Checks if dotnet is installed +function checkDotnet() +{ + try { dotnet | Out-Null } + catch [System.Management.Automation.CommandNotFoundException] + { + Write-Output "ERROR: Dotnet is not installed. Please install dotnet to download the t4 tool." + exit + } +} + +function checkMsbuild () +{ + try { msbuild | Out-Null } + catch [System.Management.Automation.CommandNotFoundException] + { + Write-Output "ERROR: Msbuild is not available, please ensure msbuild.exe is installed and added to the PATH Environment Variable." + exit + } +} + +function check7zip () +{ + if ((Test-Path "C:\Program Files\7-Zip") -eq 0) + { + Write-Output "ERROR: 7zip is not installed, please install 7zip and try again." + exit + } +} + +function installT4 () +{ + if (checkDotnet) { Invoke-Expression 'dotnet tool install -g dotnet-t4' } +} + +function checkGit () +{ + try { git | Out-Null } + catch [System.Management.Automation.CommandNotFoundException] + { + Write-Output "ERROR: Git is not installed. Please install git to download FNA." + exit + } +} + +function downloadFNA() +{ + checkGit + git -C $PSScriptRoot clone https://github.com/FNA-XNA/FNA.git --recursive + + if ($? -eq 1) { Write-Output "Finished Downloading!" } + else { Write-Output "ERROR: Download failed, try again later?" exit} + +} + +function updateFNA () +{ + checkGit + Write-Output "Updating to the latest git version of FNA..." + + git -C "${PSScriptRoot}\FNA" pull --recurse-submodules + + if ($? -eq 1) { Write-Output "Finished updating!" } + else { Write-Output "ERROR: Unable to update." exit} +} + + + +function getLibs () +{ + Write-Output "Downloading the latest FNAlibs..." + Invoke-WebRequest -Uri http://fna.flibitijibibo.com/archive/fnalibs.tar.bz2 -OutFile "${PSScriptRoot}/fnalibs.tar.bz2" + if ($? -eq 1) { Write-Output "Finished downloading!" } + else { Write-Output "ERROR: Unable to download successfully." exit} + + Write-Output "Decompressing fnalibs..." + check7zip + if ((Test-Path "${PSScriptRoot}\fnalibs") -eq 0) + { + & "C:\Program Files\7-Zip\7z.exe" x "fnalibs.tar.bz2" + if ($? -eq 1){ Remove-Item "fnalibs.tar.bz2"} + else { Write-Output "ERROR: Unable to decompress successfully." exit } + & "C:\Program Files\7-Zip\7z.exe" x "fnalibs.tar" -ofnalibs + if ($? -eq 1) + { + Remove-Item "fnalibs.tar" + Write-Output "Finished decompressing!" + } + else { Write-Output "ERROR: Unable to decompress successfully." exit } + } + +} + +checkMsbuild + +if (Test-Path "${PSScriptRoot}\FNA") +{ + #if ((Read-Host -Prompt "Update FNA (y/n)?") -like 'y') { $shouldUpdate = true } + $shouldUpdate = Read-Host -Prompt "Update FNA (y/n)?" +} +else +{ + #if ((Read-Host -Prompt "Download FNA (y/n)?") -like 'y') { $shouldDownload = true } + $shouldDownload = Read-Host -Prompt "Download FNA (y/n)?" +} + +if (Test-Path "${PSScriptRoot}\fnalibs") +{ + #if ((Read-Host -Prompt "Redownload fnalibs (y/n)?") -like 'y') { $shouldDownloadLibs = true } + $shouldDownloadLibs = Read-Host -Prompt "Redownload fnalibs (y/n)?" +} +else +{ + #if ((Read-Host -Prompt "Download fnalibs (y/n)?") -like 'y') { $shouldDownloadLibs = true } + $shouldDownloadLibs = Read-Host -Prompt "Download fnalibs (y/n)?" +} + +if ((Test-Path "${PSScriptRoot}\project_name") -eq 1) +{ + $newProjectName = Read-Host -Prompt "Enter the project name to use for your folder and csproj file or 'exit' to quit: " +} + +if ($shouldDownload -like 'y') { downloadFNA } +elseif ($shouldUpdate -like 'y') { updateFNA } + +if ($shouldDownloadLibs -like 'y') { getLibs } + +installT4 + +# Only proceed from here if we have not yet renamed the project +if ((Test-Path "${PSScriptRoot}\project_name") -ne 1) { exit } + + +if ($newProjectName -eq "exit" -or $newProjectName -eq "") { exit } + +$files= "project_name.sln", + ".gitignore", + "project_name/project_name.csproj", + "project_name/Game1.cs", + "project_name/DemoComponent.cs", + "project_name/DefaultScene.cs", + "project_name/Program.cs", + ".vscode/tasks.json", + ".vscode/settings.json", + ".vscode/launch.json", + ".vscode/buildEffects.sh", + ".vscode/processT4Templates.sh", + ".vscode/buildEffects.ps1", + ".vscode/processT4Templates.ps1" + +foreach ($file in $files) +{ + ((Get-Content -Path $file -Raw) -replace 'project_name', $newProjectName) | Set-Content -Path $file +} + +Rename-Item -Path "project_name.sln" -NewName "${newProjectName}.sln" +Rename-Item -Path "project_name/project_name.csproj" -NewName "${newProjectName}.csproj" +Rename-Item -Path "project_name/project_name.csproj.user" -NewName "${newProjectName}.csproj.user" +Rename-Item -Path "project_name" -NewName $newProjectName + +git init +git submodule add https://github.com/prime31/Nez.git +Set-Location Nez +git submodule init +git submodule update + +"Restoring..." +Set-Location $PSScriptRoot +dotnet restore "Nez/Nez.sln" + +"Building..." +msbuild "Nez/Nez.sln" +msbuild -t:restore $newProjectName +msbuild -t:buildcontent $newProjectName +msbuild "${newProjectName}.sln" diff --git a/project_name.sln b/project_name.sln index c956a2f..c930ef8 100644 --- a/project_name.sln +++ b/project_name.sln @@ -24,8 +24,19 @@ Global {16DA6D66-4DFD-46D4-A367-C02B48B80CAA}.Debug|Any CPU.Build.0 = Debug|Any CPU {26DA6D66-4DFD-46D4-A367-C02B48B80CAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {26DA6D66-4DFD-46D4-A367-C02B48B80CAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3CB9E917-FEF7-453F-A88D-6B85B552B058}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3CB9E917-FEF7-453F-A88D-6B85B552B058}.Release|Any CPU.Build.0 = Release|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|Any CPU.Build.0 = Release|Any CPU + {11A5855C-B12C-4F8D-B935-56F3D0B671C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11A5855C-B12C-4F8D-B935-56F3D0B671C3}.Release|Any CPU.Build.0 = Release|Any CPU + {16DA6D66-4DFD-46D4-A367-C02B48B80CAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16DA6D66-4DFD-46D4-A367-C02B48B80CAA}.Release|Any CPU.Build.0 = Release|Any CPU + {26DA6D66-4DFD-46D4-A367-C02B48B80CAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26DA6D66-4DFD-46D4-A367-C02B48B80CAA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU EndGlobalSection EndGlobal diff --git a/project_name/project_name.csproj b/project_name/project_name.csproj index e6bd126..9699cfa 100644 --- a/project_name/project_name.csproj +++ b/project_name/project_name.csproj @@ -8,6 +8,7 @@ project_name DesktopGL True + false From 8712e57f07bbe39dab1cc9e462c4bf340b724002 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 20 Sep 2019 23:12:31 -0700 Subject: [PATCH 11/11] release build fix --- .vscode/settings.json | 2 +- project_name/DemoComponent.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2882144..36e0cbf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,7 +10,7 @@ "files.exclude": { "**/.[^v]*": true, // hide any files that start with a '.' but keep the .vscode folder ".vs": true, // Visual Studio settings - "getFNA.sh": true, + "getFNA.*": true, "imgui.ini": true, "MonoGameContent.targets": true, "**/obj": true, diff --git a/project_name/DemoComponent.cs b/project_name/DemoComponent.cs index 9f3e548..2c823a1 100755 --- a/project_name/DemoComponent.cs +++ b/project_name/DemoComponent.cs @@ -11,13 +11,13 @@ namespace project_name public override void OnAddedToEntity() { // register with the ImGuiMangaer letting it know we want to render some IMGUI - Core.GetGlobalManager().RegisterDrawCommand(ImGuiDraw); + Core.GetGlobalManager()?.RegisterDrawCommand(ImGuiDraw); } public override void OnRemovedFromEntity() { // remove ourselves when we are removed from the Scene - Core.GetGlobalManager().UnregisterDrawCommand(ImGuiDraw); + Core.GetGlobalManager()?.UnregisterDrawCommand(ImGuiDraw); } void ImGuiDraw()