Add project files.
This commit is contained in:
164
Assets/Cryville/Crtr/ChartHandler.cs
Normal file
164
Assets/Cryville/Crtr/ChartHandler.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
//#define NO_SOUND
|
||||
|
||||
using Cryville.Audio.Source;
|
||||
using Cryville.Crtr.Event;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class ChartHandler : ContainerHandler {
|
||||
//private StampedState cs;
|
||||
|
||||
public Chart chart;
|
||||
//readonly Dictionary<string, Sound> sounds = new Dictionary<string, Sound>();
|
||||
readonly List<LibavFileAudioSource> sounds = new List<LibavFileAudioSource>();
|
||||
|
||||
public ChartHandler(Chart _chart, DirectoryInfo dir) : base() {
|
||||
if (dir == null) throw new ArgumentNullException("dir");
|
||||
|
||||
chart = _chart;
|
||||
|
||||
/*foreach (Chart.Group g in chart.groups) {
|
||||
var gh = new GroupHandler(g, this);
|
||||
// cs.AddChild(new StampedState(new StampedState(chart, sevs)));
|
||||
}*/
|
||||
|
||||
//PrehandleEvents();
|
||||
}
|
||||
|
||||
public override string TypeName {
|
||||
get {
|
||||
return "chart";
|
||||
}
|
||||
}
|
||||
|
||||
public override void PreInit() {
|
||||
base.PreInit();
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
#if !NO_SOUND
|
||||
/*foreach (Chart.Sound ev in chart.sounds) {
|
||||
sounds.Add(ev, new LibavFileAudioSource(
|
||||
Game.GameDataPath + "/songs/" + ev.id + "/.ogg"
|
||||
));
|
||||
Logger.Log("main", 0, "Load", "Loading song: {0}", ev.id);
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
if (Disposed) return;
|
||||
base.Dispose();
|
||||
// foreach (var h in handlers) h.Dispose();
|
||||
foreach (var s in sounds) s.Dispose();
|
||||
}
|
||||
|
||||
/*List<StampedEvent> sevs = new List<StampedEvent>();
|
||||
public void PrehandleEvents() {
|
||||
EventPrehandler ph = new EventPrehandler(
|
||||
chart,
|
||||
chart.motions.Cast<Chart.Event>()
|
||||
.Concat<Chart.Event>(chart.signs.Cast<Chart.Event>())
|
||||
.Concat<Chart.Event>(chart.sounds.Cast<Chart.Event>())
|
||||
);
|
||||
// foreach (var h in handlers) h.StartPrehandler(ph);
|
||||
ph.Forward(ev => {
|
||||
if (ev is Chart.Sound) {
|
||||
Chart.Sound tev = (Chart.Sound)ev;
|
||||
sevs.Add(new StampedEvent.PlaySound() {
|
||||
Time = ph.Time - tev.offset + Settings.Default.SoundOffset,
|
||||
Event = tev
|
||||
});
|
||||
}
|
||||
// foreach (var h in handlers) h.PrehandleToTime(ph.Time);
|
||||
});
|
||||
|
||||
sevs = sevs.Concat(ph.Result).ToList();
|
||||
cs = new StampedState(chart, sevs);
|
||||
// foreach (var h in handlers) h.EndPrehandler(cs);
|
||||
}*/
|
||||
|
||||
public override void Update(ContainerState s, StampedEvent ev) {
|
||||
base.Update(s, ev);
|
||||
if (s.CloneType == 16) {
|
||||
if (ev == null) { }
|
||||
else if (ev.Unstamped == null) { }
|
||||
else if (ev.Unstamped is Chart.Sound) {
|
||||
Chart.Sound tev = (Chart.Sound)ev.Unstamped;
|
||||
var source = new LibavFileAudioSource(
|
||||
Game.GameDataPath + "/songs/" + tev.id + "/.ogg"
|
||||
);
|
||||
source.SelectStream();
|
||||
sounds.Add(source);
|
||||
Game.AudioSession.Sequence(
|
||||
s.Time - tev.offset + ChartPlayer.soundOffset,
|
||||
source
|
||||
);
|
||||
/*var l = new List<StampedEvent> {
|
||||
new StampedEvent.PlaySound() {
|
||||
Time = s.Time - tev.offset + ChartPlayer.soundOffset,
|
||||
Container = chart,
|
||||
Unstamped = tev
|
||||
}
|
||||
};
|
||||
cs.Bus.IssuePatch(l);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExUpdate(ContainerState s, StampedEvent ev) {
|
||||
base.ExUpdate(s, ev);
|
||||
if (s.CloneType == 0) {
|
||||
/*#if !NO_SOUND
|
||||
if (ev is StampedEvent.PlaySound) {
|
||||
StampedEvent.PlaySound tev = (StampedEvent.PlaySound)ev;
|
||||
// sounds[tev.Event.file.ToLower()].audioSource.time = toTime - cs.Time;
|
||||
sounds[tev.Unstamped.id].audioSource.Play();
|
||||
}
|
||||
#endif*/
|
||||
}
|
||||
}
|
||||
|
||||
public override void EndUpdate(ContainerState s) {
|
||||
base.EndUpdate(s);
|
||||
// TODO End of chart
|
||||
}
|
||||
|
||||
/*public void SendInput(int id, TouchPhase phase, Vector2 pos) {
|
||||
// Vector2 jpos = Camera.main.ScreenToWorldPoint(new Vector3(pos.x, pos.y, -cameraZ));
|
||||
/*foreach (var h in handlers) {
|
||||
h.SendInput(id, phase, jpos);
|
||||
}*
|
||||
}
|
||||
|
||||
int hits = 0;
|
||||
int misses = 0;
|
||||
public void ReportJudge(bool hit) {
|
||||
if (hit) hits++;
|
||||
else misses++;
|
||||
GameObject.Find("Status").GetComponent<Text>().text = string.Format("Hits: {0}\nMisses: {1}", hits, misses);
|
||||
}*/
|
||||
}
|
||||
|
||||
/*public class ChartState : ChartEventStateBase {
|
||||
public ChartState(Chart c) : base(
|
||||
c,
|
||||
c.motions.Cast<Chart.Event>()
|
||||
.Concat<Chart.Event>(c.signs.Cast<Chart.Event>())
|
||||
.Concat<Chart.Event>(c.sounds.Cast<Chart.Event>())
|
||||
) { }
|
||||
|
||||
protected override void Handle(Chart.Event ev) {
|
||||
/*if (ev is Chart.Signature) {
|
||||
Chart.Signature tev = (Chart.Signature)ev;
|
||||
float tempo = tev.tempo;
|
||||
if (tempo != 0)
|
||||
Tempo = tempo;
|
||||
}*
|
||||
base.Handle(ev);
|
||||
}
|
||||
}*/
|
||||
}
|
Reference in New Issue
Block a user