Working a bit
This commit is contained in:
@@ -4,3 +4,5 @@
|
||||
/.idea/
|
||||
/bin/
|
||||
/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.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -8,17 +11,30 @@ namespace fxl.codes.kisekae.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly ConfigurationReaderService _readerService;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger<HomeController> logger, ConfigurationReaderService readerService)
|
||||
{
|
||||
_logger = logger;
|
||||
_readerService = readerService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using fxl.codes.kisekae.Services;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
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.
|
||||
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.
|
||||
@@ -50,8 +49,8 @@ namespace fxl.codes.kisekae
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
"default",
|
||||
"{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";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
</div>
|
||||
<form enctype="multipart/form-data" method="post" asp-action="LoadConfiguration">
|
||||
<input type="file" name="file">
|
||||
<input class="btn" type="submit" value="Upload">
|
||||
</form>
|
||||
+20
-30
@@ -3,43 +3,33 @@
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>@ViewData["Title"] - fxl.codes.kisekae</title>
|
||||
<link rel="stylesheet" href="~/css/site.css"/>
|
||||
<title>Kisekae Online - @ViewData["Title"]</title>
|
||||
<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>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">fxl.codes.kisekae</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<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>
|
||||
<header class="mdc-top-app-bar">
|
||||
<div class="mdc-top-app-bar__row">
|
||||
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
|
||||
<button class="material-icons mdc-top-app-bar__navigation-icon mdc-icon-button" aria-label="Open navigation menu">menu</button>
|
||||
<span class="mdc-top-app-bar__title">@ViewData["Title"]</span>
|
||||
</section>
|
||||
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
|
||||
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Favorite">favorite</button>
|
||||
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Search">search</button>
|
||||
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Options">more_vert</button>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
<main class="mdc-top-app-bar--fixed-adjust" role="main">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
<footer>
|
||||
© 2021 - <a href="https://fxl.codes">fxl</a> - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
<script src="~/js/main.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", false)
|
||||
</body>
|
||||
</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>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
|
||||
</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>
|
||||
<TypeScriptCompile Include="Scripts\main.ts" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.10" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user