Skip to content

Commit

Permalink
Various tweaks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Dec 20, 2024
1 parent a87172c commit eb22778
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 98 deletions.
1 change: 1 addition & 0 deletions Src/NationsConverter/NationsConverter.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.0.0-alpha.1</Version>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
12 changes: 6 additions & 6 deletions Src/NationsConverter/Stages/MediaTrackerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace NationsConverter.Stages;

internal sealed class MediaTrackerStage
internal sealed class MediaTrackerStage : EnvironmentStageBase
{
private readonly CGameCtnChallenge mapIn;
private readonly CGameCtnChallenge mapOut;
Expand All @@ -12,14 +12,14 @@ internal sealed class MediaTrackerStage
private readonly Int3 blockSize;
private readonly Int3 centerOffset;

public MediaTrackerStage(CGameCtnChallenge mapIn, CGameCtnChallenge mapOut, NationsConverterConfig config)
public MediaTrackerStage(CGameCtnChallenge mapIn, CGameCtnChallenge mapOut, NationsConverterConfig config) : base(mapIn)
{
this.mapIn = mapIn;
this.mapOut = mapOut;
this.config = config;

blockSize = mapIn.Collection.GetValueOrDefault().GetBlockSize();
centerOffset = new Int3((mapOut.Size.X - mapIn.Size.X) / 2, 0, (mapOut.Size.Z - mapIn.Size.Z) / 2) ;
centerOffset = new Int3((mapOut.Size.X - mapIn.Size.X) / 2, 0, (mapOut.Size.Z - mapIn.Size.Z) / 2);
}

public void Convert()
Expand Down Expand Up @@ -182,7 +182,7 @@ public void Convert()
Start = cameraGame.Start,
End = cameraGame.End,
};
newCameraGame.CreateChunk<CGameCtnMediaBlockCameraGame.Chunk03084007>().Version = 2;
newCameraGame.CreateChunk<CGameCtnMediaBlockCameraGame.Chunk03084007>().Version = 4;

newTrack.Blocks.Add(newCameraGame);
break;
Expand Down Expand Up @@ -214,9 +214,9 @@ public void Convert()
var coordEnumerable = trigger.Coords?.Select(coord => coord with
{
X = coord.X * blockSize.X / 32,
Y = coord.Y * blockSize.Y / 8 + 9,
Y = coord.Y * blockSize.Y / 8 + 8,
Z = coord.Z * blockSize.Z / 32,
});
} + centerOffset);
var coords = new List<Int3>();

foreach (var coord in coordEnumerable ?? [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ Blocks:
StadiumRoadDirtToRoadGrass:
Items:
- Name: RoadDirt/RoadLow/StadiumRoadDirt/Ground_3_0.Item.Gbx
Modernized: true
- Name: RoadDirt/RoadLow/StadiumRoadDirtFenceStraight/Ground_0_0.Item.Gbx
Modernized: true
StadiumRoadDirtCheckpoint:
NoItem: true
NoTerrainModifier: true
Expand Down Expand Up @@ -944,11 +946,13 @@ Blocks:
Modernized: true
Conversion:
Name: StadiumRoadDirtHigh
Modernized: true
Variant: 3
Items:
- Name: Misc/Waypoint/Checkpoint.Item.Gbx
OffsetY: 8
- Name: RoadDirt/RoadHigh/StadiumRoadDirtHighFenceStraight/Ground_0_0.Item.Gbx
Modernized: true
StadiumRoadDirtHighGTCurve2:
Modernized: true
StadiumRoadDirtHighGTCurve3:
Expand Down
1 change: 1 addition & 0 deletions Src/NationsConverterCLI/NationsConverterCLI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.0.0-alpha.1</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
<div class="image-comparison">
<div class="images-container">
<img class="before-image" src="img/comparisons/before.png" alt="" />
<img class="after-image" src="img/comparisons/after.png" alt="" />
@rendermode InteractiveServer

<div class="image-comparison">
<div class="images-container">
<img class="before-image" src="@BeforeImage" alt="" style="@(sliderValue is not null ? $"width: {sliderValue}%" : "")" />
<img class="after-image" src="@AfterImage" alt="" />

<div class="slider-line"></div>
<div class="slider-icon">
<div class="slider-line" style="@(sliderValue is not null ? $"left: {sliderValue}%" : "")"></div>
<div class="slider-icon" style="@(sliderValue is not null ? $"left: {sliderValue}%" : "")">
<svg xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1"
stroke="currentColor"
class="w-6 h-6">
fill="none"
viewBox="0 0 24 24"
stroke-width="1"
stroke="currentColor"
class="w-6 h-6">
<path stroke-linecap="round"
stroke-linejoin="round"
d="M8.25 15L12 18.75 15.75 15m-7.5-6L12 5.25 15.75 9" />
stroke-linejoin="round"
d="M8.25 15L12 18.75 15.75 15m-7.5-6L12 5.25 15.75 9" />
</svg>
</div>

<input type="range" class="slider" min="0" max="100" step="0.01" />
<input type="range" class="slider" min="0" max="100" step="0.01" @oninput="@((args) => OnInput(args.Value.ToString()))" />
</div>
</div>

@code {
[Parameter]
public string? BeforeImage { get; set; }

[Parameter]
public string? AfterImage { get; set; }

private string? sliderValue;

public void OnInput(string value)
{
sliderValue = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="inner">
@if (Released)
{
<div class="nav-item"><a href="https://github.com/BigBang1112/nations-converter"><img src="img/discord-mark-white.svg" width="32" /></a></div>
<div class="nav-item"><a href="https://discord.gg/BJB3hjfkJa"><img src="img/discord-mark-white.svg" width="32" /></a></div>
}
<div class="nav-item"><a href="https://github.com/BigBang1112/nations-converter">GitHub</a></div>
<div class="nav-item"><a href="/login-discord">Sign in with Discord</a></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@page "/about"
@attribute [AllowAnonymous]

<PageTitle>About - Nations Converter 2</PageTitle>

<NavMenu Released="true" />
<div class="downloads">
<div class="readable-width white-mention">
<div class="readable-width-container">
<h2>About this project</h2>
<p>One day, we will write something here...</p>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
.download-latest {
padding: 20px;
font-size: 120%;
}

.download-latest div {
max-width: 1200px;
margin: 0 auto;
}

.latest-version {
text-align: center;
font-size: 150%;
}

.download-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
}

.download-button-set {
display: flex;
flex-direction: column;
gap: 8px;
}

.download-button-set a {
padding: 5px 10px;
}

.download-button-set a:first-child {
font-weight: bold;
}

.download-button-set div {
font-size: 80%;
}

.button-download-platform {
display: flex;
align-items: center;
width: 180px;
border-radius: 10px;
}

.button-download-platform img {
padding-right: 5px;
border-right: 2px solid #FFF5;
}

.button-download-platform span {
flex: 1;
text-align: center;
}

.edition-row {
display: flex;
gap: 5px;
flex-grow: 1;
width: 100%;
}

.button-download-assets {
display: flex;
padding: 5px 10px;
width: 100%;
align-items: center;
justify-content: center;
}

.button-download-assets span {
flex: 1;
text-align: center;
}

.download-assets {
display: flex;
flex-direction: column;
gap: 5px;
width: 400px;
font-size: 90%;
font-weight: bold;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@attribute [Authorize(Roles = "Admin,Developer,Modeler")]
@inject IDbContextFactory<AppDbContext> DbFactory
@inject IJSRuntime JS
@inject IWebHostEnvironment Env
@inject ILogger<Dashboard> Logger
@rendermode InteractiveServer

Expand Down Expand Up @@ -101,6 +102,7 @@
{
<button class="button" @onclick="DownloadValueReviewItemsAsync">Download value review items</button>
<button class="button" @onclick="UpdatePayoutValuesAsync">Update payout values</button>
<button class="button" @onclick="PublishCurrentZipAssetsAsync">Publish current ZIP assets</button>
<a href="/bulkfix">Bulk fix</a>
}

Expand Down Expand Up @@ -213,12 +215,12 @@

currentDiscordUser = discordUsers.FirstOrDefault(x => x.Id == snowflake);

/*blocks = db.Blocks
.Where(x => x.Name.Contains(searchValue))
.Where(x => x.EnvironmentId.Contains(Environment ?? ""))
.Include(x => x.AssignedTo)
.ThenInclude(x => x!.DiscordUser)
.AsNoTracking()
/*blocks = db.Blocks
.Where(x => x.Name.Contains(searchValue))
.Where(x => x.EnvironmentId.Contains(Environment ?? ""))
.Include(x => x.AssignedTo)
.ThenInclude(x => x!.DiscordUser)
.AsNoTracking()
.Select(x => new BlockDto
{
Id = x.Id,
Expand Down Expand Up @@ -291,6 +293,72 @@
await JS.InvokeVoidAsync("downloadFileFromStream", "UserData.zip", streamRef);
}

private async Task PublishCurrentZipAssetsAsync()
{
await using var db = DbFactory.CreateDbContext();

var uploads = await db.ItemUploads
.Include(x => x.BlockItem)
.ThenInclude(x => x.Block)
.GroupBy(x => x.BlockItem)
.Select(x => x.OrderByDescending(x => x.UploadedAt).First())
.ToListAsync();

var zipStreamDict = new Dictionary<string, MemoryStream>();
var zipDict = new Dictionary<string, ZipArchive>();

foreach (var env in new string[] { "Desert", "Rally", "Snow" })
{
var zipMs = new MemoryStream();
var zip = new ZipArchive(zipMs, ZipArchiveMode.Create, leaveOpen: true);
zipStreamDict[env] = zipMs;
zipDict[env] = zip;
}

foreach (var upload in uploads)
{
if (!zipDict.TryGetValue(upload.BlockItem.Block.EnvironmentId, out var zip))
{
continue;
}

var filePath = Path.Combine(
"Items",
"NC2",
upload.BlockItem.Block.CategoryId,
upload.BlockItem.Block.SubCategoryId,
"MM_Collision",
upload.BlockItem.Block.EnvironmentId,
upload.BlockItem.Block.PageName,
upload.BlockItem.Block.Name,
upload.BlockItem.FileName);

var entry = zip.CreateEntry(filePath, CompressionLevel.SmallestSize);

entry.LastWriteTime = upload.LastModifiedAt;

using var entryStream = entry.Open();
await using var uploadStream = new MemoryStream(upload.Data);
await uploadStream.CopyToAsync(entryStream);
}

foreach (var (env, zip) in zipDict)
{
zip.Dispose();
}

foreach (var (env, zipMs) in zipStreamDict)
{
zipMs.Position = 0;

var assets = Path.Combine(Env.WebRootPath, "assets");
Directory.CreateDirectory(assets);
await using var fs = new FileStream(Path.Combine(assets, $"{env}.zip"), FileMode.Create, FileAccess.Write, FileShare.None, 4096, useAsync: true);

await zipMs.CopyToAsync(fs);
}
}

private async Task DownloadClaimedInitItemsAsync()
{
if (currentDiscordUser is null)
Expand Down
Loading

0 comments on commit eb22778

Please sign in to comment.