Build ServerShared without Unity and add AetherDb scripts
Aetheria.Shared.csproj compiles ServerShared with MessagePack, UniRx core, Ink and Unity.Mathematics from source against .NET Standard 2.1 (Unity's API level) with no Unity defines; a clean build checks that the simulation stays engine-independent. tools/AetherDb opens AetherDB.msgpack through the game's own CultCache for file-based C# scripts; station-fit checks every station hull can take a docking bay. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
25ecb46fcd
commit
02058a3cdf
6 changed files with 126 additions and 3 deletions
37
tools/AetherDb/AetherDb.cs
Normal file
37
tools/AetherDb/AetherDb.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
// Opens GameData/AetherDB.msgpack through the game's own CultCache and data types, for inspection and editing scripts.
|
||||
// Close the editor's Database Tools before saving from a script, or its next Save will overwrite the script's changes.
|
||||
public sealed class AetherDb
|
||||
{
|
||||
public string Root { get; }
|
||||
public CultCache Cache { get; }
|
||||
private readonly SingleFileMessagePackBackingStore _store;
|
||||
|
||||
private AetherDb(string root)
|
||||
{
|
||||
Root = root;
|
||||
RegisterResolver.Register();
|
||||
var gameData = Path.Combine(root, "GameData");
|
||||
_store = new SingleFileMessagePackBackingStore(Path.Combine(gameData, "AetherDB.msgpack"));
|
||||
Cache = new CultCache();
|
||||
Cache.AddBackingStore(_store);
|
||||
Cache.AddBackingStore(new MultiFileMessagePackBackingStore(gameData), typeof(NameFile));
|
||||
Cache.PullAllBackingStores();
|
||||
}
|
||||
|
||||
// With no root given, walks up from the working directory to the repository
|
||||
public static AetherDb Open(string root = null) => new AetherDb(root ?? FindRoot());
|
||||
|
||||
// Writes every entry back to AetherDB.msgpack, as the editor's Save button does
|
||||
public void Save() => _store.PushAll();
|
||||
|
||||
private static string FindRoot()
|
||||
{
|
||||
for (var dir = new DirectoryInfo(Environment.CurrentDirectory); dir != null; dir = dir.Parent)
|
||||
if (File.Exists(Path.Combine(dir.FullName, "GameData", "AetherDB.msgpack")))
|
||||
return dir.FullName;
|
||||
throw new DirectoryNotFoundException("Run from inside the Aetheria repository.");
|
||||
}
|
||||
}
|
||||
14
tools/AetherDb/Directory.Build.props
Normal file
14
tools/AetherDb/Directory.Build.props
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<Project>
|
||||
<!-- Applies to every script under tools/AetherDb. Scripts are file-based programs: pass a script path to dotnet run
|
||||
with its file option. They load game data through the headless Aetheria.Shared build of ServerShared. -->
|
||||
<PropertyGroup>
|
||||
<Nullable>disable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<!-- File-based programs default to AOT, which disables the dynamic code MessagePack's resolvers generate -->
|
||||
<PublishAot>false</PublishAot>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)AetherDb.cs" />
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Aetheria.Shared\Aetheria.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
22
tools/AetherDb/scripts/station-fit.cs
Normal file
22
tools/AetherDb/scripts/station-fit.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Checks that some docking bay fits every station hull, which LoadoutGenerator.GenerateStationLoadout requires.
|
||||
// Exits with the number of station hulls that cannot take any docking bay.
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
var db = AetherDb.Open();
|
||||
var bays = db.Cache.GetAll<DockingBayData>().ToArray();
|
||||
var failures = 0;
|
||||
foreach (var hull in db.Cache.GetAll<HullData>().Where(h => h.HullType == HullType.Station))
|
||||
{
|
||||
// Hardpoint gear is equipped before the docking bay, so the worst case leaves only the non-hardpoint interior free
|
||||
var worstCase = new Shape(hull.Shape.Width, hull.Shape.Height);
|
||||
foreach (var v in hull.InteriorCells.Coordinates) worstCase[v] = true;
|
||||
foreach (var hardpoint in hull.Hardpoints)
|
||||
foreach (var v in hardpoint.Shape.Coordinates)
|
||||
worstCase[hardpoint.Position + v] = false;
|
||||
|
||||
var fitting = bays.Where(b => b.Shape.FitsWithin(worstCase, out _, out _)).Select(b => b.Name).ToArray();
|
||||
if (fitting.Length == 0) failures++;
|
||||
Console.WriteLine($"{hull.Name}: {(fitting.Length == 0 ? "NO docking bay fits" : string.Join(", ", fitting))}");
|
||||
}
|
||||
return failures;
|
||||
Loading…
Reference in a new issue