Exemplo n.º 1
0
        public void SavePreset(string path, int flags)
        {
            J.Node.SaveContext = SaveContext.CreateForPreset(
                Bits.IsSet(flags, Utilities.PresetUsePlaceholder));

            if (Bits.IsSet(flags, Utilities.FullPreset))
            {
                var o = ToJSON() as J.Object;
                o.Add("version", Version.String);
                o.Save(path);
            }
            else if (Bits.IsSet(flags, Utilities.StepPreset))
            {
                var s = Synergy.Instance.UI.CurrentStep;
                if (s == null)
                {
                    return;
                }

                var o = s.ToJSON() as J.Object;
                o.Add("version", Version.String);
                o.Save(path);
            }
            else if (Bits.IsSet(flags, Utilities.ModifierPreset))
            {
                var m = Synergy.Instance.UI.CurrentModifier;
                if (m == null)
                {
                    return;
                }

                var o = m.ToJSON() as J.Object;
                o.Add("version", Version.String);
                o.Save(path);
            }

            J.Node.SaveContext = SaveContext.CreateForScene();
        }
Exemplo n.º 2
0
        public void LoadPreset(string path, int flags)
        {
            J.Node.SaveContext = SaveContext.CreateForPreset(
                Bits.IsSet(flags, Utilities.PresetUsePlaceholder));

            var node = J.Node.Wrap(SuperController.singleton.LoadJSON(path));

            if (Bits.IsSet(flags, Utilities.FullPreset))
            {
                if (Bits.IsSet(flags, Utilities.PresetReplace))
                {
                    FromJSON(node);
                }
                else if (Bits.IsSet(flags, Utilities.PresetAppend))
                {
                    var m = new Manager();
                    m.FromJSON(node);

                    foreach (var s in m.Steps)
                    {
                        AddStep(s);
                    }
                }
            }
            else if (Bits.IsSet(flags, Utilities.StepPreset))
            {
                if (Bits.IsSet(flags, Utilities.PresetReplace))
                {
                    var s = Synergy.Instance.UI.CurrentStep;
                    if (s == null)
                    {
                        Synergy.LogError("no current step");
                        return;
                    }

                    s.FromJSON(node);
                    s.Reset();
                }
                else if (Bits.IsSet(flags, Utilities.PresetAppend))
                {
                    var s = new Step();
                    s.FromJSON(node);
                    AddStep(s);
                    s.Reset();
                }
                else if (Bits.IsSet(flags, Utilities.PresetMerge))
                {
                    var s = Synergy.Instance.UI.CurrentStep;
                    if (s == null)
                    {
                        Synergy.LogError("no current step");
                        return;
                    }

                    var newStep = new Step();
                    newStep.FromJSON(node);

                    foreach (var m in newStep.Modifiers)
                    {
                        s.AddModifier(m);
                    }

                    newStep.RelinquishModifiers();

                    s.Reset();
                }
            }
            else if (Bits.IsSet(flags, Utilities.ModifierPreset))
            {
                if (Bits.IsSet(flags, Utilities.PresetReplace))
                {
                    var m = Synergy.Instance.UI.CurrentModifier;
                    if (m == null)
                    {
                        Synergy.LogError("no current modifier");
                        return;
                    }

                    m.FromJSON(node);
                }
                else if (Bits.IsSet(flags, Utilities.PresetAppend))
                {
                    var s = Synergy.Instance.UI.CurrentStep;
                    if (s == null)
                    {
                        Synergy.LogError("no current step");
                        return;
                    }

                    var m = new ModifierContainer();
                    m.FromJSON(node);

                    s.AddModifier(m);
                }
            }

            J.Node.SaveContext = SaveContext.CreateForScene();
        }