diff --git a/.env b/.env new file mode 100644 index 0000000..13efeba --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +SOLUTION=Mod.Template.sln +ARTIFACTS=Build/Distance Mod Template.zip +RELEASE_BODY=This release was automatically generated as part of a GitHub workflow. Please read the repository README for more info. \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e2f92bb --- /dev/null +++ b/.gitattributes @@ -0,0 +1,66 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain + +*.bat text eol=crlf +*.csproj text eol=crlf \ No newline at end of file diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml new file mode 100644 index 0000000..3047161 --- /dev/null +++ b/.github/workflows/auto-deploy.yml @@ -0,0 +1,46 @@ +name: Build and Release +on: + push: + branches: + - main + paths-ignore: + - "*.md" + pull_request: + branches: + - main + paths-ignore: + - "*.md" + workflow_dispatch: +jobs: + build: + name: Build and Publish GitHub Release + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + - name: DotEnv + uses: xom9ikk/dotenv@v1.0.2 + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v1.0.2 + - name: Setup NuGet + uses: NuGet/setup-nuget@v1.0.5 + - name: Restore Solution Packages + run: nuget restore $env:SOLUTION + - name: Build Solution + run: msbuild $env:SOLUTION -m + - name: Format Artifact List + id: artifacts + uses: frabert/replace-string-action@v2.0 + with: + string: ${{ env.ARTIFACTS }} + pattern: ';' + replace-with: '\n' + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + name: "Workflow-Automated Deployment [#${{ github.run_number }}]" + tag_name: release-workflow-${{ github.run_number }} + body: "${{ env.RELEASE_BODY }}" + files: "${{ steps.artifacts.outputs.replaced }}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8925f53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,341 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Bb]uild/ +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ec9fa50 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "Tool.BuildTargets"] + path = Tool.BuildTargets + url = https://github.com/Distance-Modding/Tool.BuildTargets +[submodule "Tool.ProjectTargets"] + path = Tool.ProjectTargets + url = https://github.com/Distance-Modding/Tool.ProjectTargets diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..9072fa2 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2021 The Distance modding community + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Mod.Template.Content/Mod.Template.Content.projitems b/Mod.Template.Content/Mod.Template.Content.projitems new file mode 100644 index 0000000..8289aae --- /dev/null +++ b/Mod.Template.Content/Mod.Template.Content.projitems @@ -0,0 +1,19 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 4e7d37c7-8afe-4f79-baf6-4ce82d05e091 + + + Mod.Template.Content + + + + PreserveNewest + + + + + + \ No newline at end of file diff --git a/Mod.Template.Content/Mod.Template.Content.shproj b/Mod.Template.Content/Mod.Template.Content.shproj new file mode 100644 index 0000000..d4502a8 --- /dev/null +++ b/Mod.Template.Content/Mod.Template.Content.shproj @@ -0,0 +1,13 @@ + + + + 4e7d37c7-8afe-4f79-baf6-4ce82d05e091 + 14.0 + + + + + + + + \ No newline at end of file diff --git a/Mod.Template.Content/Mod/mod.json b/Mod.Template.Content/Mod/mod.json new file mode 100644 index 0000000..6fe0e0f --- /dev/null +++ b/Mod.Template.Content/Mod/mod.json @@ -0,0 +1,12 @@ +{ + "FriendlyName": "Mod Template", + "Author": "You", + "Contact": "N/A", + "ModuleFileName": "Mod.Template.dll", + "Dependencies": [], + "RequiredGSLs": [ + "com.github.reherc/Centrifuge.Distance" + ], + "SkipLoad": false, + "Priority": 10 +} \ No newline at end of file diff --git a/Mod.Template.sln b/Mod.Template.sln new file mode 100644 index 0000000..5ea1c6d --- /dev/null +++ b/Mod.Template.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31515.178 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Mod.Template.Content", "Mod.Template.Content\Mod.Template.Content.shproj", "{4E7D37C7-8AFE-4F79-BAF6-4CE82D05E091}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mod.Template", "Mod.Template\Mod.Template.csproj", "{7BCB2908-B003-45D9-BE68-50CBA5217603}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{08A1C9FA-7DC2-4A60-B9A6-AC0EB7132893}" + ProjectSection(SolutionItems) = preProject + .gitattributes = .gitattributes + .gitignore = .gitignore + LICENSE.md = LICENSE.md + README.md = README.md + EndProjectSection +EndProject +Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + Mod.Template.Content\Mod.Template.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13 + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7BCB2908-B003-45D9-BE68-50CBA5217603}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BCB2908-B003-45D9-BE68-50CBA5217603}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BCB2908-B003-45D9-BE68-50CBA5217603}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BCB2908-B003-45D9-BE68-50CBA5217603}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E6970D48-CD23-4427-951B-448B144F30DA} + EndGlobalSection +EndGlobal diff --git a/Mod.Template/Mod.Template.csproj b/Mod.Template/Mod.Template.csproj new file mode 100644 index 0000000..186296c --- /dev/null +++ b/Mod.Template/Mod.Template.csproj @@ -0,0 +1,110 @@ + + + + + Debug + AnyCPU + {7BCB2908-B003-45D9-BE68-50CBA5217603} + Library + Properties + Mod.Template + Mod.Template + v3.5 + 512 + true + true + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\HarmonyX.2.5.1\lib\net35\0Harmony.dll + + + ..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\Assembly-CSharp.dll + + + ..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\Centrifuge.Distance.dll + + + ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.dll + + + ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Mdb.dll + + + ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Pdb.dll + + + ..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Rocks.dll + + + ..\packages\MonoMod.RuntimeDetour.21.7.8.3\lib\net35\MonoMod.RuntimeDetour.dll + + + ..\packages\MonoMod.Utils.21.7.8.3\lib\net35\MonoMod.Utils.dll + + + ..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\NAudio.dll + + + ..\packages\Json.Net.Unity3D.9.0.1\lib\net35\Newtonsoft.Json.dll + + + ..\packages\Centrifuge.Mod.SDK.3.2.0\lib\net35\Reactor.API.dll + + + + + + + + + ..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.dll + + + ..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.Networking.dll + + + ..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.UI.dll + + + + + + + + + + + + + + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + true + + true + + false + + + + \ No newline at end of file diff --git a/Mod.Template/Mod.Template.targets b/Mod.Template/Mod.Template.targets new file mode 100644 index 0000000..fc29990 --- /dev/null +++ b/Mod.Template/Mod.Template.targets @@ -0,0 +1,5 @@ + + + Distance Mod Template + + \ No newline at end of file diff --git a/Mod.Template/Mod.cs b/Mod.Template/Mod.cs new file mode 100644 index 0000000..a08b398 --- /dev/null +++ b/Mod.Template/Mod.cs @@ -0,0 +1,57 @@ +using Reactor.API.Attributes; +using Reactor.API.Interfaces.Systems; +using Reactor.API.Logging; +using Reactor.API.Runtime.Patching; +using UnityEngine; + +namespace Distance.ModTemplate +{ + /// + /// The mod's main class containing its entry point + /// + [ModEntryPoint("")] + public sealed class Mod : MonoBehaviour + { + public static Mod Instance { get; private set; } + + public IManager Manager { get; private set; } + + public Log Logger { get; private set; } + + /// + /// Method called as soon as the mod is loaded. + /// WARNING: Do not load asset bundles/textures in this function + /// The unity assets systems are not yet loaded when this + /// function is called. Loading assets here can lead to + /// unpredictable behaviour and crashes! + /// + public void Initialize(IManager manager) + { + // Do not destroy the current game object when loading a new scene + DontDestroyOnLoad(this); + + Instance = this; + + Manager = manager; + + // Create a log file + Logger = LogManager.GetForCurrentAssembly(); + + Logger.Info("Hello World!"); + + RuntimePatcher.AutoPatch(); + } + + /// + /// Method called after + /// GameManager.Start() + /// This initialisation method is the same as + /// the Spectrum mod loader initialisation procedure. + /// + public void LateInitialize(IManager manager) + { + // Code here... + Initialize(manager); + } + } +} diff --git a/Mod.Template/Properties/AssemblyInfo.cs b/Mod.Template/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2ff0ed0 --- /dev/null +++ b/Mod.Template/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Distance.ModTemplate")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Distance.ModTemplate")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7bcb2908-b003-45d9-be68-50cba5217603")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Mod.Template/packages.config b/Mod.Template/packages.config new file mode 100644 index 0000000..1795d29 --- /dev/null +++ b/Mod.Template/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..89f2589 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Distance mod template + +Use this repository as a base to create your own Distance mods. + +# Using the template +On github, click the `Use this template` button to create a new repository based on this one + +Once the repository is created, be sure to clone it locally **with submodules**: +```sh +git clone --recurse-submodules -j8 +``` + +# Setting up the project +After cloning the repository on your local drive, run the [setup.ps1](setup.ps1) script using [PowerShell 7 or higher](https://github.com/PowerShell/PowerShell#get-powershell). + +This script will rename the files correctly and replace their content to match your mod name. \ No newline at end of file diff --git a/Tool.BuildTargets b/Tool.BuildTargets new file mode 160000 index 0000000..dc3ac06 --- /dev/null +++ b/Tool.BuildTargets @@ -0,0 +1 @@ +Subproject commit dc3ac061231383a07eb67f8da5af0eee7a92db2a diff --git a/Tool.ProjectTargets b/Tool.ProjectTargets new file mode 160000 index 0000000..0ef6203 --- /dev/null +++ b/Tool.ProjectTargets @@ -0,0 +1 @@ +Subproject commit 0ef6203a66c657f2ecb1ed85fdc9908cc8f46f60 diff --git a/setup.ps1 b/setup.ps1 new file mode 100644 index 0000000..0343983 --- /dev/null +++ b/setup.ps1 @@ -0,0 +1,97 @@ +Set-Variable Source -Option Constant -Value $MyInvocation.MyCommand.Definition; +Set-Variable ValidationRegex -Option Constant -Value "^([a-zA-Z]+([ ]?[a-zA-Z0-9])*)\r?$"; + +$Extensions = ".txt", ".json", ".env", ".sln", ".proj", ".csproj", ".vbproj", ".shproj", ".projitems", ".cs", ".vb", ".targets", ".props"; + +Class ProjectInfo { + [string]$Namespace; + [string]$Title; + + ProjectInfo([string]$namespace, [string]$title) { + $this.Namespace = $namespace; + $this.Title = $title; + } +} + +Function Read-ProjectInfo { + [OutputType([ProjectInfo])] + Param () + + Write-Host "Enter a new project name to setup your mod (Example: 'My First Mod')."; + Write-Host "In order to be valid, a name must respect the following rules:"; + Write-Host "- The project name can't begin with a number"; + Write-Host "- The project name can't start or end with one or more spaces"; + Write-Host "- The name can't contain a series of more than 1 consecutive space character"; + Write-Host "- Words must be composed only of (latin) letters and numbers (a-zA-Z0-9)"; + Write-Host "- Any special characters are not allowed (@#-.;:/!§,?%=+* ...)"; + Write-Host ""; + Write-Host "The program will prompt you to type a name until it is a valid one."; + Write-Host "To exit it, press CTRL + C"; + Write-Host ""; + + Do { + $ProjectName = Read-Host -Prompt "Enter project name"; + } + Until ($ProjectName -match $ValidationRegex); + + Return [ProjectInfo]::new("Distance." + $ProjectName.Replace(" ", ""), "Distance " + $ProjectName); +} + +Function Rename-Files { + Param ([string]$Find, [string]$Replace) + + Rename-Items -Find $Find -Replace $Replace -Attributes "Directory"; + Rename-Items -Find $Find -Replace $Replace -Attributes "!Directory"; + Write-FilesContent -Find $Find -Replace $Replace +} + +Function Rename-Items { + Param ([string]$Find, [string]$Replace, [string]$Attributes) + $Items = Get-ChildItem -Attributes $Attributes -Recurse | Where-Object -FilterScript {$_.FullName -Ne $Source}; + + ForEach ($Item in $Items) { + If ($Item.Name.Contains($Find)) { + Rename-Item -Path $Item.PSPath -NewName $Item.Name.Replace($Find, $Replace); + } + } +} + +Function Write-FilesContent { + Param ([string]$Find, [string]$Replace) + + $Files = Get-ChildItem -File -Recurse | Where-Object -FilterScript {$_.FullName -Ne $Source -And $Extensions.Contains($_.Extension.ToLower())}; + + ForEach ($File in $Files) { + $Content = (Get-Content -Path $File.FullName -Encoding utf8 -Raw).Replace($Find, $Replace); + Set-Content -Path $File.FullName -Value $Content -Encoding utf8; + } +} + +Function Remove-Script { + [OutputType([bool])] + Param () + + $Yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Remove this powershell script from the disk."; + $No = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Keep this powershell script on the disk."; + + $Options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No); + + $ChoiceResult = $Host.Ui.PromptForChoice("Setup complete!", "Do you want to delete this powershell script?", $Options, 0); + + Return $ChoiceResult -Eq 0; +} + +Function Init { + [ProjectInfo]$Info = Read-ProjectInfo; + + Rename-Files -Find "Mod.Template" -Replace $Info.Namespace; + Rename-Files -Find "Distance.ModTemplate" -Replace $Info.Namespace; + Rename-Files -Find "Mod Template" -Replace $Info.Title; + + [bool]$RemoveFiles = Remove-Script; + If ($RemoveFiles) { + Remove-Item -Path "$Source" -Force + } +} + +Init; \ No newline at end of file