Skip to content

Commit f4fb8f7

Browse files
authored
Merge pull request #93 from EverestAPI/grouped_trigger_spikes
Grouped trigger spikes
2 parents c6a4b8d + ada657b commit f4fb8f7

File tree

3 files changed

+429
-0
lines changed

3 files changed

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

Ahorn/lang/en_gb.lang

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.sprite=The texture
9595
placements.entities.SpringCollab2020/InstantFallingBlock.tooltips.climbFall=After a delay, the block will physically fall down until it comes into contact with another block.
9696
placements.entities.SpringCollab2020/InstantFallingBlock.tooltips.tiletype=Changes the visual appearance of the falling block.
9797
placements.entities.SpringCollab2020/InstantFallingBlock.tooltips.behind=Whether the block should visually be further behind in the scene or not.
98+
99+
# Grouped Trigger Spikes
100+
placements.entities.SpringCollab2020/GroupedTriggerSpikesUp.tooltips.type=Changes the visual appearance of the spikes.
101+
placements.entities.SpringCollab2020/GroupedTriggerSpikesDown.tooltips.type=Changes the visual appearance of the spikes.
102+
placements.entities.SpringCollab2020/GroupedTriggerSpikesLeft.tooltips.type=Changes the visual appearance of the spikes.
103+
placements.entities.SpringCollab2020/GroupedTriggerSpikesRight.tooltips.type=Changes the visual appearance of the spikes.

0 commit comments

Comments
 (0)