-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlagToggleWater.cs
36 lines (32 loc) · 1.29 KB
/
FlagToggleWater.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
using Celeste.Mod.Entities;
using Microsoft.Xna.Framework;
using Monocle;
namespace Celeste.Mod.SpringCollab2020.Entities {
[CustomEntity("SpringCollab2020/FlagToggleWater")]
[TrackedAs(typeof(Water))]
class FlagToggleWater : Water {
private FlagToggleComponent toggle;
public FlagToggleWater(EntityData data, Vector2 offset) : base(data, offset) {
// look up the displacement renderer to be able to toggle it.
DisplacementRenderHook displacementHook = null;
foreach (Component component in this) {
if (component is DisplacementRenderHook displacement) {
displacementHook = displacement;
break;
}
}
// when the water is toggled, toggle the displacement as well.
Add(toggle = new FlagToggleComponent(data.Attr("flag"), data.Bool("inverted"),
() => Remove(displacementHook), () => Add(displacementHook)));
}
public override void Update() {
if (toggle.Enabled) {
// update the entity as usual
base.Update();
} else {
// freeze the entity, but continue updating the component
toggle.Update();
}
}
}
}