Files
systemrevivalserver/data/entities/ClientAsset.cs
T
2025-12-19 10:12:17 -05:00

112 lines
3.0 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Server.Data.Entities;
/// <summary>
/// Tracks all client-side files that can be hot-updated from CDN.
/// Files are stored at: https://assets.aeternalisgames.com/downloads/{FilePath}
/// </summary>
[Table("client_assets")]
public class ClientAsset
{
[Key]
public int Id { get; set; }
/// <summary>
/// Path relative to client root (e.g., "scenes/mobs/skeleton.tscn", "scripts/ui/hud.gd")
/// This is where the file will be saved on the client
/// </summary>
[Required]
[MaxLength(256)]
public string FilePath { get; set; } = "";
/// <summary>
/// Type of asset for categorization and loading behavior
/// </summary>
public ClientAssetType AssetType { get; set; } = ClientAssetType.Texture;
/// <summary>
/// MD5 hash of file contents for change detection
/// </summary>
[Required]
[MaxLength(32)]
public string FileHash { get; set; } = "";
/// <summary>
/// File size in bytes (for download progress)
/// </summary>
public long FileSize { get; set; } = 0;
/// <summary>
/// Version number - increment when file changes
/// </summary>
public int Version { get; set; } = 1;
/// <summary>
/// If true, must be downloaded before game can start
/// If false, can be lazy-loaded when needed
/// </summary>
public bool IsRequired { get; set; } = false;
/// <summary>
/// Minimum client version required to use this asset
/// Clients below this version will be told to update
/// Format: "1.0.0"
/// </summary>
[MaxLength(16)]
public string? MinClientVersion { get; set; }
/// <summary>
/// Optional CDN path if different from FilePath
/// If null, uses FilePath as CDN path
/// </summary>
[MaxLength(256)]
public string? CdnPath { get; set; }
/// <summary>
/// When the file was last updated
/// </summary>
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
/// <summary>
/// When the file was first added
/// </summary>
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public bool IsEnabled { get; set; } = true;
/// <summary>
/// Get the CDN download path
/// </summary>
[NotMapped]
public string DownloadPath => CdnPath ?? FilePath;
}
public enum ClientAssetType
{
/// <summary>Scene file (.tscn) - mobs, UI, effects</summary>
Scene = 0,
/// <summary>GDScript file (.gd)</summary>
Script = 1,
/// <summary>Image file (.png, .jpg, .webp)</summary>
Texture = 2,
/// <summary>Resource file (.tres) - themes, materials, etc.</summary>
Resource = 3,
/// <summary>Audio file (.ogg, .wav, .mp3)</summary>
Audio = 4,
/// <summary>Shader file (.gdshader)</summary>
Shader = 5,
/// <summary>Font file (.ttf, .otf)</summary>
Font = 6,
/// <summary>JSON data file</summary>
Data = 7
}