/// <summary> /// Updates the current key bind configuration. /// </summary> public static bool TryUpdateConfig(BindsConfig cfg) { Binds newBinds = new Binds(); KeyBindData[] bindData = cfg.bindData; bool bindError = false; if (bindData != null && bindData.Length > 0) { foreach (KeyBindData bind in bindData) { if (!newBinds.TryUpdateBind(bind.name, bind.controlNames, true)) { bindError = true; break; } } if (bindError) { BvMain.Instance.SendChatMessage("One or more keybinds in the given configuration were invalid."); return(false); } else { Instance = newBinds; return(true); } } else { BvMain.Instance.SendChatMessage("Bind data cannot be null or empty."); return(false); } }
public void Validate() { if (versionID != BvMain.configVersionID) { versionID = BvMain.configVersionID; } if (menu != null) { menu.Validate(); } else { menu = PropMenuConfig.Defaults; } if (binds != null) { binds.Validate(); } else { binds = BindsConfig.Defaults; } if (propertyBlock != null) { propertyBlock.Validate(); } else { propertyBlock = PropBlockConfig.Defaults; } }
public override void Validate() { if (VersionID != vID) { VersionID = vID; targeting = TargetingConfig.Defaults; genUI = UIConfig.Defaults; block = PropBlockConfig.Defaults; binds = BindsConfig.Defaults; WasConfigOld = true; } else { if (targeting != null) { targeting.Validate(); } else { targeting = TargetingConfig.Defaults; } if (genUI != null) { genUI.Validate(); } else { genUI = UIConfig.Defaults; } if (binds != null) { binds.Validate(); } else { binds = BindsConfig.Defaults; } if (block != null) { block.Validate(); } else { block = PropBlockConfig.Defaults; } if (genUI.legacyModeEnabled) { targeting.canOpenIfPlacing = true; } } }
/// <summary> /// Returns the current instance or creates one if necessary. /// </summary> public static void Init(BindsConfig cfg) { if (Instance == null) { Instance = new Binds(); if (!TryUpdateConfig(cfg)) { TryUpdateConfig(BindsConfig.Defaults); } } }