intermediat fleet loader, no processing yet.
This commit is contained in:
parent
40cf280127
commit
64c99fa1a0
@ -96,6 +96,7 @@ public partial class CSVDataLoader : IEnableLogger
|
|||||||
|
|
||||||
FleetManager.PostProcessImportedData();
|
FleetManager.PostProcessImportedData();
|
||||||
FleetManager fleetManager = Locator.Current.GetService<FleetManager>()!;
|
FleetManager fleetManager = Locator.Current.GetService<FleetManager>()!;
|
||||||
|
fleetManager.InitFromDatabase();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Reactive;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Avalonia.Controls.Platform;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
using DynamicData.Binding;
|
using DynamicData.Binding;
|
||||||
|
using ReactiveUI;
|
||||||
using Splat;
|
using Splat;
|
||||||
using StarsAssistant.Model;
|
using StarsAssistant.Model;
|
||||||
using StarsAssistant.ViewModels;
|
using StarsAssistant.ViewModels;
|
||||||
|
|
||||||
namespace StarsAssistant.Services;
|
namespace StarsAssistant.Services;
|
||||||
|
|
||||||
public class FleetManager
|
public class FleetManager : IEnableLogger
|
||||||
{
|
{
|
||||||
protected Services.Game Game = Locator.Current.GetService<Services.Game>()!;
|
protected Services.Game Game = Locator.Current.GetService<Services.Game>()!;
|
||||||
|
|
||||||
@ -28,31 +33,75 @@ public class FleetManager
|
|||||||
public int TotalBoranium { get; set; }
|
public int TotalBoranium { get; set; }
|
||||||
public int TotalGermanium { get; set; }
|
public int TotalGermanium { get; set; }
|
||||||
public int TotalColonists { get; set; }
|
public int TotalColonists { get; set; }
|
||||||
|
|
||||||
|
public override string ToString() => $"To {Destination}: {TotalIronium}I/{TotalBoranium}B/{TotalGermanium}G/{TotalColonists}C";
|
||||||
}
|
}
|
||||||
private IObservable<IChangeSet<FleetSummary, string>>? _fleetSummaries;
|
private IObservable<IChangeSet<FleetSummary>>? _fleetSummaries;
|
||||||
|
|
||||||
|
private ReadOnlyObservableCollection<FleetSummary>? summaries;
|
||||||
|
|
||||||
|
private IDisposable? d1;
|
||||||
|
|
||||||
|
private IDisposable? d2;
|
||||||
|
|
||||||
|
|
||||||
public void test()
|
public void test()
|
||||||
{
|
{
|
||||||
var xxxxx = _fleets.Connect()
|
_fleetSummaries = _fleets.Connect()
|
||||||
|
.Filter(fleet => fleet.TrueDestination != "-- ")
|
||||||
.GroupOn(fleet => fleet.TrueDestination)
|
.GroupOn(fleet => fleet.TrueDestination)
|
||||||
.Transform(group =>
|
.Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher", grp => $"{grp.TotalChanges} detected")
|
||||||
group.List.Connect()
|
.Transform(group => new FleetSummary
|
||||||
.ToCollection()
|
{
|
||||||
.Select(query =>
|
Destination = group.GroupKey,
|
||||||
|
TotalIronium = group.List.Items.Sum(f => f.Ironium),
|
||||||
|
TotalBoranium = group.List.Items.Sum(f => f.Boranium),
|
||||||
|
TotalGermanium = group.List.Items.Sum(f => f.Germanium),
|
||||||
|
TotalColonists = group.List.Items.Sum(f => f.Colonists)
|
||||||
|
})
|
||||||
|
// .Transform(group =>
|
||||||
|
// group.List.Connect()
|
||||||
|
// .QueryWhenChanged(query =>
|
||||||
|
// {
|
||||||
|
// var iro = query.Sum(f => f.Ironium);
|
||||||
|
// var bor = query.Sum(f => f.Boranium);
|
||||||
|
// var ger = query.Sum(f => f.Germanium);
|
||||||
|
// var col = query.Sum(f => f.Colonists);
|
||||||
|
// return new FleetSummary
|
||||||
|
// {
|
||||||
|
// Destination = group.GroupKey,
|
||||||
|
// TotalIronium = iro,
|
||||||
|
// TotalBoranium = bor,
|
||||||
|
// TotalGermanium = ger,
|
||||||
|
// TotalColonists = col
|
||||||
|
// };
|
||||||
|
// })
|
||||||
|
// )
|
||||||
|
;
|
||||||
|
|
||||||
|
_fleetSummaries
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Bind(out summaries)
|
||||||
|
.DisposeMany()
|
||||||
|
.Subscribe();
|
||||||
|
|
||||||
|
d1 = summaries
|
||||||
|
.Subscribe(Observer.Create<FleetSummary>(f =>
|
||||||
{
|
{
|
||||||
var iro = query.Sum(f => f.Ironium);
|
this.Log().Debug($"FleetSummary observed: {f}");
|
||||||
var bor = query.Sum(f => f.Boranium);
|
}
|
||||||
var ger = query.Sum(f => f.Germanium);
|
));
|
||||||
var col = query.Sum(f => f.Colonists);
|
|
||||||
return new FleetSummary
|
d2 = _fleetSummaries
|
||||||
{
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
Destination = group.GroupKey,
|
.Subscribe(x =>
|
||||||
TotalIronium = iro,
|
{
|
||||||
TotalBoranium = bor,
|
var lst = x.ToList();
|
||||||
TotalGermanium = ger,
|
foreach (var f in lst)
|
||||||
TotalColonists = col
|
{
|
||||||
};
|
this.Log().Debug($"Reason {f.Reason}, Type {f.Type}: {f.Item.Current}");
|
||||||
})
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +145,8 @@ public class Game
|
|||||||
__createTestData();
|
__createTestData();
|
||||||
|
|
||||||
PlanetManager.InitFromDatabase();
|
PlanetManager.InitFromDatabase();
|
||||||
|
FleetManager.InitFromDatabase();
|
||||||
|
FleetManager.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user