2022-02-08 14:26:55 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2022-02-09 10:29:09 +00:00
|
|
|
using System;
|
|
|
|
using Starpelly;
|
|
|
|
using DG.Tweening;
|
2022-02-08 14:26:55 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-02-08 14:26:55 +00:00
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class AgbHairLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller) {
|
|
|
|
return new Minigame("rhythmTweezers", "Rhythm Tweezers", "98b389", false, false, new List<GameAction>()
|
|
|
|
{
|
2022-08-20 23:03:51 +00:00
|
|
|
new GameAction("start interval", "Start Interval")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-20 23:03:51 +00:00
|
|
|
function = delegate { RhythmTweezers.instance.SetIntervalStart(eventCaller.currentEntity.beat, eventCaller.currentEntity.length); },
|
|
|
|
defaultLength = 4f,
|
|
|
|
resizable = true
|
|
|
|
},
|
|
|
|
new GameAction("short hair", "Short Hair")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-20 23:03:51 +00:00
|
|
|
|
|
|
|
function = delegate { RhythmTweezers.instance.SpawnHair(eventCaller.currentEntity.beat); },
|
|
|
|
defaultLength = 0.5f
|
|
|
|
},
|
|
|
|
new GameAction("long hair", "Curly Hair")
|
|
|
|
{
|
|
|
|
function = delegate { RhythmTweezers.instance.SpawnLongHair(eventCaller.currentEntity.beat); },
|
|
|
|
defaultLength = 0.5f
|
|
|
|
},
|
|
|
|
new GameAction("next vegetable", "Swap Vegetable")
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; RhythmTweezers.instance.NextVegetable(e.beat, e["type"], e["colorA"], e["colorB"]); },
|
2022-08-20 23:03:51 +00:00
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("type", RhythmTweezers.VegetableType.Onion, "Type", "The vegetable to switch to"),
|
|
|
|
new Param("colorA", RhythmTweezers.defaultOnionColor, "Onion Color", "The color of the onion"),
|
|
|
|
new Param("colorB", RhythmTweezers.defaultPotatoColor, "Potato Color", "The color of the potato")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("change vegetable", "Change Vegetable (Instant)")
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; RhythmTweezers.instance.ChangeVegetableImmediate(e["type"], e["colorA"], e["colorB"]); },
|
2022-08-20 23:03:51 +00:00
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("type", RhythmTweezers.VegetableType.Onion, "Type", "The vegetable to switch to"),
|
|
|
|
new Param("colorA", RhythmTweezers.defaultOnionColor, "Onion Color", "The color of the onion"),
|
|
|
|
new Param("colorB", RhythmTweezers.defaultPotatoColor, "Potato Color", "The color of the potato")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("set tweezer delay", "Offset Tweezer")
|
|
|
|
{
|
|
|
|
function = delegate { RhythmTweezers.instance.tweezerBeatOffset = eventCaller.currentEntity.length; },
|
|
|
|
resizable = true
|
|
|
|
},
|
|
|
|
new GameAction("reset tweezer delay", "Reset Tweezer Offset")
|
|
|
|
{
|
|
|
|
function = delegate { RhythmTweezers.instance.tweezerBeatOffset = 0f; },
|
|
|
|
defaultLength = 0.5f
|
|
|
|
},
|
|
|
|
new GameAction("set background color", "Background Colour")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; RhythmTweezers.instance.ChangeBackgroundColor(e["colorA"], 0f); },
|
2022-08-20 23:03:51 +00:00
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("colorA", RhythmTweezers.defaultBgColor, "Background Color", "The background color to change to")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("fade background color", "Background Fade")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; RhythmTweezers.instance.FadeBackgroundColor(e["colorA"], e["colorB"], e.length); },
|
2022-08-20 23:03:51 +00:00
|
|
|
resizable = true,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("colorA", Color.white, "Start Color", "The starting color in the fade"),
|
|
|
|
new Param("colorB", RhythmTweezers.defaultBgColor, "End Color", "The ending color in the fade")
|
|
|
|
}
|
|
|
|
}
|
2022-04-12 16:14:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2022-02-08 14:26:55 +00:00
|
|
|
{
|
2022-03-12 04:10:13 +00:00
|
|
|
using Scripts_RhythmTweezers;
|
|
|
|
|
2022-02-08 14:26:55 +00:00
|
|
|
public class RhythmTweezers : Minigame
|
|
|
|
{
|
2022-02-20 13:31:55 +00:00
|
|
|
public enum VegetableType
|
|
|
|
{
|
|
|
|
Onion,
|
|
|
|
Potato
|
|
|
|
}
|
|
|
|
|
2022-02-13 14:02:55 +00:00
|
|
|
[Header("References")]
|
2022-02-09 10:29:09 +00:00
|
|
|
public Transform VegetableHolder;
|
2022-02-13 14:02:55 +00:00
|
|
|
public SpriteRenderer Vegetable;
|
|
|
|
public SpriteRenderer VegetableDupe;
|
2022-02-09 06:52:50 +00:00
|
|
|
public Animator VegetableAnimator;
|
2022-02-17 12:11:06 +00:00
|
|
|
public SpriteRenderer bg;
|
2022-02-09 06:52:50 +00:00
|
|
|
public Tweezers Tweezers;
|
2022-02-09 10:29:09 +00:00
|
|
|
public GameObject hairBase;
|
2022-02-10 08:13:54 +00:00
|
|
|
public GameObject longHairBase;
|
2022-02-10 15:29:53 +00:00
|
|
|
public GameObject pluckedHairBase;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-02-10 10:14:15 +00:00
|
|
|
public GameObject HairsHolder;
|
2022-02-10 15:29:53 +00:00
|
|
|
public GameObject DroppedHairsHolder;
|
2022-02-09 10:29:09 +00:00
|
|
|
[NonSerialized] public int hairsLeft = 0;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-02-13 14:02:55 +00:00
|
|
|
[Header("Variables")]
|
2022-02-09 10:29:09 +00:00
|
|
|
public float beatInterval = 4f;
|
|
|
|
float intervalStartBeat;
|
|
|
|
bool intervalStarted;
|
|
|
|
public float tweezerBeatOffset = 0f;
|
|
|
|
|
2022-02-13 14:02:55 +00:00
|
|
|
[Header("Sprites")]
|
2022-02-10 15:29:53 +00:00
|
|
|
public Sprite pluckedHairSprite;
|
|
|
|
public Sprite missedHairSprite;
|
2022-02-13 14:02:55 +00:00
|
|
|
public Sprite onionSprite;
|
|
|
|
public Sprite potatoSprite;
|
2022-02-10 15:29:53 +00:00
|
|
|
|
|
|
|
[NonSerialized] public int eyeSize = 0;
|
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
Tween transitionTween;
|
|
|
|
bool transitioning = false;
|
2022-02-17 12:11:06 +00:00
|
|
|
Tween bgColorTween;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-02-13 14:02:55 +00:00
|
|
|
private static Color _defaultOnionColor;
|
|
|
|
public static Color defaultOnionColor
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
ColorUtility.TryParseHtmlString("#C89600", out _defaultOnionColor);
|
|
|
|
return _defaultOnionColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Color _defaultPotatoColor;
|
|
|
|
public static Color defaultPotatoColor
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
ColorUtility.TryParseHtmlString("#FFDC00", out _defaultPotatoColor);
|
|
|
|
return _defaultPotatoColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-17 12:11:06 +00:00
|
|
|
private static Color _defaultBgColor;
|
|
|
|
public static Color defaultBgColor
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2022-06-24 04:51:22 +00:00
|
|
|
ColorUtility.TryParseHtmlString("#A14FA1", out _defaultBgColor);
|
2022-02-17 12:11:06 +00:00
|
|
|
return _defaultBgColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-09 03:58:25 +00:00
|
|
|
public static RhythmTweezers instance { get; set; }
|
|
|
|
|
|
|
|
private void Awake()
|
2022-02-08 14:26:55 +00:00
|
|
|
{
|
2022-02-09 03:58:25 +00:00
|
|
|
instance = this;
|
|
|
|
}
|
2022-02-08 14:26:55 +00:00
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
public void SpawnHair(float beat)
|
2022-02-09 03:58:25 +00:00
|
|
|
{
|
2022-02-09 10:29:09 +00:00
|
|
|
// End transition early if the next hair is a lil early.
|
|
|
|
StopTransitionIfActive();
|
|
|
|
|
|
|
|
// If interval hasn't started, assume this is the first hair of the interval.
|
|
|
|
if (!intervalStarted)
|
2022-02-09 03:58:25 +00:00
|
|
|
{
|
2022-02-09 10:29:09 +00:00
|
|
|
SetIntervalStart(beat, beatInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
Jukebox.PlayOneShotGame("rhythmTweezers/shortAppear", beat);
|
|
|
|
Hair hair = Instantiate(hairBase, HairsHolder.transform).GetComponent<Hair>();
|
|
|
|
hair.gameObject.SetActive(true);
|
2022-02-11 02:14:09 +00:00
|
|
|
hair.GetComponent<Animator>().Play("SmallAppear", 0, 0);
|
2022-02-09 10:29:09 +00:00
|
|
|
|
|
|
|
float rot = -58f + 116 * Mathp.Normalize(beat, intervalStartBeat, intervalStartBeat + beatInterval - 1f);
|
2022-02-10 08:13:54 +00:00
|
|
|
hair.transform.eulerAngles = new Vector3(0, 0, rot);
|
|
|
|
hair.createBeat = beat;
|
|
|
|
hairsLeft++;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SpawnLongHair(float beat)
|
|
|
|
{
|
|
|
|
StopTransitionIfActive();
|
|
|
|
|
|
|
|
if (!intervalStarted)
|
|
|
|
{
|
|
|
|
SetIntervalStart(beat, beatInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
Jukebox.PlayOneShotGame("rhythmTweezers/longAppear", beat);
|
|
|
|
LongHair hair = Instantiate(longHairBase, HairsHolder.transform).GetComponent<LongHair>();
|
|
|
|
hair.gameObject.SetActive(true);
|
2022-02-11 02:14:09 +00:00
|
|
|
hair.GetComponent<Animator>().Play("LongAppear", 0, 0);
|
2022-02-10 08:13:54 +00:00
|
|
|
|
|
|
|
float rot = -58f + 116 * Mathp.Normalize(beat, intervalStartBeat, intervalStartBeat + beatInterval - 1f);
|
2022-02-09 10:29:09 +00:00
|
|
|
hair.transform.eulerAngles = new Vector3(0, 0, rot);
|
|
|
|
hair.createBeat = beat;
|
|
|
|
hairsLeft++;
|
2022-02-08 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
public void SetIntervalStart(float beat, float interval = 4f)
|
2022-02-08 14:26:55 +00:00
|
|
|
{
|
2022-02-10 10:14:15 +00:00
|
|
|
// Don't do these things if the interval was already started.
|
|
|
|
if (!intervalStarted)
|
|
|
|
{
|
|
|
|
// End transition early if the interval starts a lil early.
|
|
|
|
StopTransitionIfActive();
|
|
|
|
hairsLeft = 0;
|
|
|
|
intervalStarted = true;
|
|
|
|
}
|
2022-02-09 10:29:09 +00:00
|
|
|
|
|
|
|
intervalStartBeat = beat;
|
|
|
|
beatInterval = interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float vegDupeOffset = 16.7f;
|
2022-02-13 14:02:55 +00:00
|
|
|
public void NextVegetable(float beat, int type, Color onionColor, Color potatoColor)
|
2022-02-09 10:29:09 +00:00
|
|
|
{
|
|
|
|
transitioning = true;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
Jukebox.PlayOneShotGame("rhythmTweezers/register", beat);
|
2022-02-08 14:26:55 +00:00
|
|
|
|
2022-02-13 14:02:55 +00:00
|
|
|
Sprite nextVeggieSprite = type == 0 ? onionSprite : potatoSprite;
|
|
|
|
Color nextColor = type == 0 ? onionColor : potatoColor;
|
|
|
|
|
|
|
|
VegetableDupe.sprite = nextVeggieSprite;
|
|
|
|
VegetableDupe.color = nextColor;
|
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
// Move both vegetables to the left by vegDupeOffset, then reset their positions.
|
|
|
|
// On position reset, reset state of core vegetable.
|
2022-02-24 14:02:21 +00:00
|
|
|
transitionTween = VegetableHolder.DOLocalMoveX(-vegDupeOffset, Conductor.instance.secPerBeat * 0.5f / Conductor.instance.musicSource.pitch)
|
2022-02-09 10:29:09 +00:00
|
|
|
.OnComplete(() => {
|
|
|
|
|
|
|
|
var holderPos = VegetableHolder.localPosition;
|
|
|
|
VegetableHolder.localPosition = new Vector3(0f, holderPos.y, holderPos.z);
|
|
|
|
|
2022-02-13 14:02:55 +00:00
|
|
|
Vegetable.sprite = nextVeggieSprite;
|
|
|
|
Vegetable.color = nextColor;
|
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
ResetVegetable();
|
|
|
|
transitioning = false;
|
|
|
|
intervalStarted = false;
|
|
|
|
|
|
|
|
}).SetEase(Ease.InOutSine);
|
2022-02-09 03:58:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 14:02:55 +00:00
|
|
|
public void ChangeVegetableImmediate(int type, Color onionColor, Color potatoColor)
|
|
|
|
{
|
|
|
|
StopTransitionIfActive();
|
|
|
|
|
|
|
|
Sprite newSprite = type == 0 ? onionSprite : potatoSprite;
|
|
|
|
Color newColor = type == 0 ? onionColor : potatoColor;
|
|
|
|
|
|
|
|
Vegetable.sprite = newSprite;
|
|
|
|
Vegetable.color = newColor;
|
|
|
|
VegetableDupe.sprite = newSprite;
|
|
|
|
VegetableDupe.color = newColor;
|
|
|
|
}
|
|
|
|
|
2022-02-17 12:11:06 +00:00
|
|
|
public void ChangeBackgroundColor(Color color, float beats)
|
|
|
|
{
|
|
|
|
var seconds = Conductor.instance.secPerBeat * beats;
|
|
|
|
|
|
|
|
if (bgColorTween != null)
|
|
|
|
bgColorTween.Kill(true);
|
|
|
|
|
|
|
|
if (seconds == 0)
|
|
|
|
{
|
|
|
|
bg.color = color;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bgColorTween = bg.DOColor(color, seconds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FadeBackgroundColor(Color start, Color end, float beats)
|
|
|
|
{
|
|
|
|
ChangeBackgroundColor(start, 0f);
|
|
|
|
ChangeBackgroundColor(end, beats);
|
|
|
|
}
|
|
|
|
|
2022-02-09 03:58:25 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2022-02-09 10:29:09 +00:00
|
|
|
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused && intervalStarted)
|
|
|
|
{
|
|
|
|
StopTransitionIfActive();
|
|
|
|
ResetVegetable();
|
|
|
|
intervalStarted = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LateUpdate()
|
|
|
|
{
|
|
|
|
// Set tweezer angle.
|
|
|
|
var tweezerAngle = -180f;
|
|
|
|
|
|
|
|
if (intervalStarted)
|
|
|
|
{
|
|
|
|
var tweezerTime = Conductor.instance.songPositionInBeats - beatInterval - tweezerBeatOffset;
|
|
|
|
var unclampedAngle = -58f + 116 * Mathp.Normalize(tweezerTime, intervalStartBeat, intervalStartBeat + beatInterval - 1f);
|
|
|
|
tweezerAngle = Mathf.Clamp(unclampedAngle, -180f, 180f);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tweezers.transform.eulerAngles = new Vector3(0, 0, tweezerAngle);
|
|
|
|
|
|
|
|
// Set tweezer to follow vegetable.
|
|
|
|
var currentTweezerPos = Tweezers.transform.localPosition;
|
2022-02-10 10:14:15 +00:00
|
|
|
var vegetablePos = Vegetable.transform.localPosition;
|
|
|
|
var vegetableHolderPos = VegetableHolder.transform.localPosition;
|
|
|
|
Tweezers.transform.localPosition = new Vector3(vegetableHolderPos.x, vegetablePos.y + 1f, currentTweezerPos.z);
|
2022-02-09 10:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ResetVegetable()
|
|
|
|
{
|
2022-02-14 18:23:24 +00:00
|
|
|
// If the tweezers happen to be holding a hair, drop it immediately so it can be destroyed below.
|
|
|
|
Tweezers.DropHeldHair();
|
|
|
|
|
2022-02-09 10:29:09 +00:00
|
|
|
foreach (Transform t in HairsHolder.transform)
|
|
|
|
{
|
2022-02-10 15:29:53 +00:00
|
|
|
GameObject.Destroy(t.gameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (Transform t in DroppedHairsHolder.transform)
|
|
|
|
{
|
|
|
|
GameObject.Destroy(t.gameObject);
|
2022-02-09 10:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VegetableAnimator.Play("Idle", 0, 0);
|
2022-02-10 15:29:53 +00:00
|
|
|
|
|
|
|
eyeSize = 0;
|
2022-02-09 10:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void StopTransitionIfActive()
|
|
|
|
{
|
|
|
|
if (transitioning)
|
|
|
|
{
|
|
|
|
if (transitionTween != null)
|
|
|
|
transitionTween.Kill(true);
|
|
|
|
}
|
2022-02-08 14:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|