// 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); }
// 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()); }