Пример #1
0
 public void Awake()
 {
     //init stuff
     Debug.Log("WS Awoke");
     CellUpdater.run = 0;
     WeatherDatabase.CheckCreateForFiles(HighLogic.SaveFolder);
     if (configSaving)
     {
         WeatherDatabase.LoadConfigSimData(HighLogic.CurrentGame.config);
     }
     else
     {
         WeatherDatabase.LoadPlanetaryData(HighLogic.SaveFolder);
     }
     GameEvents.onGameSceneLoadRequested.Remove(OnSceneLoadRequested);
     GameEvents.onGameSceneLoadRequested.Add(OnSceneLoadRequested);
     GameEvents.onLaunch.Remove(OnLaunch);
     GameEvents.onLaunch.Add(OnLaunch);
     GameEvents.onGamePause.Remove(OnPause);
     GameEvents.onGamePause.Add(OnPause);
     GameEvents.onGameUnpause.Remove(OnUnPause);
     GameEvents.onGameUnpause.Add(OnUnPause);
     GameEvents.onGameStateSaved.Remove(OnGameSaved);
     GameEvents.onGameStateSaved.Add(OnGameSaved);
     GameEvents.onGameStatePostLoad.Remove(OnGamePostLoad);
     GameEvents.onGameStatePostLoad.Add(OnGamePostLoad);
     GameEvents.onGameStateCreated.Remove(OnGameCreated);
     GameEvents.onGameStateCreated.Add(OnGameCreated);
 }
Пример #2
0
        public static BodyResourceData Load(IResourceGenerator generator, PlanetData PD, ConfigNode bodyNode)
        {
            if (bodyNode == null)
            {
                bodyNode = new ConfigNode();
            }
            var resources = generator.Load(PD.body, bodyNode.GetNode("GeneratorData"));
            var scans     = new CellSet(PD.gridLevel);

            var scanMask = bodyNode.GetValue("ScanMask");

            if (scanMask != null)
            {
                try
                {
                    scans = new CellSet(PD.gridLevel, WeatherDatabase.FromBase64String(scanMask));
                }
                catch (FormatException e)
                {
                    Debug.LogError(String.Format("[Kethane] Failed to parse {0} scan string, resetting ({1})", PD.body.name, e.Message));
                }
            }

            return(new BodyResourceData(resources, scans));
        }
Пример #3
0
 protected virtual void OnBodyChanged()
 {
     PD = WeatherDatabase.GetPlanetData(body);
     if (OnBodyChange != null)
     {
         OnBodyChange(PD);
     }
 }
Пример #4
0
 internal static void InitPlanetData(PlanetData PD)
 {
     InitTropopauseAlts(PD);
     InitStuff(PD);
     if (configSaving)
     {
         WeatherDatabase.SaveConfigSimData(HighLogic.CurrentGame.config, 0);
     }
 }
Пример #5
0
        public void Save(ConfigNode bodyNode)
        {
            bodyNode.AddValue("ScanMask", WeatherDatabase.ToBase64String(scans.ToByteArray()));

            var node = Resources.Save() ?? new ConfigNode();

            node.name = "GeneratorData";
            bodyNode.AddNode(node);
        }
Пример #6
0
        public void Awake()
        {
            //this is a comment
            Logger("Awoke!");
            DontDestroyOnLoad(this);
            Logger("Checking basic files");
            WeatherDatabase.BasicSanityCheck();
            WeatherSettings.SettingsFileIntegrityCheck();
            if (WeatherDatabase.BasicFileIntegrityCheck())
            {
                Logger("Integrity check passed, continuing");
            }
            else
            {
                Logger("Integrity check failed, quitting.");
                return;
            }
            //init planet
            WeatherDatabase.LoadInitPlanetaryData();
            WeatherSettings.LoadSettings();
            GameEvents.onGameSceneSwitchRequested.Add(scene =>
            {
                if (scene.from == GameScenes.MAINMENU && scene.to == GameScenes.SPACECENTER)
                {
                    prepToNew = true;
                }
                else if (scene.from == GameScenes.SPACECENTER && scene.to == GameScenes.MAINMENU)
                {
                    prepToDestroy = true;
                    sim           = null;
                    Destroy(this.gameObject.GetComponent <WeatherSimulator>());
                    Destroy(this.gameObject.GetComponent <MapOverlay>());
                    Destroy(this.gameObject.GetComponent <WeatherGUI.WeatherGUI>());
                    prepToDestroy = false;
                }
            });
            GameEvents.onGameStateLoad.Add(node =>
            {
                if (HighLogic.LoadedScene == GameScenes.SPACECENTER && prepToNew)
                {
                    //new up simulator

                    sim = this.gameObject.AddComponent <WeatherSimulator>();
                    this.gameObject.AddComponent <MapOverlay>();
                    this.gameObject.AddComponent <WeatherGUI.WeatherGUI>();
                    prepToNew = false;
                }
                if (HighLogic.LoadedScene == GameScenes.MAINMENU && prepToDestroy)
                {
                    sim = null;
                    Destroy(this.gameObject.GetComponent <WeatherSimulator>());
                    Destroy(this.gameObject.GetComponent <MapOverlay>());
                    Destroy(this.gameObject.GetComponent <WeatherGUI.WeatherGUI>());
                    prepToDestroy = false;
                }
            });
        }
Пример #7
0
 public void OnGamePostLoad(ConfigNode node)
 {
     Debug.Log("[KWS] Loading game state...");
     if (configSaving)
     {
         WeatherDatabase.LoadConfigSimData(node);
     }
     else
     {
         WeatherDatabase.LoadPlanetaryData(HighLogic.SaveFolder);
     }
     Debug.Log("[KWS] Game state loaded");
 }
Пример #8
0
 public void OnLaunch(EventReport report)
 {
     //save initial flight state
     isPaused = false;
     if (configSaving)
     {
         WeatherDatabase.SaveConfigSimData(HighLogic.CurrentGame.config, cellindex);
     }
     else
     {
         WeatherDatabase.SaveInitFlightState(cellindex, HighLogic.SaveFolder);
     }
 }
Пример #9
0
 public void OnGameSaved(Game game)
 {
     Debug.Log("[KWS] Saving game state...");
     if (configSaving)
     {
         WeatherDatabase.SaveConfigSimData(game.config, cellindex);
     }
     else
     {
         WeatherDatabase.CheckCreateForFiles(HighLogic.SaveFolder);
         WeatherDatabase.SavePlanetaryData(cellindex, HighLogic.SaveFolder);
     }
     Debug.Log("[KWS] Game state saved");
 }
 void CellDataTest(int windowId)
 {
     GUILayout.BeginVertical();
     //GUILayout.Label("CellID: " + CellIDLabel); CellIDLabel = GUILayout.TextField(CellIDLabel, 10); CellIDInt = int.Parse(CellIDLabel);
     GUILayout.Label("CellID: " + CellIDInt);
     GUILayout.BeginHorizontal();
     if (GUILayout.Button("CellID ++"))
     {
         if (CellIDInt < Cell.KWSBODY[FlightGlobals.currentMainBody].Count - 1)
         {
             CellIDInt++;
         }
     }
     if (GUILayout.Button("CellID +360"))
     {
         if (CellIDInt < Cell.KWSBODY[FlightGlobals.currentMainBody].Count - 360)
         {
             CellIDInt += 360;
         }
     }
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal();
     if (GUILayout.Button("CellID --"))
     {
         if (CellIDInt > 0)
         {
             CellIDInt--;
         }
     }
     if (GUILayout.Button("CellID -360"))
     {
         if (CellIDInt > 359)
         {
             CellIDInt -= 360;
         }
     }
     GUILayout.EndHorizontal();
     if (GUILayout.Button("CellID 0"))
     {
         CellIDInt = 0;
     }
     GUILayout.Label("Temperature: " + WeatherDatabase.getCellTemperature(FlightGlobals.currentMainBody, CellIDInt).ToString("0.00"));
     GUILayout.Label("Pressure: " + WeatherDatabase.getCellPressure(FlightGlobals.currentMainBody, CellIDInt).ToString("0.000"));
     GUILayout.Label("Cell Latitude: " + WeatherDatabase.getCellLat(FlightGlobals.currentMainBody, CellIDInt));
     GUILayout.Label("Cell Longitude: " + WeatherDatabase.getCellLong(FlightGlobals.currentMainBody, CellIDInt));
     GUILayout.Label("Cell Altitude: " + WeatherDatabase.getCellAltitude(FlightGlobals.currentMainBody, CellIDInt));
     //GUILayout.Label("Cell Pos: " + Cell.KWSBODY[FlightGlobals.currentMainBody][CellIDInt].CellPosition);
     GUILayout.EndVertical();
     GUI.DragWindow();
 }
Пример #11
0
 private void test_button_Click(object sender, RoutedEventArgs e)
 {
     logger.Trace("Нажата тестовая кнопка настроек");
     RotateStatusImg(true);
     Task.Factory.StartNew(async() =>
     {
         Weather weather = new Weather();
         if (await WeatherDatabase.CheckAsync())
         {
             weather = await Weather.NowAsync();
             await WeatherDatabase.WriteAsync(weather);
         }
         Dispatcher.Invoke(() => RotateStatusImg(false));
     });
 }
Пример #12
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public WeatherData()
 {
     if (_objectCount == 0)                                                                              //如果本类从未实例化
     {
         _sqlCon = WeatherDatabase.GetSqlConnection();                                                   //获取数据库连接
         try
         {
             _sqlCon.Open();                                                                                                             //尝试打开数据库
         }
         catch (Exception ex)                                                                                                            //捕捉异常
         {
             throw ex;                                                                                                                   //重抛
         }
     }
     ++_objectCount;                                                                                                                     //对象计数器加一
 }
Пример #13
0
        public void UpdateOffset(float rateOffset, bool rotation)
        {
            //CelestialBody body = FlightGlobals.currentMainBody;

            if (rotation)
            {
                //Debug.Log("This one"); called in tandum with "or this one" at space center
                this.Offset.x = rateOffset * (Wind.windDirection.x * (WeatherDatabase.GetOffSetMultiplier()));     //this.Speed.x;
                this.Offset.y = rateOffset * (Wind.windDirection.y * (WeatherDatabase.GetOffSetMultiplier()));     //this.Speed.y;
            }
            else
            {
                //Debug.Log("Or this one"); // called in tandum with "This one" at space center
                this.Offset.x += rateOffset * (Wind.windDirection.x * (WeatherDatabase.GetOffSetMultiplier()));
                this.Offset.y += rateOffset * (Wind.windDirection.y * (WeatherDatabase.GetOffSetMultiplier()));
                SaturateOffset();
            }
        }
Пример #14
0
 internal static bool configSaving  = false; //KSP integrated(true) or standalone?
 public void OnSceneLoadRequested(GameScenes scene)
 {
     if (scene == GameScenes.MAINMENU)
     {
         isPaused = true;
         //do the saving
     }
     if (scene == GameScenes.SPACECENTER && HighLogic.LoadedScene == GameScenes.EDITOR)
     {
         isPaused = false;
     }
     if (scene == GameScenes.FLIGHT && scene == GameScenes.SPACECENTER)
     {
         isPaused = false;
         if (configSaving)
         {
             Debug.Log("[KWS] Reverting to space center config state");
             WeatherDatabase.LoadConfigSimData(HighLogic.CurrentGame.config);
         }
         else
         {
             Debug.Log("[KWS] Reverting to space center state");
             WeatherDatabase.LoadInitFlightState(HighLogic.SaveFolder);
         }
     }
     if (scene == GameScenes.EDITOR || scene == GameScenes.FLIGHT)
     {
         if (FlightDriver.StartupBehaviour == FlightDriver.StartupBehaviours.RESUME_SAVED_CACHE || EditorDriver.StartupBehaviour == EditorDriver.StartupBehaviours.LOAD_FROM_CACHE)
         {
             //load flight launch state
             //we can assume that reverting to the editor allows us to have flight state because we must first have gone into flight to be able to revert to editor.
             if (configSaving)
             {
                 Debug.Log("[KWS] Loading init config flight state");
                 WeatherDatabase.LoadConfigSimData(HighLogic.CurrentGame.config);
             }
             else
             {
                 Debug.Log("[KWS] Loading init flight state");
                 WeatherDatabase.LoadInitFlightState(HighLogic.SaveFolder);
             }
         }
         if (scene == GameScenes.FLIGHT)
         {
             if (configSaving)
             {
                 Debug.Log("[KWS] Saving init config flight state");
                 WeatherDatabase.SaveConfigSimData(HighLogic.CurrentGame.config, cellindex);
             }
             else
             {
                 Debug.Log("[KWS] Saving init flight state");
                 WeatherDatabase.SaveInitFlightState(cellindex, HighLogic.SaveFolder);
             }
         }
         if (scene == GameScenes.EDITOR)
         {
             isPaused = true;
         }
     }
 }
Пример #15
0
 public void OnGameCreated(Game game)
 {
     Logger("Checking for files...");
     WeatherDatabase.CheckCreateForFiles(game.linkURL);
 }