GithubHelp home page GithubHelp logo

jiowchern / relationaltables Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 1.0 108 KB

A common data table creation tool for the game industry.

License: MIT License

C# 100.00%
gamedev-tool game-design-document

relationaltables's Introduction

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.

public class TestConfig1 
{        
    public int Field1;
    public string Field2;
    public float Field3;
}

Query from database.

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

Types of support

Separate tables.

Field1 Field2 Field3
1 2 3
public class TestConfig1 
{        
    public int Field1;
    public string Field2;
    public float Field3;
}

Array field.

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

Related Table

Table A

Field1 Field2 Field3
1 2 3

Table B

Field1 Field2
1 1
public class TableA : Regulus.RelationalTables.IRelatable
{        
    public int Field1;
    public string Field2;
    public float Field3;

    bool IRelatable.Compare(string val)
    {
        int outVal;
        if (int.TryParse(val, out outVal))
        {
            return outVal == Field1;
        }
        return false;
    }

}

public class TableB
{        
    public int Field1;
    public TestConfig1 Field2;    
}

Inversely related
Table A

Table2s
1

Table B

Owner Data
1 1
1 2
class TableA
{            
    [Attributes.InverselyRelated]
    public TableB[] Table2s;
}

class TableB : IRelatable
{
    public int Owner;
    public int Data;
    bool IRelatable.Compare(string val)
    {
        int owner;
        if (int.TryParse(val , out owner))
        {
            return owner == Owner;
        }
        return false;
    }
}

Inversely related by column
Table A

Id
1

Table B

Owner Data
1 1
1 2
class TableA
{            
    [Attributes.InverselyRelatedByColumn("Id")]
    public TableB[] Table2s;
}

class TableB : IRelatable
{
    public int Owner;
    public int Data;
    bool IRelatable.Compare(string val)
    {
        int owner;
        if (int.TryParse(val , out owner))
        {
            return owner == Owner;
        }
        return false;
    }
}

Custom Parser

public class CustomFieldParser : Regulus.RelationalTables.Attributes.FieldParser
{
    public override object Parse(FieldInfo field, IEnumerable<Column> row, ITableable table)
    {
        //todo : Implement your method... 
    }
}

public class Table
{
    [CustomFieldParser()]
    public int Field1;        
}

Create database

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

Row provider

namespace Regulus.RelationalTables.Raw
{
    public interface IRowProvidable
    {
        Type GetTableType();
        IEnumerable<IColumnProvidable> GetRows();
    }
}

Column provider

namespace Regulus.RelationalTables.Raw
{
    public interface IColumnProvidable
    {
        IEnumerable<Column> GetColumns();
    }
}

New a database

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

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

Read from stream

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

ITypeProviable
Need to implement ITypeProviable to provide type information.

relationaltables's People

Contributors

chindarcy avatar jiowchern avatar kikitubby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

lupinchiu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.