|
| 1 | +using Microsoft.EntityFrameworkCore; |
| 2 | +using OpenLoco.Definitions.Database; |
| 3 | +using OpenLoco.Definitions.SourceData; |
| 4 | +using System.Text.Json; |
| 5 | +using System.Text.Json.Serialization; |
| 6 | + |
| 7 | +var builder = new DbContextOptionsBuilder<LocoDb>(); |
| 8 | +const string connectionString = "Data Source=Q:\\Games\\Locomotion\\Database\\loco.db"; |
| 9 | +_ = builder.UseSqlite(connectionString); |
| 10 | +var db = new LocoDb(builder.Options); |
| 11 | + |
| 12 | +var jsonOptions = new JsonSerializerOptions() { WriteIndented = true, Converters = { new JsonStringEnumConverter() }, }; |
| 13 | + |
| 14 | +Console.WriteLine("loading"); |
| 15 | + |
| 16 | +var authors = JsonSerializer.Serialize<IEnumerable<string>>(db.Authors.Select(a => a.Name).ToList().Order(), jsonOptions); |
| 17 | +var tags = JsonSerializer.Serialize<IEnumerable<string>>(db.Tags.Select(t => t.Name).ToList().Order(), jsonOptions); |
| 18 | +var licences = JsonSerializer.Serialize<IEnumerable<LicenceJsonRecord>>(db.Licences.Select(l => new LicenceJsonRecord(l.Name, l.Text)).ToList().OrderBy(l => l.Name), jsonOptions); |
| 19 | +var modpacks = JsonSerializer.Serialize<IEnumerable<ModpackJsonRecord>>(db.Modpacks.Select(m => new ModpackJsonRecord(m.Name, m.Author)).ToList().OrderBy(m => m.Name), jsonOptions); |
| 20 | + |
| 21 | +var objs = new List<ObjectMetadata>(); |
| 22 | + |
| 23 | +foreach (var o in db.Objects |
| 24 | + .Include(l => l.Licence) |
| 25 | + .Select(x => new ExpandedTblLocoObject(x, x.Authors, x.Tags, x.Modpacks)) |
| 26 | + .ToList() |
| 27 | + .OrderBy(x => x.Object.Name)) |
| 28 | +{ |
| 29 | + var obj = new ObjectMetadata( |
| 30 | + o.Object.OriginalName, |
| 31 | + o.Object.OriginalChecksum, |
| 32 | + o.Object.Description, |
| 33 | + o.Authors.Select(a => a.Name).ToList(), |
| 34 | + o.Tags.Select(t => t.Name).ToList(), |
| 35 | + o.Modpacks.Select(m => m.Name).ToList(), |
| 36 | + o.Object.Licence?.Name); |
| 37 | + objs.Add(obj); |
| 38 | +} |
| 39 | + |
| 40 | +var objects = JsonSerializer.Serialize<IEnumerable<ObjectMetadata>>(objs, jsonOptions); |
| 41 | + |
| 42 | +Console.WriteLine("writing"); |
| 43 | + |
| 44 | +File.WriteAllText("Q:\\Games\\Locomotion\\Database\\authors.json", authors); |
| 45 | +File.WriteAllText("Q:\\Games\\Locomotion\\Database\\tags.json", tags); |
| 46 | +File.WriteAllText("Q:\\Games\\Locomotion\\Database\\licences.json", licences); |
| 47 | +File.WriteAllText("Q:\\Games\\Locomotion\\Database\\modpacks.json", modpacks); |
| 48 | +File.WriteAllText("Q:\\Games\\Locomotion\\Database\\objects.json", objects); |
| 49 | + |
| 50 | +Console.WriteLine("done"); |
0 commit comments