Example #1
0
        internal static void Load(MachineInfo machineInfo)
        {
            try
            {
                AxisManager.MachineAxes.Clear();
                ControlManager.Blocks.Clear();

                // read mod version
                if (!machineInfo.MachineData.HasKey("ac-version"))
                {
                    return;
                }
                var version = new Version(machineInfo.MachineData.ReadString("ac-version").TrimStart('v'));

                // version alert
                if (version < Assembly.GetExecutingAssembly().GetName().Version)
                {
                    Debug.Log("[ACM]: " + machineInfo.Name + " was saved with mod version " + version + ".\n\tIt may not be compatible with some newer features.");
                }

                // return if no input axes are present
                if (!machineInfo.MachineData.HasKey("ac-axislist"))
                {
                    return;
                }
                var axes = machineInfo.MachineData.ReadStringArray("ac-axislist");

                // load all axes
                foreach (var name in axes)
                {
                    InputAxis axis = null;
                    if (!machineInfo.MachineData.HasKey("axis-" + name + "-type"))
                    {
                        continue;
                    }
                    var type = machineInfo.MachineData.ReadString("axis-" + name + "-type");
                    if (type == AxisType.Chain.ToString())
                    {
                        axis = new ChainAxis(name);
                    }
                    if (type == AxisType.Controller.ToString())
                    {
                        axis = new ControllerAxis(name);
                    }
                    if (type == AxisType.Custom.ToString())
                    {
                        axis = new CustomAxis(name);
                    }
                    if (type == AxisType.Standard.ToString() || // backwards compatibility
                        type == AxisType.Inertial.ToString() || // backwards compatibility
                        type == AxisType.Key.ToString())
                    {
                        axis = new KeyAxis(name);
                    }
                    if (type == AxisType.Mouse.ToString())
                    {
                        axis = new MouseAxis(name);
                    }
                    if (axis != null)
                    {
                        axis?.Load(machineInfo);
                        AxisManager.AddMachineAxis(axis);
                    }
                }

                // refresh chain axis links
                foreach (var entry in AxisManager.MachineAxes)
                {
                    if (entry.Value.Type == AxisType.Chain)
                    {
                        (entry.Value as ChainAxis).RefreshLinks();
                    }
                }

                // resolve from foreign controllers
                AxisManager.ResolveMachineAxes();

                // load all controls
                foreach (BlockInfo blockInfo in machineInfo.Blocks)
                {
                    if (!blockInfo.BlockData.HasKey("ac-controllist"))
                    {
                        continue;
                    }
                    var control_list  = ControlManager.GetBlockControls(blockInfo.ID, blockInfo.Guid);
                    var control_names = blockInfo.BlockData.ReadStringArray("ac-controllist");
                    foreach (string name in control_names)
                    {
                        foreach (Control c in control_list)
                        {
                            if (name == c.Name)
                            {
                                c.Load(blockInfo);
                            }
                        }
                    }
                }

                ACM.Instance.LoadedMachine = true;
            }
            catch (Exception e)
            {
                Debug.Log("[ACM]: Error loading machine's controls:");
                Debug.LogException(e);
            }
        }
Example #2
0
        internal static void Load()
        {
            try
            {
                // load mod configuration
                ACM.Instance.ModEnabled        = spaar.ModLoader.Configuration.GetBool("acm-enabled", true);
                ACM.Instance.ModUpdaterEnabled = spaar.ModLoader.Configuration.GetBool("mod-updater-enabled", true);
                ACM.Instance.DBUpdaterEnabled  = spaar.ModLoader.Configuration.GetBool("db-updater-enabled", true);

                // read input axes
                int count = spaar.ModLoader.Configuration.GetInt("number-of-axes", 0);
                for (int i = 0; i < count; i++)
                {
                    string    name = spaar.ModLoader.Configuration.GetString("axis-" + i + "-name", null);
                    InputAxis axis = null;
                    if (name != null)
                    {
                        var type = spaar.ModLoader.Configuration.GetString("axis-" + name + "-type", null);
                        if (type == AxisType.Chain.ToString())
                        {
                            axis = new ChainAxis(name);
                        }
                        if (type == AxisType.Controller.ToString())
                        {
                            axis = new ControllerAxis(name);
                        }
                        if (type == AxisType.Custom.ToString())
                        {
                            axis = new CustomAxis(name);
                        }
                        if (type == AxisType.Standard.ToString() || // backwards compatibility
                            type == AxisType.Inertial.ToString() || // backwards compatibility
                            type == AxisType.Key.ToString())
                        {
                            axis = new KeyAxis(name);
                        }
                        if (type == AxisType.Mouse.ToString())
                        {
                            axis = new MouseAxis(name);
                        }
                    }
                    if (axis != null)
                    {
                        axis?.Load();
                        AxisManager.AddLocalAxis(axis);
                    }
                }

                // refresh chain axis links
                foreach (var entry in AxisManager.LocalAxes)
                {
                    if (entry.Value.Type == AxisType.Chain)
                    {
                        (entry.Value as ChainAxis).RefreshLinks();
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Log("[ACM]: Error loading saved axes:");
                Debug.LogException(e);
            }
        }