-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModReloader.cs
More file actions
61 lines (54 loc) · 2.17 KB
/
ModReloader.cs
File metadata and controls
61 lines (54 loc) · 2.17 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
using System;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework.Graphics;
using ModReloader.Common.PacketHandlers;
using ModReloader.Core.Features.API;
using ReLogic.Content;
namespace ModReloader
{
public class ModReloader : Mod
{
public static ModReloader Instance { get; private set; }
public override void Load()
{
Instance = this;
Conf.C.ModsToReload = Conf.C.ModsToReload
.Distinct()
.Select(modName => modName.Trim())
.Where(modName => !string.IsNullOrEmpty(modName))
.ToList();
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
ModNetHandler.HandlePacket(reader, whoAmI);
}
public override object Call(params object[] args)
{
if (args.Length < 3 || args[0] is not string command)
{
Log.Error($"Invalid arguments for ModReloader.Call. Please supply the following arguments: command, name, action, [asset], [tooltip]. For example: ModReloader.Call('AddButton', 'Example Button', ExampleAsset.Value, 'Example Tooltip').");
return false;
}
if (command.Equals("AddButton", StringComparison.CurrentCultureIgnoreCase))
{
string name = args[1]?.ToString();
Action action = args[2] as Action;
Asset<Texture2D> asset = args.Length > 3 ? args[3] as Asset<Texture2D> : null;
string tooltip = args.Length > 4 ? args[4]?.ToString() : null;
if (string.IsNullOrEmpty(name) || action == null)
{
Log.Error("Invalid arguments for AddButton. Please provide a valid name and action.");
return false;
}
Log.Info($"Adding button '{name}' with asset '{asset?.Name}' and tooltip '{tooltip}'.");
return ModReloaderAPI.AddButton(name, action, asset, tooltip);
}
else
{
Log.Error($"Unknown command '{command}' for ModReloader.Call.");
}
return false;
}
}
}