Example #1
0
        /// <summary>
        /// A preference that is stored in the cloud. Automatically added to the <see cref="DataManager"/>.
        /// </summary>
        /// <param name="key">A unique identifier used to identify this particular value.</param>
        /// <param name="type">The method of conflict resolution to be used in case of a data conflict. Can happen if the data is altered by a different device.</param>
        /// <param name="value">The starting value for this preference.</param>
        /// <param name="defaultValue">The value the preference will be set to if it is ever reset.</param>
        /// <param name="valueLoader"><c>delegate</c> used to get the preference.</param>
        /// <param name="valueSetter"><c>delegate</c> used to set the preference.</param>
        protected PersistentValue(string key, PersistenceType type, T value, T defaultValue, ValueLoaderDelegate valueLoader, ValueSetterDelegate valueSetter)
        {
            // Compiler directives need to be placed in the specific order they're in, don't move/combine them
#if UNITY_EDITOR
            // Workaround for Unity Editor serialization weirdness
            if (Guid.NewGuid() == Guid.Empty)
            {
                return;
            }
#endif
            Key             = key;
            Value           = value;
            PersistenceType = type;
            DefaultValue    = defaultValue;
            ValueLoader     = valueLoader;
            ValueSetter     = valueSetter;

            DataManager.CloudPrefs[key] = this;

#if UNITY_EDITOR
            // 1 is the main thread
            if (System.Threading.Thread.CurrentThread.ManagedThreadId != 1 || !Application.isPlaying)
            {
                return;
            }
#endif
            DataManager.InitDataManager();
        }
Example #2
0
        /// <summary>
        /// Builds the properties for the labels's <see cref="ILabelModel"/> type.
        /// </summary>
        protected virtual void BuildModelProperties(IPropertyBuildContext <ILabel> context)
        {
            ValueGetterDelegate <Type> labelModelGetter = new ValueGetterDelegate <Type>(
                delegate {
                var type = context.CurrentInstance.LayoutParameter.Model.GetType();
                while (!type.IsPublic)
                {
                    type = type.BaseType;
                }
                return(type);
            });
            ValueSetterDelegate <Type> labelModelSetter = new ValueSetterDelegate <Type>(
                delegate(Type value) {
                IGraph graph = context.Lookup(typeof(IGraph)) as IGraph;
                if (graph != null)
                {
                    ILabelModel model = Activator.CreateInstance(value) as ILabelModel;
                    if (model != null)
                    {
                        ILabelModelParameterFinder finder =
                            model.Lookup(typeof(ILabelModelParameterFinder)) as ILabelModelParameterFinder;
                        ILabelModelParameter parameter;
                        ILabel subject = context.CurrentInstance;
                        if (finder != null)
                        {
                            parameter = finder.FindBestParameter(subject, model, subject.GetLayout());
                        }
                        else
                        {
                            parameter = model.CreateDefaultParameter();
                        }
                        graph.SetLabelLayoutParameter(subject, parameter);
                    }
                }
            });
            ILabel currentLabel;

            currentLabel = context.CurrentInstance;
            if (currentLabel == null)
            {
                return;
            }
            if (currentLabel.Owner is IEdge)
            {
                context.AddEntry(EdgeLabelModelProperty,
                                 labelModelGetter,
                                 labelModelSetter, null);
            }

            if (currentLabel.Owner is INode)
            {
                context.AddEntry(NodeLabelModelProperty, labelModelGetter, labelModelSetter, null);
            }

            if (currentLabel.Owner is IPort)
            {
                context.AddEntry(PortLabelModelProperty, labelModelGetter, labelModelSetter, null);
            }
        }
Example #3
0
            public BoundVariable(XmlLayoutElement element, T instance, IVariableValue <P> value, ValueSetterDelegate <T, P> setter)
            {
                this.element  = element;
                this.instance = instance;
                this.value    = value;
                this.setter   = setter;

                value.OnValueChanged += ApplyChanged;
            }
Example #4
0
        /// <summary>
        /// A preference that is stored in the cloud. Automatically added to the <see cref="DataManager"/>.
        /// </summary>
        /// <param name="key">A unique identifier used to identify this particular value.</param>
        /// <param name="type">The method of conflict resolution to be used in case of a data conflict. Can happen if the data is altered by a different device.</param>
        /// <param name="value">The starting value for this preference.</param>
        /// <param name="defaultValue">The value the preference will be set to if it is ever reset.</param>
        /// <param name="valueLoader"><c>delegate</c> used to get the preference.</param>
        /// <param name="valueSetter"><c>delegate</c> used to set the preference.</param>
        protected PersistentValue(string key, PersistenceType type, T value, T defaultValue, ValueLoaderDelegate valueLoader, ValueSetterDelegate valueSetter)
        {
            Key             = key;
            Value           = value;
            PersistenceType = type;
            DefaultValue    = defaultValue;
            ValueLoader     = valueLoader;
            ValueSetter     = valueSetter;

            DataManager.CloudPrefs[key] = this;
            DataManager.InitDataManager();
            Load();
        }
Example #5
0
        public AttributeHandler <T> AddGenericAttr <P>(TypeInfo <P> typeInfo, string name,
                                                       ValueSetterDelegate <T, P> setter, bool isSerializable = true)
        {
            var parser = typeInfo.parser;

            propertyInfos.Add(new PropertyInfo
            {
                name           = name,
                schema         = typeInfo,
                propertyParser = (values, props) =>
                {
                    if (!values.TryGetValue(name, out var attrText))
                    {
                        return;
                    }

                    if (attrText.StartsWith("$"))
                    {
                        var referenceName = attrText.Substring(1);
                        props.AddVariable(name, referenceName, setter);
                        return;
                    }

                    // Escape $ as \$
                    if (attrText.StartsWith("\\$"))
                    {
                        attrText = attrText.Substring(1);
                    }

                    if (parser == null)
                    {
                        Debug.LogError($"Value of type {typeof(P)} cannot be created from XML");
                    }
                    else if (parser(attrText, out var result))
                    {
                        props.AddConstant(name, result, setter, isSerializable);
                    }
                    else
                    {
                        Debug.Log($"Cannot parse value \"{attrText}\" of attribute \"{name}\" as {typeof(P)}");
                    }
                }
            });
 /// <summary>
 /// Decorates the setters to seemlessly perform the cloning on a set operation.
 /// </summary>
 internal ValueSetterDelegate <TValue> decorate <TValue>(ValueSetterDelegate <TValue> setter)
 {
     if (parent.useClone && this.context.Policy == AssignmentPolicy.CreateNewInstance)
     {
         return(delegate(TValue value) {
             T1 t1 = parent.CreateCopy(this, CurrentInstance);
             SetTempInstance(t1);
             try {
                 setter(value);
             } finally {
                 ResetTempInstance();
             }
             SetNewInstance(t1);
         });
     }
     else
     {
         return(setter);
     }
 }
Example #7
0
        private Map(int width, int height, System.Windows.Forms.PictureBox dbox, ValueSetterDelegate undo, ValueSetterDelegate redo, ValueSetterDelegate postMode)
        {
            box         = dbox;
            setUndo     = undo;
            setRedo     = redo;
            setPostMode = postMode;

            Width  = width;
            Height = height;

            scrollBlockers = new List <Pair <int, int> >();
            scrollBlockers.Add(new Pair <int, int>(-1, -1));

            changes = new List <BaseChange>();
            changes.Add(new ChangeDummy());
            changesIndex = 0;
            post         = false;
            lastToggle   = -1;

            tiles = makeTiles(width, height);
        }
Example #8
0
        private Map(int width, int height, System.Windows.Forms.PictureBox dbox, ValueSetterDelegate undo, ValueSetterDelegate redo, ValueSetterDelegate postMode)
        {
            box = dbox;
            setUndo = undo;
            setRedo = redo;
            setPostMode = postMode;

            Width = width;
            Height = height;

            scrollBlockers = new List<Pair<int, int>>();
            scrollBlockers.Add(new Pair<int, int>(-1, -1));

            changes = new List<BaseChange>();
            changes.Add(new ChangeDummy());
            changesIndex = 0;
            post = false;
            lastToggle = -1;

            tiles = makeTiles(width, height);
        }
Example #9
0
        /// <summary>
        /// Load a map instance from a file.
        /// </summary>
        /// <param name="fileName">Path for the file</param>
        /// <param name="dbox">Drawing box for the map representation</param>
        /// <param name="undo">Delegate disabling and enabling the 'undo' action</param>
        /// <param name="redo">Delegate disabling and enabling the 'redo' action</param>
        /// <param name="postMode">Delegate changing edit mode on the interface</param>
        /// <returns></returns>
        public static Map LoadMap(string fileName, System.Windows.Forms.PictureBox dbox, ValueSetterDelegate undo, ValueSetterDelegate redo, ValueSetterDelegate postMode)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);
            XmlElement d = doc.DocumentElement;

            if (d.Name != "tilemap")
            {
                throw new XmlMapperException("not a tiled map file");
            }

            bool convert = !d.HasAttribute("version");

            bool convert2 = convert || !d.GetAttribute("version").Equals(Config.MapVersion);

            XmlElement el = d.FirstChildElement("header");
            if (el == null)
                throw new XmlMapperException("no header was found");

            int width = el.GetIntAttribute("width");
            int height = el.GetIntAttribute("height");
            bool post = el.GetBoolAttribute("details");

            Map map = new Map(width, height, dbox, undo, redo, postMode);

            el = d.FirstChildElement("scrollblockers");
            if (el == null)
                throw new XmlMapperException("no scrollblockers info found");

            XmlNodeList nl = el.GetElementsByTagName("scrollblocker");
            for (int i = 0; i < nl.Count; i++)
            {
                XmlElement sn = nl.Item(i).TryToElement();
                if (sn == null) continue;
                int x = sn.GetIntAttribute("x");
                int y = sn.GetIntAttribute("y");

                map.tiles[x, y].ScrollBlocker = map.scrollBlockers.Count;
                map.scrollBlockers.Add(new Pair<int, int>(x, y));
            }

            el = d.FirstChildElement("tiles");
            if (el == null)
                throw new XmlMapperException("no tiles info found");

            nl = el.GetElementsByTagName("tile");
            for (int i = 0; i < nl.Count; i++)
            {
                XmlElement sn = nl.Item(i).TryToElement();
                if (sn == null) continue;
                int x = sn.GetIntAttribute("x");
                int y = sn.GetIntAttribute("y");
                int variant = sn.GetIntAttribute("variant");
                bool filled = sn.TryGetBoolAttribute("filled");
                if (convert)
                {
                    if (variant == 0) variant = -1;
                    else if (variant == 1) variant = 0;
                }

                if (convert2)
                {
                    if (variant == -1)
                        variant = 0;
                    else filled = true;
                }

                bool wide = sn.GetBoolAttribute("wide");
                string walls = sn.GetAttribute("walls");

                Tile tile = map.tiles[x, y];
                tile.Filled = filled;
                tile.Variant = variant;
                tile.Wide = wide;

                bool[] w = parseBools(walls);
                for (int j = 0; j < 4; j++)
                    tile.SetBlock(j, w[j]);
            }
            map.post = post;

            map.setPostMode(post);
            map.FullRedraw();
            return map;
        }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="setter">The setter to use.</param>
 public DelegateSetter(ValueSetterDelegate <T> setter)
 {
     this.setter = setter;
 }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="setter">The setter to use.</param>
 /// <param name="predicate">The predicate to use</param>
 public DelegateSetter(ValueSetterDelegate <T> setter, ValueSetterValidityPredicate predicate)
 {
     this.setter    = setter;
     this.predicate = predicate;
 }
Example #12
0
 public AttributeHandler <T> AddResourceAttr <P>(string name, ValueSetterDelegate <T, P> setter, bool isSerializable = true)
     where P : Object => AddGenericAttr(AttributeType.GetResourceType <P>(), name, setter, isSerializable);
Example #13
0
 public AttributeHandler <T> AddEnumAttr <P>(string name, ValueSetterDelegate <T, P> setter, bool isSerializable = true)
     where P : struct, Enum => AddGenericAttr(AttributeType.GetEnumTypeInfo <P>(), name, setter, isSerializable);
Example #14
0
        /// <summary>
        /// Create a new map instance and associate the form controls.
        /// </summary>
        /// <param name="width">Width of the map in tiles</param>
        /// <param name="height">Height of the map in tiles</param>
        /// <param name="dbox">Drawing box for the map representation</param>
        /// <param name="undo">Delegate disabling and enabling the 'undo' action</param>
        /// <param name="redo">Delegate disabling and enabling the 'redo' action</param>
        /// <param name="postMode">Delegate changing edit mode on the interface</param>
        /// <returns></returns>
        public static Map NewMap(int width, int height, System.Windows.Forms.PictureBox dbox, ValueSetterDelegate undo, ValueSetterDelegate redo, ValueSetterDelegate postMode)
        {
            Map map = new Map(width, height, dbox, undo, redo, postMode);
            map.setPostMode(false);
            map.FullRedraw();

            return map;
        }
Example #15
0
 public AttributeHandler <T> AddComponentReferenceAttr <C>(string name, ValueSetterDelegate <T, C> setter, bool isSerializable = true) =>
 AddGenericAttr(AttributeType.String, name, (e, c, v) => setter(e, c, e.FindComponentById <C>(v)));
 public IPropertyItem AddEntry <TValue>(string virtualPropertyName, ValueGetterDelegate <TValue> getter,
                                        ValueSetterDelegate <TValue> setter)
 {
     return(AddEntry(virtualPropertyName, new DelegateGetter <TValue>(getter), new DelegateSetter <TValue>(setter), null));
 }
Example #17
0
        /// <summary>
        /// Create a new map instance and associate the form controls.
        /// </summary>
        /// <param name="width">Width of the map in tiles</param>
        /// <param name="height">Height of the map in tiles</param>
        /// <param name="dbox">Drawing box for the map representation</param>
        /// <param name="undo">Delegate disabling and enabling the 'undo' action</param>
        /// <param name="redo">Delegate disabling and enabling the 'redo' action</param>
        /// <param name="postMode">Delegate changing edit mode on the interface</param>
        /// <returns></returns>
        public static Map NewMap(int width, int height, System.Windows.Forms.PictureBox dbox, ValueSetterDelegate undo, ValueSetterDelegate redo, ValueSetterDelegate postMode)
        {
            Map map = new Map(width, height, dbox, undo, redo, postMode);

            map.setPostMode(false);
            map.FullRedraw();

            return(map);
        }
Example #18
0
 public AttributeHandler <T> AddIntAttr(string name, ValueSetterDelegate <T, int> setter, bool isSerializable = true) =>
 AddGenericAttr(AttributeType.Integer, name, setter, isSerializable);
Example #19
0
 public AttributeHandler <T> AddBoolAttr(string name, ValueSetterDelegate <T, bool> setter, bool isSerializable = true) =>
 AddGenericAttr(AttributeType.Boolean, name, setter, isSerializable);
Example #20
0
 public AttributeHandler <T> AddStringAttr(string name, ValueSetterDelegate <T, string> setter, bool isSerializable = true) =>
 AddGenericAttr(AttributeType.String, name, setter, isSerializable);
Example #21
0
 public VariableBinder(string[] attributeNames, string variableName, ValueSetterDelegate <T, P> setter)
 {
     AttributeNames = attributeNames;
     Setter         = setter;
     VariableName   = variableName;
 }
Example #22
0
 public AttributeHandler <T> AddYogaValueAttr(string name, ValueSetterDelegate <T, YogaValue> setter, bool isSerializable = true) =>
 AddGenericAttr(AttributeType.YogaValue, name, setter, isSerializable);
Example #23
0
 public AttributeHandler <T> AddFloatAttr(string name, ValueSetterDelegate <T, float> setter, bool isSerializable = true) =>
 AddGenericAttr(AttributeType.Float, name, setter, isSerializable);
Example #24
0
        /// <summary>
        /// Load a map instance from a file.
        /// </summary>
        /// <param name="fileName">Path for the file</param>
        /// <param name="dbox">Drawing box for the map representation</param>
        /// <param name="undo">Delegate disabling and enabling the 'undo' action</param>
        /// <param name="redo">Delegate disabling and enabling the 'redo' action</param>
        /// <param name="postMode">Delegate changing edit mode on the interface</param>
        /// <returns></returns>
        public static Map LoadMap(string fileName, System.Windows.Forms.PictureBox dbox, ValueSetterDelegate undo, ValueSetterDelegate redo, ValueSetterDelegate postMode)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(fileName);
            XmlElement d = doc.DocumentElement;

            if (d.Name != "tilemap")
            {
                throw new XmlMapperException("not a tiled map file");
            }

            bool convert = !d.HasAttribute("version");

            bool convert2 = convert || !d.GetAttribute("version").Equals(Config.MapVersion);

            XmlElement el = d.FirstChildElement("header");

            if (el == null)
            {
                throw new XmlMapperException("no header was found");
            }

            int  width  = el.GetIntAttribute("width");
            int  height = el.GetIntAttribute("height");
            bool post   = el.GetBoolAttribute("details");

            Map map = new Map(width, height, dbox, undo, redo, postMode);

            el = d.FirstChildElement("scrollblockers");
            if (el == null)
            {
                throw new XmlMapperException("no scrollblockers info found");
            }

            XmlNodeList nl = el.GetElementsByTagName("scrollblocker");

            for (int i = 0; i < nl.Count; i++)
            {
                XmlElement sn = nl.Item(i).TryToElement();
                if (sn == null)
                {
                    continue;
                }
                int x = sn.GetIntAttribute("x");
                int y = sn.GetIntAttribute("y");

                map.tiles[x, y].ScrollBlocker = map.scrollBlockers.Count;
                map.scrollBlockers.Add(new Pair <int, int>(x, y));
            }

            el = d.FirstChildElement("tiles");
            if (el == null)
            {
                throw new XmlMapperException("no tiles info found");
            }

            nl = el.GetElementsByTagName("tile");
            for (int i = 0; i < nl.Count; i++)
            {
                XmlElement sn = nl.Item(i).TryToElement();
                if (sn == null)
                {
                    continue;
                }
                int  x       = sn.GetIntAttribute("x");
                int  y       = sn.GetIntAttribute("y");
                int  variant = sn.GetIntAttribute("variant");
                bool filled  = sn.TryGetBoolAttribute("filled");
                if (convert)
                {
                    if (variant == 0)
                    {
                        variant = -1;
                    }
                    else if (variant == 1)
                    {
                        variant = 0;
                    }
                }

                if (convert2)
                {
                    if (variant == -1)
                    {
                        variant = 0;
                    }
                    else
                    {
                        filled = true;
                    }
                }

                bool   wide  = sn.GetBoolAttribute("wide");
                string walls = sn.GetAttribute("walls");

                Tile tile = map.tiles[x, y];
                tile.Filled  = filled;
                tile.Variant = variant;
                tile.Wide    = wide;

                bool[] w = parseBools(walls);
                for (int j = 0; j < 4; j++)
                {
                    tile.SetBlock(j, w[j]);
                }
            }
            map.post = post;

            map.setPostMode(post);
            map.FullRedraw();
            return(map);
        }
 public IPropertyItem AddEntry <TValue>(string virtualPropertyName, ValueGetterDelegate <TValue> getter, ValueSetterDelegate <TValue> setter, IEqualityComparer comparer)
 {
     return(context.AddEntry(virtualPropertyName, getter, decorate(setter), comparer));
 }
Example #26
0
 public AttributeHandler <T> AddColorAttr(string name, ValueSetterDelegate <T, Color> setter, bool isSerializable = true) =>
 AddGenericAttr(AttributeType.HtmlColor, name, setter, isSerializable);
 public IPropertyItem AddEntry <TValue>(string virtualPropertyName, ValueGetterDelegate <TValue> getter, ValueSetterDelegate <TValue> setter)
 {
     return(childContext.AddEntry(virtualPropertyName, getter, wrapper.decorate(setter)));
 }
Example #28
0
 public AttributeHandler <T> AddVectorAttr(string name, ValueSetterDelegate <T, Vector4> setter, bool isSerializable = true) =>
 AddGenericAttr(AttributeType.VectorValue, name, setter, isSerializable);