/// <summary> /// Configure this computer for operation. /// </summary> public void Start() { if (!HighLogic.LoadedSceneIsEditor) { vid = vessel.id; refreshDataRate = RPMGlobals.defaultRefreshRate; GameEvents.onVesselWasModified.Add(onVesselWasModified); GameEvents.onVesselChange.Add(onVesselChange); GameEvents.onVesselCrewWasModified.Add(onVesselCrewWasModified); installedModules.Add(new JSIParachute(vessel)); installedModules.Add(new JSIMechJeb(vessel)); installedModules.Add(new JSIInternalRPMButtons(vessel)); installedModules.Add(new JSIFAR(vessel)); installedModules.Add(new JSIKAC(vessel)); #if ENABLE_ENGINE_MONITOR installedModules.Add(new JSIEngine(vessel)); #endif installedModules.Add(new JSIPilotAssistant(vessel)); installedModules.Add(new JSIChatterer(vessel)); if (string.IsNullOrEmpty(RPMCid)) { id = Guid.NewGuid(); RPMCid = id.ToString(); if (part.internalModel != null) { JUtil.LogMessage(this, "Start: Creating GUID {0} in {1}", id, part.internalModel.internalName); } else { JUtil.LogMessage(this, "Start: Creating GUID {0}", id); } } else { id = new Guid(RPMCid); if (part.internalModel != null) { JUtil.LogMessage(this, "Start: Loading GUID string {0} in {1}", RPMCid, part.internalModel.internalName); } else { JUtil.LogMessage(this, "Start: Loading GUID {0}", id); } } plugins = new ExternalVariableHandlers(part); RPMVesselComputer comp = RPMVesselComputer.Instance(vessel); if (!string.IsNullOrEmpty(vesselDescription)) { comp.SetVesselDescription(vesselDescription); } var restoredPersistents = comp.RestorePersistents(id); if (restoredPersistents != null) { persistentVars = restoredPersistents; } // Make sure we have the description strings parsed. string[] descriptionStrings = vesselDescription.UnMangleConfigText().Split(JUtil.LineSeparator, StringSplitOptions.None); for (int i = 0; i < descriptionStrings.Length; i++) { if (descriptionStrings[i].StartsWith("AG", StringComparison.Ordinal) && descriptionStrings[i][3] == '=') { uint groupID; if (uint.TryParse(descriptionStrings[i][2].ToString(), out groupID)) { descriptionStrings[i] = string.Empty; } } } vesselDescriptionForDisplay = string.Join(Environment.NewLine, descriptionStrings).MangleConfigText(); if (string.IsNullOrEmpty(vesselDescriptionForDisplay)) { vesselDescriptionForDisplay = " "; // Workaround for issue #466. } // Now let's parse our stored strings... if (!string.IsNullOrEmpty(storedStrings)) { var storedStringsSplit = storedStrings.Split('|'); for (int i = 0; i < storedStringsSplit.Length; ++i) { storedStringsArray.Add(storedStringsSplit[i]); } } // TODO: If there are triggered events, register for an undock // callback so we can void and rebuild the callbacks after undocking. // Although it didn't work when I tried it... if (!string.IsNullOrEmpty(triggeredEvents)) { string[] varstring = triggeredEvents.Split('|'); for (int i = 0; i < varstring.Length; ++i) { AddTriggeredEvent(varstring[i].Trim()); } } ConfigNode[] moduleConfigs = part.partInfo.partConfig.GetNodes("MODULE"); for (int moduleId = 0; moduleId < moduleConfigs.Length; ++moduleId) { if (moduleConfigs[moduleId].GetValue("name") == moduleName) { ConfigNode[] overrideColorSetup = moduleConfigs[moduleId].GetNodes("RPM_COLOROVERRIDE"); for (int colorGrp = 0; colorGrp < overrideColorSetup.Length; ++colorGrp) { ConfigNode[] colorConfig = overrideColorSetup[colorGrp].GetNodes("COLORDEFINITION"); for (int defIdx = 0; defIdx < colorConfig.Length; ++defIdx) { if (colorConfig[defIdx].HasValue("name") && colorConfig[defIdx].HasValue("color")) { string name = "COLOR_" + (colorConfig[defIdx].GetValue("name").Trim()); Color32 color = ConfigNode.ParseColor32(colorConfig[defIdx].GetValue("color").Trim()); if (overrideColors.ContainsKey(name)) { overrideColors[name] = color; } else { overrideColors.Add(name, color); } } } } } } UpdateLocalCrew(); UpdateLocalVars(); } }