Skip to content

Commit 004c60a

Browse files
authored
Merge pull request #81 from EverestAPI/flag_touch_switches
Flag Touch Switches and Flag Switch Gates
2 parents 9b5170b + dddea46 commit 004c60a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+710
-0
lines changed

Ahorn/entities/flagSwitchGate.jl

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
module SpringCollab2020FlagSwitchGate
2+
3+
using ..Ahorn, Maple
4+
5+
@pardef FlagSwitchGate(x1::Integer, y1::Integer, x2::Integer=x1+16, y2::Integer=y1, width::Integer=Maple.defaultBlockWidth, height::Integer=Maple.defaultBlockHeight,
6+
sprite::String="block", persistent::Bool=false, flag::String="flag_touch_switch", icon::String="vanilla", inactiveColor::String="5FCDE4", activeColor::String="FFFFFF", finishColor::String="F141DF") =
7+
Entity("SpringCollab2020/FlagSwitchGate", x=x1, y=y1, nodes=Tuple{Int, Int}[(x2, y2)], width=width, height=height, sprite=sprite, persistent=persistent, flag=flag, icon=icon,
8+
inactiveColor=inactiveColor, activeColor=activeColor, finishColor=finishColor)
9+
10+
function gateFinalizer(entity)
11+
x, y = Ahorn.position(entity)
12+
13+
width = Int(get(entity.data, "width", 8))
14+
height = Int(get(entity.data, "height", 8))
15+
16+
entity.data["nodes"] = [(x + width, y)]
17+
end
18+
19+
const textures = String["block", "mirror", "temple", "stars"]
20+
const bundledIcons = String["vanilla", "tall", "triangle", "circle"]
21+
22+
const placements = Ahorn.PlacementDict(
23+
"Flag Switch Gate ($(uppercasefirst(texture))) (Spring Collab 2020)" => Ahorn.EntityPlacement(
24+
FlagSwitchGate,
25+
"rectangle",
26+
Dict{String, Any}(
27+
"sprite" => texture
28+
),
29+
gateFinalizer
30+
) for texture in textures
31+
)
32+
33+
Ahorn.editingOptions(entity::FlagSwitchGate) = Dict{String, Any}(
34+
"sprite" => textures,
35+
"icon" => bundledIcons
36+
)
37+
38+
Ahorn.nodeLimits(entity::FlagSwitchGate) = 1, 1
39+
40+
Ahorn.minimumSize(entity::FlagSwitchGate) = 16, 16
41+
Ahorn.resizable(entity::FlagSwitchGate) = true, true
42+
43+
function Ahorn.selection(entity::FlagSwitchGate)
44+
x, y = Ahorn.position(entity)
45+
stopX, stopY = Int.(entity.data["nodes"][1])
46+
47+
width = Int(get(entity.data, "width", 8))
48+
height = Int(get(entity.data, "height", 8))
49+
50+
return [Ahorn.Rectangle(x, y, width, height), Ahorn.Rectangle(stopX, stopY, width, height)]
51+
end
52+
53+
function renderGateSwitch(ctx::Ahorn.Cairo.CairoContext, entity::FlagSwitchGate, x::Number, y::Number, width::Number, height::Number, sprite::String)
54+
icon = get(entity.data, "icon", "vanilla")
55+
56+
iconResource = "objects/switchgate/icon00"
57+
if icon != "vanilla"
58+
iconResource = "objects/SpringCollab2020/flagSwitchGate/$(icon)/icon00"
59+
end
60+
61+
iconSprite = Ahorn.getSprite(iconResource, "Gameplay")
62+
63+
tilesWidth = div(width, 8)
64+
tilesHeight = div(height, 8)
65+
66+
frame = "objects/switchgate/$sprite"
67+
68+
for i in 2:tilesWidth - 1
69+
Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y, 8, 0, 8, 8)
70+
Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y + height - 8, 8, 16, 8, 8)
71+
end
72+
73+
for i in 2:tilesHeight - 1
74+
Ahorn.drawImage(ctx, frame, x, y + (i - 1) * 8, 0, 8, 8, 8)
75+
Ahorn.drawImage(ctx, frame, x + width - 8, y + (i - 1) * 8, 16, 8, 8, 8)
76+
end
77+
78+
for i in 2:tilesWidth - 1, j in 2:tilesHeight - 1
79+
Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y + (j - 1) * 8, 8, 8, 8, 8)
80+
end
81+
82+
Ahorn.drawImage(ctx, frame, x, y, 0, 0, 8, 8)
83+
Ahorn.drawImage(ctx, frame, x + width - 8, y, 16, 0, 8, 8)
84+
Ahorn.drawImage(ctx, frame, x, y + height - 8, 0, 16, 8, 8)
85+
Ahorn.drawImage(ctx, frame, x + width - 8, y + height - 8, 16, 16, 8, 8)
86+
87+
Ahorn.drawImage(ctx, iconSprite, x + div(width - iconSprite.width, 2), y + div(height - iconSprite.height, 2))
88+
end
89+
90+
function Ahorn.renderSelectedAbs(ctx::Ahorn.Cairo.CairoContext, entity::FlagSwitchGate, room::Maple.Room)
91+
sprite = get(entity.data, "sprite", "block")
92+
startX, startY = Int(entity.data["x"]), Int(entity.data["y"])
93+
stopX, stopY = Int.(entity.data["nodes"][1])
94+
95+
width = Int(get(entity.data, "width", 32))
96+
height = Int(get(entity.data, "height", 32))
97+
98+
renderGateSwitch(ctx, entity, stopX, stopY, width, height, sprite)
99+
Ahorn.drawArrow(ctx, startX + width / 2, startY + height / 2, stopX + width / 2, stopY + height / 2, Ahorn.colors.selection_selected_fc, headLength=6)
100+
end
101+
102+
function Ahorn.renderAbs(ctx::Ahorn.Cairo.CairoContext, entity::FlagSwitchGate, room::Maple.Room)
103+
sprite = get(entity.data, "sprite", "block")
104+
105+
x = Int(get(entity.data, "x", 0))
106+
y = Int(get(entity.data, "y", 0))
107+
108+
width = Int(get(entity.data, "width", 32))
109+
height = Int(get(entity.data, "height", 32))
110+
111+
renderGateSwitch(ctx, entity, x, y, width, height, sprite)
112+
end
113+
114+
end

Ahorn/entities/flagTouchSwitch.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module SpringCollab2020FlagTouchSwitch
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/FlagTouchSwitch" FlagTouchSwitch(x::Integer, y::Integer,
6+
flag::String="flag_touch_switch", icon::String="vanilla", persistent::Bool=false, inactiveColor::String="5FCDE4", activeColor::String="FFFFFF", finishColor::String="F141DF")
7+
8+
const bundledIcons = String["vanilla", "tall", "triangle", "circle"]
9+
10+
const placements = Ahorn.PlacementDict(
11+
"Flag Touch Switch (Spring Collab 2020)" => Ahorn.EntityPlacement(
12+
FlagTouchSwitch
13+
)
14+
)
15+
16+
Ahorn.editingOptions(entity::FlagTouchSwitch) = Dict{String,Any}(
17+
"icon" => bundledIcons
18+
)
19+
20+
function Ahorn.selection(entity::FlagTouchSwitch)
21+
x, y = Ahorn.position(entity)
22+
23+
return Ahorn.Rectangle(x - 7, y - 7, 14, 14)
24+
end
25+
26+
function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::FlagTouchSwitch, room::Maple.Room)
27+
Ahorn.drawSprite(ctx, "objects/touchswitch/container.png", 0, 0)
28+
29+
icon = get(entity.data, "icon", "vanilla")
30+
31+
iconPath = "objects/touchswitch/icon00.png"
32+
if icon != "vanilla"
33+
iconPath = "objects/SpringCollab2020/flagTouchSwitch/$(icon)/icon00.png"
34+
end
35+
36+
Ahorn.drawSprite(ctx, iconPath, 0, 0)
37+
end
38+
39+
end

Ahorn/lang/en_gb.lang

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,20 @@ placements.triggers.SpringCollab2020/CustomSandwichLavaSettingsTrigger.tooltips.
7373
placements.entities.SpringCollab2020/SidewaysLava.tooltips.intro=Determines whether the lava moves into the screen or starts already present on the screen. Not suitable for sandwich lava.
7474
placements.entities.SpringCollab2020/SidewaysLava.tooltips.lavaMode=Determines which side(s) of the screen the lava comes from.
7575
placements.entities.SpringCollab2020/SidewaysLava.tooltips.speedMultiplier=Modifies the lava speed. 1 is vanilla lava speed, 2 is twice as fast.
76+
77+
# Flag Touch Switch
78+
placements.entities.SpringCollab2020/FlagTouchSwitch.tooltips.flag=The session flag this touch switch sets. Give the same to multiple touch switches and switch gates to group them.
79+
placements.entities.SpringCollab2020/FlagTouchSwitch.tooltips.icon=The name of the icon for the touch switch (relative to objects/SpringCollab2020/flagTouchSwitch), or "vanilla" for the default one.
80+
placements.entities.SpringCollab2020/FlagTouchSwitch.tooltips.persistent=If enabled, the touch switch will stay active when the player dies or changes rooms.
81+
placements.entities.SpringCollab2020/FlagTouchSwitch.tooltips.inactiveColor=The switch colour when not triggered yet.
82+
placements.entities.SpringCollab2020/FlagTouchSwitch.tooltips.activeColor=The switch colour when triggered, but the group is not complete yet.
83+
placements.entities.SpringCollab2020/FlagTouchSwitch.tooltips.finishColor=The switch colour when the group is complete.
84+
85+
# Flag Switch Gate
86+
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.flag=The session flag this switch gate reacts to. Give the same to multiple touch switches and switch gates to group them.
87+
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.icon=The name of the icon for the switch gate (relative to objects/SpringCollab2020/flagSwitchGate), or "vanilla" for the default one.
88+
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.persistent=If enabled, the switch gate will stay open when the player dies or changes rooms.
89+
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.inactiveColor=The gate icon colour when not triggered yet.
90+
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.activeColor=The gate icon colour when triggered, but the group is not complete yet.
91+
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.

0 commit comments

Comments
 (0)