Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a few windows issues, make Monogame optional without requiring .csproj edits #4

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
26 changes: 26 additions & 0 deletions .vscode/buildEffects.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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 build process..."

Set-Location $PSScriptRoot
Set-Location ../project_name


$fxc = "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86\fxc.exe"

$files = Get-ChildItem -Path "Content\*" -Recurse -Include *fx

foreach ($file in $files)
{
$fileName = $file.BaseName
$filePath = $file.FullName
& $fxc /T fx_2_0 $filePath /Fo "${filePath}b"

Write-Output "Built ${fileName}.fx to ${filePath}b"
}


4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
// Change "mono" to "clr" for 64-bit .NET Framework debugging on Windows.
// Delete unnecessary configurations if unneeded. "type" isnt supported for platform specifc properties.
// (See: https://github.com/OmniSharp/omnisharp-vscode/wiki/Desktop-.NET-Framework)

"version": "0.2.0",
Expand Down Expand Up @@ -57,4 +57,4 @@
"port": 55555
}
]
}
}
11 changes: 6 additions & 5 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
],
"group": "build",
"problemMatcher": "$msCompile",
"dependsOn": "Build Content",
},

{
Expand Down Expand Up @@ -77,6 +76,7 @@
"command": "start",
"args": [
"/wait",
"\"project_name.exe\"", //names the console window
"${workspaceFolder}/project_name/bin/Debug/project_name.exe"
]
},
Expand All @@ -95,7 +95,8 @@
"command": "start",
"args": [
"/wait",
"${workspaceFolder}/project_name/bin/Release/project_name.exe"
"\"project_name.exe\"", //names the console window
"${workspaceFolder}/project_name/bin/Release/project_name.exe"
]
},
"dependsOn": "Build (Release)",
Expand All @@ -118,7 +119,7 @@
},
"problemMatcher": "$msCompile"
},

{
"label": "Build Content",
"type": "shell",
Expand Down Expand Up @@ -162,7 +163,7 @@
},
"problemMatcher": "$msCompile"
},

{
"label": "Process T4 Templates",
"type": "shell",
Expand All @@ -180,4 +181,4 @@
"problemMatcher": "$msCompile",
},
]
}
}
26 changes: 16 additions & 10 deletions MonoGameContent.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MonoGameInstallDirectory
Condition=" '$(MonoGameInstallDirectory)' == '' And Exists('/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/MonoGame.Common.props') ">/Library/Frameworks/Mono.framework/External/xbuild</MonoGameInstallDirectory>
Condition=" '$(OS)' == 'Windows_NT' And '$(MonoGameInstallDirectory)' == '' And Exists('C:\Program Files (x86)\MSBuild\MonoGame\v3.0\MonoGame.Common.props') ">C:\Program Files (x86)\MSBuild</MonoGameInstallDirectory>
<MonoGameInstallDirectory
Condition=" '$(OS)' != 'Windows_NT' And '$(MonoGameInstallDirectory)' == '' And Exists('/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/MonoGame.Common.props') ">/Library/Frameworks/Mono.framework/External/xbuild</MonoGameInstallDirectory>
<MonoGameInstallDirectory
Condition=" '$(MonoGameInstallDirectory)' == '' ">$(MSBuildProgramFiles32)</MonoGameInstallDirectory>
<MonoGameContentBuilderExe
Condition="'$(MonoGameContentBuilderExe)' == ''">$(MonoGameInstallDir)Tools\MGCB.exe</MonoGameContentBuilderExe>
<ContentOutputDir>bin/DesktopGL</ContentOutputDir>
<ContentIntermediateDir>obj/DesktopGL</ContentIntermediateDir>
</PropertyGroup>

<UsingTask TaskName="MonoGame.Build.Tasks.CollectContentReferences"
<UsingTask Condition=" '$(OS)' == 'Windows_NT' " TaskName="MonoGame.Build.Tasks.CollectContentReferences"
AssemblyFile="C:\Program Files (x86)\MSBuild\MonoGame\v3.0\MonoGame.Build.Tasks.dll" />
<UsingTask Condition=" '$(OS)' != 'Windows_NT' " TaskName="MonoGame.Build.Tasks.CollectContentReferences"
AssemblyFile="\Library\Frameworks\MonoGame.framework\v3.0\MonoGame.Build.Tasks.dll" />

<!-- Add MonoGameContentReference to item type selection in Visual Studio -->
<ItemGroup>
<AvailableItemName Include="MonoGameContentReference" />
Expand All @@ -34,7 +40,7 @@
<MonoExe Condition=" '$(OS)' != 'Windows_NT' And Exists ('/usr/local/bin/mono') ">/usr/local/bin/mono</MonoExe>
<MonoExe Condition=" '$(OS)' != 'Windows_NT' And Exists ('/usr/bin/mono') ">/usr/bin/mono</MonoExe>
<MonoExe Condition=" '$(OS)' != 'Windows_NT' And '$(MonoExe)' == '' ">mono</MonoExe>
<MonoGameContentBuilderExe Condition="'$(MonoGameContentBuilderExe)' == ''">$(MonoGameInstallDir)Tools\MGCB.exe</MonoGameContentBuilderExe>
<!-- <MonoGameContentBuilderExe Condition="'$(MonoGameContentBuilderExe)' == ''">$(MonoGameInstallDirectory)Tools\MGCB.exe</MonoGameContentBuilderExe> -->
<MonoGameContentBuilderCmd>"$(MonoGameContentBuilderExe)"</MonoGameContentBuilderCmd>
<MonoGameContentBuilderCmd Condition=" '$(OS)' != 'Windows_NT' ">$(MonoExe) $(MonoGameContentBuilderCmd)</MonoGameContentBuilderCmd>
<PlatformResourcePrefix Condition="'$(MonoGamePlatform)' == 'MacOSX'">$(MonoMacResourcePrefix)</PlatformResourcePrefix>
Expand All @@ -46,17 +52,17 @@
<Header>/platform:$(MonoGamePlatform)</Header>
</PropertyGroup>

<Error
Text="The MonoGame content builder executable could not be located at '$(MonoGameContentBuilderExe)'!"
Condition="!Exists('$(MonoGameContentBuilderExe)')"
/>

<!-- Get all Mono Game Content References and store them in a list -->
<!-- We do this here so we are compatible with xbuild -->
<CollectContentReferences ContentReferences="@(MonoGameContentReference)" MonoGamePlatform="$(MonoGamePlatform)">
<Output TaskParameter="Output" ItemName="ContentReferences" />
</CollectContentReferences>

<Error
Text="The MonoGame content builder executable could not be located at '$(MonoGameContentBuilderExe)'!"
Condition="!Exists('$(MonoGameContentBuilderExe)')"
/>

<Warning
Text="No Content References Found. Please make sure your .mgcb file has a build action of MonoGameContentReference"
Condition=" '%(ContentReferences.FullPath)' == '' "
Expand All @@ -81,7 +87,7 @@
</CreateItem>
</Target>

<Target Name="BuildContent" DependsOnTargets="Prepare;RunContentBuilder" AfterTargets="Build" Condition=" '@(MonoGameContentReference)' != '' "
<Target Name="BuildContent" DependsOnTargets="Prepare;RunContentBuilder" AfterTargets="Build" Condition=" '@(MonoGameContentReference)' != '' And Exists('$(MonoGameContentBuilderExe)')"
Outputs="%(ExtraContent.RecursiveDir)%(ExtraContent.Filename)%(ExtraContent.Extension)">
<CreateItem Include="%(ExtraContent.FullPath)" AdditionalMetadata="Link=$(PlatformResourcePrefix)%(ExtraContent.ContentOutputDir)%(ExtraContent.RecursiveDir)%(ExtraContent.Filename)%(ExtraContent.Extension);CopyToOutputDirectory=PreserveNewest"
Condition="'%(ExtraContent.Filename)' != ''">
Expand Down
36 changes: 16 additions & 20 deletions getFNA.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ function checkDotnet()
catch [System.Management.Automation.CommandNotFoundException]
{
Write-Output "ERROR: Dotnet is not installed. Please install dotnet to download the t4 tool."
return 0;
}
return 1;
}

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
}
}
Expand All @@ -34,21 +50,6 @@ function check7zip ()
}
}

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
Expand Down Expand Up @@ -101,23 +102,19 @@ 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)?"
}

Expand Down Expand Up @@ -177,5 +174,4 @@ dotnet restore "Nez/Nez.sln"
"Building..."
msbuild "Nez/Nez.sln"
msbuild -t:restore $newProjectName
msbuild -t:buildcontent $newProjectName
msbuild "${newProjectName}.sln"
Empty file modified getFNA.sh
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion project_name.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Global
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
EndGlobal
EndGlobal
2 changes: 1 addition & 1 deletion project_name/DefaultScene.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void Initialize()
.AddComponent<DemoComponent>()
.AddComponent(new PrototypeSprite(20, 20));

var logo = Content.Load<Texture2D>("nez-logo-black");
var logo = Content.LoadTexture("Textures/nez-logo-black");
CreateEntity("logo")
.SetPosition(Screen.Center)
.AddComponent(new SpriteRenderer(logo));
Expand Down
9 changes: 5 additions & 4 deletions project_name/DemoComponent.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace project_name
{
public class DemoComponent : Component
{
int _buttonClickCounter;
int _ButtonClickCounter;

public override void OnAddedToEntity()
{
Expand All @@ -23,12 +23,13 @@ public override void OnRemovedFromEntity()
void ImGuiDraw()
{
// do your actual drawing here
ImGui.Begin("Your ImGui Window", ImGuiWindowFlags.AlwaysAutoResize);
ImGui.Begin("Your ImGui Window", ImGuiWindowFlags.AlwaysAutoResize);
ImGui.Text("This is being drawn in DemoComponent");
if(ImGui.Button($"Clicked me {_buttonClickCounter} times"))
_buttonClickCounter++;
if (ImGui.Button($"Clicked me {_ButtonClickCounter} times"))
_ButtonClickCounter++;
ImGui.End();
}

}
}

Empty file modified project_name/Game1.cs
100755 → 100644
Empty file.
Empty file modified project_name/T4Templates/ContentPathGenerator.tt
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions project_name/project_name.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<!-- Include the CompiledContent bin (MGCB output). Copy it to the Content folder in the build. -->
<ItemGroup>
<Content Include="CompiledContent/bin/DesktopGL/**/*.xnb">
Expand All @@ -58,7 +58,6 @@

<Import Project="../MonoGameContent.targets"/>


<PropertyGroup>
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
Expand Down