-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeybindSystem.cs
More file actions
78 lines (66 loc) · 2.58 KB
/
Copy pathKeybindSystem.cs
File metadata and controls
78 lines (66 loc) · 2.58 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
78
using Terraria;
using Terraria.ModLoader;
using Terraria.GameInput;
using Microsoft.Xna.Framework.Input;
using Terraria.IO;
using System.Collections.Generic;
using System.Linq;
namespace TSC
{
public class KeybindSystem : ModSystem
{
public static ModKeybind TogglePanicButton { get; private set; }
public static ResourcePackList PreviousPacks { get; private set; }
public override void Load()
{
TogglePanicButton = KeybindLoader.RegisterKeybind(Mod, "Toggle Safe Mode", Keys.P);
}
public override void Unload()
{
TogglePanicButton = null;
PreviousPacks = null;
}
public static void SetPreviousPacks(ResourcePackList packs)
{
PreviousPacks = packs;
}
}
public class TSCPlayer : ModPlayer
{
public override void ProcessTriggers(TriggersSet triggersSet)
{
if (KeybindSystem.TogglePanicButton.JustPressed)
{
var config = ModContent.GetInstance<TSCConfig>();
config.SafeModeActive = !config.SafeModeActive;
string message = config.SafeModeActive ? "[TSC] Safe Mode ACTIVE. Purging textures..." : "[TSC] Safe Mode DEACTIVATED. Restoring textures...";
Main.NewText(message, config.SafeModeActive ? byte.MinValue : byte.MaxValue, 255, byte.MinValue);
ApplyResourcePacks(config);
}
}
private void ApplyResourcePacks(TSCConfig config)
{
if (config.CensoredResourcePacks == null || config.CensoredResourcePacks.Count == 0)
return;
if (config.SafeModeActive)
{
// Save the current state of textures
KeybindSystem.SetPreviousPacks(Main.AssetSourceController.ActiveResourcePackList);
// Filter out the naughty ones using the Dictionary logic
var safePacks = KeybindSystem.PreviousPacks.AllPacks
.Where(pack => !(config.CensoredResourcePacks.TryGetValue(pack.Name, out int state) && state > 0))
.ToList();
// Apply the clean list
Main.AssetSourceController.UseResourcePacks(new ResourcePackList(safePacks));
}
else
{
// Restore the original state if we have it saved
if (KeybindSystem.PreviousPacks != null)
{
Main.AssetSourceController.UseResourcePacks(KeybindSystem.PreviousPacks);
}
}
}
}
}