CDN Integration

This commit is contained in:
dingo
2025-12-19 10:12:17 -05:00
parent 351478fedb
commit 260e6fa072
11 changed files with 2316 additions and 63 deletions
+1
View File
@@ -34,6 +34,7 @@ public sealed class GameDbContext : DbContext
public DbSet<DeathChest> DeathChests => Set<DeathChest>();
public DbSet<DeathChestItem> DeathChestItems => Set<DeathChestItem>();
public DbSet<DungeonPersistence> DungeonInstances => Set<DungeonPersistence>();
public DbSet<ClientAsset> ClientAssets => Set<ClientAsset>();
protected override void OnModelCreating(ModelBuilder b)
{
b.ApplyConfigurationsFromAssembly(typeof(GameDbContext).Assembly);
+111
View File
@@ -0,0 +1,111 @@
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
}
+14
View File
@@ -64,6 +64,20 @@ public class DungeonItemDefinition
public int MaxStack { get; set; } = 1;
// Visuals
/// <summary>
/// Path to the item's sprite image on CDN (e.g., "textures/items/sword_iron.png")
/// If null/empty, client uses fallback placeholder based on item type
/// </summary>
[MaxLength(256)]
public string? SpritePath { get; set; }
/// <summary>
/// Optional color tint as hex (e.g., "#ff0000" for red tint)
/// </summary>
[MaxLength(16)]
public string? TintColor { get; set; }
// Legacy field - kept for backwards compatibility
public int SpriteId { get; set; } = 0;
public bool IsEnabled { get; set; } = true;
+21 -16
View File
@@ -68,26 +68,31 @@ public class DungeonMobDefinition
[MaxLength(1024)]
public string AbilitiesJson { get; set; } = "{}";
// Visuals - reference to sprite/animation
// Visuals
/// <summary>
/// Path to the mob's .tscn scene file on CDN (e.g., "scenes/mobs/skeleton.tscn")
/// If null/empty, client uses fallback placeholder shape
/// </summary>
[MaxLength(256)]
public string? ScenePath { get; set; }
/// <summary>
/// Color tint applied to the mob (hex, e.g., "#ff0000" for red variant)
/// </summary>
[MaxLength(16)]
public string TintColor { get; set; } = "#ffffff";
/// <summary>
/// Scale multiplier for the mob (1.0 = normal size)
/// </summary>
public float Scale { get; set; } = 1.0f;
// Legacy fields - kept for backwards compatibility, ScenePath takes priority
[MaxLength(128)]
public string SpriteSheet { get; set; } = "mobs/skeleton.png";
public int SpriteIndex { get; set; } = 0; // Index in spritesheet
public string SpriteSheet { get; set; } = "";
public int SpriteWidth { get; set; } = 32;
public int SpriteHeight { get; set; } = 32;
[MaxLength(16)]
public string TintColor { get; set; } = "#ffffff"; // Color tint for variants
// Animation frames (JSON array of frame indices)
[MaxLength(256)]
public string IdleFrames { get; set; } = "[0]";
[MaxLength(256)]
public string WalkFrames { get; set; } = "[0,1,2,3]";
[MaxLength(256)]
public string AttackFrames { get; set; } = "[4,5]";
[MaxLength(256)]
public string DeathFrames { get; set; } = "[6,7]";
public float AnimationSpeed { get; set; } = 8f; // Frames per second
public bool IsEnabled { get; set; } = true;