2026-06-13 04:56:50 +01:00
/ * This Source Code Form is subject to the terms of the Mozilla Public
2020-12-22 03:13:43 +00:00
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at https : //mozilla.org/MPL/2.0/. */
using System ;
2020-03-22 19:05:26 +00:00
using System.Linq ;
using MessagePack ;
2021-03-30 01:17:58 +01:00
using MessagePack.Formatters ;
2020-03-22 19:05:26 +00:00
// TODO: USE THIS EVERYWHERE
using Unity.Mathematics ;
using static Unity . Mathematics . math ;
public interface INamedEntry
{
string EntryName { get ; set ; }
}
2021-03-31 04:07:11 +01:00
[ MessagePackObject ,
2026-06-13 04:56:50 +01:00
Union ( 0 , typeof ( SimpleCommodityData ) ) ,
2020-04-09 07:48:45 +01:00
Union ( 1 , typeof ( CompoundCommodityData ) ) ,
2026-06-13 04:56:50 +01:00
Union ( 2 , typeof ( GearData ) ) ,
Union ( 3 , typeof ( HullData ) ) ,
Union ( 4 , typeof ( SimpleCommodity ) ) ,
Union ( 5 , typeof ( CompoundCommodity ) ) ,
2020-12-10 23:20:38 +00:00
Union ( 6 , typeof ( EquippableItem ) ) ,
2020-04-23 03:31:17 +01:00
Union ( 8 , typeof ( GalaxyMapLayerData ) ) ,
2026-06-13 04:56:50 +01:00
Union ( 9 , typeof ( NameFile ) ) ,
//Union(10, typeof(ZoneData)),
Union ( 11 , typeof ( PlayerData ) ) ,
2021-03-31 04:07:11 +01:00
// Union(12, typeof(Corporation)),
2021-03-20 04:20:17 +00:00
Union ( 13 , typeof ( Faction ) ) ,
2026-06-13 04:56:50 +01:00
Union ( 14 , typeof ( OrbitalEntity ) ) ,
Union ( 15 , typeof ( OrbitData ) ) ,
2020-11-29 22:50:12 +00:00
Union ( 16 , typeof ( BodyData ) ) ,
2020-05-03 00:36:47 +01:00
Union ( 17 , typeof ( PersonalityAttribute ) ) ,
2020-05-07 03:53:54 +01:00
Union ( 18 , typeof ( AgentTask ) ) ,
2021-03-22 05:22:31 +00:00
// Union(19, typeof(LoadoutData)),
2021-03-31 04:07:11 +01:00
Union ( 20 , typeof ( Ship ) ) ,
Union ( 21 , typeof ( Mining ) ) ,
2026-06-13 04:56:50 +01:00
Union ( 22 , typeof ( StationTowing ) ) ,
Union ( 23 , typeof ( Survey ) ) ,
Union ( 24 , typeof ( HaulingTask ) ) ,
Union ( 25 , typeof ( AsteroidBeltData ) ) ,
Union ( 26 , typeof ( GasGiantData ) ) ,
Union ( 27 , typeof ( SunData ) ) ,
Union ( 28 , typeof ( PlanetData ) ) ,
Union ( 29 , typeof ( CargoBayData ) ) ,
Union ( 30 , typeof ( DockingBayData ) ) ,
2021-03-30 01:17:58 +01:00
Union ( 31 , typeof ( WeaponItemData ) ) ]
2020-03-22 19:05:26 +00:00
public abstract class DatabaseEntry
{
2026-06-13 04:56:50 +01:00
[Key(0)]
2020-05-14 02:47:07 +01:00
public Guid ID = Guid . NewGuid ( ) ;
2021-04-07 01:27:35 +01:00
public override int GetHashCode ( )
{
return ID . GetHashCode ( ) ;
}
public override bool Equals ( object obj )
{
if ( obj is DatabaseEntry entry ) return entry . ID = = ID ;
return false ;
}
2021-03-31 04:07:11 +01:00
}
2026-06-13 04:56:50 +01:00
[MessagePackObject]
2021-03-31 04:07:11 +01:00
public class DatabaseLink < T > : DatabaseLinkBase where T : DatabaseEntry
{
[IgnoreMember]
2026-06-13 06:45:07 +01:00
public T Value = > ResolveLegacyCatalog < T > ( LinkID ) ;
2021-03-31 04:07:11 +01:00
}
2026-06-13 04:56:50 +01:00
[MessagePackObject]
2021-03-31 04:07:11 +01:00
public class DatabaseLinkBase
{
2026-06-13 04:56:50 +01:00
[Key(0)]
2021-03-31 04:07:11 +01:00
public Guid LinkID ;
2026-06-13 04:56:50 +01:00
2021-03-31 04:07:11 +01:00
[IgnoreMember]
2026-06-13 07:11:16 +01:00
private static LegacyCatalogCache CatalogCache { get ; set ; }
2026-06-13 06:45:07 +01:00
protected static T ResolveLegacyCatalog < T > ( Guid linkId ) where T : DatabaseEntry
{
2026-06-13 07:11:16 +01:00
if ( CatalogCache = = null )
2026-06-13 06:45:07 +01:00
throw new InvalidOperationException ( "Legacy DatabaseLink resolution is not bound. Open LegacyCatalogBoundary before reading legacy catalog object graphs." ) ;
2026-06-13 07:11:16 +01:00
return CatalogCache . Get < T > ( linkId ) ;
2026-06-13 06:45:07 +01:00
}
2026-06-13 07:11:16 +01:00
public static void BindLegacyCatalog ( LegacyCatalogCache cache )
2026-06-13 06:45:07 +01:00
{
if ( cache = = null ) throw new ArgumentNullException ( nameof ( cache ) ) ;
2026-06-13 07:11:16 +01:00
CatalogCache = cache ;
2026-06-13 06:45:07 +01:00
}
2021-04-07 01:27:35 +01:00
}
public interface ITintInspector
{
float3 TintColor { get ; }
2026-06-13 06:45:07 +01:00
}