示例#1
0
        private static void ReactToStateNameChange(object oldValue, StateSave stateSave, StateSaveCategory category, IElement parentObject)
        {
            PluginManager.ReactToStateNameChange(parentObject as IElement, (string)oldValue, stateSave.Name);


            IElement parentAsElement = parentObject as IElement;

            string name = parentObject.Name;

            string typeToMatch = "VariableState";

            if (category != null && category.SharesVariablesWithOtherCategories == false)
            {
                typeToMatch = "Current" + category.Name + "State";
            }

            var matchingVariables = from variable in parentAsElement.CustomVariables
                                    where variable.DefaultValue == oldValue &&
                                    variable.Type == typeToMatch
                                    select variable;

            foreach (CustomVariable variable in matchingVariables)
            {
                variable.DefaultValue = stateSave.Name;
            }

            string variableName = stateSave.GetExposedVariableName(parentObject);
            string variableType = stateSave.GetEnumTypeName(parentObject);

            // Find any NOSs that use the ParentObject as their type
            foreach (ScreenSave screenSave in ObjectFinder.Self.GlueProject.Screens)
            {
                var customQuery = from nos in screenSave.AllNamedObjects
                                  where nos.SourceType == SourceType.Entity &&
                                  nos.SourceClassType == name
                                  select nos;

                foreach (var nos in customQuery)
                {
                    if (nos.CurrentState == (oldValue as string))
                    {
                        nos.CurrentState = stateSave.Name;
                    }
                    foreach (var variable in nos.InstructionSaves.Where(item => item.Member == variableName && (item.Value as string) == (oldValue as string)))
                    {
                        variable.Value = stateSave.Name;
                    }
                }
            }

            foreach (EntitySave entitySave in ObjectFinder.Self.GlueProject.Entities)
            {
                var customQuery = from nos in entitySave.AllNamedObjects
                                  where nos.SourceType == SourceType.Entity &&
                                  nos.SourceClassType == name
                                  select nos;

                foreach (var nos in customQuery)
                {
                    if (nos.CurrentState == (oldValue as string))
                    {
                        nos.CurrentState = stateSave.Name;
                    }
                    foreach (var variable in nos.InstructionSaves.Where(item => item.Member == variableName && (item.Value as string) == (oldValue as string)))
                    {
                        variable.Value = stateSave.Name;
                    }
                }
            }
        }