2019-11-17 04:16:42 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reactive.Subjects;
|
2019-12-04 04:12:08 +00:00
|
|
|
|
using Wabbajack.Common.StatusFeed;
|
2019-11-17 04:16:42 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Common
|
|
|
|
|
{
|
|
|
|
|
public class StatusUpdateTracker
|
|
|
|
|
{
|
|
|
|
|
private Subject<string> _stepName = new Subject<string>();
|
|
|
|
|
public IObservable<string> StepName => _stepName;
|
|
|
|
|
|
|
|
|
|
private Subject<int> _step = new Subject<int>();
|
|
|
|
|
public IObservable<int> Step => _step;
|
|
|
|
|
|
|
|
|
|
private Subject<int> _maxStep = new Subject<int>();
|
|
|
|
|
public IObservable<int> MaxStep => _maxStep;
|
|
|
|
|
|
|
|
|
|
private Subject<float> _progress = new Subject<float>();
|
|
|
|
|
public IObservable<float> Progress => _progress;
|
|
|
|
|
|
|
|
|
|
private int _internalCurrentStep;
|
|
|
|
|
private int _internalMaxStep;
|
|
|
|
|
|
|
|
|
|
public StatusUpdateTracker(int maxStep)
|
|
|
|
|
{
|
|
|
|
|
_internalMaxStep = maxStep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
_maxStep.OnNext(_internalMaxStep);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void NextStep(string name)
|
|
|
|
|
{
|
|
|
|
|
_internalCurrentStep += 1;
|
2019-11-24 23:03:36 +00:00
|
|
|
|
Utils.Log(name);
|
2019-11-17 04:16:42 +00:00
|
|
|
|
_step.OnNext(_internalCurrentStep);
|
|
|
|
|
_stepName.OnNext(name);
|
2019-11-24 23:03:36 +00:00
|
|
|
|
MakeUpdate(0.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float OverAllStatus(float sub_status)
|
|
|
|
|
{
|
|
|
|
|
var per_step = 1.0f / _internalMaxStep;
|
|
|
|
|
var macro = _internalCurrentStep * per_step;
|
|
|
|
|
return macro + (per_step * sub_status);
|
2019-11-17 04:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-24 03:11:25 +00:00
|
|
|
|
public void MakeUpdate(float progress)
|
2019-11-17 04:16:42 +00:00
|
|
|
|
{
|
2019-11-24 23:03:36 +00:00
|
|
|
|
_progress.OnNext(OverAllStatus(progress));
|
2019-11-17 04:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MakeUpdate(int max, int curr)
|
|
|
|
|
{
|
2019-11-24 23:03:36 +00:00
|
|
|
|
MakeUpdate((float)curr / (max == 0 ? 1 : max));
|
2019-11-17 04:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|