mirror of
https://github.com/sebastian-heinz/Arrowgene.DragonsDogmaOnline
synced 2026-08-03 11:12:41 -04:00
- Server settings which are read by the C# server software now provide defaults in the server code. - When the server loads, using reflection, it generates a csx setting file in a new script_templates directory. The server admin can copy these templates into the "settings" module to be loaded and override the default settings. - Server defaults apply first, then settings provided in the script override the defaults. The script files only need to provide the settings they wish to override. They do not need to provide all settings. - Removed the files GameLogicSettings.csx, SeasonalEvents.csx, ChatCommands.csx and PointModifiers.csx.
72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Arrowgene.Ddon.Server.Scripting.utils
|
|
{
|
|
public class ScriptableSettings
|
|
{
|
|
/// <summary>
|
|
/// Settings data is organized as ScriptName.FieldName
|
|
/// </summary>
|
|
private Dictionary<string, Dictionary<string, object>> Data { get; set; }
|
|
|
|
public ScriptableSettings()
|
|
{
|
|
Data = new Dictionary<string, Dictionary<string, object>>();
|
|
}
|
|
|
|
public void CreateScriptStorage(string scriptName)
|
|
{
|
|
if (Data.ContainsKey(scriptName))
|
|
{
|
|
throw new Exception($"The script '{scriptName}' already exists, unable to create a new settings entry");
|
|
}
|
|
|
|
Data[scriptName] = new Dictionary<string, object>();
|
|
}
|
|
|
|
public Dictionary<string, object> GetScriptData(string scriptName)
|
|
{
|
|
if (!Data.ContainsKey(scriptName))
|
|
{
|
|
throw new Exception($"The script '{scriptName}' doesn't exist");
|
|
}
|
|
|
|
return Data[scriptName];
|
|
}
|
|
|
|
public T Get<T>(string scriptName, string variableName)
|
|
{
|
|
if (!Data.ContainsKey(scriptName))
|
|
{
|
|
throw new Exception($"The script '{scriptName}' doesn't exist");
|
|
}
|
|
|
|
if (!Data[scriptName].ContainsKey(variableName))
|
|
{
|
|
throw new Exception($"The setting '{scriptName}.{variableName}' doesn't exist");
|
|
}
|
|
return (T)Data[scriptName][variableName];
|
|
}
|
|
|
|
public T TryGet<T>(string scriptName, string variableName, T defaultValue)
|
|
{
|
|
if (!Data.ContainsKey(scriptName))
|
|
{
|
|
throw new Exception($"The script '{scriptName}' doesn't exist");
|
|
}
|
|
|
|
return Data[scriptName].TryGetValue(variableName, out object result) ? (T) result : defaultValue;
|
|
}
|
|
|
|
public void Set<T>(string scriptName, string variableName, T value)
|
|
{
|
|
if (!Data.ContainsKey(scriptName))
|
|
{
|
|
Data[scriptName] = new Dictionary<string, object>();
|
|
}
|
|
|
|
Data[scriptName][variableName] = value;
|
|
}
|
|
}
|
|
}
|