Giter Site home page Giter Site logo

jimmycushnie / succ Goto Github PK

View Code? Open in Web Editor NEW
155.0 8.0 16.0 3.43 MB

Jimmy's Epic Config System

License: Do What The F*ck You Want To Public License

C# 100.00%
markup-language serialization config configuration-files csharp-library unity unity3d unity3d-plugin serialization-library serialization-format csharp csharp-code

succ's Introduction

JECS

Jimmy's Epic Config System


JECS is a C# library for reading and writing configuration files. It is focused on ease of use: the API is simple and intuitive, and the generated files are likewise straightforward, readable, and easy to manually tweak.

JECS makes it easy for you to expose data in your program through human-readable and human-editable plaintext files. We use it extensively in Logic World for the game's user settings, save files, modding system, and more.

Basic usage

Create a DataFile object, which corresponds to an actual .jecs file on disk. Use the Get() and Set() methods to get and set data in the file.

var userSettingsFile = new DataFile(path: "user_settings.jecs");

// Gets the string stored in user_settings.jecs under the key `user_name`.
// If no key by that name exists, it will be created set to `Spongebob Squarepants`.
string userName = userSettingsFile.Get(key: "user_name", defaultValue: "Spongebob Squarepants");

// Outputs the value stored in the file, or "Spongebob Squarepants" if the value/file didn't exist yet.
Console.WriteLine(userName);

The above code will create a file called user_settings.jecs with the following contents:

user_name: Spongebob Squarepants

Intermediate usage

JECS cleanly handles complex nested data structures. You can feed JECS most kinds of data, and that data will be saved and loaded as expected.

class RepeatingReminder
{
    public string ReminderText;
    public DayOfWeek Day;
    public BigInteger Importance;
}

static void Main()
{
    var reminders = new RepeatingReminder[]
    {
        new RepeatingReminder()
        {
            ReminderText = "Water plants",
            Day = DayOfWeek.Thursday,
            Importance = 100,
        },
        new RepeatingReminder()
        {
            ReminderText = "Check mail",
            Day = DayOfWeek.Thursday,
            Importance = 75,
        },
        new RepeatingReminder()
        {
            ReminderText = "Have a shower",
            Day = DayOfWeek.Monday,
            Importance = BigInteger.Pow(9, 40),
        },
    };

    var remindersFile = new DataFile("reminders.jecs");
    remindersFile.Set(key: "reminders", value: reminders);
}

The above code will create will create a file called reminders.jecs with the following contents:

reminders:
    -
        ReminderText: Water plants
        Day: Thursday
        Importance: 100
    -
        ReminderText: Check mail
        Day: Thursday
        Importance: 75
    -
        ReminderText: Have a shower
        Day: Monday
        Importance: 147808829414345923316083210206383297601

This is a great example of how nice JECS files are. Notice how this config file has everything laid out clearly so that it's easy to find what you're looking for. The file has minimal formatting boilerplate, so that almost everything in the file is the actual data. This file is fast for a human to read, and fast for a human to edit or expand.

Furthermore, JECS gives you a lot of freedom when writing or editing config files. You can add or remove whitespace, use a different indentation level, or add comments. For example:

reminders:
    -
        ReminderText  :  Water plants
        Day           :  Thursday
        Importance    :  100
    
    -
        ReminderText  :  Check mail
        Day           :  Wednesday
        Importance    :  75 # Don't change this. Critical that it's exactly 75
    
    -
        ReminderText  :  Have a shower
        Day           :  Monday
        Importance    :  147808829414345923316083210206383297601

# Todo: add reminders about skydiving

For more information on the file format, see the File Structure wiki page.

Advanced usage

JECS has many powerful features that make working with it, both from code and in the config files themselves, smooth and easy. This includes [custom base types], [control over the format of generated files], [auto-reloading when a file changes on disk], and much more.


For full documentation on all of JECS's features, and a guide to installing + getting started, see the wiki.

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.