项目作者: jiowchern

项目描述 :
A common data table creation tool for the game industry.
高级语言: C#
项目地址: git://github.com/jiowchern/RelationalTables.git
创建时间: 2020-07-07T06:29:40Z
项目社区:https://github.com/jiowchern/RelationalTables

开源协议:MIT License

下载


Relational Tables

Maintainability
Coverage Status
Actions Status

A simple game development spreadsheet conversion tool.

Introduce

Often, working in the game industry requires that the game designer take edit of the game configuration.
However, the difficulty of facing various data table-read associations was the reason for the creation of this tool.

Usage

If you have a table like it.

Field1 Field2 Field3
1 2 3

Define the class.

  1. public class TestConfig1
  2. {
  3. public int Field1;
  4. public string Field2;
  5. public float Field3;
  6. }

Query from database.

  1. var db = new Regulus.RelationalTables.Database(new IRowProvidable[] { /*Data source ...*/ });
  2. var config = db.Query<TestConfig1>().First();
  3. // config.Field1 == 1
  4. // config.Field2 == "2"
  5. // config.Field3 == 3f

Types of support

Separate tables.

Field1 Field2 Field3
1 2 3
  1. public class TestConfig1
  2. {
  3. public int Field1;
  4. public string Field2;
  5. public float Field3;
  6. }

Array field.

Field1 Field2 Field3
1 2 3
  1. public class TestConfig1
  2. {
  3. [Regulus.RelationalTables.Attributes.Merge("Field1","Field2","Field3")]
  4. public int[] Field;
  5. }

Related Table

Table A

Field1 Field2 Field3
1 2 3

Table B

Field1 Field2
1 1
  1. public class TableA : Regulus.RelationalTables.IRelatable
  2. {
  3. public int Field1;
  4. public string Field2;
  5. public float Field3;
  6. bool IRelatable.Compare(string val)
  7. {
  8. int outVal;
  9. if (int.TryParse(val, out outVal))
  10. {
  11. return outVal == Field1;
  12. }
  13. return false;
  14. }
  15. }
  16. public class TableB
  17. {
  18. public int Field1;
  19. public TestConfig1 Field2;
  20. }

Inversely related
Table A

Table2s
1

Table B

Owner Data
1 1
1 2
  1. class TableA
  2. {
  3. [Attributes.InverselyRelated]
  4. public TableB[] Table2s;
  5. }
  6. class TableB : IRelatable
  7. {
  8. public int Owner;
  9. public int Data;
  10. bool IRelatable.Compare(string val)
  11. {
  12. int owner;
  13. if (int.TryParse(val , out owner))
  14. {
  15. return owner == Owner;
  16. }
  17. return false;
  18. }
  19. }

Inversely related by column
Table A

Id
1

Table B

Owner Data
1 1
1 2
  1. class TableA
  2. {
  3. [Attributes.InverselyRelatedByColumn("Id")]
  4. public TableB[] Table2s;
  5. }
  6. class TableB : IRelatable
  7. {
  8. public int Owner;
  9. public int Data;
  10. bool IRelatable.Compare(string val)
  11. {
  12. int owner;
  13. if (int.TryParse(val , out owner))
  14. {
  15. return owner == Owner;
  16. }
  17. return false;
  18. }
  19. }

Custom Parser

  1. public class CustomFieldParser : Regulus.RelationalTables.Attributes.FieldParser
  2. {
  3. public override object Parse(FieldInfo field, IEnumerable<Column> row, ITableable table)
  4. {
  5. //todo : Implement your method...
  6. }
  7. }
  8. public class Table
  9. {
  10. [CustomFieldParser()]
  11. public int Field1;
  12. }

Create database

Whether you are using Excel, CSV, Google Sheet, or another spreadsheet source, you just need to implement the following interface…

Row provider

  1. namespace Regulus.RelationalTables.Raw
  2. {
  3. public interface IRowProvidable
  4. {
  5. Type GetTableType();
  6. IEnumerable<IColumnProvidable> GetRows();
  7. }
  8. }

Column provider

  1. namespace Regulus.RelationalTables.Raw
  2. {
  3. public interface IColumnProvidable
  4. {
  5. IEnumerable<Column> GetColumns();
  6. }
  7. }

New a database

  1. var db = new Regulus.RelationalTables.Database(/* IRowProvidable */);

Serialization

Because it takes time to set up the database, it is recommended that the tables be serialized at edit time for runtime use.

Write to stream

  1. var stream = // file stream.
  2. var db = new Regulus.RelationalTables.Database(/* IRowProvidable */);
  3. var converter = new Regulus.RelationalTables.Serialization.BinaryConverter();
  4. converter.WriteToStream(db.Tables, stream , /* ITypeProviable */);

Read from stream

  1. var stream = // file stream.
  2. var converter = new Regulus.RelationalTables.Serialization.BinaryConverter();
  3. var tables = converter.ReadFromStream(stream, /* ITypeProviable */);
  4. var db = new Regulus.RelationalTables.Database(tables);

ITypeProviable
Need to implement ITypeProviable to provide type information.