Skip to content

Commit 9af194c

Browse files
committed
move objectindex into Definitions
1 parent 60506da commit 9af194c

File tree

17 files changed

+96
-44
lines changed

17 files changed

+96
-44
lines changed

Dat/Types/GlobalUsings.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma warning disable IDE0079 // Remove unnecessary suppression
2+
#pragma warning disable IDE0005 // Using directive is unnecessary.
3+
4+
global using char_t = System.Byte;
5+
global using coord_t = System.Int16;
6+
global using image_id = System.UInt32;
7+
global using int16_t = System.Int16;
8+
global using int32_t = System.Int32;
9+
global using int8_t = System.SByte;
10+
global using MicroZ = System.Byte;
11+
global using object_id = System.Byte;
12+
global using size_t = System.UInt32;
13+
global using SoundObjectId = System.Byte;
14+
global using Speed16 = System.Int16;
15+
global using Speed32 = System.Int32;
16+
global using string_id = System.UInt16;
17+
global using uint16_t = System.UInt16;
18+
global using uint32_t = System.UInt32;
19+
global using uint8_t = System.Byte;
20+
21+
#pragma warning restore IDE0005 // Using directive is unnecessary.
22+
#pragma warning restore IDE0079 // Remove unnecessary suppression

Dat/Types/Typedefs.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
global using char_t = System.Byte;
2-
global using coord_t = System.Int16;
3-
global using image_id = System.UInt32;
4-
global using int16_t = System.Int16;
5-
global using int32_t = System.Int32;
6-
global using int8_t = System.SByte;
7-
global using MicroZ = System.Byte;
8-
global using object_id = System.Byte;
9-
global using size_t = System.UInt32;
10-
global using SoundObjectId = System.Byte;
11-
global using Speed16 = System.Int16;
12-
global using Speed32 = System.Int32;
13-
global using string_id = System.UInt16;
14-
global using uint16_t = System.UInt16;
15-
global using uint32_t = System.UInt32;
16-
global using uint8_t = System.Byte;
171
using OpenLoco.Dat.FileParsing;
182
using System.ComponentModel;
193

DataQuery/DataQuery.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<ItemGroup>
1111
<ProjectReference Include="..\Dat\Dat.csproj" />
12+
<ProjectReference Include="..\Definitions\Definitions.csproj" />
1213
</ItemGroup>
1314

1415
</Project>

DataQuery/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// See https://aka.ms/new-console-template for more information
22
using OpenLoco.Common.Logging;
3-
using OpenLoco.Dat;
43
using OpenLoco.Dat.Data;
54
using OpenLoco.Dat.FileParsing;
65
using OpenLoco.Dat.Objects;
6+
using OpenLoco.Definitions.Database;
77
using System.Reflection;
88

99
var dir = "Q:\\Games\\Locomotion\\Server\\Objects";

DataSanitiser/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// 1. objectMetadata.json must contain a single record for every unique object we have
22
using Common.Json;
33
using OpenLoco.Common.Logging;
4-
using OpenLoco.Dat;
54
using OpenLoco.Dat.Data;
65
using OpenLoco.Dat.FileParsing;
76
using OpenLoco.Dat.Objects;
87
using OpenLoco.Dat.Types;
8+
using OpenLoco.Definitions.Database;
99
using OpenLoco.Definitions.SourceData;
1010
using System.Data;
1111
using System.Text.Json;

DatabaseExporter/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
using OpenLoco.Definitions.SourceData;
55
using System.Text.Json;
66

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);
7+
var db = LocoDb.GetDbFromFile(LocoDb.DefaultDb);
118

129
Console.WriteLine("loading");
1310

DatabaseImporter/Program.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
static LocoDb Seed()
1818
{
19-
var builder = new DbContextOptionsBuilder<LocoDb>();
20-
const string connectionString = "Data Source=Q:\\Games\\Locomotion\\Server\\loco.db";
21-
_ = builder.UseSqlite(connectionString);
22-
var db = new LocoDb(builder.Options);
19+
var db = LocoDb.GetDbFromFile(LocoDb.DefaultDb);
2320

2421
// Note: The database must exist before this script works
25-
Console.WriteLine($"Database path: {connectionString}");
22+
Console.WriteLine($"Database path: {LocoDb.DefaultDb}");
2623

2724
const bool seed = true;
2825
const bool DeleteExisting = true;

Definitions/Database/LocoDb.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,28 @@ public LocoDb()
2828
public LocoDb(DbContextOptions<LocoDb> options) : base(options)
2929
{ }
3030

31-
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
31+
public static string DefaultDb = "Q:\\Games\\Locomotion\\Server\\loco.db";
32+
33+
protected override void OnConfiguring(DbContextOptionsBuilder builder)
3234
{
33-
if (!optionsBuilder.IsConfigured)
35+
if (!builder.IsConfigured)
3436
{
35-
_ = optionsBuilder.UseSqlite("Data Source=Q:\\Games\\Locomotion\\Server\\loco.db");
37+
_ = builder.UseSqlite($"Data Source={DefaultDb}");
3638
}
3739
}
3840

41+
public static LocoDb? GetDbFromFile(string path) // path is the full/absolute file path
42+
{
43+
if (!string.IsNullOrEmpty(path) && File.Exists(path))
44+
{
45+
var builder = new DbContextOptionsBuilder<LocoDb>();
46+
_ = builder.UseSqlite($"Data Source={path}");
47+
return new LocoDb(builder.Options);
48+
}
49+
50+
return null;
51+
}
52+
3953
protected override void OnModelCreating(ModelBuilder modelBuilder)
4054
{
4155
_ = modelBuilder.Entity<TblLocoObject>()

Dat/ObjectIndex.cs renamed to Definitions/Database/ObjectIndex.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Collections.ObjectModel;
99
using System.Text.Json.Serialization;
1010

11-
namespace OpenLoco.Dat
11+
namespace OpenLoco.Definitions.Database
1212
{
1313
public class ObjectIndex
1414
{
@@ -17,6 +17,9 @@ public class ObjectIndex
1717
[JsonIgnore]
1818
public const string DefaultIndexFileName = "objectIndex.json";
1919

20+
[JsonIgnore]
21+
public const string DefaultIndexDbFileName = "objectIndex.db";
22+
2023
public ObjectIndex()
2124
{ }
2225

Definitions/Definitions.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<Compile Include="..\Dat\Types\GlobalUsings.cs" Link="GlobalUsings.cs" />
11+
</ItemGroup>
12+
913
<ItemGroup>
1014
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
1115
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">

0 commit comments

Comments
 (0)