File tree Expand file tree Collapse file tree 17 files changed +96
-44
lines changed Expand file tree Collapse file tree 17 files changed +96
-44
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 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 ;
17
1
using OpenLoco . Dat . FileParsing ;
18
2
using System . ComponentModel ;
19
3
Original file line number Diff line number Diff line change 9
9
10
10
<ItemGroup >
11
11
<ProjectReference Include =" ..\Dat\Dat.csproj" />
12
+ <ProjectReference Include =" ..\Definitions\Definitions.csproj" />
12
13
</ItemGroup >
13
14
14
15
</Project >
Original file line number Diff line number Diff line change 1
1
// See https://aka.ms/new-console-template for more information
2
2
using OpenLoco . Common . Logging ;
3
- using OpenLoco . Dat ;
4
3
using OpenLoco . Dat . Data ;
5
4
using OpenLoco . Dat . FileParsing ;
6
5
using OpenLoco . Dat . Objects ;
6
+ using OpenLoco . Definitions . Database ;
7
7
using System . Reflection ;
8
8
9
9
var dir = "Q:\\ Games\\ Locomotion\\ Server\\ Objects" ;
Original file line number Diff line number Diff line change 1
1
// 1. objectMetadata.json must contain a single record for every unique object we have
2
2
using Common . Json ;
3
3
using OpenLoco . Common . Logging ;
4
- using OpenLoco . Dat ;
5
4
using OpenLoco . Dat . Data ;
6
5
using OpenLoco . Dat . FileParsing ;
7
6
using OpenLoco . Dat . Objects ;
8
7
using OpenLoco . Dat . Types ;
8
+ using OpenLoco . Definitions . Database ;
9
9
using OpenLoco . Definitions . SourceData ;
10
10
using System . Data ;
11
11
using System . Text . Json ;
Original file line number Diff line number Diff line change 4
4
using OpenLoco . Definitions . SourceData ;
5
5
using System . Text . Json ;
6
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 ) ;
7
+ var db = LocoDb . GetDbFromFile ( LocoDb . DefaultDb ) ;
11
8
12
9
Console . WriteLine ( "loading" ) ;
13
10
Original file line number Diff line number Diff line change 16
16
17
17
static LocoDb Seed ( )
18
18
{
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 ) ;
23
20
24
21
// Note: The database must exist before this script works
25
- Console . WriteLine ( $ "Database path: { connectionString } ") ;
22
+ Console . WriteLine ( $ "Database path: { LocoDb . DefaultDb } ") ;
26
23
27
24
const bool seed = true ;
28
25
const bool DeleteExisting = true ;
Original file line number Diff line number Diff line change @@ -28,14 +28,28 @@ public LocoDb()
28
28
public LocoDb ( DbContextOptions < LocoDb > options ) : base ( options )
29
29
{ }
30
30
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 )
32
34
{
33
- if ( ! optionsBuilder . IsConfigured )
35
+ if ( ! builder . IsConfigured )
34
36
{
35
- _ = optionsBuilder . UseSqlite ( "Data Source=Q: \\ Games \\ Locomotion \\ Server \\ loco.db " ) ;
37
+ _ = builder . UseSqlite ( $ "Data Source={ DefaultDb } ") ;
36
38
}
37
39
}
38
40
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
+
39
53
protected override void OnModelCreating ( ModelBuilder modelBuilder )
40
54
{
41
55
_ = modelBuilder . Entity < TblLocoObject > ( )
Original file line number Diff line number Diff line change 8
8
using System . Collections . ObjectModel ;
9
9
using System . Text . Json . Serialization ;
10
10
11
- namespace OpenLoco . Dat
11
+ namespace OpenLoco . Definitions . Database
12
12
{
13
13
public class ObjectIndex
14
14
{
@@ -17,6 +17,9 @@ public class ObjectIndex
17
17
[ JsonIgnore ]
18
18
public const string DefaultIndexFileName = "objectIndex.json" ;
19
19
20
+ [ JsonIgnore ]
21
+ public const string DefaultIndexDbFileName = "objectIndex.db" ;
22
+
20
23
public ObjectIndex ( )
21
24
{ }
22
25
Original file line number Diff line number Diff line change 6
6
<Nullable >enable</Nullable >
7
7
</PropertyGroup >
8
8
9
+ <ItemGroup >
10
+ <Compile Include =" ..\Dat\Types\GlobalUsings.cs" Link =" GlobalUsings.cs" />
11
+ </ItemGroup >
12
+
9
13
<ItemGroup >
10
14
<PackageReference Include =" Microsoft.EntityFrameworkCore" Version =" 9.0.3" />
11
15
<PackageReference Include =" Microsoft.EntityFrameworkCore.Design" Version =" 9.0.3" >
You can’t perform that action at this time.
0 commit comments