Esempio n. 1
0
        public override void OnLoad(XDataHolder stream)
        {
            LoadMapperValues(stream);

            // "bmt-" prefix is necessary to enable copying&pasting of actions, keys that don't have it are deleted upon copying
            // String can be empty when it shouldn't be because of a bug in Undosystem, so ignore that.
            if (stream.HasKey("bmt-automatron-actions") && stream.ReadString("bmt-automatron-actions") != "")
            {
                // Clear actions so they don't get duplicated if OnLoad is called by the UndoSystem
                actions.Clear();

                DeserializeActions(stream.ReadString("bmt-automatron-actions"));
            }
            // Since earlier versions of the Automatron didn't use the prefix, also check for the presence of the key without
            // in order to preserve backwards-compatibility
            else if (stream.HasKey("automatron-actions") && stream.ReadString("automatron-actions") != "")
            {
                // Clear actions so they don't get duplicated if OnLoad is called by the UndoSystem
                actions.Clear();

                DeserializeActions(stream.ReadString("automatron-actions"));
            }
            else
            {
                Debug.Log("OnLoad called without action data.");
            }
        }
 public override void LoadConfiguration(XDataHolder BlockData)
 {
     if (BlockData.HasKey("bmt-" + "CameraTarget"))
     {
         SaveTargetToDict(BlockData.ReadInt("bmt-" + "CameraTarget"));
     }
 }
Esempio n. 3
0
 public override void Apply(XDataHolder input)
 {
     if (input.HasKey("BlockID"))
     {
         var blockType = input.ReadInt("BlockID");
         AddPiece.Instance?.SetBlockType((BlockType)blockType);
     }
 }
Esempio n. 4
0
 public override void Apply(XDataHolder input)
 {
     input.Write(_defaultInput);
     foreach (var uiContainer in _containers)
     {
         if (_defaultInput.HasKey(uiContainer.Title))
         {
             uiContainer.Display =
                 _defaultInput.ReadBool(uiContainer.Title);
         }
     }
 }
        public static Configuration FormatXDataToConfig(Configuration config = null)
        {
            XDataHolder xDataHolder = Modding.Configuration.GetData();
            bool        reWrite     = true;
            bool        needWrite   = false;

            if (config == null)
            {
                reWrite   = false;
                needWrite = true;
                config    = new Configuration();
            }

            for (int i = 0; i < Propertises.Count; i++)
            {
                var value = Propertises[i];

                if (value is Propertise <int> )
                {
                    value = getValue(value as Propertise <int>);
                }
                else if (value is Propertise <bool> )
                {
                    value = getValue(value as Propertise <bool>);
                }
                else if (value is Propertise <float> )
                {
                    value = getValue(value as Propertise <float>);
                }
                else if (value is Propertise <string> )
                {
                    value = getValue(value as Propertise <string>);
                }
                else if (value is Propertise <Vector3> )
                {
                    value = getValue(value as Propertise <Vector3>);
                }
                Propertises[i] = value;
            }

            if (needWrite)
            {
                Modding.Configuration.Save();
            }

            return(config);

            Propertise <T> getValue <T>(Propertise <T> propertise)
            {
                var key          = propertise.Key;
                var defaultValue = propertise.Value;

                if (xDataHolder.HasKey(key) && !reWrite)
                {
                    defaultValue = (T)Convert.ChangeType(typeSpecialAction[typeof(T)](xDataHolder, key), typeof(T));
                }
                else
                {
                    xDataHolder.Write(key, defaultValue);
                    needWrite = true;
                }

                return(new Propertise <T>(key, defaultValue));
            }
        }