From 9fecd4aba9b6b454e99f91e88e1d0467d5d96c0c Mon Sep 17 00:00:00 2001 From: vitellaryjr <43586575+vitellaryjr@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:08:17 -0700 Subject: [PATCH] add "Any" input & "Hold Input" options --- Code/TriggerTrigger.cs | 86 ++++++++++++++++++++---------- Loenn/lang/en_gb.lang | 1 + Loenn/triggers/trigger_trigger.lua | 4 ++ 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/Code/TriggerTrigger.cs b/Code/TriggerTrigger.cs index 841bc09..12535ea 100644 --- a/Code/TriggerTrigger.cs +++ b/Code/TriggerTrigger.cs @@ -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")] @@ -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"); @@ -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()) { + if (CheckInput(input, inputHeld)) { result = true; - - break; + break; + } + } } break; case ActivationTypes.OnGrounded: @@ -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; } @@ -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 entitiesInside; @@ -566,6 +597,7 @@ public enum InputTypes { Grab, Interact, CrouchDash, + Any, }; private static List bypassGlobal = new List() { ActivationTypes.OnHoldableEnter, diff --git a/Loenn/lang/en_gb.lang b/Loenn/lang/en_gb.lang index c3a2955..8e14450 100644 --- a/Loenn/lang/en_gb.lang +++ b/Loenn/lang/en_gb.lang @@ -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 diff --git a/Loenn/triggers/trigger_trigger.lua b/Loenn/triggers/trigger_trigger.lua index 56e278a..086ca05 100644 --- a/Loenn/triggers/trigger_trigger.lua +++ b/Loenn/triggers/trigger_trigger.lua @@ -38,6 +38,7 @@ local inputTypes = { "Grab", "Interact", "CrouchDash", + "Any", } local triggerTrigger = {} @@ -85,6 +86,7 @@ function triggerTrigger.ignoredFields(entity) "solidType", "entityType", "inputType", + "holdInput", "onlyIfSafe", } @@ -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 @@ -169,6 +172,7 @@ for _, mode in pairs(activationTypes) do solidType = "", entityType = "", inputType = "Grab", + holdInput = false, onlyIfSafe = false, } }