finally added a proper build script to the example mod

This commit is contained in:
Ell 2022-09-12 13:21:27 +02:00
parent 1097f6d8f9
commit 307ad45de9
7 changed files with 86 additions and 45 deletions

12
.config/dotnet-tools.json Normal file
View file

@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"cake.tool": {
"version": "2.2.0",
"commands": [
"dotnet-cake"
]
}
}
}

View file

@ -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%

View file

@ -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

View file

@ -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).
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.

11
Run.bat
View file

@ -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

11
Run.sh
View file

@ -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

73
build.cake Normal file
View file

@ -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);