From 744fc6bc574f48e7aca5411cae0a497a84a40d23 Mon Sep 17 00:00:00 2001 From: Lani Aung Date: Fri, 19 Nov 2021 23:04:15 -0700 Subject: [PATCH] Converting to EF, need to work on TS --- Controllers/HomeController.cs | 7 +- Controllers/PlayController.cs | 10 +- Entities/Action.cs | 8 + Entities/Cel.cs | 16 + Entities/CelConfig.cs | 19 + Entities/CelConfigDto.cs | 23 -- Entities/CelDto.cs | 13 - Entities/CelRenderDto.cs | 13 - Entities/Configuration.cs | 18 + Entities/ConfigurationDto.cs | 19 - Entities/IKisekaeFile.cs | 14 - Entities/Kisekae.cs | 14 + Entities/KisekaeDto.cs | 15 - Entities/Palette.cs | 14 + Entities/PaletteColor.cs | 10 + Entities/PaletteColorDto.cs | 13 - Entities/PaletteDto.cs | 14 - Entities/Render.cs | 8 + Extensions/DapperExtensions.cs | 96 ----- KisekaeContext.cs | 20 + Migrations/20211120044959_Startup.Designer.cs | 367 +++++++++++++++++ Migrations/20211120044959_Startup.cs | 275 +++++++++++++ Migrations/20211120052043_Renders.Designer.cs | 372 ++++++++++++++++++ Migrations/20211120052043_Renders.cs | 19 + .../20211120054914_RendersP2.Designer.cs | 353 +++++++++++++++++ Migrations/20211120054914_RendersP2.cs | 105 +++++ Migrations/KisekaeContextModelSnapshot.cs | 351 +++++++++++++++++ Models/CelModel.cs | 30 +- Models/ConfigurationModel.cs | 21 - Models/Coordinate.cs | 14 - Models/ErrorViewModel.cs | 2 - Models/KisekaeModel.cs | 18 + Models/PaletteModel.cs | 12 - Models/PlaysetModel.cs | 20 +- Services/ConfigurationReaderService.cs | 29 +- Services/DatabaseService.cs | 183 +++------ Services/FileParserService.cs | 93 ++--- Startup.cs | 6 +- Views/Home/Index.cshtml | 4 +- Views/Home/Play.cshtml | 36 -- Views/Play/Index.cshtml | 6 +- fxl.codes.kisekae.csproj | 14 +- global.json | 7 + 43 files changed, 2159 insertions(+), 542 deletions(-) create mode 100644 Entities/Action.cs create mode 100644 Entities/Cel.cs create mode 100644 Entities/CelConfig.cs delete mode 100644 Entities/CelConfigDto.cs delete mode 100644 Entities/CelDto.cs delete mode 100644 Entities/CelRenderDto.cs create mode 100644 Entities/Configuration.cs delete mode 100644 Entities/ConfigurationDto.cs delete mode 100644 Entities/IKisekaeFile.cs create mode 100644 Entities/Kisekae.cs delete mode 100644 Entities/KisekaeDto.cs create mode 100644 Entities/Palette.cs create mode 100644 Entities/PaletteColor.cs delete mode 100644 Entities/PaletteColorDto.cs delete mode 100644 Entities/PaletteDto.cs create mode 100644 Entities/Render.cs delete mode 100644 Extensions/DapperExtensions.cs create mode 100644 KisekaeContext.cs create mode 100644 Migrations/20211120044959_Startup.Designer.cs create mode 100644 Migrations/20211120044959_Startup.cs create mode 100644 Migrations/20211120052043_Renders.Designer.cs create mode 100644 Migrations/20211120052043_Renders.cs create mode 100644 Migrations/20211120054914_RendersP2.Designer.cs create mode 100644 Migrations/20211120054914_RendersP2.cs create mode 100644 Migrations/KisekaeContextModelSnapshot.cs delete mode 100644 Models/ConfigurationModel.cs delete mode 100644 Models/Coordinate.cs create mode 100644 Models/KisekaeModel.cs delete mode 100644 Models/PaletteModel.cs delete mode 100644 Views/Home/Play.cshtml create mode 100644 global.json diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 440e20c..a075d04 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.Linq; -using System.Threading.Tasks; using fxl.codes.kisekae.Models; using fxl.codes.kisekae.Services; using Microsoft.AspNetCore.Http; @@ -21,10 +20,10 @@ namespace fxl.codes.kisekae.Controllers _databaseService = databaseService; } - public async Task Index() + public IActionResult Index() { - var files = await _databaseService.GetAll(); - return View(files.Select(x => new ConfigurationModel(x))); + var files = _databaseService.GetAll(); + return View(files.Select(x => new KisekaeModel(x))); } [HttpPost] diff --git a/Controllers/PlayController.cs b/Controllers/PlayController.cs index 8875a82..4aa9eb1 100644 --- a/Controllers/PlayController.cs +++ b/Controllers/PlayController.cs @@ -1,4 +1,4 @@ -using System.Threading.Tasks; +using fxl.codes.kisekae.Models; using fxl.codes.kisekae.Services; using Microsoft.AspNetCore.Mvc; @@ -13,11 +13,11 @@ namespace fxl.codes.kisekae.Controllers _databaseService = databaseService; } - public async Task Index(int id) + public IActionResult Index(int id) { - var model = await _databaseService.LoadConfig(id); - - return View(model); + var config = _databaseService.GetConfig(id); + + return View(new PlaysetModel(config)); } } } \ No newline at end of file diff --git a/Entities/Action.cs b/Entities/Action.cs new file mode 100644 index 0000000..28f474f --- /dev/null +++ b/Entities/Action.cs @@ -0,0 +1,8 @@ +namespace fxl.codes.kisekae.Entities +{ + public class Action + { + public int Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Entities/Cel.cs b/Entities/Cel.cs new file mode 100644 index 0000000..7c71600 --- /dev/null +++ b/Entities/Cel.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace fxl.codes.kisekae.Entities +{ + public class Cel + { + public int Id { get; set; } + public string FileName { get; set; } + public byte[] Data { get; set; } + public int OffsetX { get; set; } + public int OffsetY { get; set; } + public int Height { get; set; } + public int Width { get; set; } + public Kisekae Kisekae { get; set; } + } +} \ No newline at end of file diff --git a/Entities/CelConfig.cs b/Entities/CelConfig.cs new file mode 100644 index 0000000..85653dd --- /dev/null +++ b/Entities/CelConfig.cs @@ -0,0 +1,19 @@ +namespace fxl.codes.kisekae.Entities +{ + public class CelConfig + { + public int Id { get; set; } + public Cel Cel { get; set; } + public Configuration Configuration { get; set; } + public int Mark { get; set; } + public int Fix { get; set; } + public Palette Palette { get; set; } + public int PaletteGroup { get; set; } + public string Comment { get; set; } + public int X { get; set; } + public int Y { get; set; } + public int Transparency { get; set; } + public Set Sets { get; set; } + public Render Render { get; set; } + } +} \ No newline at end of file diff --git a/Entities/CelConfigDto.cs b/Entities/CelConfigDto.cs deleted file mode 100644 index 4af34ed..0000000 --- a/Entities/CelConfigDto.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; -using System.Runtime.Serialization; - -namespace fxl.codes.kisekae.Entities -{ - [Table("cel_config")] - public class CelConfigDto - { - public int Id { get; set; } - [Column("cel_id")] public int CelId { get; set; } - [Column("config_id")] public int ConfigId { get; set; } - public int Mark { get; set; } - public int Fix { get; set; } - public Set Sets { get; set; } = Set.Unset; - public int Transparency { get; set; } - public string Comment { get; set; } - [Column("palette_id")] public int PaletteId { get; set; } - [IgnoreDataMember] public int PaletteIndex { get; set; } - [Column("palette_group")] public int PaletteGroup { get; set; } - public int X { get; set; } - public int Y { get; set; } - } -} \ No newline at end of file diff --git a/Entities/CelDto.cs b/Entities/CelDto.cs deleted file mode 100644 index ae8c49d..0000000 --- a/Entities/CelDto.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace fxl.codes.kisekae.Entities -{ - [Table("cel")] - public class CelDto : IKisekaeFile, IKisekaeParseable - { - public int Id { get; set; } - [Column("kisekae_id")] public int KisekaeId { get; set; } - public string Filename { get; set; } - public byte[] Data { get; set; } - } -} \ No newline at end of file diff --git a/Entities/CelRenderDto.cs b/Entities/CelRenderDto.cs deleted file mode 100644 index afe774d..0000000 --- a/Entities/CelRenderDto.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace fxl.codes.kisekae.Entities -{ - [Table("cel_render")] - public class CelRenderDto - { - public int Id { get; set; } - [Column("cel_id")] public int CelId { get; set; } - [Column("palette_id")] public int PaletteId { get; set; } - public byte[] Data { get; set; } - } -} \ No newline at end of file diff --git a/Entities/Configuration.cs b/Entities/Configuration.cs new file mode 100644 index 0000000..1d5c787 --- /dev/null +++ b/Entities/Configuration.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace fxl.codes.kisekae.Entities +{ + public class Configuration + { + public int Id { get; set; } + public string Name { get; set; } + public Kisekae Kisekae { get; set; } + public List Cels { get; set; } = new(); + public List Actions { get; set; } = new(); + + public string Data { get; set; } + public int Height { get; set; } + public int Width { get; set; } + public int BorderIndex { get; set; } + } +} \ No newline at end of file diff --git a/Entities/ConfigurationDto.cs b/Entities/ConfigurationDto.cs deleted file mode 100644 index 3467790..0000000 --- a/Entities/ConfigurationDto.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; - -namespace fxl.codes.kisekae.Entities -{ - [Table("configuration")] - public class ConfigurationDto : IKisekaeFile - { - public string Data { get; set; } - public int? Height { get; set; } - public int? Width { get; set; } - [Column("border_index")] public int? BorderIndex { get; set; } - public List Cels { get; set; } = new(); - public List Palettes { get; set; } = new(); - public int Id { get; set; } - [Column("kisekae_id")] public int KisekaeId { get; set; } - public string Filename { get; set; } - } -} \ No newline at end of file diff --git a/Entities/IKisekaeFile.cs b/Entities/IKisekaeFile.cs deleted file mode 100644 index ac7ffa9..0000000 --- a/Entities/IKisekaeFile.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace fxl.codes.kisekae.Entities -{ - public interface IKisekaeFile - { - int Id { get; set; } - int KisekaeId { get; set; } - string Filename { get; set; } - } - - public interface IKisekaeParseable - { - byte[] Data { get; set; } - } -} \ No newline at end of file diff --git a/Entities/Kisekae.cs b/Entities/Kisekae.cs new file mode 100644 index 0000000..3c061b0 --- /dev/null +++ b/Entities/Kisekae.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace fxl.codes.kisekae.Entities +{ + public class Kisekae + { + public int Id { get; set; } + public string FileName { get; set; } + public string CheckSum { get; set; } + public List Configurations { get; set; } = new(); + public List Cels { get; set; } = new(); + public List Palettes { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Entities/KisekaeDto.cs b/Entities/KisekaeDto.cs deleted file mode 100644 index 0357800..0000000 --- a/Entities/KisekaeDto.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; - -namespace fxl.codes.kisekae.Entities -{ - [Table("kisekae")] - public class KisekaeDto - { - public int Id { get; set; } - public string Name { get; init; } - public string Filename { get; init; } - public string Checksum { get; set; } - public IEnumerable Configurations { get; set; } - } -} \ No newline at end of file diff --git a/Entities/Palette.cs b/Entities/Palette.cs new file mode 100644 index 0000000..a261e09 --- /dev/null +++ b/Entities/Palette.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace fxl.codes.kisekae.Entities +{ + public class Palette + { + public int Id { get; set; } + public Kisekae Kisekae { get; set; } + public string FileName { get; set; } + public string Comment { get; set; } + public List Colors { get; set; } = new(); + public byte[] Data { get; set; } + } +} \ No newline at end of file diff --git a/Entities/PaletteColor.cs b/Entities/PaletteColor.cs new file mode 100644 index 0000000..4aa28ba --- /dev/null +++ b/Entities/PaletteColor.cs @@ -0,0 +1,10 @@ +namespace fxl.codes.kisekae.Entities +{ + public class PaletteColor + { + public int Id { get; set; } + public Palette Palette { get; set; } + public int Group { get; set; } + public string Hex { get; set; } + } +} \ No newline at end of file diff --git a/Entities/PaletteColorDto.cs b/Entities/PaletteColorDto.cs deleted file mode 100644 index 03dcd2e..0000000 --- a/Entities/PaletteColorDto.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace fxl.codes.kisekae.Entities -{ - [Table("palette_color")] - public class PaletteColorDto - { - public int Id { get; set; } - [Column("palette_id")] public int PaletteId { get; set; } - public int Group { get; set; } - public string Hex { get; set; } - } -} \ No newline at end of file diff --git a/Entities/PaletteDto.cs b/Entities/PaletteDto.cs deleted file mode 100644 index c2b6dcd..0000000 --- a/Entities/PaletteDto.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace fxl.codes.kisekae.Entities -{ - [Table("palette")] - public class PaletteDto : IKisekaeFile, IKisekaeParseable - { - public string Comment { get; set; } - public int Id { get; set; } - [Column("kisekae_id")] public int KisekaeId { get; set; } - public string Filename { get; set; } - public byte[] Data { get; set; } - } -} \ No newline at end of file diff --git a/Entities/Render.cs b/Entities/Render.cs new file mode 100644 index 0000000..39ad0cf --- /dev/null +++ b/Entities/Render.cs @@ -0,0 +1,8 @@ +namespace fxl.codes.kisekae.Entities +{ + public class Render + { + public int Id { get; set; } + public byte[] Image { get; set; } + } +} \ No newline at end of file diff --git a/Extensions/DapperExtensions.cs b/Extensions/DapperExtensions.cs deleted file mode 100644 index 5310bba..0000000 --- a/Extensions/DapperExtensions.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Data; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Dapper; - -namespace fxl.codes.kisekae.Extensions -{ - public static class DapperExtensions - { - public static async Task InsertAsync(this IDbConnection connection, T item) - { - var info = GetTableInfo(typeof(T)); - var statement = $"insert into {info.TableName} ({string.Join(",", info.Columns)}) values ({string.Join(",", info.Parameters)}) returning id"; - return await connection.QuerySingleAsync(statement, item); - } - - public static async Task InsertAsync(this IDbConnection connection, IEnumerable items) - { - var info = GetTableInfo(typeof(T)); - var statement = $"insert into {info.TableName} ({string.Join(",", info.Columns)}) values ({string.Join(",", info.Parameters)}) returning id"; - - var count = 0; - foreach (var item in items) - { - await connection.ExecuteAsync(statement, item); - count++; - } - - return count; - } - - public static async Task UpdateAsync(this IDbConnection connection, T item) - { - var list = new List { item }; - return await UpdateAsync(connection, list); - } - - public static async Task UpdateAsync(this IDbConnection connection, IEnumerable items) - { - var info = GetTableInfo(typeof(T)); - var statement = new StringBuilder().AppendLine($"update {info.TableName} set"); - - var sets = new List(); - for (var index = 0; index < info.Columns.Length; index++) - if (!info.Columns[index].Contains("_id")) - sets.Add($"{info.Columns[index]} = {info.Parameters[index]}"); - - statement.AppendLine(string.Join(",", sets)); - statement.AppendLine("where id = @Id"); - - var count = 0; - foreach (var item in items) - { - await connection.ExecuteAsync(statement.ToString(), item); - count++; - } - - return count; - } - - private static TableInfo GetTableInfo(Type type) - { - var tableAttribute = type.GetCustomAttribute(); - var tableName = tableAttribute?.Name ?? type.Name.ToLowerInvariant(); - - var columns = new List(); - var parameters = new List(); - foreach (var property in type.GetProperties(BindingFlags.Default | BindingFlags.Public | BindingFlags.Instance)) - { - if (string.Equals(property.Name, "id", StringComparison.InvariantCultureIgnoreCase) || property.PropertyType.IsGenericType) continue; - - var columnAttribute = property.GetCustomAttribute(); - columns.Add($"\"{columnAttribute?.Name ?? property.Name.ToLowerInvariant()}\""); - parameters.Add($"@{property.Name}"); - } - - return new TableInfo - { - TableName = tableName, - Columns = columns.ToArray(), - Parameters = parameters.ToArray() - }; - } - - private class TableInfo - { - public string TableName { get; set; } - public string[] Columns { get; set; } - public string[] Parameters { get; set; } - } - } -} \ No newline at end of file diff --git a/KisekaeContext.cs b/KisekaeContext.cs new file mode 100644 index 0000000..e1d70e0 --- /dev/null +++ b/KisekaeContext.cs @@ -0,0 +1,20 @@ +using fxl.codes.kisekae.Entities; +using Microsoft.EntityFrameworkCore; + +namespace fxl.codes.kisekae +{ + public class KisekaeContext : DbContext + { + public KisekaeContext(DbContextOptions options) : base(options) + { + } + + public DbSet KisekaeSets { get; set; } + public DbSet Configurations { get; set; } + public DbSet Cels { get; set; } + public DbSet CelConfigs { get; set; } + public DbSet Renders { get; set; } + public DbSet Palettes { get; set; } + public DbSet PaletteColors { get; set; } + } +} \ No newline at end of file diff --git a/Migrations/20211120044959_Startup.Designer.cs b/Migrations/20211120044959_Startup.Designer.cs new file mode 100644 index 0000000..b6d8aea --- /dev/null +++ b/Migrations/20211120044959_Startup.Designer.cs @@ -0,0 +1,367 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using fxl.codes.kisekae; + +#nullable disable + +namespace fxl.codes.kisekae.Migrations +{ + [DbContext(typeof(KisekaeContext))] + [Migration("20211120044959_Startup")] + partial class Startup + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Action", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConfigurationId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ConfigurationId"); + + b.ToTable("Action"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("FileName") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.Property("OffsetX") + .HasColumnType("integer"); + + b.Property("OffsetY") + .HasColumnType("integer"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Cels"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.CelConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CelId") + .HasColumnType("integer"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("ConfigurationId") + .HasColumnType("integer"); + + b.Property("Fix") + .HasColumnType("integer"); + + b.Property("Mark") + .HasColumnType("integer"); + + b.Property("PaletteGroup") + .HasColumnType("integer"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.Property("Sets") + .HasColumnType("integer"); + + b.Property("Transparency") + .HasColumnType("integer"); + + b.Property("X") + .HasColumnType("integer"); + + b.Property("Y") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CelId"); + + b.HasIndex("ConfigurationId"); + + b.HasIndex("PaletteId"); + + b.ToTable("CelConfigs"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BorderIndex") + .HasColumnType("integer"); + + b.Property("Data") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Kisekae", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CheckSum") + .HasColumnType("text"); + + b.Property("FileName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("KisekaeSets"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("FileName") + .HasColumnType("text"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Palettes"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.PaletteColor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Group") + .HasColumnType("integer"); + + b.Property("Hex") + .HasColumnType("text"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("PaletteId"); + + b.ToTable("PaletteColors"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Render", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CelId") + .HasColumnType("integer"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CelId"); + + b.HasIndex("PaletteId"); + + b.ToTable("Renders"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Action", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Configuration", null) + .WithMany("Actions") + .HasForeignKey("ConfigurationId"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Cels") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.CelConfig", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Cel", "Cel") + .WithMany() + .HasForeignKey("CelId"); + + b.HasOne("fxl.codes.kisekae.Entities.Configuration", "Configuration") + .WithMany("Cels") + .HasForeignKey("ConfigurationId"); + + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany() + .HasForeignKey("PaletteId"); + + b.Navigation("Cel"); + + b.Navigation("Configuration"); + + b.Navigation("Palette"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Configurations") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Palettes") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.PaletteColor", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany("Colors") + .HasForeignKey("PaletteId"); + + b.Navigation("Palette"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Render", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Cel", "Cel") + .WithMany() + .HasForeignKey("CelId"); + + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany() + .HasForeignKey("PaletteId"); + + b.Navigation("Cel"); + + b.Navigation("Palette"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.Navigation("Actions"); + + b.Navigation("Cels"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Kisekae", b => + { + b.Navigation("Cels"); + + b.Navigation("Configurations"); + + b.Navigation("Palettes"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.Navigation("Colors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20211120044959_Startup.cs b/Migrations/20211120044959_Startup.cs new file mode 100644 index 0000000..f0d709c --- /dev/null +++ b/Migrations/20211120044959_Startup.cs @@ -0,0 +1,275 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace fxl.codes.kisekae.Migrations +{ + public partial class Startup : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "KisekaeSets", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FileName = table.Column(type: "text", nullable: true), + CheckSum = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_KisekaeSets", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Cels", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FileName = table.Column(type: "text", nullable: true), + Data = table.Column(type: "bytea", nullable: true), + OffsetX = table.Column(type: "integer", nullable: false), + OffsetY = table.Column(type: "integer", nullable: false), + Height = table.Column(type: "integer", nullable: false), + Width = table.Column(type: "integer", nullable: false), + KisekaeId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Cels", x => x.Id); + table.ForeignKey( + name: "FK_Cels_KisekaeSets_KisekaeId", + column: x => x.KisekaeId, + principalTable: "KisekaeSets", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Configurations", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: true), + KisekaeId = table.Column(type: "integer", nullable: true), + Data = table.Column(type: "text", nullable: true), + Height = table.Column(type: "integer", nullable: false), + Width = table.Column(type: "integer", nullable: false), + BorderIndex = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Configurations", x => x.Id); + table.ForeignKey( + name: "FK_Configurations_KisekaeSets_KisekaeId", + column: x => x.KisekaeId, + principalTable: "KisekaeSets", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Palettes", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + KisekaeId = table.Column(type: "integer", nullable: true), + FileName = table.Column(type: "text", nullable: true), + Comment = table.Column(type: "text", nullable: true), + Data = table.Column(type: "bytea", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Palettes", x => x.Id); + table.ForeignKey( + name: "FK_Palettes_KisekaeSets_KisekaeId", + column: x => x.KisekaeId, + principalTable: "KisekaeSets", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Action", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: true), + ConfigurationId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Action", x => x.Id); + table.ForeignKey( + name: "FK_Action_Configurations_ConfigurationId", + column: x => x.ConfigurationId, + principalTable: "Configurations", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "CelConfigs", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CelId = table.Column(type: "integer", nullable: true), + ConfigurationId = table.Column(type: "integer", nullable: true), + Mark = table.Column(type: "integer", nullable: false), + Fix = table.Column(type: "integer", nullable: false), + PaletteId = table.Column(type: "integer", nullable: true), + PaletteGroup = table.Column(type: "integer", nullable: false), + Comment = table.Column(type: "text", nullable: true), + X = table.Column(type: "integer", nullable: false), + Y = table.Column(type: "integer", nullable: false), + Transparency = table.Column(type: "integer", nullable: false), + Sets = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CelConfigs", x => x.Id); + table.ForeignKey( + name: "FK_CelConfigs_Cels_CelId", + column: x => x.CelId, + principalTable: "Cels", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_CelConfigs_Configurations_ConfigurationId", + column: x => x.ConfigurationId, + principalTable: "Configurations", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_CelConfigs_Palettes_PaletteId", + column: x => x.PaletteId, + principalTable: "Palettes", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "PaletteColors", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + PaletteId = table.Column(type: "integer", nullable: true), + Group = table.Column(type: "integer", nullable: false), + Hex = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PaletteColors", x => x.Id); + table.ForeignKey( + name: "FK_PaletteColors_Palettes_PaletteId", + column: x => x.PaletteId, + principalTable: "Palettes", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Renders", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CelId = table.Column(type: "integer", nullable: true), + PaletteId = table.Column(type: "integer", nullable: true), + Image = table.Column(type: "bytea", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Renders", x => x.Id); + table.ForeignKey( + name: "FK_Renders_Cels_CelId", + column: x => x.CelId, + principalTable: "Cels", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Renders_Palettes_PaletteId", + column: x => x.PaletteId, + principalTable: "Palettes", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Action_ConfigurationId", + table: "Action", + column: "ConfigurationId"); + + migrationBuilder.CreateIndex( + name: "IX_CelConfigs_CelId", + table: "CelConfigs", + column: "CelId"); + + migrationBuilder.CreateIndex( + name: "IX_CelConfigs_ConfigurationId", + table: "CelConfigs", + column: "ConfigurationId"); + + migrationBuilder.CreateIndex( + name: "IX_CelConfigs_PaletteId", + table: "CelConfigs", + column: "PaletteId"); + + migrationBuilder.CreateIndex( + name: "IX_Cels_KisekaeId", + table: "Cels", + column: "KisekaeId"); + + migrationBuilder.CreateIndex( + name: "IX_Configurations_KisekaeId", + table: "Configurations", + column: "KisekaeId"); + + migrationBuilder.CreateIndex( + name: "IX_PaletteColors_PaletteId", + table: "PaletteColors", + column: "PaletteId"); + + migrationBuilder.CreateIndex( + name: "IX_Palettes_KisekaeId", + table: "Palettes", + column: "KisekaeId"); + + migrationBuilder.CreateIndex( + name: "IX_Renders_CelId", + table: "Renders", + column: "CelId"); + + migrationBuilder.CreateIndex( + name: "IX_Renders_PaletteId", + table: "Renders", + column: "PaletteId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Action"); + + migrationBuilder.DropTable( + name: "CelConfigs"); + + migrationBuilder.DropTable( + name: "PaletteColors"); + + migrationBuilder.DropTable( + name: "Renders"); + + migrationBuilder.DropTable( + name: "Configurations"); + + migrationBuilder.DropTable( + name: "Cels"); + + migrationBuilder.DropTable( + name: "Palettes"); + + migrationBuilder.DropTable( + name: "KisekaeSets"); + } + } +} diff --git a/Migrations/20211120052043_Renders.Designer.cs b/Migrations/20211120052043_Renders.Designer.cs new file mode 100644 index 0000000..20c75fc --- /dev/null +++ b/Migrations/20211120052043_Renders.Designer.cs @@ -0,0 +1,372 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using fxl.codes.kisekae; + +#nullable disable + +namespace fxl.codes.kisekae.Migrations +{ + [DbContext(typeof(KisekaeContext))] + [Migration("20211120052043_Renders")] + partial class Renders + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Action", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConfigurationId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ConfigurationId"); + + b.ToTable("Action"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("FileName") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.Property("OffsetX") + .HasColumnType("integer"); + + b.Property("OffsetY") + .HasColumnType("integer"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Cels"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.CelConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CelId") + .HasColumnType("integer"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("ConfigurationId") + .HasColumnType("integer"); + + b.Property("Fix") + .HasColumnType("integer"); + + b.Property("Mark") + .HasColumnType("integer"); + + b.Property("PaletteGroup") + .HasColumnType("integer"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.Property("Sets") + .HasColumnType("integer"); + + b.Property("Transparency") + .HasColumnType("integer"); + + b.Property("X") + .HasColumnType("integer"); + + b.Property("Y") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CelId"); + + b.HasIndex("ConfigurationId"); + + b.HasIndex("PaletteId"); + + b.ToTable("CelConfigs"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BorderIndex") + .HasColumnType("integer"); + + b.Property("Data") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Kisekae", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CheckSum") + .HasColumnType("text"); + + b.Property("FileName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("KisekaeSets"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("FileName") + .HasColumnType("text"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Palettes"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.PaletteColor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Group") + .HasColumnType("integer"); + + b.Property("Hex") + .HasColumnType("text"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("PaletteId"); + + b.ToTable("PaletteColors"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Render", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CelId") + .HasColumnType("integer"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CelId"); + + b.HasIndex("PaletteId"); + + b.ToTable("Renders"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Action", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Configuration", null) + .WithMany("Actions") + .HasForeignKey("ConfigurationId"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Cels") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.CelConfig", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Cel", "Cel") + .WithMany() + .HasForeignKey("CelId"); + + b.HasOne("fxl.codes.kisekae.Entities.Configuration", "Configuration") + .WithMany("Cels") + .HasForeignKey("ConfigurationId"); + + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany() + .HasForeignKey("PaletteId"); + + b.Navigation("Cel"); + + b.Navigation("Configuration"); + + b.Navigation("Palette"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Configurations") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Palettes") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.PaletteColor", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany("Colors") + .HasForeignKey("PaletteId"); + + b.Navigation("Palette"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Render", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Cel", "Cel") + .WithMany("Renders") + .HasForeignKey("CelId"); + + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany() + .HasForeignKey("PaletteId"); + + b.Navigation("Cel"); + + b.Navigation("Palette"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.Navigation("Renders"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.Navigation("Actions"); + + b.Navigation("Cels"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Kisekae", b => + { + b.Navigation("Cels"); + + b.Navigation("Configurations"); + + b.Navigation("Palettes"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.Navigation("Colors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20211120052043_Renders.cs b/Migrations/20211120052043_Renders.cs new file mode 100644 index 0000000..4dcc739 --- /dev/null +++ b/Migrations/20211120052043_Renders.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace fxl.codes.kisekae.Migrations +{ + public partial class Renders : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Migrations/20211120054914_RendersP2.Designer.cs b/Migrations/20211120054914_RendersP2.Designer.cs new file mode 100644 index 0000000..59be4d7 --- /dev/null +++ b/Migrations/20211120054914_RendersP2.Designer.cs @@ -0,0 +1,353 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using fxl.codes.kisekae; + +#nullable disable + +namespace fxl.codes.kisekae.Migrations +{ + [DbContext(typeof(KisekaeContext))] + [Migration("20211120054914_RendersP2")] + partial class RendersP2 + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Action", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConfigurationId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ConfigurationId"); + + b.ToTable("Action"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("FileName") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.Property("OffsetX") + .HasColumnType("integer"); + + b.Property("OffsetY") + .HasColumnType("integer"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Cels"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.CelConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CelId") + .HasColumnType("integer"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("ConfigurationId") + .HasColumnType("integer"); + + b.Property("Fix") + .HasColumnType("integer"); + + b.Property("Mark") + .HasColumnType("integer"); + + b.Property("PaletteGroup") + .HasColumnType("integer"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.Property("RenderId") + .HasColumnType("integer"); + + b.Property("Sets") + .HasColumnType("integer"); + + b.Property("Transparency") + .HasColumnType("integer"); + + b.Property("X") + .HasColumnType("integer"); + + b.Property("Y") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CelId"); + + b.HasIndex("ConfigurationId"); + + b.HasIndex("PaletteId"); + + b.HasIndex("RenderId"); + + b.ToTable("CelConfigs"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BorderIndex") + .HasColumnType("integer"); + + b.Property("Data") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Kisekae", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CheckSum") + .HasColumnType("text"); + + b.Property("FileName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("KisekaeSets"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("FileName") + .HasColumnType("text"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Palettes"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.PaletteColor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Group") + .HasColumnType("integer"); + + b.Property("Hex") + .HasColumnType("text"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("PaletteId"); + + b.ToTable("PaletteColors"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Render", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Image") + .HasColumnType("bytea"); + + b.HasKey("Id"); + + b.ToTable("Renders"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Action", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Configuration", null) + .WithMany("Actions") + .HasForeignKey("ConfigurationId"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Cels") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.CelConfig", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Cel", "Cel") + .WithMany() + .HasForeignKey("CelId"); + + b.HasOne("fxl.codes.kisekae.Entities.Configuration", "Configuration") + .WithMany("Cels") + .HasForeignKey("ConfigurationId"); + + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany() + .HasForeignKey("PaletteId"); + + b.HasOne("fxl.codes.kisekae.Entities.Render", "Render") + .WithMany() + .HasForeignKey("RenderId"); + + b.Navigation("Cel"); + + b.Navigation("Configuration"); + + b.Navigation("Palette"); + + b.Navigation("Render"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Configurations") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Palettes") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.PaletteColor", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany("Colors") + .HasForeignKey("PaletteId"); + + b.Navigation("Palette"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.Navigation("Actions"); + + b.Navigation("Cels"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Kisekae", b => + { + b.Navigation("Cels"); + + b.Navigation("Configurations"); + + b.Navigation("Palettes"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.Navigation("Colors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20211120054914_RendersP2.cs b/Migrations/20211120054914_RendersP2.cs new file mode 100644 index 0000000..6ce169d --- /dev/null +++ b/Migrations/20211120054914_RendersP2.cs @@ -0,0 +1,105 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace fxl.codes.kisekae.Migrations +{ + public partial class RendersP2 : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Renders_Cels_CelId", + table: "Renders"); + + migrationBuilder.DropForeignKey( + name: "FK_Renders_Palettes_PaletteId", + table: "Renders"); + + migrationBuilder.DropIndex( + name: "IX_Renders_CelId", + table: "Renders"); + + migrationBuilder.DropIndex( + name: "IX_Renders_PaletteId", + table: "Renders"); + + migrationBuilder.DropColumn( + name: "CelId", + table: "Renders"); + + migrationBuilder.DropColumn( + name: "PaletteId", + table: "Renders"); + + migrationBuilder.AddColumn( + name: "RenderId", + table: "CelConfigs", + type: "integer", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_CelConfigs_RenderId", + table: "CelConfigs", + column: "RenderId"); + + migrationBuilder.AddForeignKey( + name: "FK_CelConfigs_Renders_RenderId", + table: "CelConfigs", + column: "RenderId", + principalTable: "Renders", + principalColumn: "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_CelConfigs_Renders_RenderId", + table: "CelConfigs"); + + migrationBuilder.DropIndex( + name: "IX_CelConfigs_RenderId", + table: "CelConfigs"); + + migrationBuilder.DropColumn( + name: "RenderId", + table: "CelConfigs"); + + migrationBuilder.AddColumn( + name: "CelId", + table: "Renders", + type: "integer", + nullable: true); + + migrationBuilder.AddColumn( + name: "PaletteId", + table: "Renders", + type: "integer", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Renders_CelId", + table: "Renders", + column: "CelId"); + + migrationBuilder.CreateIndex( + name: "IX_Renders_PaletteId", + table: "Renders", + column: "PaletteId"); + + migrationBuilder.AddForeignKey( + name: "FK_Renders_Cels_CelId", + table: "Renders", + column: "CelId", + principalTable: "Cels", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Renders_Palettes_PaletteId", + table: "Renders", + column: "PaletteId", + principalTable: "Palettes", + principalColumn: "Id"); + } + } +} diff --git a/Migrations/KisekaeContextModelSnapshot.cs b/Migrations/KisekaeContextModelSnapshot.cs new file mode 100644 index 0000000..b4db2cf --- /dev/null +++ b/Migrations/KisekaeContextModelSnapshot.cs @@ -0,0 +1,351 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using fxl.codes.kisekae; + +#nullable disable + +namespace fxl.codes.kisekae.Migrations +{ + [DbContext(typeof(KisekaeContext))] + partial class KisekaeContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Action", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConfigurationId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ConfigurationId"); + + b.ToTable("Action"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("FileName") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.Property("OffsetX") + .HasColumnType("integer"); + + b.Property("OffsetY") + .HasColumnType("integer"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Cels"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.CelConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CelId") + .HasColumnType("integer"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("ConfigurationId") + .HasColumnType("integer"); + + b.Property("Fix") + .HasColumnType("integer"); + + b.Property("Mark") + .HasColumnType("integer"); + + b.Property("PaletteGroup") + .HasColumnType("integer"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.Property("RenderId") + .HasColumnType("integer"); + + b.Property("Sets") + .HasColumnType("integer"); + + b.Property("Transparency") + .HasColumnType("integer"); + + b.Property("X") + .HasColumnType("integer"); + + b.Property("Y") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CelId"); + + b.HasIndex("ConfigurationId"); + + b.HasIndex("PaletteId"); + + b.HasIndex("RenderId"); + + b.ToTable("CelConfigs"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BorderIndex") + .HasColumnType("integer"); + + b.Property("Data") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Kisekae", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CheckSum") + .HasColumnType("text"); + + b.Property("FileName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("KisekaeSets"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("FileName") + .HasColumnType("text"); + + b.Property("KisekaeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("KisekaeId"); + + b.ToTable("Palettes"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.PaletteColor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Group") + .HasColumnType("integer"); + + b.Property("Hex") + .HasColumnType("text"); + + b.Property("PaletteId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("PaletteId"); + + b.ToTable("PaletteColors"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Render", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Image") + .HasColumnType("bytea"); + + b.HasKey("Id"); + + b.ToTable("Renders"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Action", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Configuration", null) + .WithMany("Actions") + .HasForeignKey("ConfigurationId"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Cel", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Cels") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.CelConfig", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Cel", "Cel") + .WithMany() + .HasForeignKey("CelId"); + + b.HasOne("fxl.codes.kisekae.Entities.Configuration", "Configuration") + .WithMany("Cels") + .HasForeignKey("ConfigurationId"); + + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany() + .HasForeignKey("PaletteId"); + + b.HasOne("fxl.codes.kisekae.Entities.Render", "Render") + .WithMany() + .HasForeignKey("RenderId"); + + b.Navigation("Cel"); + + b.Navigation("Configuration"); + + b.Navigation("Palette"); + + b.Navigation("Render"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Configurations") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Kisekae", "Kisekae") + .WithMany("Palettes") + .HasForeignKey("KisekaeId"); + + b.Navigation("Kisekae"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.PaletteColor", b => + { + b.HasOne("fxl.codes.kisekae.Entities.Palette", "Palette") + .WithMany("Colors") + .HasForeignKey("PaletteId"); + + b.Navigation("Palette"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Configuration", b => + { + b.Navigation("Actions"); + + b.Navigation("Cels"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Kisekae", b => + { + b.Navigation("Cels"); + + b.Navigation("Configurations"); + + b.Navigation("Palettes"); + }); + + modelBuilder.Entity("fxl.codes.kisekae.Entities.Palette", b => + { + b.Navigation("Colors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Models/CelModel.cs b/Models/CelModel.cs index f811bd4..9066d2a 100644 --- a/Models/CelModel.cs +++ b/Models/CelModel.cs @@ -1,25 +1,21 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; +using System; +using fxl.codes.kisekae.Entities; namespace fxl.codes.kisekae.Models { public class CelModel { - public Dictionary ImageByPalette = new(); + public readonly int Fix; + public readonly string Image; + public readonly int Mark; + public readonly int ZIndex; - public int Id { get; init; } - public int Fix { get; init; } - public string FileName { get; init; } - public int PaletteId { get; init; } - public bool[] Sets { get; } = new bool[10]; - public string Comment { get; init; } - [JsonIgnore] public int Transparency { get; set; } - public double Opacity { get; internal set; } = 1.0; - public Coordinate[] InitialPositions { get; } = new Coordinate[10]; - [JsonIgnore] public string DefaultImage => ImageByPalette.ContainsKey(PaletteId) ? ImageByPalette[PaletteId] : null; - public Coordinate Offset { get; set; } - [JsonIgnore] public int Height { get; internal set; } - [JsonIgnore] public int Width { get; internal set; } - [JsonIgnore] public int ZIndex { get; internal set; } + internal CelModel(CelConfig celConfig, Render render, int zIndex) + { + Mark = celConfig.Mark; + Fix = celConfig.Fix; + ZIndex = zIndex; + Image = Convert.ToBase64String(render.Image); + } } } \ No newline at end of file diff --git a/Models/ConfigurationModel.cs b/Models/ConfigurationModel.cs deleted file mode 100644 index 538ff24..0000000 --- a/Models/ConfigurationModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using fxl.codes.kisekae.Entities; - -namespace fxl.codes.kisekae.Models -{ - public class ConfigurationModel - { - public ConfigurationModel(KisekaeDto dto) - { - Id = dto.Id; - Name = dto.Name; - - Configurations = new Dictionary(); - foreach (var config in dto.Configurations) Configurations.Add(config.Id, config.Filename); - } - - public int Id { get; } - public string Name { get; } - public IDictionary Configurations { get; } - } -} \ No newline at end of file diff --git a/Models/Coordinate.cs b/Models/Coordinate.cs deleted file mode 100644 index a5b1d1a..0000000 --- a/Models/Coordinate.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace fxl.codes.kisekae.Models -{ - public class Coordinate - { - public Coordinate(int x = 0, int y = 0) - { - X = x; - Y = y; - } - - public int X { get; } - public int Y { get; } - } -} \ No newline at end of file diff --git a/Models/ErrorViewModel.cs b/Models/ErrorViewModel.cs index c3990d3..3d04f69 100644 --- a/Models/ErrorViewModel.cs +++ b/Models/ErrorViewModel.cs @@ -1,5 +1,3 @@ -using System; - namespace fxl.codes.kisekae.Models { public class ErrorViewModel diff --git a/Models/KisekaeModel.cs b/Models/KisekaeModel.cs new file mode 100644 index 0000000..6819681 --- /dev/null +++ b/Models/KisekaeModel.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Linq; +using fxl.codes.kisekae.Entities; + +namespace fxl.codes.kisekae.Models +{ + public class KisekaeModel + { + public readonly IEnumerable> Configurations; + public readonly string Name; + + internal KisekaeModel(Kisekae kisekae) + { + Name = kisekae.FileName; + Configurations = kisekae.Configurations.Select(x => new KeyValuePair(x.Id, x.Name)).ToArray(); + } + } +} \ No newline at end of file diff --git a/Models/PaletteModel.cs b/Models/PaletteModel.cs deleted file mode 100644 index bfc7ef9..0000000 --- a/Models/PaletteModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using SixLabors.ImageSharp; - -namespace fxl.codes.kisekae.Models -{ - public class PaletteModel - { - public string FileName { get; internal set; } - public string Comment { get; internal set; } - public Color[] Colors { get; internal set; } = Array.Empty(); - } -} \ No newline at end of file diff --git a/Models/PlaysetModel.cs b/Models/PlaysetModel.cs index 893d4f8..0cccf2a 100644 --- a/Models/PlaysetModel.cs +++ b/Models/PlaysetModel.cs @@ -1,17 +1,25 @@ using System.Collections.Generic; using System.Text.Json.Serialization; using SixLabors.ImageSharp; +using Configuration = fxl.codes.kisekae.Entities.Configuration; namespace fxl.codes.kisekae.Models { public class PlaysetModel { + public readonly int Height; + public readonly string Name; + public readonly int Width; + public readonly CelModel[] Cels; + [JsonIgnore] public Color BorderColor = Color.Black; - public string Name { get; set; } - public int Height { get; set; } - public int Width { get; set; } - [JsonIgnore] public List Palettes { get; } = new(); - public List Cels { get; } = new(); - public bool[] EnabledSets { get; } = new bool[10]; + + internal PlaysetModel(Configuration configuration) + { + Name = configuration.Name; + Height = configuration.Height; + Width = configuration.Width; + Cels = new CelModel[0]; + } } } \ No newline at end of file diff --git a/Services/ConfigurationReaderService.cs b/Services/ConfigurationReaderService.cs index eb328b6..debc9bb 100644 --- a/Services/ConfigurationReaderService.cs +++ b/Services/ConfigurationReaderService.cs @@ -22,7 +22,7 @@ namespace fxl.codes.kisekae.Services _logger = logger; } - public void ReadConfigurationToDto(ConfigurationDto dto, IDictionary cels, IDictionary palettes) + public void ReadConfigurationToDto(Configuration dto, IDictionary cels, IDictionary palettes) { var initialPositions = new StringBuilder(); @@ -41,10 +41,10 @@ namespace fxl.codes.kisekae.Services dto.BorderIndex = int.Parse(borderValue); break; case '%': - dto.Palettes.Add(SetPalette(line, palettes)); + UpdatePalette(line, palettes); break; case '#': - dto.Cels.Add(SetCel(line, dto, cels)); + dto.Cels.Add(SetCelConfig(line, dto, cels, palettes.Values.ToArray())); break; case '$': case ' ': @@ -55,11 +55,11 @@ namespace fxl.codes.kisekae.Services SetInitialPositions(dto, initialPositions.ToString()); } - private CelConfigDto SetCel(string line, IKisekaeFile configuration, IDictionary cels) + private static CelConfig SetCelConfig(string line, Configuration configuration, IDictionary cels, IReadOnlyList palettes) { - var cel = new CelConfigDto + var cel = new CelConfig { - ConfigId = configuration.Id + Configuration = configuration }; if (line.Contains("%t")) @@ -81,11 +81,17 @@ namespace fxl.codes.kisekae.Services if (string.Equals(groupName, "FileName")) { - cel.CelId = cels[group.Value.ToLowerInvariant()].Id; + cel.Cel = cels[group.Value.ToLowerInvariant()]; continue; } - var property = typeof(CelConfigDto).GetProperty(groupName); + if (string.Equals(groupName, "PaletteIndex")) + { + cel.Palette = palettes[int.Parse(group.Value)]; + continue; + } + + var property = typeof(CelConfig).GetProperty(groupName); if (property == null) continue; var value = group.Value.Trim(); @@ -106,18 +112,19 @@ namespace fxl.codes.kisekae.Services } } + cel.Palette ??= palettes[0]; + return cel; } - private static PaletteDto SetPalette(string line, IDictionary palettes) + private static void UpdatePalette(string line, IDictionary palettes) { var parts = line.Split(';'); var palette = palettes[parts[0].Trim().ToLowerInvariant().Replace("%", "")]; if (parts.Length > 1) palette.Comment = parts[1].Trim(); - return palette; } - private static void SetInitialPositions(ConfigurationDto dto, string positions) + private static void SetInitialPositions(Configuration dto, string positions) { var sets = positions.Split('$', StringSplitOptions.RemoveEmptyEntries); foreach (var set in sets) diff --git a/Services/DatabaseService.cs b/Services/DatabaseService.cs index 5c62ac7..5bc69af 100644 --- a/Services/DatabaseService.cs +++ b/Services/DatabaseService.cs @@ -1,161 +1,98 @@ using System; using System.Collections.Generic; -using System.Data; using System.IO; using System.IO.IsolatedStorage; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using Dapper; using fxl.codes.kisekae.Entities; -using fxl.codes.kisekae.Extensions; -using fxl.codes.kisekae.Models; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; -using Npgsql; namespace fxl.codes.kisekae.Services { public class DatabaseService { - private const string ResolutionRegexPattern = @"\((?[0-9]*).(?[0-9]*)\)"; private readonly ConfigurationReaderService _configurationReaderService; + private readonly IDbContextFactory _contextFactory; - private readonly string _connectionString; private readonly FileParserService _fileParserService; private readonly ILogger _logger; private readonly IsolatedStorageFile _storage; public DatabaseService(ILogger logger, - IConfiguration configuration, ConfigurationReaderService configurationReaderService, - FileParserService fileParserService) + FileParserService fileParserService, + IDbContextFactory contextFactory) { _logger = logger; _configurationReaderService = configurationReaderService; _fileParserService = fileParserService; - _connectionString = configuration.GetConnectionString("kisekae"); + _contextFactory = contextFactory; _storage = IsolatedStorageFile.GetUserStoreForApplication(); } - public async Task> GetAll() + public IEnumerable GetAll() { - await using var connection = new NpgsqlConnection(_connectionString); - await connection.OpenAsync(); + using var context = _contextFactory.CreateDbContext(); + return context.KisekaeSets + .Include(x => x.Configurations) + .ToArray(); + } - using var multi = await connection.QueryMultipleAsync("select * from kisekae; select * from configuration"); - var files = multi.Read(); - var configs = multi.Read(); - var dictionary = configs.ToLookup(x => x.KisekaeId); - await connection.CloseAsync(); - - foreach (var kiss in files) kiss.Configurations = dictionary[kiss.Id]; - return files; + public Configuration GetConfig(int id) + { + using var context = _contextFactory.CreateDbContext(); + return context.Configurations + .Include(x => x.Cels).ThenInclude(x => x.Cel) + .Include(x => x.Kisekae).ThenInclude(x => x.Palettes).ThenInclude(x => x.Colors) + .FirstOrDefault(x => x.Id == id); } public async void StoreToDatabase(IFormFile file) { var memoryStream = await GetAsMemoryStream(file); - var checksum = Convert.ToBase64String(await new SHA256Managed().ComputeHashAsync(memoryStream)); + var checksum = Convert.ToBase64String(await SHA256.Create().ComputeHashAsync(memoryStream)); memoryStream.Position = 0; // Reset for re-read - await using var connection = new NpgsqlConnection(_connectionString); - await connection.OpenAsync(); - var transaction = await connection.BeginTransactionAsync(); + await using var context = await _contextFactory.CreateDbContextAsync(); + var existing = await context.KisekaeSets + .FirstOrDefaultAsync(x => string.Equals(x.FileName, file.FileName) + || string.Equals(x.CheckSum, checksum)); + if (existing != null) return; - try + _fileParserService.UnzipLzh(file, memoryStream); + var directory = Path.GetFileNameWithoutExtension(file.FileName); + + var kisekae = new Kisekae { - var existing = GetExisting(connection, file.FileName, checksum); - if (existing != null) return; + FileName = file.FileName, + CheckSum = checksum + }; - _fileParserService.UnzipLzh(file, memoryStream); - var directory = Path.GetFileNameWithoutExtension(file.FileName); - var kisekae = new KisekaeDto - { - Filename = file.FileName, - Name = directory, - Checksum = checksum - }; + var filenames = _storage.GetFileNames($"{Path.Combine(directory, "*")}"); + await SetInnerFiles(kisekae, directory, filenames); - kisekae.Id = await connection.InsertAsync(kisekae); + foreach (var config in kisekae.Configurations) + _configurationReaderService.ReadConfigurationToDto(config, + kisekae.Cels.ToDictionary(x => x.FileName.ToLowerInvariant()), + kisekae.Palettes.ToDictionary(x => x.FileName.ToLowerInvariant())); - var filenames = _storage.GetFileNames($"{Path.Combine(directory, "*")}"); - await SetInnerFiles(connection, directory, filenames, kisekae.Id); + SetPaletteColors(kisekae.Palettes); - using var saved = await connection.QueryMultipleAsync( - "select * from configuration where kisekae_id = @id; select * from cel where kisekae_id = @id; select * from palette where kisekae_id = @id", - new { id = kisekae.Id }); - var configs = saved.Read().ToList(); - var cels = saved.Read().ToDictionary(x => x.Filename.ToLowerInvariant()); - var palettes = saved.Read().ToDictionary(x => x.Filename.ToLowerInvariant()); - - foreach (var config in configs) - { - _configurationReaderService.ReadConfigurationToDto(config, cels, palettes); - await connection.InsertAsync(config.Cels); - await connection.UpdateAsync(config.Palettes); - await connection.UpdateAsync(config); - } - - var paletteColors = SetPaletteColors(palettes.Values); - await connection.InsertAsync(paletteColors); - - await transaction.CommitAsync(); - } - catch (Exception e) + foreach (var celConfig in kisekae.Configurations.SelectMany(config => config.Cels)) { - await transaction.RollbackAsync(); - _logger.LogError(e, $"Error saving file {file.FileName}"); + _fileParserService.RenderCel(celConfig); } - await connection.CloseAsync(); + await context.AddAsync(kisekae); + await context.SaveChangesAsync(); } - public async Task LoadConfig(int configId) + private async Task SetInnerFiles(Kisekae kisekae, string directory, IEnumerable filenames) { - await using var connection = new NpgsqlConnection(_connectionString); - await connection.OpenAsync(); - - var config = await connection.QuerySingleAsync("select * from configuration where id = @configId", new { configId }); - - var celIds = await connection.QueryAsync("select cel_id from cel_config where config_id = @configId", new { configId }); - var renders = await connection.QueryAsync($"select * from cel_render where cel_id in ({string.Join(",", celIds)})"); - if (!renders.Any()) - { - using var reader = await connection.QueryMultipleAsync($"select * from cel where id in ({string.Join(",", celIds)});" - + "select * from palette where kisekae_id = @kisekaeId", new { kisekaeId = config.KisekaeId }); - - var cels = reader.Read(); - var palettes = reader.Read().ToDictionary(x => x.Id); - - - } - - await connection.CloseAsync(); - return null; - } - - private KisekaeDto GetExisting(IDbConnection connection, string filename, string checksum) - { - var existing = connection.QuerySingleOrDefault("select * from kisekae where kisekae.filename = @Filename", new { Filename = filename }); - if (existing != null) - { - _logger.LogInformation($"Already existing upload {filename} under id {existing.Id}"); - return existing; - } - - existing = connection.QuerySingleOrDefault("select * from kisekae where kisekae.checksum = @Checksum", new { Checksum = checksum }); - if (existing == null) return null; - - _logger.LogInformation($"Already existing upload (checksum: {checksum}) under id {existing.Id} and filename {existing.Filename}"); - return existing; - } - - private async Task SetInnerFiles(IDbConnection connection, string directory, IEnumerable filenames, int id) - { - var files = new List(); foreach (var filename in filenames) { await using var reader = _storage.OpenFile(Path.Combine(directory, filename), FileMode.Open); @@ -167,40 +104,32 @@ namespace fxl.codes.kisekae.Services switch (Path.GetExtension(filename).ToLower()) { case ".cel": - files.Add(new CelDto + kisekae.Cels.Add(new Cel { - Filename = filename, - Data = bytes, - KisekaeId = id + FileName = filename, + Data = bytes }); break; case ".cnf": - files.Add(new ConfigurationDto + kisekae.Configurations.Add(new Configuration { - Filename = filename, - Data = Encoding.ASCII.GetString(bytes), - KisekaeId = id + Name = filename, + Data = Encoding.ASCII.GetString(bytes) }); break; case ".kcf": - files.Add(new PaletteDto + kisekae.Palettes.Add(new Palette { - Filename = filename, - Data = bytes, - KisekaeId = id + FileName = filename, + Data = bytes }); break; } } - - await connection.InsertAsync(files.OfType()); - await connection.InsertAsync(files.OfType()); - await connection.InsertAsync(files.OfType()); } - private List SetPaletteColors(IEnumerable palettes) + private void SetPaletteColors(IEnumerable palettes) { - var paletteColors = new List(); foreach (var palette in palettes) { var colors = _fileParserService.ParsePalette(palette, out var groups, out var colorsPerGroup); @@ -209,23 +138,19 @@ namespace fxl.codes.kisekae.Services for (var colorIndex = 0; colorIndex < colorsPerGroup; colorIndex++) { var color = colors[groupIndex * colorsPerGroup + colorIndex]; - paletteColors.Add(new PaletteColorDto + palette.Colors.Add(new PaletteColor { Group = groupIndex, - PaletteId = palette.Id, Hex = color.ToHex() }); } } - - return paletteColors; } private static async Task GetAsMemoryStream(IFormFile file) { var stream = new MemoryStream(); await file.CopyToAsync(stream); - return stream; } } diff --git a/Services/FileParserService.cs b/Services/FileParserService.cs index 0fdb64a..205e309 100644 --- a/Services/FileParserService.cs +++ b/Services/FileParserService.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Reflection; using System.Text; using fxl.codes.kisekae.Entities; -using fxl.codes.kisekae.Models; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using SixLabors.ImageSharp; @@ -79,16 +78,16 @@ namespace fxl.codes.kisekae.Services _storage.DeleteFile(file.FileName); } - public Color[] ParsePalette(PaletteDto palette, out int groups, out int colorsPerGroup) + public Color[] ParsePalette(Palette palette, out int groups, out int colorsPerGroup) { groups = 0; colorsPerGroup = 0; - + if (palette.Data.Length == 0) return null; if (!palette.Data[..KissHeader.Length].SequenceEqual(KissHeader)) return GetColors(palette.Data); - + // Verify palette mark? - if (palette.Data[4] != 16) _logger.LogError($"{palette.Filename} is not a valid palette file"); + if (palette.Data[4] != 16) _logger.LogError($"{palette.FileName} is not a valid palette file"); var colorDepth = Convert.ToInt32(palette.Data[5]); colorsPerGroup = BitConverter.ToInt16(palette.Data, 8); @@ -97,16 +96,16 @@ namespace fxl.codes.kisekae.Services return GetColors(palette.Data[32..], colorDepth, colorsPerGroup, groups); } - public void ParseCel(string directory, CelModel cel, IEnumerable palettes) + public void RenderCel(CelConfig celConfig) { - _logger.LogTrace($"Reading cel {cel.FileName} from {directory}"); - var buffer = ReadToBuffer(directory, cel.FileName); - if (buffer.Length == 0) return; + _logger.LogTrace($"Reading cel {celConfig.Cel.FileName}"); + var buffer = celConfig.Cel?.Data?.ToArray(); + if (buffer == null || buffer.Length == 0) return; if (buffer[..KissHeader.Length].SequenceEqual(KissHeader)) { // Verify cel mark? - if (buffer[4] != 32) _logger.LogError($"{cel.FileName} is not a valid cel file"); + if (buffer[4] != 32) _logger.LogError($"{celConfig.Cel.FileName} is not a valid cel file"); var pixelBits = Convert.ToInt32(buffer[5]); var width = BitConverter.ToInt16(buffer, 8); @@ -114,33 +113,24 @@ namespace fxl.codes.kisekae.Services var xOffset = BitConverter.ToInt16(buffer, 12); var yOffset = BitConverter.ToInt16(buffer, 14); - cel.ImageByPalette = GetCelImages(buffer[32..], palettes.ToArray(), width, height, pixelBits); - cel.Offset = new Coordinate(xOffset, yOffset); - cel.Height = height; - cel.Width = width; + celConfig.Cel.OffsetX = xOffset; + celConfig.Cel.OffsetY = yOffset; + celConfig.Cel.Height = height; + celConfig.Cel.Width = width; + + celConfig.Render = GetCelImage(buffer[32..], celConfig.Palette, width, height, pixelBits); } else { var width = BitConverter.ToInt16(buffer, 0); var height = BitConverter.ToInt16(buffer, 2); - cel.ImageByPalette = GetCelImages(buffer[4..], palettes.ToArray(), width, height); - cel.Height = height; - cel.Width = width; + celConfig.Cel.Height = height; + celConfig.Cel.Width = width; + celConfig.Render = GetCelImage(buffer[4..], celConfig.Palette, width, height); } } - private byte[] ReadToBuffer(string directory, string filename) - { - using var stream = _storage.OpenFile(Path.Combine(directory, filename), FileMode.Open); - if (!stream.CanRead) throw new InvalidDataException(); - - var buffer = new byte[stream.Length]; - stream.Read(buffer, 0, buffer.Length); - - return buffer; - } - private Color[] GetColors(IReadOnlyCollection bytes, int depth = 12, int colorsPerGroup = 16, int groups = 10) { _logger.LogTrace("Converting byte array to colors"); @@ -163,41 +153,38 @@ namespace fxl.codes.kisekae.Services return colors; } - private Dictionary GetCelImages(IReadOnlyCollection bytes, - IReadOnlyList palettes, - int width, - int height, - int pixelBits = 4) + private Render GetCelImage(IReadOnlyCollection bytes, + Palette palette, + int width, + int height, + int pixelBits = 4) { _logger.LogTrace("Converting byte array to base64 encoded gifs per palette"); - var dictionary = new Dictionary(); var values = GetValues(bytes, pixelBits); - for (var paletteIndex = 0; paletteIndex < palettes.Count; paletteIndex++) + using var bitmap = new Image(width, height); + var index = 0; + + for (var row = 0; row < height; row++) { - var palette = palettes[paletteIndex]; - using var bitmap = new Image(width, height); - var index = 0; - - for (var row = 0; row < height; row++) + var span = bitmap.GetPixelRowSpan(row); + for (var column = 0; column < width; column++) { - var span = bitmap.GetPixelRowSpan(row); - for (var column = 0; column < width; column++) - { - var value = values[index]; - span[column] = value == 0 || value >= palette.Colors.Length ? Transparent : palette.Colors[value]; - index++; - } - - if (width % 2 != 0 && pixelBits == 4) index++; + var value = values[index]; + span[column] = value == 0 || value >= palette.Colors.Count ? Transparent : Color.ParseHex(palette.Colors[value].Hex); + index++; } - using var memory = new MemoryStream(); - bitmap.SaveAsGif(memory); - dictionary.Add(paletteIndex, Convert.ToBase64String(memory.ToArray())); + if (width % 2 != 0 && pixelBits == 4) index++; } - return dictionary; + using var memory = new MemoryStream(); + bitmap.SaveAsGif(memory); + + return new Render + { + Image = memory.ToArray() + }; } private static int[] GetValues(IReadOnlyCollection bytes, int bits = 4) diff --git a/Startup.cs b/Startup.cs index d2c9921..ec26521 100644 --- a/Startup.cs +++ b/Startup.cs @@ -1,7 +1,7 @@ -using Dapper; using fxl.codes.kisekae.Services; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -24,6 +24,8 @@ namespace fxl.codes.kisekae services.AddControllersWithViews() .AddRazorRuntimeCompilation(); + services.AddDbContextFactory(options => { options.UseNpgsql(Configuration.GetConnectionString("kisekae")); }); + services.AddSingleton(); services.AddSingleton(); services.AddScoped(); @@ -58,8 +60,6 @@ namespace fxl.codes.kisekae "default", "{controller=Home}/{action=Index}/{id?}"); }); - - DefaultTypeMap.MatchNamesWithUnderscores = true; } } } \ No newline at end of file diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index 8dc80e0..24219a2 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -1,4 +1,4 @@ -@model IEnumerable +@model IEnumerable @{ ViewData["Title"] = "Select"; @@ -32,7 +32,7 @@ @foreach (var (key, value) in kiss.Configurations) {
  • - @value + @value
  • } diff --git a/Views/Home/Play.cshtml b/Views/Home/Play.cshtml deleted file mode 100644 index ba9eef0..0000000 --- a/Views/Home/Play.cshtml +++ /dev/null @@ -1,36 +0,0 @@ -@model PlaysetModel - -@{ - ViewData["Title"] = $"Play with {Model.Name}"; -} - -
    -
      -
    • - -
    • -
    • Sets
    • -
    -
    -
    -
    - @for (var index = 0; index < Model.Cels.Count; index++) - { - var cel = Model.Cels[index]; -
    - } -
    -
    -@section Scripts -{ - -} \ No newline at end of file diff --git a/Views/Play/Index.cshtml b/Views/Play/Index.cshtml index ba9eef0..a9c09cc 100644 --- a/Views/Play/Index.cshtml +++ b/Views/Play/Index.cshtml @@ -18,12 +18,12 @@
    - @for (var index = 0; index < Model.Cels.Count; index++) + @for (var index = 0; index < Model.Cels.Length; index++) { var cel = Model.Cels[index];
    }
    diff --git a/fxl.codes.kisekae.csproj b/fxl.codes.kisekae.csproj index c63101f..d2ab6fb 100644 --- a/fxl.codes.kisekae.csproj +++ b/fxl.codes.kisekae.csproj @@ -1,8 +1,9 @@ - net5.0 + net6.0 true + latestmajor @@ -14,9 +15,14 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/global.json b/global.json new file mode 100644 index 0000000..f443bd4 --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "6.0", + "rollForward": "latestMajor", + "allowPrerelease": true + } +} \ No newline at end of file