mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
improve Config API
This commit is contained in:
parent
905cf8a085
commit
3f37b3913e
5 changed files with 28 additions and 20 deletions
|
@ -230,7 +230,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
private static void StepConfigure ()
|
||||
{
|
||||
TextureDictionary.DontLoadTextures = Config.Get<bool>("dontLoadTextures");
|
||||
TextureDictionary.DontLoadTextures = Config.GetBool("dontLoadTextures");
|
||||
}
|
||||
|
||||
private static IEnumerator StepSelectGTAPath ()
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
{
|
||||
MapTexture = new Texture2D(mapSize, mapSize, TextureFormat.ARGB32, false, true);
|
||||
|
||||
if (Config.Get<bool>("skip_minimap_load"))
|
||||
if (Config.GetBool("skip_minimap_load"))
|
||||
return;
|
||||
|
||||
TextureLoadParams textureLoadParams = new TextureLoadParams() { makeNoLongerReadable = false };
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace SanAndreasUnity.Net
|
|||
_client = new HttpClient();
|
||||
_client.Timeout = System.TimeSpan.FromSeconds(7);
|
||||
|
||||
_masterServerUrl = Config.Get<string>("master_server_url");
|
||||
_masterServerUrl = Config.GetString("master_server_url");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_masterServerUrl))
|
||||
Debug.LogError("Url of master server not defined in config");
|
||||
|
@ -60,7 +60,7 @@ namespace SanAndreasUnity.Net
|
|||
{
|
||||
return new ServerInfo
|
||||
{
|
||||
Name = Config.Get<string>("server_name"),
|
||||
Name = Config.GetString("server_name"),
|
||||
Port = NetManager.listenPortNumber,
|
||||
NumPlayersOnline = NetManager.numConnections,
|
||||
MaxPlayers = NetManager.maxNumPlayers,
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace SanAndreasUnity.RCON
|
|||
|
||||
public static void StartServer()
|
||||
{
|
||||
password = Config.Get<string>("RCON_password");
|
||||
portNumber = Config.Get<int>("RCON_port");
|
||||
password = Config.GetString("RCON_password");
|
||||
portNumber = Config.GetInt("RCON_port");
|
||||
|
||||
if (workerInstance != null)
|
||||
return;
|
||||
|
@ -92,7 +92,7 @@ namespace SanAndreasUnity.RCON
|
|||
{
|
||||
if (NetStatus.IsServer)
|
||||
{
|
||||
if (Config.Get<bool>("RCON_enabled"))
|
||||
if (Config.GetBool("RCON_enabled"))
|
||||
StartServer();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,8 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
private static TVal ConvertVal<TVal>(JToken val)
|
||||
{
|
||||
// note that if you pass string[] as type, it will fail on IL2CPP
|
||||
|
||||
try
|
||||
{
|
||||
return (TVal)Convert.ChangeType(val, typeof(TVal));
|
||||
|
@ -86,24 +88,30 @@ namespace SanAndreasUnity.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
public static TVal Get<TVal>(string key)
|
||||
private static TVal Get<TVal>(string key)
|
||||
{
|
||||
var userVal = _user[key];
|
||||
if (userVal != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ConvertVal<TVal>(userVal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.LogWarningFormat("[config] Invalid value for key '{0}'.", key);
|
||||
}
|
||||
}
|
||||
return ConvertVal<TVal>(userVal);
|
||||
|
||||
return ConvertVal<TVal>(_root[key]);
|
||||
}
|
||||
|
||||
public static string GetString(string key)
|
||||
{
|
||||
return Get<string>(key);
|
||||
}
|
||||
|
||||
public static int GetInt(string key)
|
||||
{
|
||||
return Get<int>(key);
|
||||
}
|
||||
|
||||
public static bool GetBool(string key)
|
||||
{
|
||||
return Get<bool>(key);
|
||||
}
|
||||
|
||||
private static string GetSubstitution(string key)
|
||||
{
|
||||
if (_substitutions.ContainsKey(key)) return _substitutions[key];
|
||||
|
@ -115,7 +123,7 @@ namespace SanAndreasUnity.Utilities
|
|||
}
|
||||
else
|
||||
{
|
||||
subs = ReplaceSubstitutions(Get<string>(key));
|
||||
subs = ReplaceSubstitutions(GetString(key));
|
||||
}
|
||||
|
||||
_substitutions.Add(key, subs);
|
||||
|
@ -131,7 +139,7 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
public static string GetPath(string key)
|
||||
{
|
||||
return ReplaceSubstitutions(Get<string>(key));
|
||||
return ReplaceSubstitutions(GetString(key));
|
||||
}
|
||||
|
||||
public static string[] GetPaths(string key)
|
||||
|
|
Loading…
Reference in a new issue