/// <summary>Only loads session settings.</summary> void Awake() { ConfigAccessor.ReadFieldsInType(typeof(Controller), null /* instance */); ConfigAccessor.ReadFieldsInType(typeof(Controller), this, group: SessionGroup); toggleConsoleKeyEvent = Event.KeyboardEvent(toggleConsoleKey); windowRect = new Rect(windowPos, windowSize); }
static UniqueIdGenerate() { var configFactory = new ConfigurationFactory(null, Enumerable.Empty <IAdditionalConfigurationSource>()); var configAccessor = new ConfigAccessor(configFactory); Generator = new UniqueIdGenerator(configAccessor); }
private Task loadTaskFromFile() { ConfigAccessor accessor = new ConfigAccessor(); if (!accessor.readConfigFromFile(TASK_FILE)) { return(null); } Catagory cat = accessor.getCatagory("Task"); if (cat == null) { return(null); } String file = cat.getAttribute("File", null); int process = cat.getIntAttribute("Process", -1); if (file == null || process < 0) { return(null); } Task task = new Task(file); task.Process = process; return(task); }
protected BaseTestsSteps() { var config = ConfigAccessor.GetApplicationConfiguration(); baseUrl = config.BaseUrl; restClient = new RestClient(baseUrl); }
/// <summary>Only loads the session settings.</summary> void Awake() { UnityEngine.Object.DontDestroyOnLoad(gameObject); // Read the configs for all the aggregators. ConfigAccessor.ReadFieldsInType(typeof(LogInterceptor), null /* instance */); ConfigAccessor.ReadFieldsInType(typeof(LogFilter), null /* instance */); ConfigAccessor.ReadFieldsInType( ConsoleUI.diskLogAggregator.GetType(), ConsoleUI.diskLogAggregator); ConfigAccessor.ReadFieldsInType( ConsoleUI.rawLogAggregator.GetType(), ConsoleUI.rawLogAggregator); ConfigAccessor.ReadFieldsInType( ConsoleUI.collapseLogAggregator.GetType(), ConsoleUI.collapseLogAggregator); ConfigAccessor.ReadFieldsInType( ConsoleUI.smartLogAggregator.GetType(), ConsoleUI.smartLogAggregator); // Start all aggregators. ConsoleUI.rawLogAggregator.StartCapture(); ConsoleUI.collapseLogAggregator.StartCapture(); ConsoleUI.smartLogAggregator.StartCapture(); ConsoleUI.diskLogAggregator.StartCapture(); LogInterceptor.StartIntercepting(); // Load UI configs. ConfigAccessor.ReadFieldsInType(typeof(ConsoleUI), null /* instance */); ConfigAccessor.ReadFieldsInType( typeof(ConsoleUI), this, group: StdPersistentGroups.SessionGroup); }
/// <summary>Calculates part's dry cost given the config and the variant.</summary> /// <param name="avPart">The part's proto.</param> /// <param name="variant"> /// The part's variant. If it's <c>null</c>, then the variant will be attempted to read from /// <paramref name="partNode"/>. /// </param> /// <param name="partNode"> /// The part's persistent config. It will be looked up for the various cost modifiers. /// </param> /// <returns>The dry cost of the part.</returns> public double GetPartDryCost( AvailablePart avPart, PartVariant variant = null, ConfigNode partNode = null) { // TweakScale compatibility if (partNode != null) { var tweakScale = KISAPI.PartNodeUtils.GetTweakScaleModule(partNode); if (tweakScale != null) { var tweakedCost = ConfigAccessor.GetValueByPath <double>(tweakScale, "DryCost"); if (tweakedCost.HasValue) { // TODO(ihsoft): Get back to this code once TweakScale supports variants. return(tweakedCost.Value); } DebugEx.Error("No dry cost specified in a tweaked part {0}:\n{1}", avPart.name, tweakScale); } } var itemCost = avPart.cost; if (variant == null && partNode != null) { variant = VariantsUtils.GetCurrentPartVariant(avPart, partNode); } VariantsUtils.ExecuteAtPartVariant(avPart, variant, p => itemCost += p.GetModuleCosts(avPart.cost)); return(itemCost); }
/// <inheritdoc/> public override void OnAwake() { ConfigAccessor.CopyPartConfigFromPrefab(this); base.OnAwake(); GameEvents.onVesselRename.Add(OnVesselRename); LocalizeModule(); }
/// <summary>Updates the part's resource.</summary> /// <param name="partNode"> /// The part's config or a persistent state. It can be a top-level node or the <c>PART</c> node. /// </param> /// <param name="name">The name of the resource.</param> /// <param name="amount">The new amount or the delta.</param> /// <param name="isAmountRelative"> /// Tells if the amount must be added to the current item's amount instead of simply replacing it. /// </param> /// <returns>The new amount or <c>null</c> if the resource was not found.</returns> public double?UpdateResource(ConfigNode partNode, string name, double amount, bool isAmountRelative = false) { if (partNode.HasNode("PART")) { partNode = partNode.GetNode("PART"); } var node = partNode.GetNodes("RESOURCE") .FirstOrDefault(r => r.GetValue("name") == name); double?setAmount = null; if (node != null) { setAmount = amount; if (isAmountRelative) { setAmount += ConfigAccessor.GetValueByPath <double>(node, "amount") ?? 0.0; } ConfigAccessor.SetValueByPath(node, "amount", setAmount.Value); } else { DebugEx.Error("Cannot find resource '{0}' in config:\n{1}", name, partNode); } return(setAmount); }
public static void Main(string[] args) { var conf = new Configuration("SharpIM", "SharpIM.Server.Config.xml"); if (!conf.Check()) { conf.LoadDefaults(); } else { ConfigAccessor.Initialize(conf); var connString = (string)ConfigAccessor.GetValue("ConnectionString"); var port = (int)ConfigAccessor.GetValue("Port"); var db = new Database(connString); DataAccessor.Initialize(db); var server = new Core.Server(port); server.StartServer(); Console.WriteLine("SharpIM Server initialized on TCP Port {0:d}", port); Console.WriteLine("Waiting for connections..."); Console.WriteLine(); while (true) { Thread.Sleep(1024); } } }
/// <inheritdoc/> public override void OnLoad(ConfigNode node) { ConfigAccessor.ReadPartConfig(this, cfgNode: node); ConfigAccessor.ReadFieldsFromNode(node, GetType(), this, StdPersistentGroups.PartPersistant); base.OnLoad(node); parsedAttachNode = part.FindAttachNode(attachNodeName); isAutoAttachNode = parsedAttachNode == null; if (isAutoAttachNode) { parsedAttachNode = KASAPI.AttachNodesUtils.ParseNodeFromString( part, attachNodeDef, attachNodeName); if (parsedAttachNode != null) { HostedDebugLog.Fine( this, "Created auto node: {0}", KASAPI.AttachNodesUtils.NodeId(parsedAttachNode)); if (coupleNode != null && (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor)) { // Only pre-add the node in the scenes that assume restoring a vessel state. // We'll drop it in the OnStartFinished if not used. KASAPI.AttachNodesUtils.AddNode(part, coupleNode); } } else { HostedDebugLog.Error(this, "Cannot create auto node from: {0}", attachNodeDef); } } if (parsedAttachNode != null) { // HACK: Handle a KIS issue which causes the nodes to be owned by the prefab part. parsedAttachNode.owner = part; nodeTransform = KASAPI.AttachNodesUtils.GetTransformForNode(part, parsedAttachNode); } }
/// <summary>Creates a new item, given a saved state.</summary> /// <remarks> /// It's intentionally private. The items must be restored thru the factory methods. /// </remarks> /// <seealso cref="RestoreItemFromNode"/> KIS_Item(AvailablePart availablePart, ConfigNode itemNode, ModuleKISInventory inventory, int quantity) { this.availablePart = availablePart; this.inventory = inventory; this.quantity = quantity; SetPrefabModule(); this.stackable = CheckItemStackable(availablePart); this.partNode = new ConfigNode(); itemNode.GetNode("PART").CopyTo(partNode); ConfigAccessor.ReadFieldsFromNode( itemNode, GetType(), this, group: StdPersistentGroups.PartPersistant); this.itemVolume = KISAPI.PartUtils.GetPartVolume(availablePart, partNode: partNode); // COMPATIBILITY: Set/restore the dry cost and mass. // TODO(ihsoft): This code is only needed for the pre-1.17 KIS version saves. Drop it one day. if (this.itemDryMass < float.Epsilon || this.itemDryCost < float.Epsilon) { this._itemDryMass = KISAPI.PartUtils.GetPartDryMass(availablePart, partNode: partNode); this._itemDryCost = KISAPI.PartUtils.GetPartDryCost(availablePart, partNode: partNode); DebugEx.Warning("Calculated values for a pre 1.17 version save: dryMass={0}, dryCost={1}", this.itemDryMass, this.itemDryCost); } RecalculateResources(); }
void Awake() { ConfigAccessor.ReadFieldsInType(GetType(), this); if (twekerEnabled) { AsyncCall.CallOnEndOfFrame(this, WaitAndApplyTweaks); } }
void Awake() { ConfigAccessor.ReadFieldsInType(GetType(), instance: this); if (!string.IsNullOrEmpty(openGUIKey)) { openGUIEvent = Event.KeyboardEvent(openGUIKey); } }
void Awake() { ConfigAccessor.ReadFieldsInType(GetType(), instance: this); if (!string.IsNullOrEmpty(openGUIKey)) { DebugEx.Info("EqippedItemAlignTool controller created"); openGUIEvent = Event.KeyboardEvent(openGUIKey); } }
/// <inheritdoc/> public override void OnAwake() { ConfigAccessor.CopyPartConfigFromPrefab(this); base.OnAwake(); LocalizeModule(); linkStateMachine = new SimpleStateMachine <LinkState>(true /* strict */); SetupStateMachine(); GameEvents.onPartCouple.Add(OnPartCoupleEvent); }
/// <summary>Only loads session settings.</summary> void Awake() { ConfigAccessor.ReadFieldsInType(typeof(Controller), null /* instance */); ConfigAccessor.ReadFieldsInType(typeof(Controller), this, group: SessionGroup); windowRect = new Rect(windowPos, windowSize); if (isUIVisible) { StartCoroutine(CheckForSettingsChange()); } }
private void saveTask(Task task) { ConfigAccessor accessor = new ConfigAccessor(); Catagory cat = new Catagory("Task"); cat.addAttribute("File", task.FileName); cat.addAttribute("Process", task.Process.ToString()); accessor.addCatagory(cat.Name, cat); accessor.writeConfigToFile(TASK_FILE); }
/// <inheritdoc/> public override void OnLoad(ConfigNode node) { ConfigAccessor.ReadPartConfig(this, cfgNode: node); ConfigAccessor.ReadFieldsFromNode(node, GetType(), this, StdPersistentGroups.PartPersistant); base.OnLoad(node); if (!PartLoader.Instance.IsReady()) { CreatePartModel(); } }
/// <inheritdoc/> public override void OnLoad(ConfigNode node) { ConfigAccessor.ReadPartConfig(this, cfgNode: node); ConfigAccessor.ReadFieldsFromNode(node, GetType(), this, StdPersistentGroups.PartPersistant); base.OnLoad(node); if (!moduleSettingsLoaded) { moduleSettingsLoaded = true; InitModuleSettings(); } }
void Awake() { DebugEx.Info("Winch remote controller created"); ConfigAccessor.ReadFieldsInType(GetType(), this); _openGuiEvent = Event.KeyboardEvent(openGuiKey); _instance = this; LoadLocalizedContent(); GameEvents.onLanguageSwitched.Add(LoadLocalizedContent); GameEvents.onVesselWasModified.Add(OnVesselUpdated); GameEvents.onVesselDestroy.Add(OnVesselUpdated); GameEvents.onVesselCreate.Add(OnVesselUpdated); }
/// <inheritdoc/> public override void OnLoad(ConfigNode node) { ConfigAccessor.ReadPartConfig(this, node); // For the procedural and simple modes use the hardcoded model names. if (sourceJointConfig.type != PipeEndType.PrefabModel) { sourceJointConfig.modelPath = ProceduralSourceJointObjectName; } if (targetJointConfig.type != PipeEndType.PrefabModel) { targetJointConfig.modelPath = ProceduralTargetJointObjectName; } base.OnLoad(node); }
/// <summary>Overridden from MonoBehaviour.</summary> /// <remarks>Registers listeners, reads configuration and creates global UI objects.</remarks> void Awake() { GameEvents.onVesselSwitching.Add(OnVesselSwitch); GameEvents.onVesselChange.Add(OnVesselChange); GameEvents.onPartCouple.Add(OnPartCouple); ConfigAccessor.ReadFieldsInType(typeof(Controller), this); _mouseInfoOverlay = new HintOverlay( infoOverlayFontSize, infoOverlayHintPadding, infoOverlayTextColor, infoOverlayBackgroundColor); // Drop vessel selection when main modifier is released. vesselSwitchKey.OnRelease += delegate { SetHoveredVessel(null); }; // Iterate thru stabilization modes. switchStabilizationModeKey.OnClick += SelectNextStabilizationMode; }
public void Awake() { ConfigAccessor.ReadFieldsInType(GetType(), this); ConfigAccessor.ReadFieldsInType(typeof(ModuleKISInventory), instance: null); // Set inventory module for every eva kerbal Logger.logInfo("Set KIS config..."); ConfigNode nodeSettings = GameDatabase.Instance.GetConfigNode("KIS/settings/KISConfig"); if (nodeSettings == null) { Logger.logError("KIS settings.cfg not found or invalid !"); return; } // Male Kerbal. UpdateEvaPrefab(PartLoader.getPartInfoByName(MaleKerbalEva), nodeSettings); // Female Kerbal. UpdateEvaPrefab(PartLoader.getPartInfoByName(FemaleKerbalEva), nodeSettings); // Set inventory module for every pod with crew capacity. Logger.logInfo("Loading pod inventories..."); foreach (AvailablePart avPart in PartLoader.LoadedPartsList) { if (avPart.name == MaleKerbalEva || avPart.name == FemaleKerbalEva || avPart.name == RdKerbalEva || !avPart.partPrefab || avPart.partPrefab.CrewCapacity < 1) { continue; } Logger.logInfo("Found part with CrewCapacity: {0}", avPart.name); for (int i = 0; i < avPart.partPrefab.CrewCapacity; i++) { try { var moduleInventory = avPart.partPrefab.AddModule(typeof(ModuleKISInventory).Name) as ModuleKISInventory; CallAwakeMethod(moduleInventory); SetInventoryConfig(moduleInventory, nodeSettings); moduleInventory.podSeat = i; moduleInventory.invType = ModuleKISInventory.InventoryType.Pod; Logger.logInfo("Pod inventory module(s) for seat {0} loaded successfully", i); } catch { Logger.logError("Pod inventory module(s) for seat {0} can't be loaded!", i); } } } }
public void Awake() { ConfigAccessor.ReadFieldsInType(GetType(), this); ConfigAccessor.ReadFieldsInType(typeof(ModuleKISInventory), instance: null); // Set inventory module for every eva kerbal Debug.Log("Set KIS config..."); ConfigNode nodeSettings = GameDatabase.Instance.GetConfigNode("KIS/settings/KISConfig"); if (nodeSettings == null) { Debug.LogError("KIS settings.cfg not found or invalid !"); return; } // Kerbal parts. UpdateEvaPrefab(MaleKerbalEva, nodeSettings); UpdateEvaPrefab(FemaleKerbalEva, nodeSettings); // Set inventory module for every pod with crew capacity. Debug.Log("Loading pod inventories..."); foreach (AvailablePart avPart in PartLoader.LoadedPartsList) { if (avPart.name == MaleKerbalEva || avPart.name == FemaleKerbalEva || avPart.name == RdKerbalEva || !avPart.partPrefab || avPart.partPrefab.CrewCapacity < 1) { continue; } Debug.LogFormat("Found part with CrewCapacity: {0}", avPart.name); for (int i = 0; i < avPart.partPrefab.CrewCapacity; i++) { try { var moduleInventory = avPart.partPrefab.AddModule(typeof(ModuleKISInventory).Name) as ModuleKISInventory; KIS_Shared.AwakePartModule(moduleInventory); var baseFields = new BaseFieldList(moduleInventory); baseFields.Load(nodeSettings.GetNode("EvaInventory")); moduleInventory.podSeat = i; moduleInventory.invType = ModuleKISInventory.InventoryType.Pod; Debug.LogFormat("Pod inventory module(s) for seat {0} loaded successfully", i); } catch { Debug.LogErrorFormat("Pod inventory module(s) for seat {0} can't be loaded!", i); } } } }
/// <summary>Updates all the localizable strings in a part.</summary> /// <param name="part">The part to load the data in.</param> static void UpdateLocalizationInPartModules(Part part) { DebugEx.Fine("Reload part {0}...", part); if (part.partInfo != null && part.partInfo.partConfig != null) { var moduleConfigs = part.partInfo.partConfig.GetNodes("MODULE"); for (var i = 0; i < part.Modules.Count && i < moduleConfigs.Length; i++) { var module = part.Modules[i]; if (!IsModuleOfThisVersion(module)) { continue; // Not our version, not our problem. } var moduleConfig = moduleConfigs[i]; // Update the custom PersistentField fields from the prefab. ConfigAccessor.ReadFieldsFromNode( moduleConfig, module.GetType(), module, group: StdPersistentGroups.PartConfigLoadGroup); } } foreach (var module in part.Modules) { // Notify the localizable modules about the change. var localizableModule = module as IsLocalizableModule; if (localizableModule != null) { try { localizableModule.LocalizeModule(); } catch (Exception ex) { DebugEx.Error( "Exception in LocalizeModule of module {0}: type={1}, error={2}. Trace:\n{3}", localizableModule, localizableModule.GetType(), ex.Message, ex.StackTrace); } } // Refresh the context menu. var hasContextMenu = module as IHasContextMenu; if (hasContextMenu != null) { try { hasContextMenu.UpdateContextMenu(); } catch (Exception ex) { DebugEx.Error( "Exception in UpdateContextMenu of module {0}: type={1}, error={2}. Trace:\n{3}", hasContextMenu, hasContextMenu.GetType(), ex.Message, ex.StackTrace); } } } }
/// <summary>Returns external part's scale given a config.</summary> /// <remarks>This is a scale applied on the module by the other mods. I.e. it's a "runtime" scale, /// not the one specified in the common part's config. /// <para>The only mod supported till now is <c>TweakScale</c>.</para> /// </remarks> /// <param name="partNode">A config to get values from.</param> /// <returns>Multiplier to a model's scale on one axis.</returns> public static float GetPartExternalScaleModifier(ConfigNode partNode) { // TweakScale compatibility. foreach (var node in partNode.GetNodes("MODULE")) { if (node.GetValue("name") == "TweakScale") { double defaultScale = 1.0f; ConfigAccessor.GetValueByPath(node, "defaultScale", ref defaultScale); double currentScale = 1.0f; ConfigAccessor.GetValueByPath(node, "currentScale", ref currentScale); return((float)(currentScale / defaultScale)); } } return(1.0f); }
/// <inheritdoc cref="IPartModule.OnLoad" /> public override void OnLoad(ConfigNode node) { ConfigAccessor.ReadPartConfig(this, cfgNode: node); ConfigAccessor.ReadFieldsFromNode(node, GetType(), this, StdPersistentGroups.PartPersistant); base.OnLoad(node); if (vessel == null && PartLoader.Instance.IsReady()) { HostedDebugLog.Info(this, "EVA construction part loaded"); OnEvaPartLoaded(); } if (!_moduleSettingsLoaded) { _moduleSettingsLoaded = true; InitModuleSettings(); } }
public void OnSave(ConfigNode node) { node.AddValue("partName", availablePart.name); node.AddValue("slot", slot); ConfigAccessor.WriteFieldsIntoNode( node, GetType(), this, group: StdPersistentGroups.PartPersistant); // Items in pod and container may have equipped status True but they are not actually equipped, // so there is no equipped part. if (equipped && equippedPart != null && (equipMode == EquipMode.Part || equipMode == EquipMode.Physic)) { HostedDebugLog.Info( inventory, "Update config node of equipped part: {0}", availablePart.name); partNode = KISAPI.PartNodeUtils.PartSnapshot(equippedPart); } partNode.CopyTo(node.AddNode("PART")); }
/// <summary>Creates an item, restored form the save file.</summary> /// <param name="itemNode">The item config node to load the data from.</param> /// <param name="inventory">The owner inventory of the item.</param> /// <returns>The item instance.</returns> public static KIS_Item RestoreItemFromNode(ConfigNode itemNode, ModuleKISInventory inventory) { var qty = ConfigAccessor.GetValueByPath <int>(itemNode, "quantity") ?? 0; var partName = itemNode.GetValue("partName"); AvailablePart avPart = null; if (partName != null) { avPart = PartLoader.getPartInfoByName(partName); } if (qty == 0 || partName == null || avPart == null) { DebugEx.Error("Bad item config:\n{0}", itemNode); throw new ArgumentException("Bad item config node", "itemNode"); } return(new KIS_Item(avPart, itemNode, inventory, qty)); }
void GuiActionAddSilence(string pattern, bool isPrefix) { if (isPrefix) { LogFilter.AddSilenceByPrefix(pattern); } else { LogFilter.AddSilenceBySource(pattern); } ConfigAccessor.WriteFieldsFromType(typeof(LogFilter), null /* instance */); rawLogAggregator.UpdateFilter(); collapseLogAggregator.UpdateFilter(); smartLogAggregator.UpdateFilter(); snapshotLogAggregator.UpdateFilter(); logsViewChanged = true; }