mirror of
https://github.com/sebastian-heinz/Arrowgene.DragonsDogmaOnline
synced 2026-08-03 11:12:41 -04:00
- Refactored code so implementation can be shared between Server and DdonGameServer. - Moved settings into settings module and implemented an example using a less structured scripting module interface. - Created new ScriptableSettings class to assist with interacting with non-structured settings module. - Created README.md files for suggestions and guidelines for module implementation.
52 lines
1.5 KiB
C#
52 lines
1.5 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 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 void Set<T>(string scriptName, string variableName, T value)
|
|
{
|
|
if (!Data.ContainsKey(scriptName))
|
|
{
|
|
Data[scriptName] = new Dictionary<string, object>();
|
|
}
|
|
|
|
Data[scriptName][variableName] = value;
|
|
}
|
|
}
|
|
}
|