-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
Mike Puskar edited this page Dec 29, 2021
·
15 revisions
IPT.Common contains an abstract Configuration class that can be inherited. This provides a simple interface to external INI files. Each desired setting is declared as a public instance member and is automatically loaded via the built-in LoadINI method. The settings can then be referenced using the Value property of each member. You must override the Load method.
NOTE: For key and button inputs, adding a modifier to the INI will automatically be handled. You do not need to specify it in the Configuration class.
using IPT.Common.User;
using IPT.Common.Settings;
namespace IPT.TestPlugin
{
internal class Config : Configuration
{
public SettingKeyCombo PerformActionKey = new SettingKeyCombo("Hotkeys", "PerformActionKey", "Performs an action.");
public SettingInt PedCount = new SettingInt("Peds", "PedCount", "The number of Peds affected by the action.", 3, 0, 5, 1);
public SettingFloat ActionRange = new SettingFloat("Peds", "ActionRange", "The range affected by the action.", 100f, 10f, 200f, 10f);
public override void Load()
{
this.LoadINI("plugins/LSPDFR/TestPlugin.ini");
}
}
}
public class Main : CommonPlugin
{
private readonly Config _config;
private readonly InputHandler _inputHandler;
public Main()
{
this._config = new Config();
this._inputHandler = new InputHandler(this._config);
}
protected override void
{
this._config.Load();
this._config.Log();
this._inputHandler.Start();
Events.OnUserInputChanged += Events_OnUserInputChanged;
}
private void Events_OnUserInputChanged(Common.User.Inputs.GenericCombo combo)
{
if (combo == this._config.PerformActionKey.Value)
{
Logging.Info($"detected action key: {combo.IsPressed}");
if (combo.IsPressed)
{
Logging.Info($"action should affect {this._config.PedCount.Value} peds");
}
}
else
{
Logging.Info($"detected unmonitored input {combo} = {combo.IsPressed}");
}
}
}
[Hotkeys]
PerformActionKey=NumPad0
PerformActionKeyModifier=LControl
[Peds]
PedCount=5
ActionRange=100