-
Notifications
You must be signed in to change notification settings - Fork 0
/
LooseFileLoader.cs
38 lines (31 loc) · 1.25 KB
/
LooseFileLoader.cs
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
using System.IO;
using System.Linq;
using Base_Mod;
namespace Decal_Loader;
public class LooseFileLoader(string configPath) : BaseLoader(configPath) {
protected override void Load() {
var files = Directory.EnumerateFiles(configPath, "*", SearchOption.TopDirectoryOnly)
.Where(file => file.EndsWith(".png")
|| file.EndsWith(".jpg")
|| file.EndsWith(".jpeg")
|| file.EndsWith(".bmp"))
.ToList();
if (files.Count == 0) return;
var category = CreateDecalCategory("Modded");
var log = new LogBuffer();
foreach (var file in files) {
CreateDecal(category, file, log);
}
log.Flush();
}
protected static void CreateDecal(DecalCategory category, string file, LogBuffer log) {
var guid = Database.instance.GetGuidForUri(file);
if (guid == null) {
guid = GUID.Create();
Database.instance.Add(file, (GUID) guid);
}
var texture = LoadTexture(file);
RegisterDecal(category, (GUID) guid, texture);
log.WriteLine($"Loaded decal: {file}.");
}
}