Files
sbox-public/engine/Sandbox.Engine/Resources/FileReference.cs
Lorenz Junglas e58dfcf938 Raw File Dependencies for Resources (#3988)
### Problem
NavMesh baking needed to store raw binary data in external files (`.navdata`) that should be tracked and packaged, but aren't native compiled resources.

### Solution
Reused the existing `RegisterAdditionalRelatedFile_Game` native infrastructure to track raw files similar to how `RegisterAdditionalRelatedFile_Content` is used to track content sources (.fbx, .tga...). `RegisterAdditionalRelatedFile_Game` was not used anywhere in the codebase, so it's safe to repurpose. This avoids changing the asset file format.

### Changes

**C# Asset System:**
- Split `GetAdditionalRelatedFiles()` into:
  - `GetAdditionalContentFiles()` - content-side files (.fbx, .lxo, .rect, etc.) filtered by `ASSET_LOCATION_CONTENT`
  - `GetAdditionalGameFiles()` - game-side data files (.navdata, etc.) filtered by `ASSET_LOCATION_GAME`

**Resource Compilation:**
- Added `FileReference` struct for JSON serialization with `{ "$reference_type: "filereference", "path": "..." }` pattern
- Added `AddGameFileReference()` to `ResourceCompileContext` which calls `RegisterAdditionalRelatedFile_Game()`

**Packaging:**
- `PackageManifest` now additionally collects game/rawfiles files for publishing (content files are still only included when publishing source)
2026-02-04 09:24:33 +01:00

34 lines
847 B
C#

using System.Text.Json.Serialization;
namespace Sandbox;
#nullable enable
/// <summary>
/// A serialized reference to a data file (like navdata) that needs to be tracked and packaged.
/// These files have no dependencies themselves.
/// </summary>
internal readonly struct FileReference
{
public const string ReferenceTypeName = "filereference";
public static FileReference FromPath( string path ) => new( ReferenceTypeName, path );
[JsonPropertyName( "$reference_type" )]
public string ReferenceType { get; }
[JsonPropertyName( "path" )]
public string Path { get; }
[JsonConstructor]
private FileReference( string referenceType, string path )
{
ReferenceType = referenceType;
Path = path;
}
public override string ToString() => Path;
public static implicit operator string( FileReference reference ) => reference.Path;
}