Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "Any" input & "Hold Input" options #53

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 59 additions & 27 deletions Code/TriggerTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Celeste;
using Celeste.Mod.Entities;
using FMOD;
using Microsoft.Xna.Framework;
using Monocle;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace vitmod {
[CustomEntity("vitellary/triggertrigger")]
Expand Down Expand Up @@ -47,6 +49,24 @@ public TriggerTrigger(EntityData data, Vector2 offset) : base(data, offset) {
waitTime = data.Float("timeToWait", 0f);
coreMode = data.Enum("coreMode", Session.CoreModes.None);
inputType = data.Enum("inputType", InputTypes.Grab);
if (data.Has("holdInput")) {
inputHeld = data.Bool("holdInput");
} else {
// account for previous behavior:
// if it's a direction, use whether the direction is held
// otherwise, just check if it's pressed
switch (inputType) {
case InputTypes.Left:
case InputTypes.Right:
case InputTypes.Up:
case InputTypes.Down:
inputHeld = true;
break;
default:
inputHeld = false;
break;
}
}
ifSafe = data.Bool("onlyIfSafe", false);
if (string.IsNullOrEmpty(data.Attr("entityType", ""))) {
collideType = data.Attr("entityTypeToCollide", "Celeste.Strawberry");
Expand Down Expand Up @@ -284,34 +304,15 @@ public bool GetActivateCondition(Player player) {
}
break;
case ActivationTypes.OnInput:
switch (inputType) {
case InputTypes.Grab:
result = Input.Grab.Pressed;
break;
case InputTypes.Jump:
result = Input.Jump.Pressed;
break;
case InputTypes.Dash:
result = Input.Dash.Pressed;
break;
case InputTypes.Interact:
result = Input.Talk.Pressed;
break;
case InputTypes.CrouchDash:
result = Input.CrouchDash.Pressed;
break;
default:
Vector2 aim = Input.Aim.Value.FourWayNormal();
if (inputType == InputTypes.Left && aim.X < 0f)
result = true;
else if (inputType == InputTypes.Right && aim.X > 0f)
result = true;
else if (inputType == InputTypes.Down && aim.Y > 0f)
result = true;
else if (inputType == InputTypes.Up && aim.Y < 0f)
if (inputType != InputTypes.Any) {
result = CheckInput(inputType, inputHeld);
} else {
foreach (InputTypes input in Enum.GetValues<InputTypes>()) {
if (CheckInput(input, inputHeld)) {
result = true;

break;
break;
}
}
}
break;
case ActivationTypes.OnGrounded:
Expand Down Expand Up @@ -448,6 +449,35 @@ private IEnumerator InteractExit() {
yield break;
}

private bool CheckInput(InputTypes inputType, bool held) {
switch (inputType) {
case InputTypes.Grab:
return (held ? Input.Grab.Check : Input.Grab.Pressed);
case InputTypes.Jump:
return (held ? Input.Jump.Check : Input.Jump.Pressed);
case InputTypes.Dash:
return (held ? Input.Dash.Check : Input.Dash.Pressed);
case InputTypes.Interact:
return (held ? Input.Talk.Check : Input.Talk.Pressed);
case InputTypes.CrouchDash:
return (held ? Input.CrouchDash.Check : Input.CrouchDash.Pressed);
default:
Vector2 aim = Input.Aim.Value.FourWayNormal();
if (held || (aim != Input.Aim.PreviousValue.FourWayNormal())) {
if (inputType == InputTypes.Left && aim.X < 0f)
return true;
else if (inputType == InputTypes.Right && aim.X > 0f)
return true;
else if (inputType == InputTypes.Down && aim.Y > 0f)
return true;
else if (inputType == InputTypes.Up && aim.Y < 0f)
return true;
}
break;
}
return false;
}

private static void Player_Jump(On.Celeste.Player.orig_Jump orig, Player self, bool particles, bool playSfx) {
orig(self, particles, playSfx);
if (self == null) { return; }
Expand Down Expand Up @@ -513,6 +543,7 @@ private static bool PlayerCollider_Check(On.Celeste.PlayerCollider.orig_Check or
private int collideCount;
private Session.CoreModes coreMode;
private InputTypes inputType;
private bool inputHeld;
private bool ifSafe;
private TalkComponent talker;
private List<Entity> entitiesInside;
Expand Down Expand Up @@ -566,6 +597,7 @@ public enum InputTypes {
Grab,
Interact,
CrouchDash,
Any,
};
private static List<ActivationTypes> bypassGlobal = new List<ActivationTypes>() {
ActivationTypes.OnHoldableEnter,
Expand Down
1 change: 1 addition & 0 deletions Loenn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ triggers.vitellary/triggertrigger.attributes.description.coreMode=Core mode the
triggers.vitellary/triggertrigger.attributes.description.entityType=Class name of the type of entity to check.
triggers.vitellary/triggertrigger.attributes.description.solidType=Class name of the type of solid to check. If left blank, the trigger will allow any solids to be considered.
triggers.vitellary/triggertrigger.attributes.description.inputType=The type of input the player needs to press.
triggers.vitellary/triggertrigger.attributes.description.holdInput=Whether the trigger will be active for the entire time the input is held, or just for the frame it's pressed.
triggers.vitellary/triggertrigger.attributes.description.onlyIfSafe=Whether the floor the player is standing on needs to be safe ground (aka. ground that a berry could be collected on).

# Edit Depth Trigger
Expand Down
4 changes: 4 additions & 0 deletions Loenn/triggers/trigger_trigger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local inputTypes = {
"Grab",
"Interact",
"CrouchDash",
"Any",
}

local triggerTrigger = {}
Expand Down Expand Up @@ -85,6 +86,7 @@ function triggerTrigger.ignoredFields(entity)
"solidType",
"entityType",
"inputType",
"holdInput",
"onlyIfSafe",
}

Expand Down Expand Up @@ -129,6 +131,7 @@ function triggerTrigger.ignoredFields(entity)
doNotIgnore("entityType")
elseif atype == "OnInput" then
doNotIgnore("inputType")
doNotIgnore("holdInput")
elseif atype == "OnGrounded" then
doNotIgnore("onlyIfSafe")
end
Expand Down Expand Up @@ -169,6 +172,7 @@ for _, mode in pairs(activationTypes) do
solidType = "",
entityType = "",
inputType = "Grab",
holdInput = false,
onlyIfSafe = false,
}
}
Expand Down
Loading