/// <summary> /// Sets this object's <see cref="IConfigStore"/>. Can only be called once. /// </summary> /// <param name="store">the <see cref="IConfigStore"/> to add to this instance</param> /// <exception cref="InvalidOperationException">If this was called before.</exception> public void SetStore(IConfigStore store) { if (Store != null) { throw new InvalidOperationException($"{nameof(SetStore)} can only be called once"); } Store = store; ConfigRuntime.ConfigChanged(); }
/// <summary> /// Gets a <see cref="Config"/> object using the specified list of preferred config types. /// </summary> /// <param name="configName">the name of the mod for this config</param> /// <param name="extensions">the preferred config types to try to get</param> /// <returns>a <see cref="Config"/> using the requested format, or of type JSON.</returns> public static Config GetConfigFor(string configName, params string[] extensions) { var chosenExt = extensions.FirstOrDefault(s => registeredProviders.ContainsKey(s)) ?? "json"; var provider = registeredProviders[chosenExt]; var filename = Path.Combine(UnityGame.UserDataPath, configName + "." + provider.Extension); var config = new Config(configName, provider, new FileInfo(filename)); ConfigRuntime.RegisterConfig(config); return(config); }
/// <summary> /// Forces an asynchronous load from disk. /// </summary> public Task LoadAsync() => ConfigRuntime.TriggerFileLoad(this);