コード例 #1
0
        void init_tank_manager()
        {
            if (tank_manager != null)
            {
                return;
            }
            tank_manager = new SwitchableTankManager(this);
            if (ModuleSave == null)
            {
                this.Log("ModuleSave is null. THIS SHOULD NEVER HAPPEN!");
                return;
            }
            ModuleSave.SetValue("Volume", Volume);
            tank_manager.Load(ModuleSave);
            var used_volume = tank_manager.TotalVolume;

            if (used_volume > Volume)
            {
                this.Log("WARNING: Volume limit is less than the total volume " +
                         "of preconfigured tanks: {} - {} = {}",
                         Volume, used_volume, Volume - used_volume);
                Volume = used_volume;
            }
            tank_manager.Volume = Volume;
        }
コード例 #2
0
        protected override void init_from_part()
        {
            if (ModuleSave == null)
            {
                ModuleSave = new ConfigNode("MODULE");
            }
            var volume = VolumeConfiguration.FromResources(part.Resources);

            if (volume == null)
            {
                Utils.Message("TankManager module is added to a part with unknown resource!\n" +
                              "This is an error in MM patch.\n" +
                              "TankManager module is disabled.");
                this.EnableModule(false);
                part.Modules.Remove(this);
            }
            volume.name = ModuleSave.GetValue("name");
            ModuleSave.RemoveValue("Volume");
            ModuleSave.RemoveNodes(TankVolume.NODE_NAME);
            volume.Save(ModuleSave);
            Volume      = volume.Volume;
            DoCostPatch = false;
            DoMassPatch = true;
//            this.Log("ModuleSave was initialized from part in flight: {}", ModuleSave);//debug
        }
コード例 #3
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
//            this.Log("OnLoad: ModuleSave: {}", node);//debug
            //if the config comes from TankManager, save its config
            if (node.HasValue(SwitchableTankManager.MANAGED))
            {
                ModuleSave = node;
                managed    = true;
            }
            //if the node is not from a TankManager, but we have a saved config, reload it
            else if (ModuleSave != null &&
                     ModuleSave.HasValue(SwitchableTankManager.MANAGED))
            {
                Load(ModuleSave);
            }
            //if it is a managed tank, but config does not come from TankManager
            else if (managed)
            {
                part.Modules.Remove(this);
            }
            //this is a stand-alone tank; save initial MODULE configuration
            else if (ModuleSave == null)
            {
                ModuleSave = node;
                //FIXME: does not work, because MM does not add this value
                //if its an existing part and CC was just added by MM patch
                ModuleSaveFromPrefab |= node.GetValue("MM_REINITIALIZE") != null;
            }
        }
コード例 #4
0
 public override void OnSave(ConfigNode node)
 {
     base.OnSave(node);
     if (tank_manager != null)
     {
         tank_manager.Save(node);
     }
     else
     {
         ModuleSave.CopyTo(node);
     }
 }