File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 ;
171using OpenLoco . Dat . FileParsing ;
182using System . ComponentModel ;
193
Original file line number Diff line number Diff line change 99
1010 <ItemGroup >
1111 <ProjectReference Include =" ..\Dat\Dat.csproj" />
12+ <ProjectReference Include =" ..\Definitions\Definitions.csproj" />
1213 </ItemGroup >
1314
1415</Project >
Original file line number Diff line number Diff line change 11// See https://aka.ms/new-console-template for more information
22using OpenLoco . Common . Logging ;
3- using OpenLoco . Dat ;
43using OpenLoco . Dat . Data ;
54using OpenLoco . Dat . FileParsing ;
65using OpenLoco . Dat . Objects ;
6+ using OpenLoco . Definitions . Database ;
77using System . Reflection ;
88
99var dir = "Q:\\ Games\\ Locomotion\\ Server\\ Objects" ;
Original file line number Diff line number Diff line change 11// 1. objectMetadata.json must contain a single record for every unique object we have
22using Common . Json ;
33using OpenLoco . Common . Logging ;
4- using OpenLoco . Dat ;
54using OpenLoco . Dat . Data ;
65using OpenLoco . Dat . FileParsing ;
76using OpenLoco . Dat . Objects ;
87using OpenLoco . Dat . Types ;
8+ using OpenLoco . Definitions . Database ;
99using OpenLoco . Definitions . SourceData ;
1010using System . Data ;
1111using System . Text . Json ;
Original file line number Diff line number Diff line change 44using OpenLoco . Definitions . SourceData ;
55using 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
129Console . WriteLine ( "loading" ) ;
1310
Original file line number Diff line number Diff line change 1616
1717static 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 ;
Original file line number Diff line number Diff 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 > ( )
Original file line number Diff line number Diff line change 88using System . Collections . ObjectModel ;
99using 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
Original file line number Diff line number Diff line change 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" >
You can’t perform that action at this time.
0 commit comments