Beispiel #1
0
        /// <summary>
        /// handles the correct merging of float values in the modules
        /// </summary>
        /// <param name="newModuleName"></param>
        /// <param name="newModule"></param>
        /// <param name="existingNewModule"></param>
        /// <param name="ModuleAttribute"></param>
        private void mergeModuleFloatValues(string newModuleName, ConfigNode newModule, ConfigNode existingNewModule, string ModuleAttribute)
        {
            Log.dbg("| {0} - {1} is float", newModuleName, ModuleAttribute);
            //merge float values if they are allowed
            if (WeldingHelpers.isArrayContaining(string.Concat(newModuleName, Constants.nameSeparator, ModuleAttribute), UbioZurWeldingLtd.instance.config.unchangedModuleAttributes))
            {
                Log.dbg("| {0} - {1} is marked as unchangeable", newModuleName, ModuleAttribute);
            }
            else
            {
                if (newModule.HasValue(ModuleAttribute) || existingNewModule.HasValue(ModuleAttribute))
                {
                    float newValue = float.TryParse(newModule.GetValue(ModuleAttribute), out newValue) == false?float.Parse(existingNewModule.GetValue(ModuleAttribute)) : float.Parse(newModule.GetValue(ModuleAttribute));

                    Log.dbg("| {0} - newValue - {1} = {2}", newModuleName, ModuleAttribute, newValue);

                    if (existingNewModule.HasValue(ModuleAttribute) && newModule.HasValue(ModuleAttribute))
                    {
                        float existingValue = float.Parse(existingNewModule.GetValue(ModuleAttribute));
                        Log.dbg("| {0} - existingValue - {1} = {2}", newModuleName, ModuleAttribute, existingValue);

                        if (WeldingHelpers.isArrayContaining(string.Concat(newModuleName, Constants.nameSeparator, ModuleAttribute), UbioZurWeldingLtd.instance.config.maximizedModuleAttributes))
                        {
                            Log.dbg("| {0} - {1} - maximized", newModuleName, ModuleAttribute);
                            existingNewModule.SetValue(ModuleAttribute, (existingValue > newValue ? existingValue : newValue).ToString());
                        }
                        else
                        {
                            if (WeldingHelpers.isArrayContaining(string.Concat(newModuleName, Constants.nameSeparator, ModuleAttribute), UbioZurWeldingLtd.instance.config.minimizedModuleAttributes))
                            {
                                Log.dbg("| {0} - {1} - minimized", newModuleName, ModuleAttribute);
                                existingNewModule.SetValue(ModuleAttribute, (existingValue < newValue ? existingValue : newValue).ToString());
                            }
                            else
                            {
                                if (WeldingHelpers.isArrayContaining(string.Concat(newModuleName, Constants.nameSeparator, ModuleAttribute), UbioZurWeldingLtd.instance.config.averagedModuleAttributes) && (newValue != 0 && existingValue != 0))
                                {
                                    Log.dbg("| {0} - {1} - averaged", newModuleName, ModuleAttribute);
                                    existingNewModule.SetValue(ModuleAttribute, ((newValue + existingValue) * 0.5f).ToString());
                                }
                                else
                                {
                                    Log.dbg("| {0} - {1} - added", newModuleName, ModuleAttribute);
                                    existingNewModule.SetValue(ModuleAttribute, (newValue + existingValue).ToString());
                                }
                            }
                        }
                    }
                    else if (!existingNewModule.HasValue(ModuleAttribute) && newModule.HasValue(ModuleAttribute))
                    {
                        Log.dbg("| {0} - setNewValue - {1} = {2}", newModuleName, ModuleAttribute, newValue);
                        existingNewModule.AddValue(ModuleAttribute, newValue.ToString());
                    }
                }
                Log.dbg("| {0} - {1} is merged with value {2}", newModuleName, ModuleAttribute, float.Parse(existingNewModule.GetValue(ModuleAttribute)));
            }
        }
        /// <summary>
        /// loads configfile and prepares it with all needed lists
        /// </summary>
        /// <returns></returns>
        public static WeldingConfiguration loadConfig()
        {
            WeldingConfiguration configuration = new WeldingConfiguration();
            ModuleLists          moduleList    = new ModuleLists();
            FileStream           FileStream;

            if (System.IO.File.Exists(_configFile))
            {
                XmlSerializer configSerializer = new XmlSerializer(typeof(WeldingConfiguration));
                configSerializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                configSerializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream    = new FileStream(_configFile, FileMode.Open);
                configuration = (WeldingConfiguration)configSerializer.Deserialize(FileStream);
                FileStream.Close();

                if (configuration.MainWindowXPosition > (Screen.width - Constants.guiScreenEdgeClearance))
                {
                    configuration.MainWindowXPosition = Screen.width - Constants.guiScreenEdgeClearance;
                }
                if (configuration.MainWindowYPosition > (Screen.height - Constants.guiScreenEdgeClearance))
                {
                    configuration.MainWindowYPosition = Screen.height - Constants.guiScreenEdgeClearance;
                }
                FileStream.Close();
            }

            if (System.IO.File.Exists(_moduleListFile))
            {
                XmlSerializer moduleListSerializer = new XmlSerializer(typeof(ModuleLists));
                moduleListSerializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                moduleListSerializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream = new FileStream(_moduleListFile, FileMode.Open);
                moduleList = (ModuleLists)moduleListSerializer.Deserialize(FileStream);
                FileStream.Close();

                configuration.vector2CurveModules       = WeldingHelpers.convertFromToStringArray(moduleList.vector2CurveModules);
                configuration.vector4CurveModules       = WeldingHelpers.convertFromToStringArray(moduleList.vector4CurveModules);
                configuration.subModules                = WeldingHelpers.convertFromToStringArray(moduleList.subModules);
                configuration.modulesToIgnore           = WeldingHelpers.convertFromToStringArray(moduleList.modulesToIgnore);
                configuration.averagedModuleAttributes  = WeldingHelpers.convertFromToStringArray(moduleList.averagedModuleAttributes);
                configuration.unchangedModuleAttributes = WeldingHelpers.convertFromToStringArray(moduleList.unchangedModuleAttributes);
                configuration.breakingModuleAttributes  = WeldingHelpers.convertFromToStringArray(moduleList.breakingModuleAttributes);
                FileStream.Close();
            }
            else
            {
                configuration.vector2CurveModules       = Constants.basicVector2CurveModules;
                configuration.vector4CurveModules       = Constants.basicVector4CurveModules;
                configuration.subModules                = Constants.basicSubModules;
                configuration.modulesToIgnore           = Constants.basicModulesToIgnore;
                configuration.averagedModuleAttributes  = Constants.basicAveragedModuleAttributes;
                configuration.unchangedModuleAttributes = Constants.basicUnchangedModuleAttributes;
                configuration.breakingModuleAttributes  = Constants.basicBreakingModuleAttributes;
            }
            Debug.Log(string.Format("{0} Config was loaded", Constants.logPrefix));
            return(configuration);
        }
        /// <summary>
        /// handles the correct merging of float values in the modules
        /// </summary>
        /// <param name="newModuleName"></param>
        /// <param name="newModule"></param>
        /// <param name="existingNewModule"></param>
        /// <param name="ModuleAttribute"></param>
        private void mergeModuleFloatValues(string newModuleName, ConfigNode newModule, ConfigNode existingNewModule, string ModuleAttribute, bool advancedDebugging)
        {
#if (DEBUG)
            //Debug.LogWarning(string.Format("{0}| {1} - {2} is float", Constants.logPrefix, newModuleName, ModuleAttribute));
#endif
            //merge float values if they are allowed
            if (!WeldingHelpers.isArrayContaining(string.Concat(newModuleName, Constants.underline, ModuleAttribute), UbioZurWeldingLtd.instance.config.unchangedModuleAttributes))
            {
                if (newModule.HasValue(ModuleAttribute) || existingNewModule.HasValue(ModuleAttribute))
                {
                    float newValue = float.TryParse(newModule.GetValue(ModuleAttribute), out newValue) == false?float.Parse(existingNewModule.GetValue(ModuleAttribute)) : float.Parse(newModule.GetValue(ModuleAttribute));

                    Debugger.AdvDebug(string.Format("| {0} - newValue - {1} = {2}", newModuleName, ModuleAttribute, newValue), advancedDebugging);

                    if (existingNewModule.HasValue(ModuleAttribute) && newModule.HasValue(ModuleAttribute))
                    {
                        float existingValue = float.Parse(existingNewModule.GetValue(ModuleAttribute));
                        Debugger.AdvDebug(string.Format("| {0} - existingValue - {1} = {2}", newModuleName, ModuleAttribute, existingValue), advancedDebugging);

                        if (WeldingHelpers.isArrayContaining(string.Concat(newModuleName, Constants.underline, ModuleAttribute), UbioZurWeldingLtd.instance.config.maximizedModuleAttributes))
                        {
                            Debugger.AdvDebug(string.Format("| {0} - {1} - maximized", newModuleName, ModuleAttribute), advancedDebugging);
                            existingNewModule.SetValue(ModuleAttribute, (existingValue > newValue ? existingValue : newValue).ToString());
                        }
                        else
                        {
                            if (WeldingHelpers.isArrayContaining(string.Concat(newModuleName, Constants.underline, ModuleAttribute), UbioZurWeldingLtd.instance.config.minimizedModuleAttributes))
                            {
                                Debugger.AdvDebug(string.Format("| {0} - {1} - minimized", newModuleName, ModuleAttribute), advancedDebugging);
                                existingNewModule.SetValue(ModuleAttribute, (existingValue < newValue ? existingValue : newValue).ToString());
                            }
                            else
                            {
                                if (WeldingHelpers.isArrayContaining(string.Concat(newModuleName, Constants.underline, ModuleAttribute), UbioZurWeldingLtd.instance.config.averagedModuleAttributes) && (newValue != 0 && existingValue != 0))
                                {
                                    Debugger.AdvDebug(string.Format("| {0} - {1} - averaged", newModuleName, ModuleAttribute), advancedDebugging);
                                    existingNewModule.SetValue(ModuleAttribute, ((newValue + existingValue) * 0.5f).ToString());
                                }
                                else
                                {
                                    Debugger.AdvDebug(string.Format("| {0} - {1} - added", newModuleName, ModuleAttribute), advancedDebugging);
                                    existingNewModule.SetValue(ModuleAttribute, (newValue + existingValue).ToString());
                                }
                            }
                        }
                    }
                    else if (!existingNewModule.HasValue(ModuleAttribute) && newModule.HasValue(ModuleAttribute))
                    {
                        Debugger.AdvDebug(string.Format("| {0} - setNewValue - {1} = {2}", newModuleName, ModuleAttribute, newValue), advancedDebugging);
                        existingNewModule.AddValue(ModuleAttribute, newValue.ToString());
                    }
                }
            }
            Debugger.AdvDebug(string.Format("| {0} - {1} is merged with value {2}", newModuleName, ModuleAttribute, float.Parse(existingNewModule.GetValue(ModuleAttribute))), advancedDebugging);
        }
Beispiel #4
0
        private static void saveConfig(WeldingConfiguration configToSave, String configFullPathName, String moduleFullPathName)
        {
            WeldingConfiguration configuration = (WeldingConfiguration)configToSave.clone();
            ModuleLists          moduleList    = new ModuleLists();
            TextWriter           fileStreamWriter;

            if (configuration == null)
            {
                configuration = new WeldingConfiguration();
            }
            configuration.vector2CurveModules       = null;
            configuration.vector4CurveModules       = null;
            configuration.subModules                = null;
            configuration.modulesToIgnore           = null;
            configuration.modulesToMultiply         = null;
            configuration.maximizedModuleAttributes = null;
            configuration.minimizedModuleAttributes = null;
            configuration.averagedModuleAttributes  = null;
            configuration.unchangedModuleAttributes = null;
            configuration.breakingModuleAttributes  = null;

            XmlSerializer configSerializer = new XmlSerializer(typeof(WeldingConfiguration));

            fileStreamWriter = new StreamWriter(configFullPathName);
            configSerializer.Serialize(fileStreamWriter, configuration);
            fileStreamWriter.Close();

            //ModuleList from the constants or the actual config, depending on length of the array, in case user did add some entries
            moduleList.vector2CurveModules       = WeldingHelpers.convertStringFromToArray(configToSave.vector2CurveModules != null && (configToSave.vector2CurveModules.Length > Constants.basicVector2CurveModules.Length) ? configToSave.vector2CurveModules : Constants.basicVector2CurveModules);
            moduleList.vector4CurveModules       = WeldingHelpers.convertStringFromToArray(configToSave.vector4CurveModules != null && (configToSave.vector4CurveModules.Length > Constants.basicVector4CurveModules.Length) ? configToSave.vector4CurveModules : Constants.basicVector4CurveModules);
            moduleList.subModules                = WeldingHelpers.convertStringFromToArray(configToSave.subModules != null && (configToSave.subModules.Length > Constants.basicSubModules.Length) ? configToSave.subModules : Constants.basicSubModules);
            moduleList.modulesToIgnore           = WeldingHelpers.convertStringFromToArray(configToSave.modulesToIgnore != null && (configToSave.modulesToIgnore.Length > Constants.basicModulesToIgnore.Length) ? configToSave.modulesToIgnore : Constants.basicModulesToIgnore);
            moduleList.modulesToMultiply         = WeldingHelpers.convertStringFromToArray(configToSave.modulesToMultiply != null && (configToSave.modulesToMultiply.Length > Constants.basicModulesToMultiply.Length) ? configToSave.modulesToMultiply : Constants.basicModulesToMultiply);
            moduleList.maximizedModuleAttributes = WeldingHelpers.convertStringFromToArray(configToSave.maximizedModuleAttributes != null && (configToSave.maximizedModuleAttributes.Length > Constants.basicMaximizedModuleAttributes.Length) ? configToSave.maximizedModuleAttributes : Constants.basicMaximizedModuleAttributes);
            moduleList.minimizedModuleAttributes = WeldingHelpers.convertStringFromToArray(configToSave.minimizedModuleAttributes != null && (configToSave.minimizedModuleAttributes.Length > Constants.basicMinimizedModuleAttributes.Length) ? configToSave.minimizedModuleAttributes : Constants.basicMinimizedModuleAttributes);
            moduleList.averagedModuleAttributes  = WeldingHelpers.convertStringFromToArray(configToSave.averagedModuleAttributes != null && (configToSave.averagedModuleAttributes.Length > Constants.basicAveragedModuleAttributes.Length) ? configToSave.averagedModuleAttributes : Constants.basicAveragedModuleAttributes);
            moduleList.unchangedModuleAttributes = WeldingHelpers.convertStringFromToArray(configToSave.unchangedModuleAttributes != null && (configToSave.unchangedModuleAttributes.Length > Constants.basicUnchangedModuleAttributes.Length) ? configToSave.unchangedModuleAttributes : Constants.basicUnchangedModuleAttributes);
            moduleList.breakingModuleAttributes  = WeldingHelpers.convertStringFromToArray(configToSave.breakingModuleAttributes != null && (configToSave.breakingModuleAttributes.Length > Constants.basicBreakingModuleAttributes.Length) ? configToSave.breakingModuleAttributes : Constants.basicBreakingModuleAttributes);

            XmlSerializer moduleListSerializer = new XmlSerializer(typeof(ModuleLists));

            fileStreamWriter = new StreamWriter(moduleFullPathName);
            moduleListSerializer.Serialize(fileStreamWriter, moduleList);

            fileStreamWriter.WriteLine("");
            foreach (string s in comments)
            {
                fileStreamWriter.WriteLine(s);
            }
            fileStreamWriter.Close();
            Log.dbg("Config was saved");
        }
        /// <summary>
        /// saves the config file and the modulelist file so that it is possible to change them without the need to recompile
        /// </summary>
        /// <param name="configToSave"></param>
        public static void saveConfig(WeldingConfiguration configToSave)
        {
            WeldingConfiguration configuration = (WeldingConfiguration)configToSave.clone();
            ModuleLists          moduleList    = new ModuleLists();
            TextWriter           fileStreamWriter;

            if (configuration == null)
            {
                configuration = new WeldingConfiguration();
            }
            configuration.vector2CurveModules       = null;
            configuration.vector4CurveModules       = null;
            configuration.subModules                = null;
            configuration.modulesToIgnore           = null;
            configuration.averagedModuleAttributes  = null;
            configuration.unchangedModuleAttributes = null;
            configuration.breakingModuleAttributes  = null;

            XmlSerializer configSerializer = new XmlSerializer(typeof(WeldingConfiguration));

            fileStreamWriter = new StreamWriter(_configFile);
            configSerializer.Serialize(fileStreamWriter, configuration);
            fileStreamWriter.Close();


            //ModuleList from the constants or the actual config, depending on length of the array, in case user did add some entries
            moduleList.vector2CurveModules       = WeldingHelpers.convertStringFromToArray(configToSave.vector2CurveModules.Length > Constants.basicVector2CurveModules.Length ? configToSave.vector2CurveModules : Constants.basicVector2CurveModules);
            moduleList.vector4CurveModules       = WeldingHelpers.convertStringFromToArray(configToSave.vector4CurveModules.Length > Constants.basicVector4CurveModules.Length ? configToSave.vector4CurveModules: Constants.basicVector4CurveModules);
            moduleList.subModules                = WeldingHelpers.convertStringFromToArray(configToSave.subModules.Length > Constants.basicSubModules.Length ?configToSave.subModules: Constants.basicSubModules);
            moduleList.modulesToIgnore           = WeldingHelpers.convertStringFromToArray(configToSave.modulesToIgnore.Length > Constants.basicModulesToIgnore.Length ? configToSave.modulesToIgnore : Constants.basicModulesToIgnore);
            moduleList.averagedModuleAttributes  = WeldingHelpers.convertStringFromToArray(configToSave.averagedModuleAttributes.Length > Constants.basicAveragedModuleAttributes.Length ? configToSave.averagedModuleAttributes:Constants.basicAveragedModuleAttributes);
            moduleList.unchangedModuleAttributes = WeldingHelpers.convertStringFromToArray(configToSave.unchangedModuleAttributes.Length > Constants.basicUnchangedModuleAttributes.Length ? configToSave.unchangedModuleAttributes: Constants.basicUnchangedModuleAttributes);
            moduleList.breakingModuleAttributes  = WeldingHelpers.convertStringFromToArray(configToSave.breakingModuleAttributes.Length > Constants.basicBreakingModuleAttributes.Length ? configToSave.breakingModuleAttributes : Constants.basicBreakingModuleAttributes);

            XmlSerializer moduleListSerializer = new XmlSerializer(typeof(ModuleLists));

            fileStreamWriter = new StreamWriter(_moduleListFile);
            moduleListSerializer.Serialize(fileStreamWriter, moduleList);

            fileStreamWriter.WriteLine("");
            foreach (string s in comments)
            {
                fileStreamWriter.WriteLine(s);
            }
            fileStreamWriter.Close();
            Debug.Log(string.Format("{0} Config was saved", Constants.logPrefix));
        }
        private void HandleAwake()
        {
            instance = this;
            Log.dbg("Platform is {0}", Application.platform);

            initConfig();
            this.state           = DisplayState.none;
            _editorErrorDial     = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH);
            _editorWarningDial   = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH);
            _editorInfoWindow    = new Rect(Screen.width / 2 - Constants.guiInfoWindowX, Screen.height / 2 - Constants.guiInfoWindowY, Constants.guiInfoWindowW, Constants.guiInfoWindowH);
            _editorOverwriteDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH);
            _editorSavedDial     = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH);
            _editorMainWindow    = new Rect(_config.MainWindowXPosition, _config.MainWindowYPosition, Constants.guiMainWindowW, Constants.guiMainWindowH);

            _catNames    = WeldingHelpers.initPartCategories(_catNames);
            _guiStyle    = WeldingHelpers.initGuiStyle(_guiStyle);
            _catDropdown = WeldingHelpers.initDropDown(_catNames, _guiStyle, _catDropdown);
            DatabaseHandler.initMMAssembly();
        }
Beispiel #7
0
        /*
         * Called when plug in loaded
         */
        public void Awake()
        {
            instance = this;
            Debug.Log(string.Format("{0}- {1} => Awake", Constants.logPrefix, instance.GetType()));
            Debug.Log(string.Format("{0} Platform is {1}", Constants.logPrefix, Application.platform));

            initConfig();
            _state               = DisplayState.none;
            _editorErrorDial     = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH);
            _editorWarningDial   = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH);
            _editorInfoWindow    = new Rect(Screen.width / 2 - Constants.guiInfoWindowX, Screen.height / 2 - Constants.guiInfoWindowY, Constants.guiInfoWindowW, Constants.guiInfoWindowH);
            _editorOverwriteDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH);
            _editorSavedDial     = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH);
            _editorMainWindow    = new Rect(_config.MainWindowXPosition, _config.MainWindowYPosition, Constants.guiMainWindowW, Constants.guiMainWindowH);

            _catNames    = WeldingHelpers.initPartCategories(_catNames);
            _guiStyle    = WeldingHelpers.initGuiStyle(_guiStyle);
            _catDropdown = WeldingHelpers.initDropDown(_catNames, _guiStyle, _catDropdown);
            DatabaseHandler.initMMAssembly();
        }
Beispiel #8
0
        /// <summary>
        /// loads configfile and prepares it with all needed lists
        /// </summary>
        /// <returns></returns>
        public static WeldingConfiguration loadConfig()
        {
            WeldingConfiguration configuration = new WeldingConfiguration();
            ModuleLists          moduleList    = new ModuleLists();
            FileStream           FileStream    = null;

            try {
                XmlSerializer configSerializer = new XmlSerializer(typeof(WeldingConfiguration));
                configSerializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                configSerializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream    = new FileStream(CONFIG_FULLPATHNAME, FileMode.Open);
                configuration = (WeldingConfiguration)configSerializer.Deserialize(FileStream);

                if (configuration.MainWindowXPosition > (Screen.width - Constants.guiScreenEdgeClearance))
                {
                    configuration.MainWindowXPosition = Screen.width - Constants.guiScreenEdgeClearance;
                }
                if (configuration.MainWindowYPosition > (Screen.height - Constants.guiScreenEdgeClearance))
                {
                    configuration.MainWindowYPosition = Screen.height - Constants.guiScreenEdgeClearance;
                }
            } catch (Exception e) {
                configuration = new WeldingConfiguration();
                Log.warn(String.Format("{0} : {1}", CONFIG_FULLPATHNAME, e.Message));
            } finally {
                if (null != FileStream)
                {
                    FileStream.Close();
                }
                FileStream = null;
            }

            try {
                XmlSerializer moduleListSerializer = new XmlSerializer(typeof(ModuleLists));
                moduleListSerializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                moduleListSerializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream = new FileStream(MODULELIST_FULLPATHNAME, FileMode.Open);
                moduleList = (ModuleLists)moduleListSerializer.Deserialize(FileStream);

                configuration.vector2CurveModules = moduleList.vector2CurveModules != null?WeldingHelpers.convertFromToStringArray(moduleList.vector2CurveModules) : new string[0];

                configuration.vector4CurveModules = moduleList.vector4CurveModules != null?WeldingHelpers.convertFromToStringArray(moduleList.vector4CurveModules) : new string[0];

                configuration.subModules = moduleList.subModules != null?WeldingHelpers.convertFromToStringArray(moduleList.subModules) : new string[0];

                configuration.modulesToIgnore = moduleList.modulesToIgnore != null?WeldingHelpers.convertFromToStringArray(moduleList.modulesToIgnore) : new string[0];

                configuration.modulesToMultiply = moduleList.modulesToMultiply != null?WeldingHelpers.convertFromToStringArray(moduleList.modulesToMultiply) : new string[0];

                configuration.maximizedModuleAttributes = moduleList.maximizedModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.maximizedModuleAttributes) : new string[0];

                configuration.minimizedModuleAttributes = moduleList.minimizedModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.minimizedModuleAttributes) : new string[0];

                configuration.averagedModuleAttributes = moduleList.averagedModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.averagedModuleAttributes) : new string[0];

                configuration.unchangedModuleAttributes = moduleList.unchangedModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.unchangedModuleAttributes) : new string[0];

                configuration.breakingModuleAttributes = moduleList.breakingModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.breakingModuleAttributes) : new string[0];
            } catch (Exception e) {
                configuration.vector2CurveModules       = Constants.basicVector2CurveModules;
                configuration.vector4CurveModules       = Constants.basicVector4CurveModules;
                configuration.subModules                = Constants.basicSubModules;
                configuration.modulesToIgnore           = Constants.basicModulesToIgnore;
                configuration.modulesToMultiply         = Constants.basicModulesToMultiply;
                configuration.maximizedModuleAttributes = Constants.basicMaximizedModuleAttributes;
                configuration.minimizedModuleAttributes = Constants.basicMinimizedModuleAttributes;
                configuration.averagedModuleAttributes  = Constants.basicAveragedModuleAttributes;
                configuration.unchangedModuleAttributes = Constants.basicUnchangedModuleAttributes;
                configuration.breakingModuleAttributes  = Constants.basicBreakingModuleAttributes;
                Log.warn(String.Format("{0} : {1}", CONFIG_FULLPATHNAME, e.Message));
            } finally {
                if (null != FileStream)
                {
                    FileStream.Close();
                }
                FileStream = null;
            }

            Log.dbg("Config was loaded");
            return(configuration);
        }
Beispiel #9
0
        /// <summary>
        /// manages the merging of submodules inside the module
        /// </summary>
        /// <param name="newModule"></param>
        /// <param name="existingNewModule"></param>
        private void mergeSubModules(ConfigNode newModule, ConfigNode existingNewModule)
        {
            bool   exist            = false;
            string newSubModuleName = "";

            Log.dbg("| Merging SubModules Start");

            foreach (string subModule in UbioZurWeldingLtd.instance.config.subModules)
            {
                ConfigNode[] newNodes      = newModule.GetNodes(subModule);
                ConfigNode[] existingNodes = existingNewModule.GetNodes(subModule);

                foreach (ConfigNode newNode in newNodes)
                {
                    newSubModuleName = newNode.GetValue(newNode.values.DistinctNames()[0]);

                    foreach (ConfigNode existingNode in existingNodes)
                    {
                        exist = false;
                        string[] breakingAttributes = new string[newNode.values.DistinctNames().Count()];
                        for (int i = 0; i < newNode.values.DistinctNames().Count(); i++)
                        {
                            breakingAttributes[i] = string.Concat(subModule, Constants.nameSeparator, newNode.values.DistinctNames()[i]);
                        }
                        breakingAttributes = WeldingHelpers.getSharedArrayValues(breakingAttributes, UbioZurWeldingLtd.instance.config.breakingModuleAttributes);
                        Log.dbg("| SubModule BreakingAttributes found = {0} ", breakingAttributes.Length);

                        if (breakingAttributes.Length > 0)
                        {
                            foreach (string s in breakingAttributes)
                            {
                                string breakingAttribute = s.Replace(string.Concat(subModule, Constants.nameSeparator), "");
                                var    existingValue     = existingNode.GetValue(breakingAttribute);
                                var    newValue          = newNode.GetValue(breakingAttribute);
                                Log.dbg("| SubModule BreakingAttributes found | current one is {0} | ExistingValue = {1} - NewValue = {2}", breakingAttribute, existingValue, newValue);
                                exist = Equals(existingValue, newValue);
                                if (!exist)
                                {
                                    break;
                                }
                            }
                            if (exist)
                            {
                                mergeContents(newSubModuleName, newNode, existingNode);
                                exist = true;
                                break;
                            }
                        }
                        else
                        {
                            mergeContents(newSubModuleName, newNode, existingNode);
                            exist = true;
                            break;
                        }
                    }
                    if (!exist)
                    {
                        if (!WeldingHelpers.isArrayContaining(newSubModuleName, UbioZurWeldingLtd.instance.config.modulesToIgnore))
                        {
                            existingNewModule.AddNode(newNode);
                        }
                    }
                }
            }
            Log.dbg("| Merging SubModules End");
        }
Beispiel #10
0
        /// <summary>
        /// merges the modules in a almost generic way.
        /// </summary>
        /// <param name="partname"></param>
        /// <param name="configuration"></param>
        public void mergeModules(string partname, UrlDir.UrlConfig configuration, List <ConfigNode> modulelist)
        {
            ConfigNode[] originalModules = configuration.config.GetNodes(Constants.weldModuleNode);
            string       newModuleName   = "";
            bool         exist           = false;

            ConfigNode newModule;

            foreach (ConfigNode originalModule in originalModules)
            {
                newModule     = originalModule.CreateCopy();
                newModuleName = newModule.GetValue(newModule.values.DistinctNames()[0]);
                exist         = false;

                foreach (ConfigNode existingNewModule in modulelist)
                {
                    if (newModuleName.Equals(existingNewModule.GetValue(existingNewModule.values.DistinctNames()[0])))
                    {
                        if (!WeldingHelpers.isArrayContaining(newModuleName, UbioZurWeldingLtd.instance.config.modulesToMultiply))
                        {
                            Log.dbg("| {0} Module already exists!!!", existingNewModule.GetValue(existingNewModule.values.DistinctNames()[0]));
                            if (newModule.values.DistinctNames().Length < 2)
                            {
                                // making shure that the MODULE gets not duplicated in case it has no attributes
                                exist = true;
                                break;
                            }
                            else
                            {
                                string[] breakingAttributes = new string[newModule.values.DistinctNames().Count()];
                                for (int i = 0; i < newModule.values.DistinctNames().Count(); i++)
                                {
                                    breakingAttributes[i] = string.Concat(newModuleName, Constants.nameSeparator, newModule.values.DistinctNames()[i]);
                                }

                                breakingAttributes = WeldingHelpers.getSharedArrayValues(breakingAttributes, UbioZurWeldingLtd.instance.config.breakingModuleAttributes);
                                Log.dbg("| BreakingAttributes found = {0} ", breakingAttributes.Length);

                                if (breakingAttributes.Length > 0)
                                {
                                    foreach (string s in breakingAttributes)
                                    {
                                        string breakingAttribute = s.Replace(string.Concat(newModuleName, Constants.nameSeparator), "");
                                        var    existingValue     = existingNewModule.GetValue(breakingAttribute);
                                        var    newValue          = newModule.GetValue(breakingAttribute);
                                        Log.dbg("| BreakingAttributes found | current one is {0} | ExistingValue = {1} - NewValue = {2}", breakingAttribute, existingValue, newValue);
                                        exist = Equals(existingValue, newValue);
                                        if (!exist)
                                        {
                                            break;
                                        }
                                    }
                                    if (exist)
                                    {
                                        mergeContents(newModuleName, newModule, existingNewModule);
                                        exist = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    mergeContents(newModuleName, newModule, existingNewModule);
                                    exist = true;
                                    break;
                                }
                            }
                        }
                    }
                    Log.dbg("| Module {1} ready to add = {0}", !exist, existingNewModule.GetValue("name"));
                }                //foreach (ConfigNode existingNewModule in _modulelist)
                if (!(exist || WeldingHelpers.isArrayContaining(newModuleName, UbioZurWeldingLtd.instance.config.modulesToIgnore)))
                {
                    addNewModule(partname, newModuleName, newModule, modulelist);
                }
            }             //foreach (ConfigNode mod in modules)
        }
        }         //private void OnDraw()

        private void weldPart(Part partToWeld)
        {
            //Lock editor
            EditorLockManager.lockEditor(Constants.settingWeldingLock);

            //process the welding
#if (DEBUG)
            Debug.ClearDeveloperConsole();

            Log.info("{0}", Constants.logVersion);
            Log.info("{0}", Constants.logStartWeld);
#endif
            bool warning = false;
            _welder = new Welder();
            _welder.init();

            partToWeld.transform.eulerAngles = Vector3.zero;
            WeldingReturn ret = 0;

            if (!WeldingHelpers.DoesTextContainRegex(partToWeld.name, "strutConnector"))
            {
                ret = _welder.weldThisPart(partToWeld);
            }

            if (ret < 0)
            {
                Log.dbg("{0}", Constants.logEndWeld);
                this.state = DisplayState.weldError;
                return;
            }
            else
            {
                warning = warning || (0 < ret);
            }

            Part[] children = partToWeld.FindChildParts <Part>(true);

            if (children != null)
            {
                foreach (Part child in children)
                {
                    if (!WeldingHelpers.DoesTextContainRegex(child.name, "strutConnector"))
                    {
                        ret = _welder.weldThisPart(child);
                    }

                    if (ret < 0)
                    {
                        Log.dbg("{0}", Constants.logEndWeld);
                        this.state = DisplayState.weldError;
                        return;
                    }
                    else
                    {
                        warning = warning || (0 < ret);
                    }
                }
            }
            _welder.processNewCoM();

            _welder.prepDecals(_welder.moduleList);
            if (_welder.isMeshSwitchRequired)
            {
                _welder.prepareWeldedMeshSwitchModule(_welder.moduleList);
            }

            _techDropdown = WeldingHelpers.initTechDropDown(_welder.techList, _guiStyle, _techDropdown);

            if (_welder.vesselTypeList.Count > 0)
            {
                _vesselTypeDropdown = WeldingHelpers.initVesselTypeDropDown(_welder.vesselTypeList, _guiStyle, _vesselTypeDropdown);
            }

            _scrollMod = Vector2.zero;
            _scrollRes = Vector2.zero;

            Log.dbg("| {0} Parts welded", _welder.NbParts);

            if (warning)
            {
                Log.dbg(Constants.logEndWeld);
                this.state = DisplayState.weldWarning;
            }
            else
            {
                Log.dbg("welder.Category: {0}", (int)_welder.Category);
                _catDropdown.SelectedItemIndex = (int)_welder.Category;
                this.state = DisplayState.infoWindow;
            }
        }
Beispiel #12
0
        }         //private void OnDraw()

        private void weldPart(Part partToWeld)
        {
            //Lock editor
            EditorLogic.fetch.Lock(true, true, true, Constants.settingWeldingLock);

            //process the welding
#if (DEBUG)
            Debug.ClearDeveloperConsole();

            Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logVersion));
            Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logStartWeld));
#endif
            bool warning = false;
            _welder = new Welder();

            partToWeld.transform.eulerAngles = Vector3.up;
            WeldingReturn ret = _welder.weldThisPart(partToWeld);

            if (ret < 0)
            {
#if (DEBUG)
                Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld));
#endif
                _state = DisplayState.weldError;
                return;
            }
            else
            {
                warning = warning || (0 < ret);
            }

            Part[] children = partToWeld.FindChildParts <Part>(true);

            if (children != null)
            {
                foreach (Part child in children)
                {
                    ret = _welder.weldThisPart(child);

                    if (ret < 0)
                    {
#if (DEBUG)
                        Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld));
#endif
                        _state = DisplayState.weldError;
                        return;
                    }
                    else
                    {
                        warning = warning || (0 < ret);
                    }
                }
            }
            _welder.processNewCoM();

            _techDropdown = WeldingHelpers.initTechDropDown(_welder.techList, _catListStyle, _techDropdown);

            _scrollMod = Vector2.zero;
            _scrollRes = Vector2.zero;
#if (DEBUG)
            Debug.Log(string.Format("{0} {1} | {2} Parts welded", Constants.logPrefix, Constants.logEndWeld, _welder.NbParts));
#endif
            if (warning)
            {
                Debug.Log(string.Format("{0} {1} | Warning", Constants.logPrefix, Constants.logEndWeld));
                _state = DisplayState.weldWarning;
            }
            else
            {
                _catDropdown.SelectedItemIndex = (int)_welder.Category;
                _state = DisplayState.infoWindow;
            }
        }