HeavenStudioPlus/Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs
minenice55 b1fab52ad9
Integration of Jukebox Library (#451) (#457)
* add Jukebox library

todo:
- saving / loading of new format
- inferrence of unknown data like past versions
- move the temporary float casts to proper use of double
- make sound related functions take double for timing
- inform people that the Jukebox sound player was renamed to SoundByte lol

* make sound, input scheduling, and super curve use double precision

* successfully load charts

* editor works again

v1 riqs can be saved and loaded

* first tempo and volume markers are unmovable

fix loading of charts' easing values

* use gsync / freesync

* update Jukebox refs to SoundByte

* game events use double part 1

Air Rally - Glee Club converted

* don't load song if chart load fails

* finish conversion of all minigames

* remove editor waveform toggle

* timeline now respects added song offset length

clear cache files on app close
prepped notes for dsp sync

* update timeline length when offset changed

* update to latest Jukebox

* make error panel object in global game manager

* improve conductor music scheduling

* added error message box

fix first game events sometimes not playing
2023-06-10 19:17:06 +00:00

89 lines
No EOL
2.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_ClappyTrio
{
public class ClappyTrioPlayer : MonoBehaviour
{
ClappyTrio game;
private double lastClapBeat;
private float lastClapLength;
public bool clapStarted = false;
public bool canHit;
private GameObject clapEffect;
private void Awake()
{
game = ClappyTrio.instance;
clapEffect = transform.GetChild(4).GetChild(3).gameObject;
}
private void Update()
{
if (PlayerInput.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN))
{
Clap(false);
game.ScoreMiss();
}
}
public void QueueClap(double startBeat, float length)
{
lastClapBeat = startBeat;
lastClapLength = length;
game.ScheduleInput(startBeat, length, InputType.STANDARD_DOWN, Just, Miss, Out);
}
private void Just(PlayerActionEvent caller, float state)
{
if (!canHit) {
Clap(false);
return;
}
if (state >= 1f || state <= -1f) { //todo: proper near miss feedback
Clap(false);
return;
}
Clap(true);
}
private void Miss(PlayerActionEvent caller) {
game.misses++;
game.emoCounter = 2;
if (clapStarted)
this.canHit = false;
}
private void Out(PlayerActionEvent caller) {}
private void Clap(bool just)
{
game.emoCounter = 2;
if (just)
{
clapEffect.SetActive(true);
SoundByte.PlayOneShotGame("clappyTrio/rightClap");
}
else
{
clapEffect.SetActive(false);
SoundByte.PlayOneShot("miss");
game.misses++;
if (clapStarted)
this.canHit = false;
}
clapStarted = false;
game.SetFace(game.Lion.Count - 1, 4);
this.GetComponent<Animator>().Play("Clap", 0, 0);
}
}
}