Esempio n. 1
0
        /// <summary>
        /// Saves the gpss to the file
        /// </summary>
        public override void SaveData()
        {
            if (!MySettingsSession.Static.IsEnabled())
            {
                return;
            }

            MyPluginLog.Log("Saving GPS manager data");

            MyObjectBuilder_WorldGpsData ob = new MyObjectBuilder_WorldGpsData();

            foreach (var entry in m_globalGpss)
            {
                PersistentGpsData item = new PersistentGpsData();
                item.Name      = entry.Value.Name;
                item.Color     = entry.Value.Color;
                item.Position  = entry.Value.Position;
                item.PlayerIds = entry.Value.Players;
                item.Id        = entry.Key;
                item.Hidden    = entry.Value.Hidden;

                ob.PersistentGpss.Add(item);
            }

            MyFileUtils.WriteXmlFileToWorld(ob, FILENAME);

            MyPluginLog.Log("Saving GPS manager data completed");
        }
Esempio n. 2
0
        /// <summary>
        /// Loads persistent gps data
        /// </summary>
        public override void LoadData()
        {
            MyPluginLog.Log("Loading GPS manager data");
            Static = this;

            MyObjectBuilder_WorldGpsData ob;

            if (MyFileUtils.FileExistsInWorldStorage(FILENAME))
            {
                ob = MyFileUtils.ReadXmlFileFromWorld <MyObjectBuilder_WorldGpsData>(FILENAME);
            }
            else
            {
                ob = new MyObjectBuilder_WorldGpsData();
            }

            m_globalGpss  = new Dictionary <Guid, MyGpsData>();
            m_dynamicGpss = new Dictionary <Tuple <Guid, long>, int>();

            foreach (var item in ob.PersistentGpss)
            {
                var data = new MyGpsData(item.Name, item.Color, item.Position, item.Id, item.PlayerIds, item.Hidden);
                m_globalGpss[item.Id] = data;
            }

            MySession.Static.OnSavingCheckpoint += delegate
            {
                foreach (var key in m_dynamicGpss.Keys)
                {
                    MySession.Static.Gpss.SendDelete(key.Item2, m_dynamicGpss[key]);
                }
                ;
                m_dynamicGpss.Clear();
            };

            MyPluginLog.Log("Loading GPS manager data completed");
        }