From 307ad45de9ae13b53db788b42dcf5d5dd53662fb Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 12 Sep 2022 13:21:27 +0200 Subject: [PATCH] finally added a proper build script to the example mod --- .config/dotnet-tools.json | 12 +++++++ Publish.bat | 11 ------ Publish.sh | 11 ------ README.md | 2 +- Run.bat | 11 ------ Run.sh | 11 ------ build.cake | 73 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 45 deletions(-) create mode 100644 .config/dotnet-tools.json delete mode 100644 Publish.bat delete mode 100644 Publish.sh delete mode 100644 Run.bat delete mode 100644 Run.sh create mode 100644 build.cake diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..7bd5f9f --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "2.2.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/Publish.bat b/Publish.bat deleted file mode 100644 index 6e2fff9..0000000 --- a/Publish.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -rem move to the script directory -cd /d "%~dp0" -rem build the mod -dotnet build || exit /b -rem zip the mod -cd ./bin/Debug/net6.0 -for /F %%p in ('dir /b "*.dll"') do (set file=%%p) -set dest=%file:~0,-4%.zip -tar -acf ../%dest% --exclude ref --exclude *.pdb --exclude *.deps.json * -echo Published to bin/Debug/%dest% \ No newline at end of file diff --git a/Publish.sh b/Publish.sh deleted file mode 100644 index 62425c4..0000000 --- a/Publish.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# move to the script directory -cd "$(dirname "$0")" -# build the mod -dotnet build || exit -# zip the mod -cd ./bin/Debug/net6.0 -file=$(find *.dll -print) -dest=${file%????}.zip -zip -FSr ../$dest * --exclude 'ref/*' --exclude '*.pdb' --exclude '*.deps.json' -echo Published to bin/Debug/$dest \ No newline at end of file diff --git a/README.md b/README.md index 1ad3674..61683b4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # Tiny Life Example Mod An example mod for my game Tiny Life. Use this template repository to create your own mod! -The Tiny Life modding and custom content documentation has found a permanent home at [docs.tinylifegame.com](https://docs.tinylifegame.com). \ No newline at end of file +To learn how to use the example mod repository and create your own mods, check out the [Modding Basics](https://docs.tinylifegame.com/articles/mod_basics.html) documentation. diff --git a/Run.bat b/Run.bat deleted file mode 100644 index 39e0c89..0000000 --- a/Run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -rem move to the script directory -cd /d "%~dp0" -rem build the mod -dotnet build || exit /b -rem copy the mod to the mods folder -robocopy ./bin/Debug/net6.0/ "%LOCALAPPDATA%/Tiny Life/Mods" /e /is -rem run the game -set /p dir=<"%LOCALAPPDATA%/Tiny Life/GameDir" -cd /d %dir% -"Tiny Life.exe" -v --skip-splash --skip-preloads \ No newline at end of file diff --git a/Run.sh b/Run.sh deleted file mode 100644 index 1e00867..0000000 --- a/Run.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# move to the script directory -cd "$(dirname "$0")" -# build the mod -dotnet build || exit -# copy the mod to the mods folder -cp -r ./bin/Debug/net6.0/* "$HOME/.local/share/Tiny Life/Mods" -# run the game -dir=$(<"$HOME/.local/share/Tiny Life/GameDir") -cd "$dir" -"./Tiny Life" -v --skip-splash --skip-preloads \ No newline at end of file diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..04e443b --- /dev/null +++ b/build.cake @@ -0,0 +1,73 @@ +using System.Diagnostics; +using System.Linq; +using System.Threading; + +var target = Argument("target", "Run"); +var config = Argument("configuration", "Release"); + +var tinyLifeDir = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/Tiny Life"; + +Task("Build").Does(() => { + foreach (var project in GetFiles("**/*.csproj")) + DotNetBuild(project.FullPath, new DotNetBuildSettings { Configuration = config }); +}); + +Task("CopyToMods").IsDependentOn("Build").Does(() => { + var dir = $"{tinyLifeDir}/Mods"; + CreateDirectory(dir); + var files = GetFiles($"bin/{config}/net*/**/*"); + CopyFiles(files, dir, true); +}); + +Task("Run").IsDependentOn("CopyToMods").Does(() => { + // start the tiny life process + var exeDir = $"{tinyLifeDir}/GameDir"; + if (!FileExists(exeDir)) + throw new Exception("Didn't find game directory information. Run the game manually at least once to allow the Run task to be executed."); + var exe = $"{System.IO.File.ReadAllText(exeDir)}/Tiny Life"; + var process = Process.Start(new ProcessStartInfo(exe) { + CreateNoWindow = true + }); + + // we wait a bit to make sure the process has generated a new log file, bleh + Thread.Sleep(1000); + + // attach to the newest log file + var logsDir = $"{tinyLifeDir}/Logs"; + var log = System.IO.Directory.EnumerateFiles(logsDir).OrderByDescending(System.IO.File.GetCreationTime).FirstOrDefault(); + if (log != null) { + using (var stream = new FileStream(log, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { + using (var reader = new StreamReader(stream)) { + var lastPos = 0L; + while (!process.HasExited) { + if (reader.BaseStream.Length > lastPos) { + reader.BaseStream.Seek(lastPos, SeekOrigin.Begin); + string line; + while ((line = reader.ReadLine()) != null) + Information(line); + lastPos = reader.BaseStream.Position; + } + Thread.Sleep(10); + } + } + } + } + + Information($"Tiny Life exited with exit code {process.ExitCode}"); +}); + +Task("Publish").IsDependentOn("Build").Does(() => { + foreach (var dir in GetDirectories($"bin/{config}/net*")) { + var dllFile = GetFiles($"{dir}/**/*.dll").FirstOrDefault(); + if (dllFile == null) { + Warning($"Couldn't find built mod in {dir}"); + continue; + } + var dllName = System.IO.Path.GetFileNameWithoutExtension(dllFile.ToString()); + var zipLoc = $"{dir.GetParent()}/{dllName}.zip"; + Zip(dir, zipLoc, GetFiles($"{dir}/**/*")); + Information($"Published {dllName} to {zipLoc}"); + } +}); + +RunTarget(target);