// Save Load private void on_game_load(ConfigNode nodeGame) { if (nodeGame != null) { KDebug.Log("Loading game...", KDebug.Type.LOAD); this.clear_missions(); // REPORT String nodeName = "Kistory"; ConfigNode nodeReport = new ConfigNode(); if (nodeGame.HasNode(nodeName)) // reserved for future if we will add variables to the report node { nodeReport = nodeGame.GetNode(nodeName); } else { nodeReport = nodeGame; } // MISSION nodeName = "Mission"; if (nodeReport.HasNode(nodeName)) { ConfigNode[] nodeMissions = nodeReport.GetNodes(nodeName); foreach (ConfigNode nodeMission in nodeMissions) { if (nodeMission.HasValue("missionId") & nodeMission.HasValue("missionName") & nodeMission.HasValue("missionTime") & nodeMission.HasValue("missionSituation")) { String missionId = nodeMission.GetValue("missionId"); String missionName = nodeMission.GetValue("missionName"); double missionTime = Convert.ToDouble(nodeMission.GetValue("missionTime")); Vessel.Situations missionSituation = (Vessel.Situations) Enum.Parse(typeof(Vessel.Situations), nodeMission.GetValue("missionSituation")); // I hope that will work // create mission Mission M = new Mission(new Guid(missionId), missionName, missionTime, missionSituation); nodeName = "Entry"; if (nodeMission.HasNode("Entry")) { // ENTRY ConfigNode[] nodeEnties = nodeMission.GetNodes("Entry"); foreach (ConfigNode nodeEntie in nodeEnties) { if (nodeEntie.HasValue("situation") & nodeEntie.HasValue("message") & nodeEntie.HasValue("time")) { // Create variables, to exclude some unknown exeptions String nodem = nodeEntie.GetValue("message"); String nodet = nodeEntie.GetValue("time"); String nodes = nodeEntie.GetValue("situation"); double t = Convert.ToDouble(nodeEntie.GetValue("time")); Entry.Situations S = (Entry.Situations) Enum.Parse(typeof(Entry.Situations), nodes); M.load_entry(S, nodem, t); // Screeshot if (nodeEntie.HasValue("screenshot")) M.add_screenshot(nodeEntie.GetValue("screenshot")); } else { KDebug.Log("on load one of the Entry field is missing", KDebug.Type.LOAD); } } } this.add_mission(M); } else { KDebug.Log("on load one of the Mission field is missing", KDebug.Type.LOAD); } } } } }
// Used to create mission private Boolean is_missionId_exists(Mission M) { return is_missionId_exists(M.missionId); }
// Triggered by creating a new vessel. Apparantelly we create a new mission. However, decoupling also create the new mission. Unfortunatelly, we cannot find the name here. // Events private void on_create(Vessel ves) { // This event should be called only if we have a new mission KDebug.Log("on_create", KDebug.Type.CREATE); Mission M = new Mission(ves); // Possible new mission (ves is check for null) if (M.missionApproved) // Mission was created { KDebug.Log("on_create approved", KDebug.Type.CREATE); int CM = ves.FindPartModulesImplementing<ModuleCommand>().Count(); KDebug.Log("Command Modules: " + CM.ToString(), KDebug.Type.CREATE); // should wotk! //Entry E = new Entry(); if(ves.situation == Vessel.Situations.PRELAUNCH) { KDebug.Log("create " + M.get_name(), KDebug.Type.CREATE); this.add_mission(M); add_event(Entry.Situations.CREATE, ves, M.get_name()); //E.add(Entry.Situations.CREATE, M.get_name(), (double)0); } else if (CM > 0) // Additional check to exclude debrees { KDebug.Log("detached " + M.get_name(), KDebug.Type.CREATE); // TODO // Find the command module and name the mission by command module (if we cannot find how to name it wihtout commant module) // Let's find the command module Part P = ves.FindPartModulesImplementing<ModuleCommand>().Last().part; this.add_mission(M); M.rename(P.partInfo.title); //add_event(Entry.Situations.DETACHED, ves, M.get_name()); add_event(Entry.Situations.DETACHED, ves, P.partInfo.title); //E.add(Entry.Situations.DETACHED, M.get_name(), (double)0); // To collect the name of the mission we probably need to listed Rename event } else { return; } // M.add_entry( E ); // I'm not sue I need this } }
// Create a new mission by Mission object. Used to crate and load mission. private void add_mission(Mission M) { KDebug.Log("Add mission from Report by Mission: " + M.get_name(), KDebug.Type.CREATE); if(!this.is_missionId_exists(M)) this.missions.Add(M); else { KDebug.Log("Mission already exists: " + M.get_name(), KDebug.Type.CREATE); } }