SSTUTools.SSTUResourceList.setResourcesToPart C# (CSharp) Method

setResourcesToPart() public method

Actually set the resources from this list to the input part; if the current part resources match this list exactly they will be updated in-place, else all resources from the part will be cleared and the new list of resources added.
public setResourcesToPart ( Part part ) : void
part Part
return void
        public void setResourcesToPart(Part part)
        {
            int len = part.Resources.Count;
            if (len == resourceList.Count)//potentially the same resources exist as we are trying to setup
            {
                bool foundAll = true;
                foreach (String name in resourceList.Keys)
                {
                    ResourceListEntry entry = resourceList[name];
                    if (part.Resources.Contains(name))//go ahead and set them as found; if not all are found we'll delete them anyway...
                    {
                        PartResource pr = part.Resources[name];
                        pr.maxAmount = entry.max;
                        pr.amount = entry.fill;
                    }
                    else
                    {
                        foundAll = false;
                        break;
                    }
                }
                if (foundAll)
                {
                    SSTUModInterop.updatePartResourceDisplay(part);
                    return;
                }
            }
            part.Resources.dict.Clear();
            ConfigNode resourceNode;
            foreach (String name in resourceList.Keys)
            {
                ResourceListEntry entry = resourceList[name];
                resourceNode = new ConfigNode("RESOURCE");
                resourceNode.AddValue("name", name);
                resourceNode.AddValue("maxAmount", entry.max);
                resourceNode.AddValue("amount", entry.fill);
                part.AddResource(resourceNode);
            }
            SSTUModInterop.updatePartResourceDisplay(part);
        }

Usage Example

Beispiel #1
0
        private void updateResources()
        {
            float scale  = Mathf.Pow(getEngineScale(), thrustScalePower);
            float volume = resourceVolume * scale * engineModels.model.numberOfEngines;

            if (!SSTUModInterop.onPartFuelVolumeUpdate(part, volume * 1000))
            {
                SSTUResourceList resources = new SSTUResourceList();
                fuelType.addResources(resources, volume);
                resources.setResourcesToPart(part);
            }
        }
All Usage Examples Of SSTUTools.SSTUResourceList::setResourcesToPart