Data Tables

thumb
Identtzainten.datatables
Typelibrary
Created
Updated
Latest Version 84092 15.5 KB ~3
Links s&box
SummaryA prototype inspired by Data Tables from Unreal Engine
Description
How to Use Data Tables provides you with a custom resource type that holds a list of data entries. You can then easily query data from this resource in C#. You define your Data Structure in C# like so: public class ExampleStruct : RowStruct { public string Text { get; set; } public Dictionary<string, SoundEvent> Sounds { get; set; } public List<string> Strings { get; set; } } And then query data from a Data Table like this: ExampleStruct Struct = Table.Get<ExampleStruct>( "NewEntry_0" ); Log.Info( Struct.Text ); When you make a change to your Data Table, those changes will be reflected in-game immediately after you save the file. [Image] Custom Attributes The [JsonTypeAnnotate] attribute will tell the serializer to also store this property's type, allowing for this property to be properly deserialized later. Combining the above attribute with the [Instanced] attribute provides you with a dropdown in the editor. You can now select any class that inherits from the property's type. public class BaseClass {} public class A : BaseClass { public int Integer { get; set; } } public class B : BaseClass { public bool Boolean { get; set; } } public class ExampleStruct : RowStruct { [JsonTypeAnnotate, Instanced] public List<BaseClass> List; } [Image] Report Issues If you encounter a bug or you want something added, your options are: • Submit a Bug Report / Feature Request right here on sbox.game • Submit an issue @ https://github.com/tzainten/DataTables/issues • I'm in the s&box Discord @tzainten
How to Use Data Tables provides you with a custom resource type that holds a list of data entries. You can then easily query data from this resource in C#. You define your Data Structure in C# like so: public class ExampleStruct : RowStruct { public string Text { get; set; } public Dictionary<string, SoundEvent> Sounds { get; set; } public List<string> Strings { get; set; } } And then query data from a Data Table like this: ExampleStruct Struct = Table.Get<ExampleStruct>( "NewEntry_0" ); Log.Info( Struct.Text ); When you make a change to your Data Table, those changes will be reflected in-game immediately after you save the file. [Image] Custom Attributes The [JsonTypeAnnotate] attribute will tell the serializer to also store this property's type, allowing for this property to be properly deserialized later. Combining the above attribute with the [Instanced] attribute provides you with a dropdown in the editor. You can now select any class that inherits from the property's type. public class BaseClass {} public class A : BaseClass { public int Integer { get; set; } } public class B : BaseClass { public bool Boolean { get; set; } } public class ExampleStruct : RowStruct { [JsonTypeAnnotate, Instanced] public List<BaseClass> List; } [Image] Report Issues If you encounter a bug or you want something added, your options are: • Submit a Bug Report / Feature Request right here on sbox.game • Submit an issue @ https://github.com/tzainten/DataTables/issues • I'm in the s&box Discord @tzainten
Votes 9 1 4
Error Rate0%
Data
{}