Working a bit
This commit is contained in:
@@ -4,3 +4,5 @@
|
|||||||
/.idea/
|
/.idea/
|
||||||
/bin/
|
/bin/
|
||||||
/obj/
|
/obj/
|
||||||
|
*.DotSettings
|
||||||
|
*.DotSettings.user
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
using System.Diagnostics;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using fxl.codes.kisekae.Models;
|
using fxl.codes.kisekae.Models;
|
||||||
|
using fxl.codes.kisekae.Services;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
@@ -8,17 +11,30 @@ namespace fxl.codes.kisekae.Controllers
|
|||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
|
private readonly ConfigurationReaderService _readerService;
|
||||||
|
|
||||||
public HomeController(ILogger<HomeController> logger)
|
public HomeController(ILogger<HomeController> logger, ConfigurationReaderService readerService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_readerService = readerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult LoadConfiguration(IFormFile file)
|
||||||
|
{
|
||||||
|
if (!(file?.FileName.EndsWith("cnf", StringComparison.InvariantCultureIgnoreCase) ?? false))
|
||||||
|
throw new Exception("Please select a *.cnf file");
|
||||||
|
|
||||||
|
var model = _readerService.ReadCnf(file);
|
||||||
|
return View("Index");
|
||||||
|
}
|
||||||
|
|
||||||
public IActionResult Privacy()
|
public IActionResult Privacy()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace fxl.codes.kisekae.Models
|
||||||
|
{
|
||||||
|
public class CelModel
|
||||||
|
{
|
||||||
|
public const string Regex = "#([0-9]*)[\\.]?([0-9]*?)\\s([a-zA-Z\\-0-9]*\\.[cCeElL]+)\\s[\\*]?([0-9]*)?\\s?:([0-9\\s]*);(.*)";
|
||||||
|
|
||||||
|
public CelModel(string line)
|
||||||
|
{
|
||||||
|
var matcher = new Regex(Regex);
|
||||||
|
var match = matcher.Match(line);
|
||||||
|
|
||||||
|
foreach (var group in matcher.GetGroupNames())
|
||||||
|
{
|
||||||
|
if (group == "0") continue;
|
||||||
|
|
||||||
|
match.Groups.TryGetValue(group, out var value);
|
||||||
|
if (string.IsNullOrEmpty(value?.Value)) continue;
|
||||||
|
|
||||||
|
switch (group)
|
||||||
|
{
|
||||||
|
case "1":
|
||||||
|
Id = int.Parse(value.Value);
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
Fix = int.Parse(value.Value);
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
FileName = value.Value;
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
|
PaletteId = int.Parse(value.Value);
|
||||||
|
break;
|
||||||
|
case "5":
|
||||||
|
foreach (var id in value.Value.Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
{
|
||||||
|
Sets[int.Parse(id)] = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "6":
|
||||||
|
Comment = value.Value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Id { get; }
|
||||||
|
public int Fix { get; }
|
||||||
|
public string FileName { get; }
|
||||||
|
public int PaletteId { get; }
|
||||||
|
public bool[] Sets { get; } = new bool[10];
|
||||||
|
public string Comment { get; }
|
||||||
|
|
||||||
|
public int CurrentPaletteId { get; set; }
|
||||||
|
public Point[] InitialPositions { get; set; } = new Point[10];
|
||||||
|
public Point[] CurrentPositions { get; set; } = new Point[10];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace fxl.codes.kisekae.Models
|
||||||
|
{
|
||||||
|
public class ConfigurationModel
|
||||||
|
{
|
||||||
|
private readonly string _originalDirectory;
|
||||||
|
|
||||||
|
public ConfigurationModel(string originalDirectory)
|
||||||
|
{
|
||||||
|
_originalDirectory = originalDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Height { get; set; }
|
||||||
|
public int Width { get; set; }
|
||||||
|
public int BorderColorIndex { get; set; }
|
||||||
|
|
||||||
|
public List<PaletteModel> Palettes { get; } = new();
|
||||||
|
public List<CelModel> Cels { get; } = new();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace fxl.codes.kisekae.Models
|
||||||
|
{
|
||||||
|
public class PaletteModel
|
||||||
|
{
|
||||||
|
private const string Regex = "%([a-zA-Z0-9\\-]*\\.[kKcCfF]+)[\\s]*;(.*)";
|
||||||
|
|
||||||
|
public string FileName { get; }
|
||||||
|
public string Comment { get; }
|
||||||
|
|
||||||
|
public PaletteModel(string line)
|
||||||
|
{
|
||||||
|
var matcher = new Regex(Regex);
|
||||||
|
var match = matcher.Match(line);
|
||||||
|
|
||||||
|
foreach (var group in matcher.GetGroupNames())
|
||||||
|
{
|
||||||
|
if (group == "0") continue;
|
||||||
|
|
||||||
|
match.Groups.TryGetValue(group, out var value);
|
||||||
|
if (string.IsNullOrEmpty(value?.Value)) continue;
|
||||||
|
|
||||||
|
switch (group)
|
||||||
|
{
|
||||||
|
case "1":
|
||||||
|
FileName = value.Value;
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
Comment = value.Value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace fxl.codes.kisekae.Models
|
||||||
|
{
|
||||||
|
public class Point
|
||||||
|
{
|
||||||
|
public int X { get; set; }
|
||||||
|
public int Y { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using fxl.codes.kisekae.Models;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace fxl.codes.kisekae.Services
|
||||||
|
{
|
||||||
|
public class ConfigurationReaderService
|
||||||
|
{
|
||||||
|
private readonly ILogger<ConfigurationReaderService> _logger;
|
||||||
|
|
||||||
|
public ConfigurationReaderService(ILogger<ConfigurationReaderService> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationModel ReadCnf(IFormFile file)
|
||||||
|
{
|
||||||
|
_logger.LogTrace($"Reading filename {file.FileName}");
|
||||||
|
|
||||||
|
var model = new ConfigurationModel("");
|
||||||
|
|
||||||
|
using var reader = new StreamReader(file.OpenReadStream());
|
||||||
|
while (!reader.EndOfStream)
|
||||||
|
{
|
||||||
|
var line = reader.ReadLine();
|
||||||
|
if (string.IsNullOrEmpty(line)) continue;
|
||||||
|
|
||||||
|
switch (line.ToCharArray()[0])
|
||||||
|
{
|
||||||
|
case '(':
|
||||||
|
var resolutionRegex = new Regex("\\(([0-9]*),([0-9]*)\\)");
|
||||||
|
var resolutionMatch = resolutionRegex.Match(line);
|
||||||
|
model.Width = int.Parse(resolutionMatch.Groups[1].Value);
|
||||||
|
model.Height = int.Parse(resolutionMatch.Groups[2].Value);
|
||||||
|
break;
|
||||||
|
case '[':
|
||||||
|
model.BorderColorIndex = int.Parse(line.Replace("[", ""));
|
||||||
|
break;
|
||||||
|
case '%':
|
||||||
|
model.Palettes.Add(new PaletteModel(line));
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
model.Cels.Add(new CelModel(line));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-8
@@ -1,10 +1,6 @@
|
|||||||
using System;
|
using fxl.codes.kisekae.Services;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.HttpsPolicy;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@@ -23,7 +19,10 @@ namespace fxl.codes.kisekae
|
|||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddControllersWithViews();
|
services.AddControllersWithViews()
|
||||||
|
.AddRazorRuntimeCompilation();
|
||||||
|
|
||||||
|
services.AddSingleton<ConfigurationReaderService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
@@ -50,8 +49,8 @@ namespace fxl.codes.kisekae
|
|||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapControllerRoute(
|
endpoints.MapControllerRoute(
|
||||||
name: "default",
|
"default",
|
||||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
"{controller=Home}/{action=Index}/{id?}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
$fxl-gray: #263238;
|
||||||
|
$fxl-orange: #ff6e40;
|
||||||
|
|
||||||
|
@use "@material/theme" with (
|
||||||
|
$primary: $fxl-orange,
|
||||||
|
$on-primary: $fxl-gray
|
||||||
|
);
|
||||||
|
|
||||||
|
@use "@material/icon-button";
|
||||||
|
@use "@material/top-app-bar/mdc-top-app-bar";
|
||||||
|
@use "@material/typography/mdc-typography";
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
footer {
|
||||||
|
font-size: smaller;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
ViewData["Title"] = "Home Page";
|
ViewData["Title"] = "Home Page";
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="text-center">
|
<form enctype="multipart/form-data" method="post" asp-action="LoadConfiguration">
|
||||||
<h1 class="display-4">Welcome</h1>
|
<input type="file" name="file">
|
||||||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
<input class="btn" type="submit" value="Upload">
|
||||||
</div>
|
</form>
|
||||||
+24
-34
@@ -3,43 +3,33 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<title>@ViewData["Title"] - fxl.codes.kisekae</title>
|
<title>Kisekae Online - @ViewData["Title"]</title>
|
||||||
<link rel="stylesheet" href="~/css/site.css"/>
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono|Roboto:900i" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="~/css/main.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header class="mdc-top-app-bar">
|
||||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
<div class="mdc-top-app-bar__row">
|
||||||
<div class="container">
|
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
|
||||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">fxl.codes.kisekae</a>
|
<button class="material-icons mdc-top-app-bar__navigation-icon mdc-icon-button" aria-label="Open navigation menu">menu</button>
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
<span class="mdc-top-app-bar__title">@ViewData["Title"]</span>
|
||||||
aria-expanded="false" aria-label="Toggle navigation">
|
</section>
|
||||||
<span class="navbar-toggler-icon"></span>
|
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
|
||||||
</button>
|
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Favorite">favorite</button>
|
||||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Search">search</button>
|
||||||
<ul class="navbar-nav flex-grow-1">
|
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Options">more_vert</button>
|
||||||
<li class="nav-item">
|
</section>
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
<div class="container">
|
|
||||||
<main role="main" class="pb-3">
|
|
||||||
@RenderBody()
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<footer class="border-top footer text-muted">
|
|
||||||
<div class="container">
|
|
||||||
© 2021 - <a href="https://fxl.codes">fxl</a> - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
</header>
|
||||||
|
<main class="mdc-top-app-bar--fixed-adjust" role="main">
|
||||||
|
@RenderBody()
|
||||||
|
</main>
|
||||||
|
<footer>
|
||||||
|
© 2021 - <a href="https://fxl.codes">fxl</a> - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
<script src="~/js/main.js" asp-append-version="true"></script>
|
||||||
@await RenderSectionAsync("Scripts", required: false)
|
@await RenderSectionAsync("Scripts", false)
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
|
||||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
|
||||||
@@ -2,25 +2,14 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="7-Zip.CommandLine" Version="18.1.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Services" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery\dist\jquery.js" />
|
|
||||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery\dist\jquery.min.js" />
|
|
||||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery\dist\jquery.min.map" />
|
|
||||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery\LICENSE.txt" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<TypeScriptCompile Include="Scripts\main.ts" />
|
<TypeScriptCompile Include="Scripts\main.ts" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.10" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user