/// <summary> /// Merge two ScaleExponents. All the values in <paramref name="source"/> that are not already present in <paramref name="destination"/> will be added to <paramref name="destination"/> /// </summary> /// <param name="destination">The ScaleExponents to update.</param> /// <param name="source">The ScaleExponents to add to <paramref name="destination"/></param> /// <returns>The updated exponentValue of <paramref name="destination"/>. Note that this exponentValue is also changed, so using the return exponentValue is not necessary.</returns> public static ScaleExponents Merge(ScaleExponents destination, ScaleExponents source) { if (destination._id != source._id) { Tools.LogWf("Wrong merge target! A name {0}, B name {1}", destination._id, source._id); } foreach (KeyValuePair <string, ScalingMode> value in source._exponents.Where(value => !destination._exponents.ContainsKey(value.Key))) { destination._exponents[value.Key] = value.Value; } foreach (string value in source._ignores.Where(value => !destination._ignores.Contains(value))) { destination._ignores.Add(value); } foreach (KeyValuePair <string, ScaleExponents> child in source._children) { if (destination._children.ContainsKey(child.Key)) { Merge(destination._children[child.Key], child.Value); } else { destination._children[child.Key] = child.Value.Clone(); } } return(destination); }
/// <summary> /// Merge two ScaleExponents. All the values in <paramref name="source"/> that are not already present in <paramref name="destination"/> will be added to <paramref name="destination"/> /// </summary> /// <param name="destination">The ScaleExponents to update.</param> /// <param name="source">The ScaleExponents to add to <paramref name="destination"/></param> /// <returns>The updated exponentValue of <paramref name="destination"/>. Note that this exponentValue is also changed, so using the return exponentValue is not necessary.</returns> public static ScaleExponents Merge(ScaleExponents destination, ScaleExponents source) { if (destination._id != source._id) { Tools.LogWf("Wrong merge target! A name {0}, B name {1}", destination._id, source._id); } foreach (var value in source._exponents) { if (!destination._exponents.ContainsKey(value.Key)) { destination._exponents[value.Key] = value.Value; } } foreach (var child in source._children) { if (destination._children.ContainsKey(child.Key)) { Merge(destination._children[child.Key], child.Value); } else { destination._children[child.Key] = child.Value.Clone(); } } return(destination); }
private ModulesAndExponents(ModuleAndPrefab modules, ScaleExponents exponents) : this() { Current = modules.Current; Prefab = modules.Prefab; Exponents = exponents; }
private ScaleExponents(ScaleExponents source) { _id = source._id; _exponents = source._exponents.Clone(); _children = source ._children .Select(a => new KeyValuePair <string, ScaleExponents>(a.Key, a.Value.Clone())) .ToDictionary(a => a.Key, a => a.Value); _ignores = new List <string>(source._ignores); }
private ScaleExponents(ScaleExponents source) { _id = source._id; _exponents = source._exponents.Clone(); _children = source ._children .Select(a => new KeyValuePair<string, ScaleExponents>(a.Key, a.Value.Clone())) .ToDictionary(a => a.Key, a => a.Value); _ignores = new List<string>(source._ignores); }
private ScaleExponents(ConfigNode node, ScaleExponents source = null) { _id = IsExponentBlock(node) ? node.GetValue("name") : node.name; _name = node.GetValue("name"); if (_id == null) { _id = ""; } if (IsExponentBlock(node)) { if (string.IsNullOrEmpty(_id)) { _id = "Part"; _name = "Part"; } } _exponents = new Dictionary <string, Tuple <string, bool> >(); _children = new Dictionary <string, ScaleExponents>(); _ignores = new List <string>(); foreach (var value in node.values.OfType <ConfigNode.Value>().Where(a => a.name != "name")) { if (value.name.StartsWith("!")) { _exponents[value.name.Substring(1)] = Tuple.Create(value.value, true); } else { if (value.name.Equals("-ignore")) { _ignores.Add(value.value); } else { _exponents[value.name] = Tuple.Create(value.value, false); } } } foreach (var childNode in node.nodes.OfType <ConfigNode>()) { _children[childNode.name] = new ScaleExponents(childNode); } if (source != null) { Merge(this, source); } }
private ScaleExponents(ConfigNode node, ScaleExponents source = null) { _id = IsExponentBlock(node) ? node.GetValue("name") : node.name; _name = node.GetValue("name"); if (_id == null) { _id = ""; } if (IsExponentBlock(node)) { if (string.IsNullOrEmpty(_id)) { _id = "Part"; _name = "Part"; } } _exponents = new Dictionary<string, ScalingMode>(); _children = new Dictionary<string, ScaleExponents>(); _ignores = new List<string>(); foreach (var value in node.values.OfType<ConfigNode.Value>().Where(a=>a.name != "name")) { if (value.name.StartsWith("!")) { _exponents[value.name.Substring(1)] = new ScalingMode(value.value, true); } else if (value.name.Equals("-ignore")) { _ignores.Add(value.value); } else { _exponents[value.name] = new ScalingMode(value.value, false); } } foreach (var childNode in node.nodes.OfType<ConfigNode>()) { _children[childNode.name] = new ScaleExponents(childNode); } if (source != null) { Merge(this, source); } }
public ScaleType(ConfigNode config) { ScaleNodes = new int[] {}; if ((object)config == null || Tools.ConfigValue(config, "name", "default") == "default") { return; // Default values. } var type = Tools.ConfigValue(config, "type", "default"); var source = GetScaleConfig(type); IsFreeScale = Tools.ConfigValue(config, "freeScale", source.IsFreeScale); MinValue = Tools.ConfigValue(config, "minScale", source.MinValue); MaxValue = Tools.ConfigValue(config, "maxScale", source.MaxValue); Suffix = Tools.ConfigValue(config, "suffix", source.Suffix); _scaleFactors = Tools.ConfigValue(config, "scaleFactors", source._scaleFactors); ScaleNodes = Tools.ConfigValue(config, "scaleNodes", source.ScaleNodes); _scaleNames = Tools.ConfigValue(config, "scaleNames", source._scaleNames).Select(a => a.Trim()).ToArray(); TechRequired = Tools.ConfigValue(config, "techRequired", source.TechRequired).Select(a => a.Trim()).ToArray(); Name = Tools.ConfigValue(config, "name", "unnamed scaletype"); Family = Tools.ConfigValue(config, "family", "default"); AttachNodes = GetNodeFactors(config.GetNode("ATTACHNODES"), source.AttachNodes); if (Name == "TweakScale") { Name = source.Name; } if (_scaleFactors.Length != _scaleNames.Length) { Tools.LogWf("Wrong number of scaleFactors compared to scaleNames: {0} scaleFactors vs {1} scaleNames", _scaleFactors.Length, _scaleNames.Length); } if (TechRequired.Length < _scaleFactors.Length) { TechRequired = TechRequired.Concat("".Repeat()).Take(_scaleFactors.Length).ToArray(); } var tmpScale = Tools.ConfigValue(config, "defaultScale", source.DefaultScale); if (!IsFreeScale) { tmpScale = Tools.Closest(tmpScale, AllScaleFactors); } DefaultScale = Tools.Clamp(tmpScale, MinValue, MaxValue); Exponents = ScaleExponents.CreateExponentsForModule(config, source.Exponents); }
private ScaleExponents(ScaleExponents source) { _id = source._id; if (source == null) { _exponents = new Dictionary<string, Tuple<string, bool>>(); _children = new Dictionary<string, ScaleExponents>(); } else { _exponents = source._exponents.Clone(); _children = source ._children .Select(a => new KeyValuePair<string, ScaleExponents>(a.Key, a.Value.Clone())) .ToDictionary(a => a.Key, a => a.Value); } }
private ScaleExponents(ScaleExponents source) { _id = source._id; if (source == null) { _exponents = new Dictionary <string, Tuple <string, bool> >(); _children = new Dictionary <string, ScaleExponents>(); } else { _exponents = source._exponents.Clone(); _children = source ._children .Select(a => new KeyValuePair <string, ScaleExponents>(a.Key, a.Value.Clone())) .ToDictionary(a => a.Key, a => a.Value); } }
public ScaleConfig(ConfigNode config) { if ((object)config == null || Tools.ConfigValue(config, "name", "default") == "default") { return; // Default values. } var type = Tools.ConfigValue(config, "type", "default"); var source = GetScaleConfig(type); isFreeScale = Tools.ConfigValue(config, "freeScale", defaultValue: source.isFreeScale); minValue = Tools.ConfigValue(config, "minScale", defaultValue: source.minValue); maxValue = Tools.ConfigValue(config, "maxScale", defaultValue: source.maxValue); suffix = Tools.ConfigValue(config, "suffix", defaultValue: source.suffix); _scaleFactors = Tools.ConfigValue(config, "scaleFactors", defaultValue: source._scaleFactors); _scaleNodes = Tools.ConfigValue(config, "scaleNodes", defaultValue: source._scaleNodes); _scaleNames = Tools.ConfigValue(config, "scaleNames", defaultValue: source._scaleNames).Select(a => a.Trim()).ToArray(); techRequired = Tools.ConfigValue(config, "techRequired", defaultValue: source.techRequired).Select(a => a.Trim()).ToArray(); name = Tools.ConfigValue(config, "name", defaultValue: "unnamed scaletype"); if (_scaleFactors.Length != _scaleNames.Length) { Tools.LogWf("Wrong number of scaleFactors compared to scaleNames: {0} vs {1}", _scaleFactors.Length, _scaleNames.Length); } if (techRequired.Length < _scaleFactors.Length) { techRequired = techRequired.Concat("".Repeat()).Take(_scaleFactors.Length).ToArray(); } var tmpScale = Tools.ConfigValue(config, "defaultScale", defaultValue: source.defaultScale); if (!isFreeScale) { tmpScale = Tools.Closest(tmpScale, allScaleFactors); } defaultScale = Tools.clamp(tmpScale, minValue, maxValue); exponents = ScaleExponents.CreateExponentsForModule(config, source.exponents); }
public double getDryCostFactor(double rescaleFactor) { double exponent = ScaleExponents.getDryCostExponent(ScaleType.Exponents); return(Math.Pow(rescaleFactor, exponent)); }
// config is a part config public ScaleType(ConfigNode partConfig) { ConfigNode scaleConfig = null; if ((object)partConfig != null) { Name = Tools.ConfigValue(partConfig, "type", Name); ScaleExponents.LoadGlobalExponents(); if (Name != null) { UrlDir.UrlConfig tmp = GameDatabase.Instance.GetConfigs("SCALETYPE").FirstOrDefault(a => a.name == Name); if (tmp != null) { scaleConfig = tmp.config; } if (scaleConfig != null) { // search scaletype for values IsFreeScale = Tools.ConfigValue(scaleConfig, "freeScale", IsFreeScale); DefaultScale = Tools.ConfigValue(scaleConfig, "defaultScale", DefaultScale); Suffix = Tools.ConfigValue(scaleConfig, "suffix", Suffix); _scaleFactors = Tools.ConfigValue(scaleConfig, "scaleFactors", _scaleFactors); ScaleNodes = Tools.ConfigValue(scaleConfig, "scaleNodes", ScaleNodes); // currently not used! _scaleNames = Tools.ConfigValue(scaleConfig, "scaleNames", _scaleNames).Select(a => a.Trim()).ToArray(); TechRequired = Tools.ConfigValue(scaleConfig, "techRequired", TechRequired).Select(a => a.Trim()).ToArray(); Family = Tools.ConfigValue(scaleConfig, "family", "default"); //AttachNodes = GetNodeFactors(scaleConfig.GetNode("ATTACHNODES"), AttachNodes); // currently not used! IncrementSlide = Tools.ConfigValue(scaleConfig, "incrementSlide", IncrementSlide); // deprecated! Exponents = ScaleExponents.CreateExponentsForModule(scaleConfig, Exponents); Log.dbg("scaleConfig:{0}", scaleConfig); Log.dbg("scaleConfig:{0}", this); Log.dbg("{0}", Exponents); } } else { Name = ""; } // search part config for overrides IsFreeScale = Tools.ConfigValue(partConfig, "freeScale", IsFreeScale); DefaultScale = Tools.ConfigValue(partConfig, "defaultScale", DefaultScale); Suffix = Tools.ConfigValue(partConfig, "suffix", Suffix); _scaleFactors = Tools.ConfigValue(partConfig, "scaleFactors", _scaleFactors); ScaleNodes = Tools.ConfigValue(partConfig, "scaleNodes", ScaleNodes); _scaleNames = Tools.ConfigValue(partConfig, "scaleNames", _scaleNames).Select(a => a.Trim()).ToArray(); TechRequired = Tools.ConfigValue(partConfig, "techRequired", TechRequired).Select(a => a.Trim()).ToArray(); Family = Tools.ConfigValue(partConfig, "family", "default"); //AttachNodes = GetNodeFactors(partConfig.GetNode("ATTACHNODES"), AttachNodes); IncrementSlide = Tools.ConfigValue(partConfig, "incrementSlide", IncrementSlide); Exponents = ScaleExponents.CreateExponentsForModule(partConfig, Exponents); ScaleExponents.treatMassAndCost(Exponents); #if DEBUG { string log = "finished ScaleExponents: "; foreach (KeyValuePair <string, ScaleExponents> e in Exponents) { log += e.ToString() + ", \n"; } Log.dbg(log); } #endif Log.dbg("partConfig:{0}", partConfig); Log.dbg("partConfig:{0}", this); Log.dbg("{0}", Exponents); } if (IsFreeScale && (_scaleFactors.Length > 1)) { bool error = false; for (int i = 0; i < _scaleFactors.Length - 1; i++) { if (_scaleFactors[i + 1] <= _scaleFactors[i]) { error = true; } } if (error) { Log.warn("scaleFactors must be in ascending order on {0}! \n{1}", Name, this); _scaleFactors = new float[0]; } } // fill in missing values if ((DefaultScale <= 0) || (_scaleFactors.Length == 0)) { RepairScaletype(scaleConfig, partConfig); } if (!IsFreeScale && (_scaleFactors.Length != _scaleNames.Length)) { if (_scaleNames.Length != 0) { Log.warn("Wrong number of scaleFactors compared to scaleNames in scaleType \"{0}\": {1} scaleFactors vs {2} scaleNames\n{3}", Name, _scaleFactors.Length, _scaleNames.Length, this); } _scaleNames = new string[_scaleFactors.Length]; for (int i = 0; i < _scaleFactors.Length; i++) { _scaleNames[i] = _scaleFactors[i].ToString(); } } if (!IsFreeScale) { DefaultScale = Tools.Closest(DefaultScale, AllScaleFactors); } DefaultScale = Tools.Clamp(DefaultScale, _scaleFactors.Min(), _scaleFactors.Max()); if (IncrementSlide.Length == 0) { IncrementSlide = new float[_scaleFactors.Length - 1]; for (int i = 0; i < _scaleFactors.Length - 1; i++) { IncrementSlide[i] = (_scaleFactors[i + 1] - _scaleFactors[i]) / 50f; } } if (IsFreeScale) { // workaround for stock bug in tweakable UI_ScaleEdit: // add a tiny dummy interval to the range because the highest one is bugged float[] tmp = _scaleFactors; _scaleFactors = new float[tmp.Length + 1]; for (int i = 0; i < tmp.Length; i++) { _scaleFactors[i] = tmp[i]; } _scaleFactors[tmp.Length] = _scaleFactors[tmp.Length - 1] + 0.1f * IncrementSlide.Max(); } int numTechs = TechRequired.Length; if ((numTechs > 0) && (numTechs != _scaleFactors.Length)) { Log.dbg("Wrong number of techRequired compared to scaleFactors in scaleType \"{0}\": {1} scaleFactors vs {2} techRequired", Name, _scaleFactors.Length, TechRequired.Length); if (numTechs < _scaleFactors.Length) { string lastTech = TechRequired[TechRequired.Length - 1]; TechRequired = TechRequired.Concat(lastTech.Repeat()).Take(_scaleFactors.Length).ToArray(); } } Log.dbg("finished config:{0}", this); Log.dbg("{0}", Exponents); }
public double getMassFactor(double rescaleFactor) { double exponent = ScaleExponents.getMassExponent(this.ScaleType.Exponents); return(Math.Pow(rescaleFactor, exponent)); }
/// <summary> /// Merge two ScaleExponents. All the values in <paramref name="source"/> that are not already present in <paramref name="destination"/> will be added to <paramref name="destination"/> /// </summary> /// <param name="destination">The ScaleExponents to update.</param> /// <param name="source">The ScaleExponents to add to <paramref name="destination"/></param> /// <returns>The updated exponentValue of <paramref name="destination"/>. Note that this exponentValue is also changed, so using the return exponentValue is not necessary.</returns> public static ScaleExponents Merge(ScaleExponents destination, ScaleExponents source) { if (destination._id != source._id) { Tools.LogWf("Wrong merge target! A name {0}, B name {1}", destination._id, source._id); } foreach (var value in source._exponents.Where(value => !destination._exponents.ContainsKey(value.Key))) { destination._exponents[value.Key] = value.Value; } foreach (var value in source._ignores.Where(value => !destination._ignores.Contains(value))) { destination._ignores.Add(value); } foreach (var child in source._children) { if (destination._children.ContainsKey(child.Key)) { Merge(destination._children[child.Key], child.Value); } else { destination._children[child.Key] = child.Value.Clone(); } } return destination; }
public void OnRescale(ScalingFactor factor) { ScaleExponents.UpdateObject(_part, _basePart, _ts.config.exponents, factor); }
// config is a part config public ScaleType(ConfigNode partConfig) { ConfigNode scaleConfig = null; if ((object)partConfig != null) { Name = Tools.ConfigValue(partConfig, "type", Name); if (Name != null) { var tmp = GameDatabase.Instance.GetConfigs("SCALETYPE").FirstOrDefault(a => a.name == Name); if (tmp != null) { scaleConfig = tmp.config; } if (scaleConfig != null) { // search scaletype for values IsFreeScale = Tools.ConfigValue(scaleConfig, "freeScale", IsFreeScale); DefaultScale = Tools.ConfigValue(scaleConfig, "defaultScale", DefaultScale); Suffix = Tools.ConfigValue(scaleConfig, "suffix", Suffix); _scaleFactors = Tools.ConfigValue(scaleConfig, "scaleFactors", _scaleFactors); ScaleNodes = Tools.ConfigValue(scaleConfig, "scaleNodes", ScaleNodes); // currently not used! _scaleNames = Tools.ConfigValue(scaleConfig, "scaleNames", _scaleNames).Select(a => a.Trim()).ToArray(); TechRequired = Tools.ConfigValue(scaleConfig, "techRequired", TechRequired).Select(a => a.Trim()).ToArray(); Family = Tools.ConfigValue(scaleConfig, "family", "default"); //AttachNodes = GetNodeFactors(scaleConfig.GetNode("ATTACHNODES"), AttachNodes); // currently not used! IncrementSlide = Tools.ConfigValue(scaleConfig, "incrementSlide", IncrementSlide); // deprecated! Exponents = ScaleExponents.CreateExponentsForModule(scaleConfig, Exponents); //Debug.Log("[TweakScale] scaleConfig:" + scaleConfig.ToString()); //Debug.Log("[TweakScale] scaleConfig:" + this.ToString()); //Debug.Log("[TweakScale]" + Exponents.ToString()); } } else { Name = ""; } // search part config for overrides IsFreeScale = Tools.ConfigValue(partConfig, "freeScale", IsFreeScale); DefaultScale = Tools.ConfigValue(partConfig, "defaultScale", DefaultScale); Suffix = Tools.ConfigValue(partConfig, "suffix", Suffix); _scaleFactors = Tools.ConfigValue(partConfig, "scaleFactors", _scaleFactors); ScaleNodes = Tools.ConfigValue(partConfig, "scaleNodes", ScaleNodes); _scaleNames = Tools.ConfigValue(partConfig, "scaleNames", _scaleNames).Select(a => a.Trim()).ToArray(); TechRequired = Tools.ConfigValue(partConfig, "techRequired", TechRequired).Select(a => a.Trim()).ToArray(); Family = Tools.ConfigValue(partConfig, "family", "default"); //AttachNodes = GetNodeFactors(partConfig.GetNode("ATTACHNODES"), AttachNodes); IncrementSlide = Tools.ConfigValue(partConfig, "incrementSlide", IncrementSlide); Exponents = ScaleExponents.CreateExponentsForModule(partConfig, Exponents); ScaleExponents.treatMassAndCost(Exponents); // string log = "finished ScaleExponents: "; // foreach(var e in Exponents) { log += e.ToString() + ", \n"; } // Debug.Log(log); //Debug.Log("[TweakScale] partConfig:" + partConfig.ToString()); //Debug.Log("[TweakScale] partConfig:" + this.ToString()); //Debug.Log("[TweakScale]" + Exponents.ToString()); } if (IsFreeScale && (_scaleFactors.Length > 1)) { bool error = false; for (int i = 0; i < _scaleFactors.Length - 1; i++) { if (_scaleFactors[i + 1] <= _scaleFactors[i]) { error = true; } } if (error) { Tools.LogWf("scaleFactors must be in ascending order! \n{0}", this.ToString()); _scaleFactors = new float[0]; } } // fill in missing values if ((DefaultScale <= 0) || (_scaleFactors.Length == 0)) { RepairScaletype(scaleConfig, partConfig); } if (!IsFreeScale && (_scaleFactors.Length != _scaleNames.Length)) { if (_scaleNames.Length != 0) { Tools.LogWf("Wrong number of scaleFactors compared to scaleNames in scaleType \"{0}\": {1} scaleFactors vs {2} scaleNames\n{3}", Name, _scaleFactors.Length, _scaleNames.Length, this.ToString()); } _scaleNames = new string[_scaleFactors.Length]; for (int i = 0; i < _scaleFactors.Length; i++) { _scaleNames[i] = _scaleFactors[i].ToString(); } } if (!IsFreeScale) { DefaultScale = Tools.Closest(DefaultScale, AllScaleFactors); } DefaultScale = Tools.Clamp(DefaultScale, _scaleFactors.Min(), _scaleFactors.Max()); if (IncrementSlide.Length == 0) { IncrementSlide = new float[_scaleFactors.Length - 1]; for (var i = 0; i < _scaleFactors.Length - 1; i++) { IncrementSlide[i] = (_scaleFactors[i + 1] - _scaleFactors[i]) / 50f; } } var numTechs = TechRequired.Length; if ((numTechs > 0) && (numTechs != _scaleFactors.Length)) { Tools.LogWf("Wrong number of techRequired compared to scaleFactors in scaleType \"{0}\": {1} scaleFactors vs {2} techRequired", Name, _scaleFactors.Length, TechRequired.Length); if (numTechs < _scaleFactors.Length) { var lastTech = TechRequired[TechRequired.Length - 1]; TechRequired = TechRequired.Concat(lastTech.Repeat()).Take(_scaleFactors.Length).ToArray(); } } //Debug.Log("[TweakScale] finished config:" + this.ToString()); //Debug.Log("[TweakScale]" + Exponents.ToString()); }
public override void OnStart() { ScaleExponents.LoadGlobalExponents(); }