2021-12-21 01:10:49 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2024-02-04 16:15:14 +00:00
|
|
|
using HeavenStudio.Games.Scripts_ForkLifter;
|
2021-12-21 01:10:49 +00:00
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class RvlForkLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller) {
|
2023-04-02 02:28:23 +00:00
|
|
|
return new Minigame("forkLifter", "Fork Lifter", "f1f1f1", false, false, new List<GameAction>()
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("flick", "Flick Food")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2024-02-04 16:15:14 +00:00
|
|
|
inactiveFunction = delegate {
|
|
|
|
var e = eventCaller.currentEntity;
|
|
|
|
ForkLifter.Flick(e.beat);
|
|
|
|
},
|
2023-10-27 20:19:11 +00:00
|
|
|
function = delegate {
|
|
|
|
var e = eventCaller.currentEntity;
|
|
|
|
ForkLifter.Flick(e.beat);
|
|
|
|
ForkLifter.instance.FlickActive(e.beat, e["type"]);
|
|
|
|
},
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 3,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("type", ForkLifter.FlickType.Pea, "Object", "Choose the object to be flicked.")
|
2023-10-27 20:19:11 +00:00
|
|
|
},
|
2022-08-21 03:13:52 +00:00
|
|
|
},
|
|
|
|
new GameAction("prepare", "Prepare Hand")
|
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
function = delegate { ForkLifter.instance.ForkLifterHand.Prepare(eventCaller.currentEntity["mute"]); },
|
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("mute", false, "Mute", "Toggle if the prepare sound effect should play.")
|
2023-10-27 20:19:11 +00:00
|
|
|
}
|
2022-08-21 03:13:52 +00:00
|
|
|
},
|
|
|
|
new GameAction("gulp", "Swallow")
|
|
|
|
{
|
2024-02-04 16:15:14 +00:00
|
|
|
function = delegate { ForkLifter.playerInstance.Eat(eventCaller.currentEntity["sfx"]); },
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("sfx", ForkLifterPlayer.EatType.Default, "SFX", "Choose the SFX to play.")
|
|
|
|
}
|
2022-08-21 03:13:52 +00:00
|
|
|
},
|
|
|
|
new GameAction("sigh", "Sigh")
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
function = delegate { SoundByte.PlayOneShot("games/forkLifter/sigh"); }
|
2022-08-21 03:13:52 +00:00
|
|
|
},
|
2024-01-15 02:04:10 +00:00
|
|
|
new GameAction("color", "Background Appearance")
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; ForkLifter.instance.BackgroundColor(e.beat, e.length, e["start"], e["end"], e["ease"]); },
|
2024-02-04 16:15:14 +00:00
|
|
|
resizable = true,
|
2023-04-23 20:17:21 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("start", Color.white, "Start Color", "Set the color at the start of the event."),
|
|
|
|
new Param("end", Color.white, "End Color", "Set the color at the end of the event."),
|
|
|
|
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease", "Set the easing of the action.")
|
2023-04-23 20:17:21 +00:00
|
|
|
},
|
|
|
|
},
|
2024-01-15 02:04:10 +00:00
|
|
|
new GameAction("colorGrad", "Gradient Appearance")
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; ForkLifter.instance.BackgroundColorGrad(e.beat, e.length, e["start"], e["end"], e["ease"]); },
|
2024-02-04 16:15:14 +00:00
|
|
|
resizable = true,
|
2023-04-23 20:17:21 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("start", Color.white, "Start Color", "Set the color at the start of the event."),
|
|
|
|
new Param("end", Color.white, "End Color", "Set the color at the end of the event."),
|
|
|
|
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease", "Set the easing of the action.")
|
2023-04-23 20:17:21 +00:00
|
|
|
},
|
|
|
|
},
|
2023-05-28 17:34:44 +00:00
|
|
|
},
|
|
|
|
new List<string>() {"rvl", "normal"},
|
|
|
|
"rvlfork", "en",
|
|
|
|
new List<string>() {}
|
|
|
|
);
|
2022-04-12 16:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
using Jukebox;
|
2022-03-12 04:10:13 +00:00
|
|
|
using Scripts_ForkLifter;
|
|
|
|
|
2021-12-24 03:36:16 +00:00
|
|
|
public class ForkLifter : Minigame
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2022-03-01 19:27:08 +00:00
|
|
|
public enum FlickType
|
|
|
|
{
|
|
|
|
Pea,
|
|
|
|
TopBun,
|
|
|
|
Burger,
|
|
|
|
BottomBun
|
|
|
|
}
|
|
|
|
|
2021-12-21 01:10:49 +00:00
|
|
|
public static ForkLifter instance;
|
2022-03-12 04:20:33 +00:00
|
|
|
public static ForkLifterPlayer playerInstance => ForkLifterPlayer.instance;
|
2021-12-21 01:10:49 +00:00
|
|
|
|
2021-12-23 00:08:35 +00:00
|
|
|
[Header("References")]
|
|
|
|
public ForkLifterHand ForkLifterHand;
|
2021-12-21 04:38:59 +00:00
|
|
|
|
2021-12-21 01:10:49 +00:00
|
|
|
[Header("Objects")]
|
|
|
|
public Animator handAnim;
|
|
|
|
public GameObject flickedObject;
|
|
|
|
public SpriteRenderer peaPreview;
|
2023-04-23 20:17:21 +00:00
|
|
|
[SerializeField] SpriteRenderer bg;
|
|
|
|
[SerializeField] SpriteRenderer bgGradient;
|
|
|
|
[SerializeField] SpriteRenderer viewerCircle;
|
|
|
|
[SerializeField] SpriteRenderer playerShadow;
|
|
|
|
[SerializeField] SpriteRenderer handShadow;
|
2021-12-21 01:10:49 +00:00
|
|
|
|
|
|
|
public Sprite[] peaSprites;
|
|
|
|
public Sprite[] peaHitSprites;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
BackgroundColorUpdate();
|
|
|
|
}
|
|
|
|
|
2023-12-05 22:38:55 +00:00
|
|
|
public override void OnPlay(double beat)
|
|
|
|
{
|
|
|
|
OnGameSwitch(beat);
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public override void OnGameSwitch(double beat)
|
2021-12-24 03:36:16 +00:00
|
|
|
{
|
2024-02-04 16:15:14 +00:00
|
|
|
var actions = GameManager.instance.Beatmap.Entities.FindAll(e => e.datamodel.Split('/')[0] == "forkLifter");
|
|
|
|
|
|
|
|
var actionsBefore = actions.FindAll(e => e.beat < beat);
|
|
|
|
|
|
|
|
var lastColor = actionsBefore.FindLast(e => e.datamodel == "forkLifter/color");
|
|
|
|
if (lastColor != null) {
|
|
|
|
BackgroundColor(lastColor.beat, lastColor.length, lastColor["start"], lastColor["end"], lastColor["ease"]);
|
2023-10-27 20:19:11 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 16:15:14 +00:00
|
|
|
var lastColorGrad = actionsBefore.FindLast(e => e.datamodel == "forkLifter/colorGrad");
|
|
|
|
if (lastColorGrad != null) {
|
|
|
|
BackgroundColorGrad(lastColorGrad.beat, lastColorGrad.length, lastColorGrad["start"], lastColorGrad["end"], lastColorGrad["ease"]);
|
|
|
|
}
|
2021-12-24 03:36:16 +00:00
|
|
|
|
2024-02-04 16:15:14 +00:00
|
|
|
var tempFlicks = actions.FindAll(e => e.datamodel == "forkLifter/flick");
|
|
|
|
|
|
|
|
foreach (var e in tempFlicks.FindAll(e => e.beat < beat && e.beat + 2 > beat)) {
|
|
|
|
FlickActive(e.beat, e["type"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ForkLifterHand.allFlickEntities = tempFlicks.FindAll(e => e.beat >= beat);
|
|
|
|
ForkLifterHand.CheckNextFlick();
|
2023-06-10 19:18:45 +00:00
|
|
|
}
|
|
|
|
|
2023-10-27 20:19:11 +00:00
|
|
|
public static void Flick(double beat)
|
|
|
|
{
|
|
|
|
var offset = SoundByte.GetClipLengthGame("forkLifter/zoomFast") - 0.03;
|
|
|
|
SoundByte.PlayOneShotGame("forkLifter/zoomFast", beat + 2, offset: offset, forcePlay: true);
|
|
|
|
|
|
|
|
SoundByte.PlayOneShotGame("forkLifter/flick", forcePlay: true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FlickActive(double beat, int type)
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2023-10-27 20:19:11 +00:00
|
|
|
|
|
|
|
handAnim.DoScaledAnimationFromBeatAsync("Hand_Flick", 0.5f, beat);
|
2023-04-23 20:17:21 +00:00
|
|
|
ForkLifterHand.currentFlickIndex++;
|
2021-12-21 01:10:49 +00:00
|
|
|
GameObject fo = Instantiate(flickedObject);
|
2021-12-25 12:16:40 +00:00
|
|
|
fo.transform.parent = flickedObject.transform.parent;
|
2022-02-03 22:20:26 +00:00
|
|
|
Pea pea = fo.GetComponent<Pea>();
|
|
|
|
pea.startBeat = beat;
|
|
|
|
pea.type = type;
|
2021-12-21 01:10:49 +00:00
|
|
|
fo.SetActive(true);
|
|
|
|
}
|
2023-04-23 20:17:21 +00:00
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
private ColorEase bgColorEase = new();
|
|
|
|
private ColorEase gradColorEase = new();
|
2023-08-12 03:30:03 +00:00
|
|
|
|
|
|
|
//call this in update
|
|
|
|
private void BackgroundColorUpdate()
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2024-03-04 03:50:46 +00:00
|
|
|
bg.color =
|
|
|
|
viewerCircle.color =
|
|
|
|
handShadow.color = bgColorEase.GetColor();
|
2023-04-23 20:17:21 +00:00
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
bgGradient.color =
|
|
|
|
playerShadow.color = gradColorEase.GetColor();
|
|
|
|
}
|
2023-08-12 03:30:03 +00:00
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
public void BackgroundColor(double beat, float length, Color startColor, Color endColor, int ease)
|
|
|
|
{
|
|
|
|
bgColorEase = new ColorEase(beat, length, startColor, endColor, ease);
|
2023-04-23 20:17:21 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
public void BackgroundColorGrad(double beat, float length, Color startColor, Color endColor, int ease)
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2024-03-04 03:50:46 +00:00
|
|
|
gradColorEase = new ColorEase(beat, length, startColor, endColor, ease);
|
2023-04-23 20:17:21 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
//call this in OnPlay(double beat) and OnGameSwitch(double beat)
|
|
|
|
private void PersistColor(double beat)
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2024-03-04 03:50:46 +00:00
|
|
|
var allEventsBeforeBeat = EventCaller.GetAllInGameManagerList("forkLifter", new string[] { "color" }).FindAll(x => x.beat < beat);
|
|
|
|
if (allEventsBeforeBeat.Count > 0)
|
|
|
|
{
|
|
|
|
allEventsBeforeBeat.Sort((x, y) => x.beat.CompareTo(y.beat)); //just in case
|
|
|
|
var lastEvent = allEventsBeforeBeat[^1];
|
|
|
|
BackgroundColor(lastEvent.beat, lastEvent.length, lastEvent["start"], lastEvent["end"], lastEvent["ease"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var allEventsBeforeBeatGrad = EventCaller.GetAllInGameManagerList("forkLifter", new string[] { "colorGrad" }).FindAll(x => x.beat < beat);
|
|
|
|
if (allEventsBeforeBeatGrad.Count > 0)
|
|
|
|
{
|
|
|
|
allEventsBeforeBeatGrad.Sort((x, y) => x.beat.CompareTo(y.beat)); //just in case
|
|
|
|
var lastEventGrad = allEventsBeforeBeatGrad[^1];
|
|
|
|
BackgroundColorGrad(lastEventGrad.beat, lastEventGrad.length, lastEventGrad["start"], lastEventGrad["end"], lastEventGrad["ease"]);
|
|
|
|
}
|
2023-08-12 03:30:03 +00:00
|
|
|
}
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|