public override void Load(ConfigNode node) { Volumes.Clear(); base.Load(node); var volumes = node.GetNodes(); for (int i = 0; i < volumes.Length; i++) { var v = volumes[i]; if (v.name == TankVolume.NODE_NAME) { var preset = VolumeConfigsLibrary.GetConfig(v.GetValue("name")); if (preset != null) { float volume; if (!float.TryParse(v.GetValue("Volume"), out volume)) { volume = 100f; } var cfg = preset.Clone <VolumeConfiguration>(); cfg.Volume = volume; Volumes.Add(cfg); } else { Volumes.Add(ConfigNodeObject.FromConfig <TankVolume>(v)); } } else if (v.name == NODE_NAME) { Volumes.Add(ConfigNodeObject.FromConfig <VolumeConfiguration>(v)); } } }
virtual public CNO Clone <CNO>() where CNO : ConfigNodeObject, new() { var node = new ConfigNode(NODE_NAME); Save(node); return(ConfigNodeObject.FromConfig <CNO>(node)); }
protected override float ResourcesMass(bool maxAmount = true) { if (ModuleSave == null || tank_manager != null) { return(0); } var volumes = ConfigNodeObject.FromConfig <VolumeConfiguration>(ModuleSave); return(volumes.ResourceMass(maxAmount)); }
protected override float TankMass(float defaultMass) { if (ModuleSave == null || tank_manager != null) { return(0); } var volumes = ConfigNodeObject.FromConfig <VolumeConfiguration>(ModuleSave); return(volumes.AddMass()); }
public override void Load(ConfigNode node) { base.Load(node); Resources.Clear(); foreach (var n in node.GetNodes(Resource.NODE_NAME)) { var res = ConfigNodeObject.FromConfig <Resource>(n); Resources.Add(res.name, res); } }
public override void Load(ConfigNode node) { base.Load(node); tanks.Clear(); total_volume = -1; init_supported_types(); if (node.HasValue(SwitchableTankManager.MANAGED)) { var existing_tanks = part.Modules.GetModules <ModuleSwitchableTank>(); foreach (var n in node.GetNodes(TankVolume.NODE_NAME)) { n.AddValue(MANAGED, true); n.AddValue("name", typeof(ModuleSwitchableTank).Name); n.SetValue("ExcludeTankTypes", ExcludeTankTypes); n.SetValue("IncludeTankTypes", IncludeTankTypes); ModuleSwitchableTank tank; var id = n.HasValue("id")? int.Parse(n.GetValue("id")) : -1; if (id >= 0 && (tank = existing_tanks.Find(t => t.id == id)) != null) { tank.Load(n); max_id = Mathf.Max(max_id, id); } else { tank = part.AddModule(n) as ModuleSwitchableTank; tank.id = ++max_id; } if (tank != null) { tank.EnablePartControls = EnablePartControls; tanks.Add(new TankWrapper(tank, this)); } else { Utils.Log("SwitchableTankManager: unable to load module from config:\n{}", n); } } tanks.ForEach(t => t.Tank.OnStart(part.StartState())); } else if (node.HasValue("Volume")) { var cfg = ConfigNodeObject.FromConfig <VolumeConfiguration>(node); var add_remove = AddRemoveEnabled; AddRemoveEnabled = true; AddConfiguration(cfg, cfg.Volume, false); AddRemoveEnabled = add_remove; } }
void volume_configs_gui() { if (!AddRemoveEnabled) { return; } GUILayout.BeginHorizontal(); VolumeConfiguration cfg = null; GUILayout.Label("Configuration Name:", GUILayout.ExpandWidth(false)); config_name = GUILayout.TextField(config_name, GUILayout.ExpandWidth(true), GUILayout.MinWidth(50)); if (GUILayout.Button(VolumeConfigsLibrary.HaveUserConfig(config_name)? "Save" : "Add", Styles.add_button, GUILayout.ExpandWidth(false)) && !string.IsNullOrEmpty(config_name)) { //add new config var node = new ConfigNode(); Save(node); cfg = ConfigNodeObject.FromConfig <VolumeConfiguration>(node); if (cfg.Valid) { cfg.name = config_name; cfg.Volume = TotalVolume; VolumeConfigsLibrary.AddOrSave(cfg); init_supported_types(); } else { Utils.Log("Configuration is invalid:\n{}\nThis should never happen!", node); } } config_name = Utils.LeftRightChooser(config_name, VolumeConfigsLibrary.UserConfigs, "Select tank configuration to edit", 200); if (GUILayout.Button("Delete", Styles.danger_button, GUILayout.ExpandWidth(false)) && !string.IsNullOrEmpty(config_name)) { //remove config if (VolumeConfigsLibrary.RemoveConfig(config_name)) { init_supported_types(); } config_name = ""; } GUILayout.EndHorizontal(); }
public string GetInfo(ConfigNode node) { base.Load(node); init_supported_types(); var info = ""; if (TypeChangeEnabled) { info += SwitchableTankType.TypesInfo(include, exclude); } var volumes = ConfigNodeObject.FromConfig <VolumeConfiguration>(node); if (volumes.Valid) { info = string.Concat(info, "Preconfigured Tanks:\n", volumes.Info()); } return(info); }