- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeybindSystem.cs
More file actions
Latest commit
96 lines (82 loc) · 3.7 KB
/
Copy pathKeybindSystem.cs
File metadata and controls
96 lines (82 loc) · 3.7 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
usingTerraria;
usingTerraria.ModLoader;
usingTerraria.GameInput;
usingMicrosoft.Xna.Framework.Input;
usingTerraria.IO;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingMicrosoft.Xna.Framework;
namespaceTSC
{
publicclassKeybindSystem:ModSystem
{
publicstaticModKeybindCycleLevelButton{get;privateset;}
publicstaticResourcePackListPreviousOriginalPacks{get;privateset;}
publicoverridevoidLoad()
{
CycleLevelButton=KeybindLoader.RegisterKeybind(Mod,"Cycle Spice Level",Keys.P);
}
publicoverridevoidUnload()
{
CycleLevelButton=null;
PreviousOriginalPacks=null;
}
publicstaticvoidSetPreviousPacks(ResourcePackListpacks)
{
PreviousOriginalPacks=packs;
}
}
publicclassTSCPlayer:ModPlayer
{
publicoverridevoidProcessTriggers(TriggersSettriggersSet)
{
if(KeybindSystem.CycleLevelButton.JustPressed)
{
varconfig=ModContent.GetInstance<TSCConfig>();
// Cycle through levels: Safe (0) -> Spicy (1) -> NSFW (2) -> Safe (0)
config.CurrentSpiceLevel=(SpiceLevel)(((int)config.CurrentSpiceLevel+1)%3);
stringmodeName=config.CurrentSpiceLevel.ToString().ToUpper();
ColormsgColor=config.CurrentSpiceLevel==SpiceLevel.Safe?Color.LightGreen:
(config.CurrentSpiceLevel==SpiceLevel.Spicy?Color.Yellow:Color.LightCoral);
Main.NewText($"[TSC] Mode Changed to: {modeName}",msgColor);
ApplyResourcePacks(config);
}
}
privatevoidApplyResourcePacks(TSCConfigconfig)
{
if(config.CensoredResourcePacks==null||config.CensoredResourcePacks.Count==0)
return;
// If we are currently allowing everything, restore the original unmodified list
if(config.CurrentSpiceLevel==SpiceLevel.NSFW)
{
if(KeybindSystem.PreviousOriginalPacks!=null)
{
Main.AssetSourceController.UseResourcePacks(KeybindSystem.PreviousOriginalPacks);
KeybindSystem.SetPreviousPacks(null);// Clear so it grabs a fresh state next time we restrict
}
}
else
{
// We are restricting textures. First, save original state if not already saved.
if(KeybindSystem.PreviousOriginalPacks==null)
{
KeybindSystem.SetPreviousPacks(Main.AssetSourceController.ActiveResourcePackList);
}
varsafePacks=KeybindSystem.PreviousOriginalPacks.AllPacks
.Where(pack =>{
// Check if pack has a "Spice State" assigned to it
if(config.CensoredResourcePacks.TryGetValue(pack.Name,outintstate)&&state>0)
{
// Keep it only if its rating is lesser or equal to our current active mode limit!
returnstate<=(int)config.CurrentSpiceLevel;
}
returntrue;
})
.OrderByDescending(pack =>config.ResourcePackPriorities!=null&&config.ResourcePackPriorities.TryGetValue(pack.Name,outintpriority)?priority:0)
.ToList();
// Apply the strictly clean list
Main.AssetSourceController.UseResourcePacks(newResourcePackList(safePacks));
}
}
}
}