diff --git a/Otakians/Pages/Index.razor b/Otakians/Pages/Index.razor index e530763..17e15c1 100644 --- a/Otakians/Pages/Index.razor +++ b/Otakians/Pages/Index.razor @@ -18,7 +18,7 @@ - + Damn @@ -34,15 +34,15 @@ @for (int i = 0; i < 200; i++) { - int postId = (LoadedImages.Count > i) ? LoadedImages[i] : GetRandomImageNumber(); + Post post = (LoadedImages.Count > i) ? posts[i] : GetRandomPost(); - + - @("@" + RandomUsernames[postId]) + @("@" + post.Publisher) - + @@ -61,19 +61,25 @@ } List LoadedImages = new List(); + List posts = new List(); private Random random = new Random(); const int numImages = 211; - int GetRandomImageNumber() + Post GetRandomPost() { - int selectedImage; + int selectedPostNum; reselect: - selectedImage = random.Next(0, numImages); - if (LoadedImages.Contains(selectedImage)) + selectedPostNum = random.Next(1, numImages); + if (LoadedImages.Contains(selectedPostNum)) goto reselect; - LoadedImages.Add(selectedImage); - return selectedImage; + LoadedImages.Add(selectedPostNum); + + + var selectedPost = new Post(selectedPostNum); + Console.WriteLine("Selected: " + selectedPost.Id); + posts.Add(selectedPost); + return selectedPost; } string GetImage(int imageIndex) @@ -88,18 +94,48 @@ // TODO: Add a "save post" button to each post. - string[] RandomUsernames = new string[1000]; + static string[]? RandomUsernames; protected override async Task OnInitializedAsync() { 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; } + + 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; + } + } + + } } \ No newline at end of file