Skip to content

Commit

Permalink
Merge pull request #29 from AdamKorinek/speedMode
Browse files Browse the repository at this point in the history
Speed mode
  • Loading branch information
maddie480 authored Aug 21, 2024
2 parents 1f34941 + 8c411a8 commit 00897df
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Ahorn/entities/maxHelpingHandFlagSwitchGate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ using ..Ahorn, Maple

@pardef FlagSwitchGate(x1::Integer, y1::Integer, x2::Integer=x1+16, y2::Integer=y1, width::Integer=Maple.defaultBlockWidth, height::Integer=Maple.defaultBlockHeight,
sprite::String="block", persistent::Bool=false, flag::String="flag_touch_switch", icon::String="vanilla", inactiveColor::String="5FCDE4", activeColor::String="FFFFFF", finishColor::String="F141DF",
shakeTime::Number=0.5, moveTime::Number=1.8, moveEased::Bool=true, allowReturn::Bool=false, moveSound::String="event:/game/general/touchswitch_gate_open", finishedSound::String="event:/game/general/touchswitch_gate_finish",
smoke::Bool=true, surfaceIndex::Int16=convert(Int16, 8), particles::Bool=true) =
shakeTime::Number=0.5, moveTime::Number=1.8, moveSpeed::Number=60.0, moveEased::Bool=true, allowReturn::Bool=false, moveSound::String="event:/game/general/touchswitch_gate_open", finishedSound::String="event:/game/general/touchswitch_gate_finish",
smoke::Bool=true, surfaceIndex::Int16=convert(Int16, 8), particles::Bool=true, speedMode::Bool=false) =
Entity("MaxHelpingHand/FlagSwitchGate", x=x1, y=y1, nodes=Tuple{Int, Int}[(x2, y2)], width=width, height=height, sprite=sprite, persistent=persistent, flag=flag, icon=icon,
inactiveColor=inactiveColor, activeColor=activeColor, finishColor=finishColor, shakeTime=shakeTime, moveTime=moveTime, moveEased=moveEased, allowReturn=allowReturn, moveSound=moveSound, finishedSound=finishedSound,
smoke=smoke, surfaceIndex=surfaceIndex, particles=particles)
Expand Down Expand Up @@ -33,7 +33,7 @@ const placements = Ahorn.PlacementDict(
) for texture in textures
)

Ahorn.editingOrder(entity::FlagSwitchGate) = String["x", "y", "width", "height", "flag", "inactiveColor", "activeColor", "finishColor", "hitSound", "moveSound", "finishedSound", "shakeTime", "moveTime"]
Ahorn.editingOrder(entity::FlagSwitchGate) = String["x", "y", "width", "height", "flag", "inactiveColor", "activeColor", "finishColor", "hitSound", "moveSound", "finishedSound", "shakeTime", "moveTime", "moveSpeed", "icon", "sprite", "surfaceIndex", "allowReturn", "moveEased", "persistent", "particles", "smoke", "speedMode"]

Ahorn.editingOptions(entity::FlagSwitchGate) = Dict{String, Any}(
"sprite" => textures,
Expand Down
2 changes: 2 additions & 0 deletions Ahorn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ placements.entities.MaxHelpingHand/FlagSwitchGate.tooltips.finishedSound=The sou
placements.entities.MaxHelpingHand/FlagSwitchGate.tooltips.smoke=Whether the switch gate should emit smoke when reaching its final position.
placements.entities.MaxHelpingHand/FlagSwitchGate.tooltips.surfaceIndex=Footstep sound when walking on the switch gate.
placements.entities.MaxHelpingHand/FlagSwitchGate.tooltips.particles=Whether the switch gate should emit particles while it is moving.
placements.entities.MaxHelpingHand/FlagSwitchGate.tooltips.speedMode=Allows defining move speed, instead of move time.\nFor this change to apply, you must reopen the edit window.
placements.entities.MaxHelpingHand/FlagSwitchGate.tooltips.moveSpeed=The speed (in pixels per second) the block travels at, if Speed Mode is checked.

# Shatter Flag Switch Gate
placements.entities.MaxHelpingHand/ShatterFlagSwitchGate.tooltips.flag=The session flag this switch gate reacts to. Give the same to multiple touch switches and switch gates to group them.
Expand Down
20 changes: 17 additions & 3 deletions Entities/FlagSwitchGate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public class FlagSwitchGate : Solid {

private readonly float shakeTime;
private readonly float moveTime;
private readonly float moveSpeed;
private readonly bool moveEased;
private readonly bool speedMode;

private readonly string moveSound;
private readonly string finishedSound;
Expand Down Expand Up @@ -77,7 +79,9 @@ public FlagSwitchGate(EntityData data, Vector2 offset)

shakeTime = data.Float("shakeTime", 0.5f);
moveTime = data.Float("moveTime", 1.8f);
moveSpeed = data.Float("moveSpeed", 60.0f);
moveEased = data.Bool("moveEased", true);
speedMode = data.Bool("speedMode", false);

moveSound = data.Attr("moveSound", "event:/game/general/touchswitch_gate_open");
finishedSound = data.Attr("finishedSound", "event:/game/general/touchswitch_gate_finish");
Expand Down Expand Up @@ -263,9 +267,19 @@ private IEnumerator moveSequence(Vector2 node, bool goingBack) {
yield return 0.1f;
if (shouldCancelMove(goingBack)) yield break;

// move the switch gate, emitting particles along the way
// move the switch gate, emitting particles along the way if particles is true
int particleAt = 0;
Tween tween = Tween.Create(Tween.TweenMode.Oneshot, moveEased ? Ease.CubeOut : null, moveTime + (moveEased ? 0.2f : 0f), start: true);

Tween tween;
if (speedMode)
{
tween = Tween.Create(Tween.TweenMode.Oneshot, null, (float)Math.Round(((Vector2.Distance(start, node)) / moveSpeed), 3), start: true);
}
else
{
tween = Tween.Create(Tween.TweenMode.Oneshot, moveEased ? Ease.CubeOut : null, moveTime + (moveEased ? 0.2f : 0f), start: true);
}

tween.OnUpdate = tweenArg => {
MoveTo(Vector2.Lerp(start, node, tweenArg.Eased));
if (particles) {
Expand All @@ -285,7 +299,7 @@ private IEnumerator moveSequence(Vector2 node, bool goingBack) {
};
Add(tween);

float moveTimeLeft = moveTime;
float moveTimeLeft = speedMode ? (float)Math.Round(((Vector2.Distance(start, node)) / moveSpeed), 3) : moveTime;
while (moveTimeLeft > 0f) {
yield return null;
moveTimeLeft -= Engine.DeltaTime;
Expand Down
22 changes: 20 additions & 2 deletions Loenn/entities/flagSwitchGate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ for i, texture in ipairs(textures) do
finishedSound = "event:/game/general/touchswitch_gate_finish",
smoke = true,
surfaceIndex = 8,
particles = true
particles = true,
speedMode = false,
moveSpeed = 60
}
}
end

switchGate.fieldOrder = {"x", "y", "width", "height", "flag", "inactiveColor", "activeColor", "finishColor", "hitSound", "moveSound", "finishedSound", "shakeTime", "moveTime", "icon", "sprite", "surfaceIndex", "allowReturn", "moveEased", "persistent", "particles", "smoke"}
switchGate.fieldOrder = {"x", "y", "width", "height", "flag", "inactiveColor", "activeColor", "finishColor", "hitSound", "moveSound", "finishedSound", "shakeTime", "moveTime", "moveSpeed", "icon", "sprite", "surfaceIndex", "allowReturn", "moveEased", "persistent", "particles", "smoke", "speedMode"}

switchGate.fieldInformation = {
inactiveColor = {
Expand Down Expand Up @@ -99,6 +101,22 @@ function switchGate.sprite(room, entity)
return sprites
end

function switchGate.ignoredFields(entity)
local ignored = {
"_id",
"_name"
}

if entity.speedMode then
table.insert(ignored, "moveTime")
table.insert(ignored, "moveEased")
else
table.insert(ignored, "moveSpeed")
end

return ignored
end

function switchGate.selection(room, entity)
local nodes = entity.nodes or {}
local x, y = entity.x or 0, entity.y or 0
Expand Down
2 changes: 2 additions & 0 deletions Loenn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ entities.MaxHelpingHand/FlagSwitchGate.attributes.description.finishedSound=The
entities.MaxHelpingHand/FlagSwitchGate.attributes.description.smoke=Whether the switch gate should emit smoke when reaching its final position.
entities.MaxHelpingHand/FlagSwitchGate.attributes.description.surfaceIndex=Footstep sound when walking on the switch gate.
entities.MaxHelpingHand/FlagSwitchGate.attributes.description.particles=Whether the switch gate should emit particles while it is moving.
entities.MaxHelpingHand/FlagSwitchGate.attributes.description.speedMode=Allows defining move speed, instead of move time.\nFor this change to apply, you must reopen the edit window.
entities.MaxHelpingHand/FlagSwitchGate.attributes.description.moveSpeed=The speed (in pixels per second) the block travels at.

# Flag Touch Switch
entities.MaxHelpingHand/FlagTouchSwitch.placements.name.touch_switch=Flag Touch Switch
Expand Down
2 changes: 1 addition & 1 deletion everest.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The mod used to be known as "max480's Helping Hand", and wasn't renamed for compatibility reasons
- Name: MaxHelpingHand
Version: 1.31.1
Version: 1.31.2
DLL: bin/Release/net452/MaxHelpingHand.dll
Dependencies:
- Name: Everest
Expand Down

0 comments on commit 00897df

Please sign in to comment.