Beispiel #1
0
        private static Layer GetLayerToAddTo(NamedObjectSave objectToLoad, Layer layerToPutOn, ElementRuntime elementRuntime)
        {
            Layer layerToAddTo = layerToPutOn;

            if (!string.IsNullOrEmpty(objectToLoad.LayerOn))
            {
                if (objectToLoad.LayerOn == "Under Everything (Engine Layer)")
                {
                    layerToAddTo = SpriteManager.UnderAllDrawnLayer;
                }
                else if (objectToLoad.LayerOn == "Top Layer (Engine Layer)")
                {
                    layerToAddTo = SpriteManager.TopLayer;
                }
                else
                {
                    ElementRuntime layerContainer = elementRuntime.GetContainedElementRuntime(objectToLoad.LayerOn);
                    if (layerContainer == null)
                    {
                        System.Windows.Forms.MessageBox.Show(
                            "Could not find a Layer by the name \"" + objectToLoad.LayerOn + "\" in the object " + objectToLoad,
                            "Layer not found");
                    }
                    else
                    {
                        layerToAddTo = ((Layer)layerContainer.DirectObjectReference);
                    }
                }
            }
            return(layerToAddTo);
        }
Beispiel #2
0
        public ElementRuntime ElementRuntimeForArrowInstance(object instance, ElementRuntime container)
        {
            // todo:  Add verification because we assume the current IElement contains a NOS for the instance

            string name = (string)LateBinder.GetInstance(instance.GetType()).GetValue(instance, "Name");

            ElementRuntime contained = container.GetContainedElementRuntime(name);

            return(contained);
        }
        void OnElementLoaded(object sender, EventArgs e)
        {
            //Parses the layers out of the currently selected element in Glue
            setUpLayerComboBox();

            if (mCurrentSelectedElementRuntime != null && mCurrentSelectedElementRuntime.AssociatedNamedObjectSave != null)
            {
                ElementRuntime newElementRuntime = GluxManager.CurrentElement;
                if (newElementRuntime.Name != mCurrentSelectedElementRuntime.Name)
                {
                    newElementRuntime = newElementRuntime.GetContainedElementRuntime(mCurrentSelectedElementRuntime.Name);
                }
                mCurrentSelectedElementRuntime = newElementRuntime;

                if (mCurrentSelectedElementRuntime != null)
                {
                    // The element has been reloaded which means the NamedObjectSaves and ElementRuntimes have been recreated.
                    // We need to update to that:
                    entityControlControls.SetCurrentNamedObject(
                        mCurrentSelectedElementRuntime,
                        mCurrentSelectedElementRuntime.AssociatedNamedObjectSave);
                }
            }
        }
Beispiel #4
0
        public string GetTypeStringForValue(string leftOfEquals, ElementRuntime elementRuntime, CodeContext codeContext, out Type runtimeType)
        {
            // try using the new method:
            var leftReference = mExpressionParser.EvaluateExpression(leftOfEquals, codeContext, ExpressionParseType.GetReference);

            if (leftReference != null)
            {
                if (leftReference is IAssignableReference)
                {
                    Type type = ((IAssignableReference)leftReference).TypeOfReference;
                    runtimeType = type;
                    string toReturn = null;
                    if (runtimeType != null)
                    {
                        toReturn = runtimeType.FullName;
                    }
                    return(toReturn);
                }
                else
                {
                    runtimeType = null;
                    return(null);
                }
            }
            else
            {
                string leftSideRaw       = leftOfEquals;
                string leftSideContainer = null;
                if (leftOfEquals.Contains('.'))
                {
                    // That means the user is setting a value on a contained object, so let's see what the raw variable is
                    int lastDot = leftOfEquals.LastIndexOf('.');

                    leftSideRaw       = leftOfEquals.Substring(lastDot + 1, leftSideRaw.Length - (lastDot + 1));
                    leftSideContainer = leftOfEquals.Substring(0, lastDot);
                }

                if (leftSideContainer == null)
                {
                    if (elementRuntime != null)
                    {
                        if (IsStateVariable(leftSideRaw, elementRuntime))
                        {
                            runtimeType = typeof(string);
                            return("String");
                        }
                    }

                    FieldInfo fieldInfo = mAllFields.GetFieldByName(leftSideRaw);
                    if (fieldInfo != null)
                    {
                        runtimeType = fieldInfo.FieldType;
                        return(fieldInfo.FieldType.ToString());
                    }

                    PropertyInfo propertyInfo = mAllProperties.GetPropertyByName(leftSideRaw);
                    if (propertyInfo != null)
                    {
                        runtimeType = propertyInfo.PropertyType;
                        return(propertyInfo.PropertyType.ToString());
                    }
                }
                // reverse loop so we get the inner-most variables first
                for (int i = mCallStackVariables.Count - 1; i > -1; i--)
                {
                    Dictionary <string, object> variableDictionary = mCallStackVariables[i];


                    if (variableDictionary.ContainsKey(leftSideRaw))
                    {
                        runtimeType = variableDictionary[leftSideRaw].GetType();
                        return(runtimeType.ToString());
                    }
                }

                if (leftSideContainer != null)
                {
                    ElementRuntime containerElementRuntime = elementRuntime.GetContainedElementRuntime(leftSideContainer);

                    if (containerElementRuntime != null)
                    {
                        return(GetTypeStringForValue(leftSideRaw, containerElementRuntime, codeContext, out runtimeType));
                    }
                }

                // If we got this far we should try to get the type through reflection
                GetTypeFromReflection(leftOfEquals, out runtimeType, null);

                if (runtimeType != null)
                {
                    return(runtimeType.ToString());
                }
                else
                {
                    return(null);
                }
            }
        }
        private static void GetObjectFromContainerAndNameEvaluate(object container, string memberName, CodeContext codeContext, ref object foundValue, ref bool wasFound)
        {
            if (container is CsvEntry)
            {
                foundValue = (container as CsvEntry).GetValue(memberName);
            }

            if (codeContext.VariableStack.Count == 0)
            {
                throw new Exception("codeContext doesn't have any entries.  It needs to have at least one");
            }

            int index = -1;

            codeContext.GetVariableInformation(memberName, out index);

            if (index != -1)
            {
                foundValue = codeContext.VariableStack[index][memberName];
                wasFound   = true;
            }

            if (wasFound == false && foundValue == null && container != null)
            {
                object instance = container;
                Type   type     = container.GetType();
                if (container is Type)
                {
                    instance = null;
                    type     = container as Type;
                }

                // First let's do reflection
                if (container is ElementRuntime && (container as ElementRuntime).DirectObjectReference != null)
                {
                    ElementRuntime containerElementRuntime = container as ElementRuntime;

                    if (LateBinder.GetInstance(containerElementRuntime.DirectObjectReference.GetType()).TryGetValue(containerElementRuntime.DirectObjectReference, memberName, out foundValue))
                    {
                        // do nothing.
                        wasFound = true;
                    }
                }
                else
                {
                    if (LateBinder.GetInstance(type).TryGetValue(instance, memberName, out foundValue))
                    {
                        // do nothing.
                        wasFound = true;
                    }
                }

                if (foundValue == null && container is ElementRuntime)
                {
                    ElementRuntime containerElementRuntime = container as ElementRuntime;

                    IElement containerElement = (container as ElementRuntime).AssociatedIElement;


                    foundValue = TryToGetStateCategoryFromElement(memberName, containerElement);

                    if (foundValue == null)
                    {
                        foundValue = containerElementRuntime.GetContainedElementRuntime(memberName);
                    }

                    if (foundValue == null)
                    {
                        foundValue = containerElementRuntime.GetReferencedFileSaveRuntime(memberName);
                    }

                    if (foundValue == null && containerElement != null)
                    {
                        // Some values like X or Y are stored inside the element runtime
                        // (because it actually stores those values locally).  However, if
                        // a value doesn't have an underlying value,
                        CustomVariable variable = containerElementRuntime.GetCustomVariable(memberName, VariableGetType.AsExistsAtRuntime);
                        //CustomVariable variable = containerElement.GetCustomVariableRecursively(memberName);
                        if (variable != null)
                        {
                            if (variable.GetIsCsv())
                            {
                                string rfsToLookFor = FileManager.RemoveExtension(variable.Type);
                                foundValue = containerElementRuntime.GetReferencedFileSaveRuntime(rfsToLookFor);
                                // if it's null, maybe it's a global file
                                if (foundValue == null)
                                {
                                    ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(variable.Type);
                                    if (rfs != null)
                                    {
                                        foundValue = GluxManager.GlobalContentFilesRuntime.LoadReferencedFileSave(rfs, true, containerElement);
                                    }
                                }

                                if (foundValue != null)
                                {
                                    foundValue = GetCsvEntryByRequiredKey(variable.DefaultValue as string, foundValue as RuntimeCsvRepresentation);
                                    // We have a RFS, so let's get values out of it
                                }
                            }
                            else
                            {
                                foundValue = variable.DefaultValue;
                                wasFound   = true;
                            }
                        }
                    }
                    wasFound = foundValue != null;
                }
                else if (container is StateSaveCategory)
                {
                    foundValue = (container as StateSaveCategory).States.FirstOrDefault(state => state.Name == memberName);
                    wasFound   = foundValue != null;
                }
                else if (container is IElement)
                {
                    foundValue = TryToGetStateCategoryFromElement(memberName, container as IElement);
                }
            }
            if (wasFound == false && foundValue == null)
            {
                foundValue = ObjectFinder.Self.GetElementUnqualified(memberName);
                wasFound   = foundValue != null;
            }
            if (wasFound == false && foundValue == null)
            {
                foundValue = TypeManager.GetTypeFromString(memberName);

                wasFound = foundValue != null;
            }
        }