Files
systemrevivalserver/data/entities/MobSpriteSheet.cs
T
2025-12-27 20:12:40 -05:00

168 lines
5.4 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataServer.Data.Entities;
/// <summary>
/// Defines a sprite sheet uploaded to the CDN
/// </summary>
[Table("mob_sprite_sheets")]
public class MobSpriteSheet
{
[Key]
public int Id { get; set; }
/// <summary>Friendly name for admin UI</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>CDN path (e.g., "textures/mobs/skeleton.png")</summary>
[Required, MaxLength(256)]
public string CdnPath { get; set; } = "";
/// <summary>Total width of the sprite sheet in pixels</summary>
public int SheetWidth { get; set; } = 512;
/// <summary>Total height of the sprite sheet in pixels</summary>
public int SheetHeight { get; set; } = 512;
/// <summary>Width of each frame in pixels</summary>
public int FrameWidth { get; set; } = 64;
/// <summary>Height of each frame in pixels</summary>
public int FrameHeight { get; set; } = 64;
/// <summary>Number of columns in the sheet (calculated from width/frameWidth)</summary>
[NotMapped]
public int Columns => SheetWidth / FrameWidth;
/// <summary>Number of rows in the sheet</summary>
[NotMapped]
public int Rows => SheetHeight / FrameHeight;
/// <summary>Total number of frames</summary>
[NotMapped]
public int TotalFrames => Columns * Rows;
public bool IsEnabled { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
// Navigation
public ICollection<MobAnimationDefinition>? Animations { get; set; }
}
/// <summary>
/// Defines a named animation using frames from a sprite sheet
/// </summary>
[Table("mob_animation_definitions")]
public class MobAnimationDefinition
{
[Key]
public int Id { get; set; }
/// <summary>Which sprite sheet this animation uses</summary>
public int SpriteSheetId { get; set; }
[ForeignKey(nameof(SpriteSheetId))]
public MobSpriteSheet? SpriteSheet { get; set; }
/// <summary>Animation key (e.g., "walk_left", "attack_down", "idle", "cast")</summary>
[Required, MaxLength(64)]
public string Key { get; set; } = "";
/// <summary>Friendly name for admin</summary>
[MaxLength(64)]
public string? Name { get; set; }
/// <summary>
/// Comma-separated list of frame indices (0-based)
/// e.g., "0,1,2,3" or "8,9,10,11,10,9" for ping-pong
/// Frames are numbered left-to-right, top-to-bottom
/// </summary>
[Required, MaxLength(256)]
public string FrameSequence { get; set; } = "0";
/// <summary>Frames per second</summary>
public float Fps { get; set; } = 8f;
/// <summary>Whether the animation loops</summary>
public bool Loop { get; set; } = true;
/// <summary>Optional: flip horizontally (for reusing left as right)</summary>
public bool FlipX { get; set; } = false;
/// <summary>Optional: flip vertically</summary>
public bool FlipY { get; set; } = false;
public bool IsEnabled { get; set; } = true;
/// <summary>Parse frame sequence into array of ints</summary>
[NotMapped]
public int[] Frames => string.IsNullOrEmpty(FrameSequence)
? new[] { 0 }
: FrameSequence.Split(',').Select(s => int.TryParse(s.Trim(), out var n) ? n : 0).ToArray();
}
/// <summary>
/// Links a mob to its animations - which animations from which sheets it uses
/// </summary>
[Table("mob_animation_assignments")]
public class MobAnimationAssignment
{
[Key]
public int Id { get; set; }
/// <summary>Which mob this animation is for</summary>
public int MobDefinitionId { get; set; }
[ForeignKey(nameof(MobDefinitionId))]
public DungeonMobDefinition? MobDefinition { get; set; }
/// <summary>Which animation definition to use</summary>
public int AnimationDefinitionId { get; set; }
[ForeignKey(nameof(AnimationDefinitionId))]
public MobAnimationDefinition? AnimationDefinition { get; set; }
/// <summary>
/// Override key for this mob (e.g., map "walk" to specific directional animation)
/// If null, uses the animation's original key
/// </summary>
[MaxLength(64)]
public string? OverrideKey { get; set; }
/// <summary>Priority when multiple animations match (higher = preferred)</summary>
public int Priority { get; set; } = 0;
public bool IsEnabled { get; set; } = true;
}
/// <summary>
/// Maps ability to animation for a specific mob
/// </summary>
[Table("mob_ability_animation_mappings")]
public class MobAbilityAnimationMapping
{
[Key]
public int Id { get; set; }
/// <summary>The mob-ability assignment this mapping is for</summary>
public int AbilityAssignmentId { get; set; }
[ForeignKey(nameof(AbilityAssignmentId))]
public MobAbilityAssignment? AbilityAssignment { get; set; }
/// <summary>
/// Animation key to play when this ability is used
/// This should match one of the mob's assigned animations
/// </summary>
[Required, MaxLength(64)]
public string AnimationKey { get; set; } = "attack";
/// <summary>Optional: specific direction variant (down, up, left, right)</summary>
[MaxLength(16)]
public string? DirectionSuffix { get; set; }
}