2024-07-19 17:08:37 +00:00
|
|
|
|
using System;
|
2024-07-23 07:40:10 +00:00
|
|
|
|
using Avalonia;
|
2024-09-11 18:04:20 +00:00
|
|
|
|
using Splat;
|
2024-07-23 18:20:01 +00:00
|
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using CsvHelper.Configuration;
|
|
|
|
|
using CsvHelper;
|
2024-08-15 19:46:43 +00:00
|
|
|
|
using StarsAssistant.Model;
|
2024-07-23 18:20:01 +00:00
|
|
|
|
using System.Globalization;
|
2024-08-23 15:59:02 +00:00
|
|
|
|
using Avalonia.ReactiveUI;
|
2024-07-23 18:20:01 +00:00
|
|
|
|
|
2024-07-23 07:40:10 +00:00
|
|
|
|
|
2024-08-15 19:46:43 +00:00
|
|
|
|
namespace StarsAssistant;
|
2024-07-23 07:40:10 +00:00
|
|
|
|
|
|
|
|
|
sealed class Program
|
|
|
|
|
{
|
|
|
|
|
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
|
|
|
|
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
|
|
|
|
// yet and stuff might break.
|
|
|
|
|
[STAThread]
|
2024-07-23 18:20:01 +00:00
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
2024-09-11 18:04:20 +00:00
|
|
|
|
ModeDetector.OverrideModeDetector(Splat.ModeDetection.Mode.Run);
|
2024-09-17 18:20:42 +00:00
|
|
|
|
|
2024-09-18 18:34:30 +00:00
|
|
|
|
var logger = new ConsoleLogger() { Level = LogLevel.Debug };
|
|
|
|
|
Locator.CurrentMutable.RegisterConstant(logger, typeof(ILogger));
|
|
|
|
|
|
2024-09-20 17:01:09 +00:00
|
|
|
|
bool newGame = false;
|
|
|
|
|
string dbPath = "/home/torben/Nextcloud/Documents/Stars!/Games/goingth/GOINGTH.sqlite";
|
|
|
|
|
Services.Game gameSvc;
|
|
|
|
|
|
|
|
|
|
using (StarsDatabase starsDB = new(dbPath))
|
2024-09-17 18:20:42 +00:00
|
|
|
|
{
|
2024-09-20 17:01:09 +00:00
|
|
|
|
if (Path.Exists(dbPath))
|
|
|
|
|
{
|
|
|
|
|
Model.Game dbGame = starsDB.Game.First();
|
|
|
|
|
gameSvc = new Services.Game(dbGame);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
starsDB.Database.EnsureCreated();
|
|
|
|
|
gameSvc = new()
|
|
|
|
|
{
|
|
|
|
|
BaseName = "GOINGTH",
|
|
|
|
|
GamePath = "/home/torben/Nextcloud/Documents/Stars!/Games/goingth/"
|
|
|
|
|
};
|
|
|
|
|
gameSvc.SaveToDatabase(starsDB);
|
|
|
|
|
newGame = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-17 18:20:42 +00:00
|
|
|
|
|
2024-09-20 17:01:09 +00:00
|
|
|
|
Locator.CurrentMutable.RegisterConstant(gameSvc, typeof(Services.Game));
|
2024-09-18 18:34:30 +00:00
|
|
|
|
Locator.CurrentMutable.RegisterConstant(new Services.CSVDataLoader(), typeof(Services.CSVDataLoader));
|
2024-09-20 17:01:09 +00:00
|
|
|
|
Locator.CurrentMutable.Register(() => new StarsDatabase(gameSvc.DatabaseFileName), typeof(StarsDatabase));
|
|
|
|
|
|
|
|
|
|
if (newGame)
|
|
|
|
|
__createTestData();
|
2024-09-11 18:04:20 +00:00
|
|
|
|
|
2024-07-23 18:20:01 +00:00
|
|
|
|
BuildAvaloniaApp()
|
2024-08-23 15:59:02 +00:00
|
|
|
|
.StartWithClassicDesktopLifetime(args);
|
2024-07-23 18:20:01 +00:00
|
|
|
|
}
|
2024-07-23 07:40:10 +00:00
|
|
|
|
|
|
|
|
|
// Avalonia configuration, don't remove; also used by visual designer.
|
|
|
|
|
public static AppBuilder BuildAvaloniaApp()
|
|
|
|
|
=> AppBuilder.Configure<App>()
|
|
|
|
|
.UsePlatformDetect()
|
|
|
|
|
.WithInterFont()
|
2024-08-23 15:59:02 +00:00
|
|
|
|
.LogToTrace()
|
|
|
|
|
.UseReactiveUI();
|
2024-07-23 18:20:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void __createTestData ()
|
|
|
|
|
{
|
2024-09-11 18:04:20 +00:00
|
|
|
|
using var db = Locator.Current.GetService<StarsDatabase>()!;
|
2024-07-23 18:20:01 +00:00
|
|
|
|
|
|
|
|
|
// Note: This sample requires the database to be created before running.
|
2024-09-11 18:04:20 +00:00
|
|
|
|
// Console.WriteLine($"Database path: {db.DbPath}.");
|
2024-07-23 18:20:01 +00:00
|
|
|
|
|
2024-08-17 14:52:31 +00:00
|
|
|
|
Race r = new()
|
|
|
|
|
{
|
|
|
|
|
Name = "Atlantis",
|
2024-08-18 17:21:18 +00:00
|
|
|
|
PlayerRace = true,
|
2024-09-17 18:20:42 +00:00
|
|
|
|
PlayerFileId = 1,
|
2024-08-17 14:52:31 +00:00
|
|
|
|
ColonistsPerResource = 1000,
|
|
|
|
|
GrowthRatePercent = 19,
|
|
|
|
|
PRT = PRT.Other,
|
|
|
|
|
HasOBRM = true,
|
|
|
|
|
FactoryCost3 = false,
|
|
|
|
|
FactoryNumberPer10k = 8,
|
|
|
|
|
FactoryResCost = 8,
|
|
|
|
|
FactoryResPer10 = 15,
|
|
|
|
|
MineResCost = 3,
|
|
|
|
|
MineMineralsPer10 = 10,
|
|
|
|
|
MineNumberPer10k = 10
|
|
|
|
|
};
|
|
|
|
|
db.Add(r);
|
2024-08-18 17:21:18 +00:00
|
|
|
|
db.SaveChanges();
|
|
|
|
|
Race.Player = r;
|
2024-08-17 14:52:31 +00:00
|
|
|
|
|
2024-09-17 18:20:42 +00:00
|
|
|
|
var loader = new CSV.PlanetLoader();
|
|
|
|
|
loader.ImportForRace(Race.Player);
|
2024-07-23 18:20:01 +00:00
|
|
|
|
}
|
2024-07-23 07:40:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2024-07-19 17:08:37 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-07-19 20:00:13 +00:00
|
|
|
|
using CsvHelper.Configuration;
|
|
|
|
|
using CsvHelper;
|
2024-08-15 19:46:43 +00:00
|
|
|
|
using StarsAssistant.model;
|
2024-07-23 07:40:10 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
|
|
|
|
|
using var db = new StarsDatabase("stars.sqlite");
|
|
|
|
|
|
|
|
|
|
db.Database.EnsureDeleted();
|
|
|
|
|
db.Database.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
// Note: This sample requires the database to be created before running.
|
|
|
|
|
Console.WriteLine($"Database path: {db.DbPath}.");
|
|
|
|
|
|
2024-07-19 20:00:13 +00:00
|
|
|
|
var config = CsvConfiguration.FromAttributes<Planet>(CultureInfo.InvariantCulture);
|
|
|
|
|
config.Delimiter = "\t";
|
|
|
|
|
config.Escape = '\0';
|
|
|
|
|
config.MissingFieldFound = null;
|
|
|
|
|
|
|
|
|
|
using (var reader = new StreamReader("/home/torben/goingth/GOINGTH.p1", Encoding.Latin1))
|
|
|
|
|
using (var csv = new CsvReader(reader, config))
|
|
|
|
|
{
|
|
|
|
|
List<Planet> records = csv.GetRecords<Planet>().ToList();
|
|
|
|
|
foreach (Planet p in records)
|
|
|
|
|
{
|
|
|
|
|
db.Add(p);
|
|
|
|
|
}
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
}
|
2024-07-23 07:40:10 +00:00
|
|
|
|
*/
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
// Create
|
|
|
|
|
Console.WriteLine("Inserting a new blog");
|
|
|
|
|
db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" });
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
|
|
|
|
|
// Read
|
|
|
|
|
Console.WriteLine("Querying for a blog");
|
|
|
|
|
var blog = db.Blogs
|
|
|
|
|
.OrderBy(b => b.BlogId)
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
// Update
|
|
|
|
|
Console.WriteLine("Updating the blog and adding a post");
|
|
|
|
|
blog.Url = "https://devblogs.microsoft.com/dotnet";
|
|
|
|
|
blog.Posts.Add(
|
|
|
|
|
new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" });
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
|
|
|
|
|
// Delete
|
|
|
|
|
// Console.WriteLine("Delete the blog");
|
|
|
|
|
// db.Remove(blog);
|
|
|
|
|
// db.SaveChanges();
|
|
|
|
|
*/
|