Onsharp
  • What is Onsharp?
  • Changelog
  • Onsharp Environment
    • Onsharp Runtime Environment
    • Installation
    • Configuration
  • Basic Usage
    • Preparation
    • Create a Basic Plugin
    • Concept of Entry Points
    • Create Commands
    • The EventAPI of Onsharp
    • Configs and DataStorage
    • Logging
    • Debugging
  • Advance Usage
    • Auto Updater
    • Overriding Entity Factories
    • Interop of LUA and vice versa
    • Entity Pool Refreshing
    • Create Console Commands
    • Providing LUA packages
  • Modules
    • Lazy Mover
    • I18n
Powered by GitBook
On this page
  • Configs using TOML
  • Data Storage

Was this helpful?

  1. Basic Usage

Configs and DataStorage

On this page we will explain the built in config system as well as the predefinied data directory for your plugin.

Configs using TOML

The built in config system of Onsharp uses the file format TOML which is a vartion of YAML and INI. The creation as well as the loading of the config will be managed by Onsharp itself. You just need to define a data class, and let Onsharp load this class.

using Onsharp.IO;

namespace Tutorial
{
    [Config("myconfig")]
    public class MyConfig
    {
        public bool IsDebug { get; set; } = false;
    }
}

This data class is marked with the config attribute. You must define the name of the config file with the first parameter. The second parameter is optional and can define a sub directory.

Now you just need to register the config:

using Onsharp.Plugins;

namespace Tutorial
{
    public class PluginMain : Plugin
    {
        public override void OnStart()
        {
             //Your start up logic here
             MyConfig config = Data.Config<MyConfig>(); 
        }
        
        public override void OnStop()
        {
            //Your stop and clean up logic here
        }  
    }
}

The config file gets automatically created in the data folder of the plugin and than loaded and returned.

Data Storage

The data storage is not fully implemented currently. If you just want to write some kind of file to your data folder, you can access the directory info via Data.Directory

PreviousThe EventAPI of OnsharpNextLogging

Last updated 4 years ago

Was this helpful?