Changed posts to be object orientated instead
This commit is contained in:
parent
c5ef374135
commit
f67676a160
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<MudOverlay @bind-Visible="isOverlayVisible" Style="backdrop-filter:blur(5px)" DarkBackground="true" AutoClose="true">
|
<MudOverlay @bind-Visible="isOverlayVisible" Style="backdrop-filter:blur(5px)" DarkBackground="true" AutoClose="true">
|
||||||
<MudPaper Elevation="3" Class="rounded-xl">
|
<MudPaper Elevation="3" Class="rounded-xl">
|
||||||
<MudImage Class="rounded-xl" Elevation="4" Src="@GetImage(selectedImage)" Width="750" Height="750"/>
|
<MudImage Class="rounded-xl" Elevation="4" Src="@selectedPost.ImagePath" Width="750" Height="750"/>
|
||||||
<MudContainer Class="pa-5 d-flex align-center justify-content-start">
|
<MudContainer Class="pa-5 d-flex align-center justify-content-start">
|
||||||
<MudText>
|
<MudText>
|
||||||
Damn
|
Damn
|
||||||
|
@ -34,15 +34,15 @@
|
||||||
<MudGrid Spacing="6" Justify="Justify.Center">
|
<MudGrid Spacing="6" Justify="Justify.Center">
|
||||||
@for (int i = 0; i < 200; i++)
|
@for (int i = 0; i < 200; i++)
|
||||||
{
|
{
|
||||||
int postId = (LoadedImages.Count > i) ? LoadedImages[i] : GetRandomImageNumber();
|
Post post = (LoadedImages.Count > i) ? posts[i] : GetRandomPost();
|
||||||
|
|
||||||
<MudItem @onclick="() => ClickPost(postId)">
|
<MudItem @onclick="() => ClickPost(post)">
|
||||||
<MudPaper Class="md-8" Style="position:relative">
|
<MudPaper Class="md-8" Style="position:relative">
|
||||||
<MudContainer Style="position:absolute;" Class="mt-4">
|
<MudContainer Style="position:absolute;" Class="mt-4">
|
||||||
<MudText Style="background-color:rgba(0, 0, 0, 0.55); backdrop-filter:blur(2px)" Class="pl-2 rounded-t-lg" Color="Color.Secondary" Typo="Typo.h6">@("@" + RandomUsernames[postId])</MudText>
|
<MudText Style="background-color:rgba(0, 0, 0, 0.55); backdrop-filter:blur(2px)" Class="pl-2 rounded-t-lg" Color="Color.Secondary" Typo="Typo.h6">@("@" + post.Publisher)</MudText>
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
<MudContainer>
|
<MudContainer>
|
||||||
<MudImage Class="rounded-lg my-4" Src="@GetImage(postId)" Height="250" Width="250"></MudImage>
|
<MudImage Class="rounded-lg my-4" Src="@post.ImagePath" Height="250" Width="250"></MudImage>
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
</MudPaper>
|
</MudPaper>
|
||||||
</MudItem>
|
</MudItem>
|
||||||
|
@ -61,19 +61,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> LoadedImages = new List<int>();
|
List<int> LoadedImages = new List<int>();
|
||||||
|
List<Post> posts = new List<Post>();
|
||||||
|
|
||||||
private Random random = new Random();
|
private Random random = new Random();
|
||||||
const int numImages = 211;
|
const int numImages = 211;
|
||||||
int GetRandomImageNumber()
|
Post GetRandomPost()
|
||||||
{
|
{
|
||||||
int selectedImage;
|
int selectedPostNum;
|
||||||
reselect:
|
reselect:
|
||||||
selectedImage = random.Next(0, numImages);
|
selectedPostNum = random.Next(1, numImages);
|
||||||
if (LoadedImages.Contains(selectedImage))
|
if (LoadedImages.Contains(selectedPostNum))
|
||||||
goto reselect;
|
goto reselect;
|
||||||
|
|
||||||
LoadedImages.Add(selectedImage);
|
LoadedImages.Add(selectedPostNum);
|
||||||
return selectedImage;
|
|
||||||
|
|
||||||
|
var selectedPost = new Post(selectedPostNum);
|
||||||
|
Console.WriteLine("Selected: " + selectedPost.Id);
|
||||||
|
posts.Add(selectedPost);
|
||||||
|
return selectedPost;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetImage(int imageIndex)
|
string GetImage(int imageIndex)
|
||||||
|
@ -88,18 +94,48 @@
|
||||||
|
|
||||||
// TODO: Add a "save post" button to each post.
|
// TODO: Add a "save post" button to each post.
|
||||||
|
|
||||||
string[] RandomUsernames = new string[1000];
|
static string[]? RandomUsernames;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
RandomUsernames = (await Http.GetStringAsync("RandomUsernames.txt")).Split("\n");
|
RandomUsernames = (await Http.GetStringAsync("RandomUsernames.txt")).Split("\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int selectedImage = 0;
|
Post selectedPost = new Post(-1);
|
||||||
|
|
||||||
void ClickPost(int postImage)
|
void ClickPost(Post post)
|
||||||
{
|
{
|
||||||
selectedImage = postImage;
|
selectedPost = post;
|
||||||
isOverlayVisible = true;
|
isOverlayVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Post
|
||||||
|
{
|
||||||
|
public Post(int imageIndex)
|
||||||
|
{
|
||||||
|
this.Id = imageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int ImageIndex { get => Id; }
|
||||||
|
public string ImagePath { get => $@"\images\AnimeImages\AnimeImage ({ImageIndex}).jpeg"; }
|
||||||
|
private string publisher = "Unknown";
|
||||||
|
|
||||||
|
public string Publisher
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (publisher == "Unknown" && RandomUsernames != null)
|
||||||
|
publisher = RandomUsernames[Id];
|
||||||
|
|
||||||
|
return publisher;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
publisher = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue