using [Link].
Generic;
using [Link];
using [Link];
using [Link];
/*HOW TO USE:
1) change the namespace
2) change the FolderName and the FileName
3) in your awake, call Check("string name") for every boolean you want to use.
- To add a new value to the config, just call Check("thevaluename")
- Alternatively if you want to set it to a specific value, you can use
Set("thevaluename", boolean value);
- Once you have "checked" all of the values you want, call TryWriteConfig();
- There is an example of how to make use of this to create a functional config
below.
*/
namespace YourNamespace
{
public static class Config
{
public const string FolderName = "SaltTestNPC";//this is the name of the
folder, you can have multiple configs in a folder just fine
public const string FileName = "GameData";//this is the file name, change
the file name for each config
public const bool Default = true;//when generating new config values, it'll
set them automatically to this value.
public static void TryWriteConfig() => WriteConfig(SaveName);
public static void ExampleAwake()
{
//pretend this is your real awake
if (Check("AddMisterOne"))
{
//[Link]();
}
if (Check("AddMisterTwo"))
{
//[Link]();
}
if (Check("AddMisterThree"))
{
//[Link]();
}
TryWriteConfig();
//that's it.
}
public static Dictionary<string, bool> SaveConfigNames;
public static void WriteConfig(string location)
{
StreamWriter text = [Link](location);
XmlDocument xmlDocument = new XmlDocument();
string xml = "<config";
foreach (string key in [Link])
{
xml += " ";
xml += key;
xml += "='";
xml += SaveConfigNames[key].ToString().ToLower();
xml += "'";
}
xml += "> </config>";
[Link](xml);
[Link]((TextWriter)text);
[Link]();
}
public static bool Check(string name)
{
if (SaveConfigNames == null)
{
SaveConfigNames = new Dictionary<string, bool>();
}
string l = SaveName;
bool add = Default;
FileStream inStream = [Link](SaveName, [Link]);
XmlDocument xmlDocument = new XmlDocument();
[Link]((Stream)inStream);
if ([Link]("config").Count > 0)
{
if ([Link]("config")
[0].Attributes[name] != null)
{
add = [Link]([Link]("config")
[0].Attributes[name].Value);
}
if ()
[Link](name, add);
else
SaveConfigNames[name] = add;
}
[Link]();
return add;
}
public static void Set(string name, bool value)
{
if (Check(name) != value)
{
SaveConfigNames[name] = value;
WriteConfig(SaveName);
}
}
static string pathPlus
{
get
{
return [Link] + "\\Plugins\\";
}
}
public static string SavePath
{
get
{
if ()
{
[Link](pathPlus + FolderName + "\\");
}
return pathPlus + FolderName + "\\";
}
}
public static string SaveName
{
get
{
if ()
{
WriteConfig(SavePath + FileName + ".config");
}
return SavePath + FileName + ".config";
}
}
}
}