Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        /// <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();
        }
Beispiel #3
0
 /// <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();
     }
 }
Beispiel #4
0
 /// <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();
     }
 }
 /// <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);
             }
         }
     }
 }
 /// <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();
     }
 }
Beispiel #7
0
        /// <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);
            }

            // COMPATIBILITY: Set/restore the resources cost and mass.
            // TODO(ihsoft): This code is only needed for the pre-1.17 KIS version saves. Drop it one day.
            var resourceNodes = PartNodeUtils.GetModuleNodes(partNode, "RESOURCE");

            if (resourceNodes.Any() &&
                (this.itemResourceMass < float.Epsilon || this.itemResourceCost < float.Epsilon))
            {
                var oldResourceMass = this.itemResourceMass;
                foreach (var resourceNode in resourceNodes)
                {
                    var resource = new ProtoPartResourceSnapshot(resourceNode);
                    this._resourceMass += (float)resource.amount * resource.definition.density;
                    this._resourceCost += (float)resource.amount * resource.definition.unitCost;
                }
                DebugEx.Warning("Calculated values for a pre 1.17 version save:"
                                + " oldResourceMass={0}, newResourceMass={1}, resourceCost={2}",
                                oldResourceMass, this.itemResourceMass, this.itemResourceCost);
            }
        }
Beispiel #8
0
 /// <inheritdoc/>
 public override void OnLoad(ConfigNode node)
 {
     ConfigAccessor.ReadPartConfig(this, cfgNode: node);
     ConfigAccessor.ReadFieldsFromNode(node, GetType(), this, StdPersistentGroups.PartPersistant);
     base.OnLoad(node);
 }