Ejemplo n.º 1
0
        public static VesselData GetVesselData(
            Vessel v,
            Dictionary <String, UpdateHelper> moduleHandlers,
            Dictionary <String, List <ResourceModuleHandler> > resourceData,
            HashSet <String> interestingResources
            )
        {
            VesselData ret = new VesselData();

            if (v.protoVessel != null)
            {
                foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)
                {
                    Part part = PartLoader.getPartInfoByName(p.partName).partPrefab;

                    if (part == null)
                    {
                        BackgroundProcessing.Debug("BackgroundProcessing: Couldn't find PartPrefab for part " + p.partName, DebugLevel.WARNING);
                        continue;
                    }

                    if (part.Modules == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < p.modules.Count; ++i)
                    {
                        if (p.modules[i].moduleName == null)
                        {
                            BackgroundProcessing.Debug("BackgroundProcessing: Null moduleName for module " + i + "/" + p.modules.Count, DebugLevel.WARNING);
                            BackgroundProcessing.Debug("BackgroundProcessing: Module values: " + p.modules[i].moduleValues, DebugLevel.WARNING);
                            continue;
                        }

                        if (moduleHandlers.ContainsKey(p.modules[i].moduleName))
                        {
                            ret.callbacks.Add(new CallbackPair(p.modules[i].moduleName, p.flightID), new ObjectHolder());
                        }

                        int j = i;
                        if (j >= part.Modules.Count || part.Modules[j].moduleName != p.modules[i].moduleName)
                        {
                            if (j < part.Modules.Count)
                            {
                                BackgroundProcessing.Debug("BackgroundProcessing: Expected " + p.modules[i].moduleName + " at index " + i + ", got " + part.Modules[j].moduleName, DebugLevel.WARNING);

                                for (j = i; j < part.Modules.Count; ++j)
                                {
                                    if (part.Modules[j].moduleName == p.modules[i].moduleName)
                                    {
                                        BackgroundProcessing.Debug("BackgroundProcessing: Found " + p.modules[i].moduleName + " at index " + j, DebugLevel.WARNING);
                                        break;
                                    }
                                }
                            }
                        }

                        if (j < part.Modules.Count)
                        {
                            if (HasResourceGenerationData(part.Modules[j], p.modules[i], resourceData, interestingResources))
                            {
                                ret.resourceModules.AddRange(GetResourceGenerationData(part.Modules[j], p, resourceData, interestingResources));
                            }
                        }
                        else
                        {
                            BackgroundProcessing.Debug("BackgroundProcessing: Ran out of modules before finding module " + p.modules[i].moduleName, DebugLevel.WARNING);

                            if (HasResourceGenerationData(null, p.modules[i], resourceData, interestingResources))
                            {
                                ret.resourceModules.AddRange(GetResourceGenerationData(null, p, resourceData, interestingResources));
                            }
                        }
                    }

                    foreach (ProtoPartResourceSnapshot r in p.resources)
                    {
                        if (r.resourceName == null)
                        {
                            BackgroundProcessing.Debug("BackgroundProcessing: Null resourceName.", DebugLevel.WARNING);
                            continue;
                        }

                        if (!r.flowState)
                        {
                            continue;
                        }

                        if (!ret.storage.ContainsKey(r.resourceName))
                        {
                            ret.storage.Add(r.resourceName, new List <ProtoPartResourceSnapshot>());
                        }
                        ret.storage[r.resourceName].Add(r);
                    }
                }
            }

            return(ret);
        }
 public abstract HashSet <ProtoPartResourceSnapshot> HandleResource(Vessel v, VesselData data, HashSet <ProtoPartResourceSnapshot> modified);