Skip to content

Commit 4dac220

Browse files
committed
Foreground tentacles
1 parent 65bccf1 commit 4dac220

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
module SpringCollab2020ForegroundReflectionTentacles
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/ForegroundReflectionTentacles" ForegroundReflectionTentacles(x::Integer, y::Integer,
6+
nodes::Array{Tuple{Integer, Integer}, 1}=Tuple{Integer, Integer}[], fear_distance::String="", slide_until::Integer=0)
7+
8+
const placements = Ahorn.PlacementDict(
9+
"Foreground Tentacles (Spring Collab 2020)" => Ahorn.EntityPlacement(
10+
ForegroundReflectionTentacles,
11+
"point",
12+
Dict{String, Any}(),
13+
function(entity)
14+
entity.data["nodes"] = [(Int(entity.data["x"]) + 32, Int(entity.data["y"]))]
15+
end
16+
)
17+
)
18+
19+
# Maple definition doesn't have "Fake keys"
20+
const fearDistance = Dict{String, String}(
21+
"None" => "",
22+
"Close" => "close",
23+
"Medium" => "medium",
24+
"Far" => "far"
25+
)
26+
27+
Ahorn.nodeLimits(entity::ForegroundReflectionTentacles) = 1, -1
28+
29+
Ahorn.editingOptions(entity::ForegroundReflectionTentacles) = Dict{String, Any}(
30+
"fear_distance" => fearDistance
31+
)
32+
33+
function Ahorn.selection(entity::ForegroundReflectionTentacles)
34+
nodes = get(entity.data, "nodes", ())
35+
x, y = Ahorn.position(entity)
36+
37+
res = Ahorn.Rectangle[Ahorn.Rectangle(x - 12, y - 12, 24, 24)]
38+
39+
for node in nodes
40+
nx, ny = Int.(node)
41+
42+
push!(res, Ahorn.Rectangle(nx - 12, ny - 12, 24, 24))
43+
end
44+
45+
return res
46+
end
47+
48+
function drawTentacleIcon(ctx::Ahorn.Cairo.CairoContext, x, y)
49+
Ahorn.drawImage(ctx, Ahorn.Assets.tentacle, x - 12, y - 12)
50+
end
51+
52+
function Ahorn.renderSelectedAbs(ctx::Ahorn.Cairo.CairoContext, entity::ForegroundReflectionTentacles)
53+
px, py = Ahorn.position(entity)
54+
55+
for node in get(entity.data, "nodes", ())
56+
nx, ny = Int.(node)
57+
58+
Ahorn.drawArrow(ctx, px, py, nx, ny, Ahorn.colors.selection_selected_fc, headLength=6)
59+
drawTentacleIcon(ctx, nx, ny)
60+
61+
px, py = nx, ny
62+
end
63+
end
64+
65+
function Ahorn.renderAbs(ctx::Ahorn.Cairo.CairoContext, entity::ForegroundReflectionTentacles, room::Maple.Room)
66+
x, y = Ahorn.position(entity)
67+
drawTentacleIcon(ctx, x, y)
68+
end
69+
70+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Celeste.Mod.Entities;
2+
using Microsoft.Xna.Framework;
3+
using Monocle;
4+
using MonoMod.Utils;
5+
6+
namespace Celeste.Mod.SpringCollab2020.Entities {
7+
[CustomEntity("SpringCollab2020/ForegroundReflectionTentacles")]
8+
[TrackedAs(typeof(ReflectionTentacles))]
9+
class ForegroundReflectionTentacles : ReflectionTentacles {
10+
public ForegroundReflectionTentacles() : base() { }
11+
public ForegroundReflectionTentacles(EntityData data, Vector2 offset) : base(data, offset) { }
12+
13+
public override void Added(Scene scene) {
14+
// turn off createdFromLevel to prevent vanilla from spawning ReflectionTentacles.
15+
DynData<ReflectionTentacles> self = new DynData<ReflectionTentacles>(this);
16+
bool createdFromLevel = self.Get<bool>("createdFromLevel");
17+
self["createdFromLevel"] = false;
18+
19+
// run vanilla code.
20+
base.Added(scene);
21+
22+
// restore the createdFromLevel value.
23+
self["createdFromLevel"] = createdFromLevel;
24+
25+
// add tentacles like vanilla would, but make them ForegroundReflectionTentacles.
26+
if (createdFromLevel) {
27+
for (int i = 1; i < 4; i++) {
28+
ForegroundReflectionTentacles reflectionTentacles = new ForegroundReflectionTentacles();
29+
reflectionTentacles.Create(self.Get<float>("fearDistance"), self.Get<int>("slideUntilIndex"), i, Nodes);
30+
scene.Add(reflectionTentacles);
31+
}
32+
}
33+
34+
// bring all tentacles to the foreground.
35+
Depth = -1000000 + self.Get<int>("layer");
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)