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;
|
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
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; ForkLifter.instance.Flick(e.beat, e["type"]); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 3,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("type", ForkLifter.FlickType.Pea, "Object", "The object to be flicked")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("prepare", "Prepare Hand")
|
|
|
|
{
|
|
|
|
function = delegate { ForkLifter.instance.ForkLifterHand.Prepare(); },
|
|
|
|
defaultLength = 0.5f
|
|
|
|
},
|
|
|
|
new GameAction("gulp", "Swallow")
|
|
|
|
{
|
|
|
|
function = delegate { ForkLifter.playerInstance.Eat(); }
|
|
|
|
},
|
|
|
|
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
|
|
|
},
|
2023-04-23 20:17:21 +00:00
|
|
|
new GameAction("color", "Background Color")
|
|
|
|
{
|
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"]); },
|
2023-04-23 20:17:21 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("start", Color.white, "Start Color", "The color to start fading from."),
|
|
|
|
new Param("end", Color.white, "End Color", "The color to end the fade."),
|
2023-08-12 03:30:03 +00:00
|
|
|
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease")
|
2023-04-23 20:17:21 +00:00
|
|
|
},
|
|
|
|
resizable = true
|
|
|
|
},
|
|
|
|
new GameAction("colorGrad", "Gradient Color")
|
|
|
|
{
|
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"]); },
|
2023-04-23 20:17:21 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("start", Color.white, "Start Color", "The color to start fading from."),
|
|
|
|
new Param("end", Color.white, "End Color", "The color to end the fade."),
|
2023-08-12 03:30:03 +00:00
|
|
|
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease")
|
2023-04-23 20:17:21 +00:00
|
|
|
},
|
|
|
|
resizable = true
|
|
|
|
},
|
2023-06-10 19:18:45 +00:00
|
|
|
new GameAction("bop", "Bop")
|
|
|
|
{
|
|
|
|
function = delegate { var e = eventCaller.currentEntity; ForkLifter.instance.Bop(e.beat, e.length, e["bop"], e["autoBop"]); },
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("bop", true, "Keep Bopping", "Should Fork bop for the duration of the block?"),
|
|
|
|
new Param("autoBop", false, "Keep Bopping (Auto)", "Should Fork bop indefinitely?"),
|
|
|
|
},
|
|
|
|
resizable = true,
|
|
|
|
},
|
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
// These are still here for backwards-compatibility but are hidden in the editor
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("pea", "")
|
|
|
|
{
|
|
|
|
function = delegate { ForkLifter.instance.Flick(eventCaller.currentEntity.beat, 0); },
|
|
|
|
defaultLength = 3,
|
|
|
|
hidden = true
|
|
|
|
},
|
|
|
|
new GameAction("topbun", "")
|
|
|
|
{
|
|
|
|
function = delegate { ForkLifter.instance.Flick(eventCaller.currentEntity.beat, 1); },
|
|
|
|
defaultLength = 3,
|
|
|
|
hidden = true
|
|
|
|
},
|
|
|
|
new GameAction("burger", "")
|
|
|
|
{
|
|
|
|
function = delegate { ForkLifter.instance.Flick(eventCaller.currentEntity.beat, 2); },
|
|
|
|
defaultLength = 3,
|
|
|
|
hidden = true
|
|
|
|
},
|
|
|
|
new GameAction("bottombun", "")
|
|
|
|
{
|
|
|
|
function = delegate { ForkLifter.instance.Flick(eventCaller.currentEntity.beat, 3); },
|
|
|
|
defaultLength = 3,
|
|
|
|
hidden = true
|
|
|
|
},
|
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
|
|
|
{
|
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-06-10 19:17:06 +00:00
|
|
|
public override void OnGameSwitch(double beat)
|
2021-12-24 03:36:16 +00:00
|
|
|
{
|
2022-03-08 04:46:49 +00:00
|
|
|
base.OnGameSwitch(beat);
|
2021-12-24 03:36:16 +00:00
|
|
|
ForkLifterHand.CheckNextFlick();
|
2023-08-12 03:30:03 +00:00
|
|
|
PersistColor(beat);
|
2021-12-24 03:36:16 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 20:01:44 +00:00
|
|
|
|
2023-06-10 20:55:10 +00:00
|
|
|
public void Bop(double beat, double length, bool doesBop, bool autoBop)
|
2023-06-10 19:18:45 +00:00
|
|
|
{
|
|
|
|
playerInstance.shouldBop = (autoBop || doesBop);
|
|
|
|
if (!autoBop && doesBop) {
|
|
|
|
BeatAction.New(gameObject, new List<BeatAction.Action>() {
|
|
|
|
new BeatAction.Action(beat + length, delegate {
|
|
|
|
playerInstance.shouldBop = false;
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public void Flick(double beat, int type)
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
SoundByte.PlayOneShotGame("forkLifter/flick");
|
2021-12-21 01:10:49 +00:00
|
|
|
handAnim.Play("Hand_Flick", 0, 0);
|
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
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
private double colorStartBeat = -1;
|
|
|
|
private float colorLength = 0f;
|
|
|
|
private Color colorStart = Color.white; //obviously put to the default color of the game
|
|
|
|
private Color colorEnd = Color.white;
|
|
|
|
private Util.EasingFunction.Ease colorEase; //putting Util in case this game is using jukebox
|
|
|
|
|
|
|
|
private double colorStartBeatGrad = -1;
|
|
|
|
private float colorLengthGrad = 0f;
|
|
|
|
private Color colorStartGrad = Color.white; //obviously put to the default color of the game
|
|
|
|
private Color colorEndGrad = Color.white;
|
|
|
|
private Util.EasingFunction.Ease colorEaseGrad; //putting Util in case this game is using jukebox
|
|
|
|
|
|
|
|
//call this in update
|
|
|
|
private void BackgroundColorUpdate()
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
float normalizedBeat = Mathf.Clamp01(Conductor.instance.GetPositionFromBeat(colorStartBeat, colorLength));
|
2023-04-23 20:17:21 +00:00
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
var func = Util.EasingFunction.GetEasingFunction(colorEase);
|
2023-04-23 20:17:21 +00:00
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
float newR = func(colorStart.r, colorEnd.r, normalizedBeat);
|
|
|
|
float newG = func(colorStart.g, colorEnd.g, normalizedBeat);
|
|
|
|
float newB = func(colorStart.b, colorEnd.b, normalizedBeat);
|
|
|
|
|
|
|
|
bg.color = new Color(newR, newG, newB);
|
|
|
|
viewerCircle.color = new Color(newR, newG, newB);
|
|
|
|
handShadow.color = new Color(newR, newG, newB);
|
|
|
|
|
|
|
|
float normalizedBeatGrad = Mathf.Clamp01(Conductor.instance.GetPositionFromBeat(colorStartBeatGrad, colorLengthGrad));
|
|
|
|
|
|
|
|
var funcGrad = Util.EasingFunction.GetEasingFunction(colorEaseGrad);
|
|
|
|
|
|
|
|
float newRGrad = func(colorStartGrad.r, colorEndGrad.r, normalizedBeatGrad);
|
|
|
|
float newGGrad = func(colorStartGrad.g, colorEndGrad.g, normalizedBeatGrad);
|
|
|
|
float newBGrad = func(colorStartGrad.b, colorEndGrad.b, normalizedBeatGrad);
|
|
|
|
|
|
|
|
bgGradient.color = new Color(newRGrad, newGGrad, newBGrad);
|
|
|
|
playerShadow.color = new Color(newRGrad, newGGrad, newBGrad);
|
2023-04-23 20:17:21 +00:00
|
|
|
}
|
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
public void BackgroundColor(double beat, float length, Color colorStartSet, Color colorEndSet, int ease)
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
colorStartBeat = beat;
|
|
|
|
colorLength = length;
|
|
|
|
colorStart = colorStartSet;
|
|
|
|
colorEnd = colorEndSet;
|
|
|
|
colorEase = (Util.EasingFunction.Ease)ease;
|
2023-04-23 20:17:21 +00:00
|
|
|
}
|
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
public void BackgroundColorGrad(double beat, float length, Color colorStartSet, Color colorEndSet, int ease)
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
colorStartBeatGrad = beat;
|
|
|
|
colorLengthGrad = length;
|
|
|
|
colorStartGrad = colorStartSet;
|
|
|
|
colorEndGrad = colorEndSet;
|
|
|
|
colorEaseGrad = (Util.EasingFunction.Ease)ease;
|
|
|
|
}
|
2023-04-23 20:17:21 +00:00
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
//call this in OnPlay(double beat) and OnGameSwitch(double beat)
|
|
|
|
private void PersistColor(double beat)
|
|
|
|
{
|
|
|
|
var allEventsBeforeBeat = EventCaller.GetAllInGameManagerList("forkLifter", new string[] { "color" }).FindAll(x => x.beat < beat);
|
|
|
|
if (allEventsBeforeBeat.Count > 0)
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
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"]);
|
2023-04-23 20:17:21 +00:00
|
|
|
}
|
2023-08-12 03:30:03 +00:00
|
|
|
|
|
|
|
var allEventsBeforeBeatGrad = EventCaller.GetAllInGameManagerList("forkLifter", new string[] { "colorGrad" }).FindAll(x => x.beat < beat);
|
|
|
|
if (allEventsBeforeBeatGrad.Count > 0)
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
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-04-23 20:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
public override void OnPlay(double beat)
|
2023-04-23 20:17:21 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
PersistColor(beat);
|
2023-04-23 20:17:21 +00:00
|
|
|
}
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|