From 0056da1aef736c2f56d4e8c1ce61ffa61740d538 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Mon, 8 May 2017 17:53:08 +0200 Subject: [PATCH 1/9] Remove OpenRA.Mods.Example.sln --- OpenRA.Mods.Example.sln | 17 ----------------- README.md | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 OpenRA.Mods.Example.sln diff --git a/OpenRA.Mods.Example.sln b/OpenRA.Mods.Example.sln deleted file mode 100644 index 22d1d11..0000000 --- a/OpenRA.Mods.Example.sln +++ /dev/null @@ -1,17 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.Example", "OpenRA.Mods.Example\OpenRA.Mods.Example.csproj", "{4E5B38F7-4E99-4C92-BB39-9100CC7F3829}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4E5B38F7-4E99-4C92-BB39-9100CC7F3829}.Debug|x86.ActiveCfg = Debug|x86 - {4E5B38F7-4E99-4C92-BB39-9100CC7F3829}.Debug|x86.Build.0 = Debug|x86 - {4E5B38F7-4E99-4C92-BB39-9100CC7F3829}.Release|x86.ActiveCfg = Release|x86 - {4E5B38F7-4E99-4C92-BB39-9100CC7F3829}.Release|x86.Build.0 = Release|x86 - EndGlobalSection -EndGlobal diff --git a/README.md b/README.md index 007402a..d01b28f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ It is not recommended or supported to use the `example` mod as the basis for a n You should now have a functioning stand-alone clone of the `cnc` mod that you can adapt / replace piece by piece with your own project. -If you don't plan on including any custom C# logic in your mod then you should delete `ExampleMod.sln`, `OpenRA.Mods.Example.sln`, and the `OpenRA.Mods.Example` directory. If you do plan on including custom logic, then you will need to make some futher changes: +If you don't plan on including any custom C# logic in your mod then you should delete `ExampleMod.sln` and the `OpenRA.Mods.Example` directory. If you do plan on including custom logic, then you will need to make some futher changes: * TODO: Explain updating the GUIDs, project name, and changing the build output to `mods/mynewmod/` ### Developing / running your in-development mod From c19beeb10908d75674b7524e5fc9bfbb8469cc1c Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Tue, 9 May 2017 18:23:24 +0200 Subject: [PATCH 2/9] Add a windows make script --- make.cmd | 1 + make.ps1 | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 312 insertions(+) create mode 100644 make.cmd create mode 100644 make.ps1 diff --git a/make.cmd b/make.cmd new file mode 100644 index 0000000..c3bc54d --- /dev/null +++ b/make.cmd @@ -0,0 +1 @@ +@powershell -NoProfile -ExecutionPolicy Unrestricted -File make.ps1 %* diff --git a/make.ps1 b/make.ps1 new file mode 100644 index 0000000..b19d248 --- /dev/null +++ b/make.ps1 @@ -0,0 +1,311 @@ +####### The starting point for the script is the bottom ####### + +############################################################### +########################## FUNCTIONS ########################## +############################################################### +function All-Command +{ + $msBuild = FindMSBuild + $msBuildArguments = "/t:Rebuild /nr:false" + if ($msBuild -eq $null) + { + echo "Unable to locate an appropriate version of MSBuild." + } + else + { + $proc = Start-Process $msBuild $msBuildArguments -NoNewWindow -PassThru -Wait + if ($proc.ExitCode -ne 0) + { + echo "Build failed. If just the development tools failed to build, try installing Visual Studio. You may also still be able to run the game." + } + else + { + echo "Build succeeded." + } + } +} + +function Clean-Command +{ + $msBuild = FindMSBuild + $msBuildArguments = "/t:Clean /nr:false" + if ($msBuild -eq $null) + { + echo "Unable to locate an appropriate version of MSBuild." + } + else + { + $proc = Start-Process $msBuild $msBuildArguments -NoNewWindow -PassThru -Wait + rm *.dll + rm *.dll.config + rm mods/*/*.dll + rm *.pdb + rm mods/*/*.pdb + rm *.exe + rm ./*/bin -r + rm ./*/obj -r + echo "Clean complete." + } +} + +function Version-Command +{ + if ($command.Length -gt 1) + { + $version = $command[1] + } + elseif (Get-Command 'git' -ErrorAction SilentlyContinue) + { + $gitRepo = git rev-parse --is-inside-work-tree + if ($gitRepo) + { + $version = git name-rev --name-only --tags --no-undefined HEAD 2>$null + if ($version -eq $null) + { + $version = "git-" + (git rev-parse --short HEAD) + } + } + else + { + echo "Not a git repository. The version will remain unchanged." + } + } + else + { + echo "Unable to locate Git. The version will remain unchanged." + } + + if ($version -ne $null) + { + $mod = "mods/" + $modID + "/mod.yaml" + $replacement = (gc $mod) -Replace "Version:.*", ("Version: {0}" -f $version) + sc $mod $replacement + + $prefix = $(gc $mod) | Where { $_.ToString().EndsWith(": User") } + if ($prefix -and $prefix.LastIndexOf("/") -ne -1) + { + $prefix = $prefix.Substring(0, $prefix.LastIndexOf("/")) + } + $replacement = (gc $mod) -Replace ".*: User", ("{0}/{1}: User" -f $prefix, $version) + sc $mod $replacement + + echo ("Version strings set to '{0}'." -f $version) + } +} + +function Test-Command +{ + if (Test-Path ./engine/OpenRA.Utility.exe) + { + $msg = "Testing " + $modID + " mod MiniYAML" + echo $msg + ./engine/OpenRA.Utility.exe $modID --check-yaml + } + else + { + UtilityNotFound + } +} + +function Check-Command +{ + if (Test-Path ./engine/OpenRA.Utility.exe) + { + echo "Checking for explicit interface violations..." + ./engine/OpenRA.Utility.exe $modID --check-explicit-interfaces + + $msg = "Checking for code style violations in OpenRA.Mods." + $modID + "..." + echo $msg + ./engine/OpenRA.Utility.exe $modID --check-code-style OpenRA.Mods.$modID + } + else + { + UtilityNotFound + } +} + +function Check-Scripts-Command +{ + if ((Get-Command "luac.exe" -ErrorAction SilentlyContinue) -ne $null) + { + echo "Testing Lua scripts..." + foreach ($script in ls "mods/*/maps/*/*.lua") + { + luac -p $script + } + echo "Check completed!" + } + else + { + echo "luac.exe could not be found. Please install Lua." + } +} + +function Docs-Command +{ + if (Test-Path ./engine/OpenRA.Utility.exe) + { + ./engine/OpenRA.Utility.exe $modID --docs | Out-File -Encoding "UTF8" DOCUMENTATION.md + ./engine/OpenRA.Utility.exe $modID --lua-docs | Out-File -Encoding "UTF8" Lua-API.md + echo "Docs generated." + } + else + { + UtilityNotFound + } +} + +function FindMSBuild +{ + $key = "HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" + $property = Get-ItemProperty $key -ErrorAction SilentlyContinue + if ($property -eq $null -or $property.MSBuildToolsPath -eq $null) + { + return $null + } + + $path = Join-Path $property.MSBuildToolsPath -ChildPath "MSBuild.exe" + if (Test-Path $path) + { + return $path + } + + return $null +} + +function UtilityNotFound +{ + echo "OpenRA.Utility.exe could not be found. Build the project first using the `"all`" command." +} + +function WaitForInput +{ + echo "Press enter to continue." + while ($true) + { + if ([System.Console]::KeyAvailable) + { + exit + } + Start-Sleep -Milliseconds 50 + } +} + +############################################################### +############################ Main ############################# +############################################################### +if ($args.Length -eq 0) +{ + echo "Command list:" + echo "" + echo " all Builds the game, its development tools and the mod dlls." + echo " version Sets the version strings for all mods to the latest" + echo " version for the current Git branch." + echo " clean Removes all built and copied files." + echo " from the mods and the engine directories." + echo " test Tests the mod's MiniYAML for errors." + echo " check Checks .cs files for StyleCop violations." + echo " check-scripts Checks .lua files for syntax errors." + echo " docs Generates the trait and Lua API documentation." + echo "" + $command = (Read-Host "Enter command").Split(' ', 2) +} +else +{ + $command = $args +} + +# Load the environment variables from the config file +# and get the mod ID from the local environment variable +$reader = [System.IO.File]::OpenText("mod.config") +while($null -ne ($line = $reader.ReadLine())) +{ + if ($line.StartsWith("MOD_ID")) + { + $env:MOD_ID = $line.Replace('MOD_ID=', '').Replace('"', '') + $modID = $env:MOD_ID + } + + if ($line.StartsWith("INCLUDE_DEFAULT_MODS")) + { + $env:INCLUDE_DEFAULT_MODS = $line.Replace('INCLUDE_DEFAULT_MODS=', '').Replace('"', '') + } +} + +$env:MOD_SEARCH_PATHS = (Get-Item -Path ".\" -Verbose).FullName + "\mods" +if ($env:INCLUDE_DEFAULT_MODS -eq "True") +{ + $env:MOD_SEARCH_PATHS = $env:MOD_SEARCH_PATHS + ",./mods" +} + +# Run the same command on the engine's make file +if ($command -eq "all" -or $command -eq "clean") +{ + if (Test-Path ./engine/OpenRA.sln) + { + cd ".\engine\" + $exp = ".\make.cmd " + $command + Invoke-Expression $exp + echo "" + cd .. + } + else + { + if (Get-Command 'git' -ErrorAction SilentlyContinue) + { + $gitRepo = git rev-parse --is-inside-work-tree + if ($gitRepo) + { + git submodule update --init + + if (Test-Path ./engine/OpenRA.sln) + { + cd ".\engine\" + $exp = ".\make.cmd " + $command + Invoke-Expression $exp + echo "" + cd .. + } + else + { + echo "Failed to initialize the submodule. You need to download the engine by hand." + WaitForInput + } + } + else + { + echo "Not a git repository. You need to download the engine by hand." + WaitForInput + } + } + else + { + echo "Unable to locate Git. You need to download the engine by hand." + WaitForInput + } + } +} + +$execute = $command +if ($command.Length -gt 1) +{ + $execute = $command[0] +} + +switch ($execute) +{ + "all" { All-Command } + "version" { Version-Command } + "clean" { Clean-Command } + "test" { Test-Command } + "check" { Check-Command } + "check-scripts" { Check-Scripts-Command } + "docs" { Docs-Command } + Default { echo ("Invalid command '{0}'" -f $command) } +} + +# In case the script was called without any parameters we keep the window open +if ($args.Length -eq 0) +{ + WaitForInput +} From e84d36059e6d7029386450a66fe86eb7b47a90e7 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Tue, 9 May 2017 18:24:01 +0200 Subject: [PATCH 3/9] Add auto generated docs to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 988e006..110d4ce 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ mods/*/*.pdb /*.pdb /*.mdb /*.exe +DOCUMENTATION.md +Lua-API.md From 15a2dcaa11a47ae2dec87697e14426983807e98f Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Wed, 10 May 2017 10:17:15 +0200 Subject: [PATCH 4/9] Add StyleCopViolations.xml to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 110d4ce..68a1168 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ mods/*/*.pdb /*.exe DOCUMENTATION.md Lua-API.md +StyleCopViolations.xml From 96e0597dce66f5f50a8f4fbcdce8d703ee57235a Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Wed, 10 May 2017 10:26:48 +0200 Subject: [PATCH 5/9] Fix the make test utility errors --- mods/example/maps/blank-map/map.yaml | 4 ++-- mods/example/rules.yaml | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mods/example/maps/blank-map/map.yaml b/mods/example/maps/blank-map/map.yaml index cd60cbd..54e2a58 100644 --- a/mods/example/maps/blank-map/map.yaml +++ b/mods/example/maps/blank-map/map.yaml @@ -4,7 +4,7 @@ RequiresMod: example Title: Placeholder Map -Author: +Author: Example Mod author Tileset: TEMPLATE @@ -21,6 +21,6 @@ Players: Name: Neutral OwnsWorld: True NonCombatant: True - Faction: Random + Faction: example Actors: diff --git a/mods/example/rules.yaml b/mods/example/rules.yaml index 8134d4b..03f8892 100644 --- a/mods/example/rules.yaml +++ b/mods/example/rules.yaml @@ -5,6 +5,11 @@ World: ActorMap: ScreenMap: LoadWidgetAtGameStart: + Faction@0: + Name: Example + InternalName: example + Side: Example + Selectable: False Player: AlwaysVisible: From 7d9d96a91784a1e3bd5a7b1bb856ba8e896945e3 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Wed, 10 May 2017 10:29:19 +0200 Subject: [PATCH 6/9] Fix the stylecop error in TemplateMenuLogic.cs --- OpenRA.Mods.Example/Widgets/Logic/TemplateMenuLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Example/Widgets/Logic/TemplateMenuLogic.cs b/OpenRA.Mods.Example/Widgets/Logic/TemplateMenuLogic.cs index 9af34fe..51b93f7 100644 --- a/OpenRA.Mods.Example/Widgets/Logic/TemplateMenuLogic.cs +++ b/OpenRA.Mods.Example/Widgets/Logic/TemplateMenuLogic.cs @@ -9,8 +9,8 @@ */ #endregion -using OpenRA.Widgets; using OpenRA.Mods.Common.Widgets; +using OpenRA.Widgets; namespace OpenRA.Mods.Example.Widgets.Logic { From 0b72a6f6b918dc794e68d6445ab273ea579348f9 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Wed, 24 May 2017 01:26:19 +0200 Subject: [PATCH 7/9] Add a new line to the end of mod.yaml --- mods/example/mod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/example/mod.yaml b/mods/example/mod.yaml index 7ed4f9f..ae7d23a 100644 --- a/mods/example/mod.yaml +++ b/mods/example/mod.yaml @@ -64,4 +64,4 @@ GameSpeeds: default: Name: Normal Timestep: 40 - OrderLatency: 3 \ No newline at end of file + OrderLatency: 3 From 2c8199a4a8b16b72179ef63e49120485e5d8b015 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Wed, 24 May 2017 01:37:54 +0200 Subject: [PATCH 8/9] Try to bypass the security warning --- make.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.cmd b/make.cmd index c3bc54d..92b05b7 100644 --- a/make.cmd +++ b/make.cmd @@ -1 +1 @@ -@powershell -NoProfile -ExecutionPolicy Unrestricted -File make.ps1 %* +@powershell -NoProfile -ExecutionPolicy Bypass -File make.ps1 %* From ab0defe965408ade5bf87d0640cec43a3ef8dd0a Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Fri, 26 May 2017 10:16:30 +0200 Subject: [PATCH 9/9] Don't let the launcher scripts close the console window and change back to the working directory --- launch-game.cmd | 3 ++- utility.cmd | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/launch-game.cmd b/launch-game.cmd index 04134a7..cca4f5b 100644 --- a/launch-game.cmd +++ b/launch-game.cmd @@ -11,7 +11,8 @@ set MOD_SEARCH_PATHS=%MOD_SEARCH_PATHS%,./mods cd engine OpenRA.Game.exe Game.Mod=%MOD_ID% Engine.LaunchPath="%TEMPLATE_LAUNCHER%" "Engine.ModSearchPaths=%MOD_SEARCH_PATHS%" "%*" if %errorlevel% neq 0 goto crashdialog -exit +cd .. +exit /b :crashdialog echo ---------------------------------------- echo OpenRA has encountered a fatal error. diff --git a/utility.cmd b/utility.cmd index fa5f9c8..1e098d8 100644 --- a/utility.cmd +++ b/utility.cmd @@ -20,7 +20,7 @@ echo Press enter to view a list of valid utility commands. echo. set /P command=Please enter a command: OpenRA.Utility.exe %MOD_ID% -if /I "%command%" EQU "--exit" (exit) +if /I "%command%" EQU "--exit" (cd .. & exit /b) echo. echo ---------------------------------------- echo.