Skip to content

Commit 0a393fd

Browse files
committed
Grouped Trigger Spikes
1 parent 004c60a commit 0a393fd

File tree

3 files changed

+466
-1
lines changed

3 files changed

+466
-1
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
module SpringCollab2020GroupedTriggerSpikes
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/GroupedTriggerSpikesUp" GroupedTriggerSpikesUp(x::Integer, y::Integer, width::Integer=Maple.defaultSpikeWidth, type::String="default")
6+
@mapdef Entity "SpringCollab2020/GroupedTriggerSpikesDown" GroupedTriggerSpikesDown(x::Integer, y::Integer, width::Integer=Maple.defaultSpikeWidth, type::String="default")
7+
@mapdef Entity "SpringCollab2020/GroupedTriggerSpikesLeft" GroupedTriggerSpikesLeft(x::Integer, y::Integer, height::Integer=Maple.defaultSpikeHeight, type::String="default")
8+
@mapdef Entity "SpringCollab2020/GroupedTriggerSpikesRight" GroupedTriggerSpikesRight(x::Integer, y::Integer, height::Integer=Maple.defaultSpikeHeight, type::String="default")
9+
10+
const placements = Ahorn.PlacementDict()
11+
12+
groupedTriggerSpikes = Dict{String, Type}(
13+
"up" => GroupedTriggerSpikesUp,
14+
"down" => GroupedTriggerSpikesDown,
15+
"left" => GroupedTriggerSpikesLeft,
16+
"right" => GroupedTriggerSpikesRight
17+
)
18+
19+
groupedTriggerSpikesUnion = Union{GroupedTriggerSpikesUp, GroupedTriggerSpikesDown, GroupedTriggerSpikesLeft, GroupedTriggerSpikesRight}
20+
21+
triggerSpikeColors = [
22+
(242, 90, 16, 255) ./ 255,
23+
(255, 0, 0, 255) ./ 255,
24+
(242, 16, 103, 255) ./ 255
25+
]
26+
27+
for variant in Maple.spike_types
28+
if variant != "tentacles"
29+
for (dir, entity) in groupedTriggerSpikes
30+
key = "Grouped Trigger Spikes ($(uppercasefirst(dir)), $(uppercasefirst(variant))) (Spring Collab 2020)"
31+
placements[key] = Ahorn.EntityPlacement(
32+
entity,
33+
"rectangle",
34+
Dict{String, Any}(
35+
"type" => variant
36+
)
37+
)
38+
end
39+
end
40+
end
41+
42+
Ahorn.editingOptions(entity::groupedTriggerSpikesUnion) = Dict{String, Any}(
43+
"type" => String[variant for variant in Maple.spike_types if variant != "tentacles"]
44+
)
45+
46+
directions = Dict{String, String}(
47+
"SpringCollab2020/GroupedTriggerSpikesUp" => "up",
48+
"SpringCollab2020/GroupedTriggerSpikesDown" => "down",
49+
"SpringCollab2020/GroupedTriggerSpikesLeft" => "left",
50+
"SpringCollab2020/GroupedTriggerSpikesRight" => "right",
51+
)
52+
53+
offsets = Dict{String, Tuple{Integer, Integer}}(
54+
"up" => (4, -4),
55+
"down" => (4, 4),
56+
"left" => (-4, 4),
57+
"right" => (4, 4),
58+
)
59+
60+
groupedTriggerSpikesOffsets = Dict{String, Tuple{Integer, Integer}}(
61+
"up" => (0, 5),
62+
"down" => (0, -4),
63+
"left" => (5, 0),
64+
"right" => (-4, 0),
65+
)
66+
67+
groupedTriggerRotationOffsets = Dict{String, Tuple{Number, Number}}(
68+
"up" => (3, -1),
69+
"right" => (4, 3),
70+
"down" => (5, 5),
71+
"left" => (-1, 4),
72+
)
73+
74+
rotations = Dict{String, Number}(
75+
"up" => 0,
76+
"right" => pi / 2,
77+
"down" => pi,
78+
"left" => pi * 3 / 2
79+
)
80+
81+
resizeDirections = Dict{String, Tuple{Bool, Bool}}(
82+
"up" => (true, false),
83+
"down" => (true, false),
84+
"left" => (false, true),
85+
"right" => (false, true),
86+
)
87+
88+
function Ahorn.renderSelectedAbs(ctx::Ahorn.Cairo.CairoContext, entity::groupedTriggerSpikesUnion)
89+
direction = get(directions, entity.name, "up")
90+
theta = rotations[direction] - pi / 2
91+
92+
width = Int(get(entity.data, "width", 0))
93+
height = Int(get(entity.data, "height", 0))
94+
95+
x, y = Ahorn.position(entity)
96+
cx, cy = x + floor(Int, width / 2) - 8 * (direction == "left"), y + floor(Int, height / 2) - 8 * (direction == "up")
97+
98+
Ahorn.drawArrow(ctx, cx, cy, cx + cos(theta) * 24, cy + sin(theta) * 24, Ahorn.colors.selection_selected_fc, headLength=6)
99+
end
100+
101+
function Ahorn.selection(entity::groupedTriggerSpikesUnion)
102+
if haskey(directions, entity.name)
103+
x, y = Ahorn.position(entity)
104+
105+
width = Int(get(entity.data, "width", 8))
106+
height = Int(get(entity.data, "height", 8))
107+
108+
direction = get(directions, entity.name, "up")
109+
variant = get(entity.data, "type", "default")
110+
111+
width = Int(get(entity.data, "width", 8))
112+
height = Int(get(entity.data, "height", 8))
113+
114+
ox, oy = offsets[direction]
115+
116+
return Ahorn.Rectangle(x + ox - 4, y + oy - 4, width, height)
117+
end
118+
end
119+
120+
Ahorn.minimumSize(entity::groupedTriggerSpikesUnion) = 8, 8
121+
122+
function Ahorn.resizable(entity::groupedTriggerSpikesUnion)
123+
if haskey(directions, entity.name)
124+
variant = get(entity.data, "type", "default")
125+
direction = get(directions, entity.name, "up")
126+
127+
return resizeDirections[direction]
128+
end
129+
end
130+
131+
function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::groupedTriggerSpikesUnion)
132+
if haskey(directions, entity.name)
133+
variant = get(entity.data, "type", "default")
134+
direction = get(directions, entity.name, "up")
135+
groupedTriggerSpikesOffset = groupedTriggerSpikesOffsets[direction]
136+
137+
width = get(entity.data, "width", 8)
138+
height = get(entity.data, "height", 8)
139+
140+
for ox in 0:8:width - 8, oy in 0:8:height - 8
141+
drawX, drawY = (ox, oy) .+ offsets[direction] .+ groupedTriggerSpikesOffset
142+
Ahorn.drawSprite(ctx, "danger/spikes/$(variant)_$(direction)00", drawX, drawY)
143+
end
144+
end
145+
end
146+
147+
end

Ahorn/lang/en_gb.lang

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,10 @@ placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.persistent=If enabl
8989
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.inactiveColor=The gate icon colour when not triggered yet.
9090
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.activeColor=The gate icon colour when triggered, but the group is not complete yet.
9191
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.finishColor=The gate icon colour when the group is complete.
92-
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.sprite=The texture for the gate block.
92+
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.sprite=The texture for the gate block.
93+
94+
# Grouped Trigger Spikes
95+
placements.entities.SpringCollab2020/GroupedTriggerSpikesUp.tooltips.type=Changes the visual appearance of the spikes.
96+
placements.entities.SpringCollab2020/GroupedTriggerSpikesDown.tooltips.type=Changes the visual appearance of the spikes.
97+
placements.entities.SpringCollab2020/GroupedTriggerSpikesLeft.tooltips.type=Changes the visual appearance of the spikes.
98+
placements.entities.SpringCollab2020/GroupedTriggerSpikesRight.tooltips.type=Changes the visual appearance of the spikes.

0 commit comments

Comments
 (0)