-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibraryExplorer.cs
More file actions
77 lines (70 loc) · 3.12 KB
/
LibraryExplorer.cs
File metadata and controls
77 lines (70 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Text.RegularExpressions;
namespace LoveMaker;
internal static class LibraryExplorer {
private static readonly string AwesomeLove2DUrl = "https://raw.githubusercontent.com/love2d-community/awesome-love2d/master/README.md";
internal record class LuaLibrary {
public String Name { set; get; } = "";
public String Description { set; get; } = "";
public String Link { set; get; } = "";
}
private static List<LuaLibrary> ParseLibraries(string markdownContent) {
var regex = new Regex(@"\[([^\]]+)\]\((https?://[^\)]+)\)\s*-\s*(.+)", RegexOptions.Compiled);
var matches = regex.Matches(markdownContent);
var libraries = new List<LuaLibrary>();
foreach (Match match in matches) {
try {
libraries.Add(new LuaLibrary {
Name = match.Groups[1].Value,
Link = match.Groups[2].Value,
Description = match.Groups[3].Value
});
} catch (Exception ex) {
MessageBox.Show($"Error parsing library: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
return libraries;
}
public static async Task<List<LuaLibrary>> ScrapeLibrariesAsync() {
string content;
try {
// Fetch the raw README content securely
using HttpClient client = new();
content = await client.GetStringAsync(new Uri(AwesomeLove2DUrl)).ConfigureAwait(false);
} catch (Exception ex) {
MessageBox.Show($"Error fetching data: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return [];
}
// Parse library information using Regex
return await Task.Run(() => ParseLibraries(content)).ConfigureAwait(false);
}
public static void Fetch(LuaLibrary lib) {
// Fetch the library from Github.
}
internal static class Libraries {
public static readonly LuaLibrary hump = new() {
Name = "hump",
Description = "LÖVE Helper Utilities for Massive Progression",
Link = "https://github.com/HDictus/hump.git"
};
public static readonly LuaLibrary lume = new() {
Name = "lume",
Description = "A collection of functions for Lua, geared towards game development.",
Link = "https://github.com/rxi/lume.git"
};
public static readonly LuaLibrary anim8 = new() {
Name = "anim8",
Description = "A small library to handle sprite animations.",
Link = "https://github.com/kikito/anim8.git"
};
public static readonly LuaLibrary sti = new() {
Name = "Simple Tiled Implementation",
Description = "Tiled map loader and renderer.",
Link = "https://github.com/karai17/Simple-Tiled-Implementation.git"
};
public static readonly LuaLibrary loveframes = new() {
Name = "LoveFrames",
Description = "A GUI library for LÖVE.",
Link = "https://github.com/NikolaiResokav/LoveFrames.git"
};
}
}