public static void ClearStatics()
 {
     ShipListMod.Debug_Log("[ShipListMod] clearstatics called");
     SLStaticData.Clear();
     //SLStaticData.UpdateGameScene();
     AllVesselData.Clear();
     staticsInitialized = false;
 }
 public void Update(Vessel v)
 {
     if (nextUpdateTimestamp < Time.time)
     {
         ShipListMod.Debug_Log("updating SingleVesselData for " + name);
         collectData(v);
     }
 }
        public void UpdateResources(Vessel v)
        {
            ShipListMod.Debug_Log("updating VesselResources for " + v.GetName());

            Dictionary <int, Resource> tempDict = new Dictionary <int, Resource>();

            foreach (ResourceDef rd in SLStaticData.resourceDefs)
            {
                tempDict.Add(rd.id, new Resource(rd));
            }

            if (v.loaded)
            {
                // active vessel or otherwise loaded vessel case:
                foreach (Part p in v.parts)
                {
                    foreach (PartResource pr in p.Resources)
                    {
                        if (tempDict.ContainsKey(pr.info.id))
                        {
                            tempDict[pr.info.id].amount    += pr.amount;
                            tempDict[pr.info.id].maxAmount += pr.maxAmount;
                        }
                    }
                }
            }
            else
            {
                // inactive vessel case:
                Dictionary <string, PartResourceDefinition> resourceIndex = SLStaticData.resourceDefsIndex;
                foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)
                {
                    foreach (ProtoPartResourceSnapshot r in p.resources)
                    {
                        if (!resourceIndex.ContainsKey(r.resourceName))
                        {
                            ShipListMod.Debug_Log("unknown resource \"" + r.resourceName + "\"");
                            continue;
                        }
                        int key = resourceIndex[r.resourceName].id;
                        if (tempDict.ContainsKey(key))
                        {
                            tempDict[key].amount    += r.amount;
                            tempDict[key].maxAmount += r.maxAmount;
                        }
                    }
                }
            }

            this.Clear();
            foreach (KeyValuePair <int, Resource> kv in tempDict)
            {
                if (kv.Value.maxAmount > 0)
                {
                    this.Add(kv.Key, kv.Value);
                }
            }
        }
        // public void Start() { }

        public void Update()
        {
            SLStaticData.UpdateGameScene();
            if (clearButton)
            {
                ShipListMod.Debug_Log("[ShipListMod] clearButton activated.");
                AllVesselData.Clear();
                clearButton = false;
            }

            // while in-flight, track the active vessel even if the gui is closed
            if ((HighLogic.LoadedSceneIsFlight) && (!showWindow))
            {
                tryGetSingleVesselData(FlightGlobals.ActiveVessel);
            }
        }
        public SingleVesselData(Vessel v)
        {
            hasData = false;
            hasAnyResourcesOrCrew = false;
            if (v == null)
            {
                name      = "??";
                otherInfo = "vessel == null";
            }
            else
            {
                name              = v.GetName();
                vesselType        = v.vesselType;
                otherInfo         = null;
                referenceBodyName = null;
            }

            ShipListMod.Debug_Log("new SingleVesselData for " + name);
            vres = new VesselResources(v);
            collectData(v);
        }
 public VesselResources(Vessel v) : base(new Dictionary <int, Resource>())
 {
     ShipListMod.Debug_Log("new VesselResources for " + v.GetName());
 }
 public void Awake()
 {
     ShipListMod.ClearStatics();
 }