コード例 #1
0
        public void RemovePropertyStringTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);

            AttachEvents(collection);

            Property prop1 = new StringProperty("test", "orange");
            Property prop2 = new StringProperty("two", "number");

            collection.Add(prop1);
            collection.Add(prop2);

            collection.PropertyRemoved += (s, e) =>
            {
                Assert.AreSame(prop1, e.Property);
                Assert.AreEqual(1, collection.Count);
                Assert.IsFalse(collection.Contains("test"));
                Assert.IsTrue(collection.Contains("two"));
                Assert.IsFalse(collection.Contains(prop1));
                Assert.IsTrue(collection.Contains(prop2));
            };

            _eventsFired = EventFlags.None;

            collection.Remove("test");

            Assert.AreEqual(EventFlags.PropertyRemoved | EventFlags.Modified, _eventsFired);
        }
コード例 #2
0
        public int getStability()
        {
            KeyValuePair <int, int> last = new KeyValuePair <int, int>(0, 0);
            int lastChange    = 0;
            int lastStability = 0;

            foreach (KeyValuePair <int, int> it in history)
            {
                PropertyCollection row = new PropertyCollection();
                row.Add(templateResultColumn.res_iteration, it.Key);
                row.Add(templateResultColumn.res_score, it.Value);
                int change    = it.Value - last.Value;
                int stability = lastStability;
                row.Add(templateResultColumn.res_change, change);
                if (it.Value > 0)
                {
                    if (change == lastChange)
                    {
                        stability++;
                    }
                    else
                    {
                        stability--;
                    }
                }
                row.Add(templateResultColumn.res_stability, stability);
                lastChange    = change;
                lastStability = stability;
                last          = it;
            }
            return(lastStability);
        }
コード例 #3
0
        public void ClearPropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);

            AttachEvents(collection);

            Property prop1 = new StringProperty("test", "orange");
            Property prop2 = new StringProperty("two", "number");

            collection.Add(prop1);
            collection.Add(prop2);

            int rmCount = 0;

            collection.PropertyRemoved += (s, e) =>
            {
                rmCount++;
            };

            _eventsFired = EventFlags.None;

            collection.Clear();

            Assert.AreEqual(EventFlags.PropertyRemoved | EventFlags.Modified, _eventsFired);
            Assert.AreEqual(2, rmCount);
            Assert.AreEqual(0, collection.Count);
        }
コード例 #4
0
        public void DataTableReaderTest()
        {
            ExecuteSQL("DROP TABLE IF EXISTS parent");
            ExecuteSQL("DROP TABLE IF EXISTS child");
            CreateTables();

            MySqlDataAdapter childDa = new MySqlDataAdapter("SELECT * FROM child", Connection);
            DataTable        childDt = new DataTable();

            childDa.FillSchema(childDt, SchemaType.Source);
            childDa.Fill(childDt);
            childDt.Columns["id"].Unique = true;

            using (DataTableReader dataTableReader = new DataTableReader(childDt))
            {
                Assert.True(dataTableReader.HasRows);
                Assert.AreEqual(3, dataTableReader.FieldCount);
            }

            PropertyCollection propertyCollection = childDt.ExtendedProperties;

            propertyCollection.Add("TimeStamp", DateTime.Now);
            propertyCollection.Add("Version", 1);

            CollectionAssert.IsNotEmpty(childDt.ExtendedProperties);
            Assert.AreEqual(2, childDt.ExtendedProperties.Count);
        }
コード例 #5
0
        private static int AddNewRandomizedMovementSpeed(ExportEntry bio_appr_character)
        {
            ImportEntry sfxMovementData = bio_appr_character.FileRef.FindImport("SFXGame.SFXMovementData");

            if (sfxMovementData == null)
            {
                // Import needs added

                // ME2 SPECIFIC!
                sfxMovementData = EntryImporter.GetOrAddCrossImportOrPackageFromGlobalFile("SFXMovementData", MEPackageHandler.OpenMEPackage(MERFileSystem.GetPackageFile("SFXGame.pcc")), bio_appr_character.FileRef) as ImportEntry;
            }

            PropertyCollection props = new PropertyCollection();

            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(70, 210) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "WalkSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(200, 700) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "GroundSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(50, 900) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "TurnSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(100, 320) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "CombatWalkSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(10, 470) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "CombatGroundSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(100, 380) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "CoverGroundSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(60, 180) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "CoverCrouchGroundSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(300, 900) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "StormSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(25, 75) + (ThreadSafeRandom.Next(10) == 0 ? 20 : 0), "StormTurnSpeed"));
            props.Add(new FloatProperty(ThreadSafeRandom.NextFloat(250, 1250) + (ThreadSafeRandom.Next(10) == 0 ? 100 : 0), "AccelRate"));

            var export = new ExportEntry(bio_appr_character.FileRef, null, new NameReference("ME2RMovementData", ThreadSafeRandom.Next(200000)), properties: props)
            {
                Class   = sfxMovementData,
                idxLink = bio_appr_character.FileRef.Exports.First(x => x.ClassName == "Package").UIndex,
            };

            bio_appr_character.FileRef.AddExport(export);
            return(export.UIndex);
        }
コード例 #6
0
        protected virtual void ReadDetail(XPathNavigator navigator, PropertyCollection collection, ReadingJournal journal)
        {
            Dictionary<string, string> attributes = GetAttributes(navigator);
            Type type = attributes["typeName"].ToType();

            if (type != typeof(ContentItem))
            {
                collection.Add(Parse(navigator.Value, type));
            }
            else
            {
                int referencedItemID = int.Parse(navigator.Value);
                ContentItem referencedItem = journal.Find(referencedItemID);
                if (referencedItem != null)
                    collection.Add(referencedItem);
                else
                    journal.ItemAdded += (sender, e) =>
            {
                if (e.AffectedItem.ID == referencedItemID)
                {
                    collection.Add(e.AffectedItem);
                }
            };
            }
        }
コード例 #7
0
#pragma warning disable CS1574 // XML comment has cref attribute 'Name' that could not be resolved
        /// <summary>
        /// From IEnumerable{Enum} makes <see cref="PropertyCollection" /> where Key is <see cref="Type.Name" /> and Value is the <see cref="Enum" /> or <see cref="Enum.ToString(string)" /> if <c>format</c> is specified
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="format">The format for .ToString() conversion of the <see cref="Enum"/> value. If it is not null but <c>empty</c> string: the value will be <see cref="Enum.ToString()"/>.</param>
        /// <returns></returns>
        public static PropertyCollection toPropertyCollection(this IEnumerable <Enum> source, String format = null)
#pragma warning restore CS1574 // XML comment has cref attribute 'Name' that could not be resolved
        {
            PropertyCollection output = new PropertyCollection();

            foreach (Enum en in source)
            {
                if (format != null)
                {
                    if (format == "")
                    {
                        output.Add(en.GetType().Name, en.toStringSafe());
                    }
                    else
                    {
                        output.Add(en.GetType().Name, en.ToString(format));
                    }
                }
                else
                {
                    output.Add(en.GetType().Name, en.toStringSafe());
                }
            }

            return(output);
        }
コード例 #8
0
        public static bool RandomizeExport(ExportEntry export, RandomizationOption option)
        {
            if (!CanRandomize(export))
            {
                return(false);
            }
            //Log.Information($@"Randomizing light {export.UIndex}");
            var lc = export.GetProperty <StructProperty>("LightColor");

            if (lc == null)
            {
                // create
                var pc = new PropertyCollection();
                pc.Add(new ByteProperty(255, "B"));
                pc.Add(new ByteProperty(255, "G"));
                pc.Add(new ByteProperty(255, "R"));
                pc.Add(new ByteProperty(0, "A"));

                lc = new StructProperty("Color", pc, "LightColor", true);
            }

            RStructs.RandomizeColor(lc, false);
            export.WriteProperty(lc);
            return(true);
        }
コード例 #9
0
 public bool getShowContext()
 {
     if (!localSettings.ContainsKey("SHOW_CONTEXT"))
     {
         localSettings.Add("SHOW_CONTEXT", System.Configuration.ConfigurationManager.AppSettings["SHOW_CONTEXT"]);
     }
     return(Boolean.Parse(localSettings["SHOW_CONTEXT"].ToString()));
 }
コード例 #10
0
        public void Property_Adds_Case_Insensitive_Compare()
        {
            var collection = new PropertyCollection();

            collection.Add(new Property(new PropertyType("propEditor", DataTypeDatabaseType.Nvarchar, "test")));
            collection.Add(new Property(new PropertyType("propEditor", DataTypeDatabaseType.Nvarchar, "Test")));

            Assert.AreEqual(1, collection.Count);
        }
コード例 #11
0
        public void AddDuplicateNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            Property           prop1      = new StringProperty("Name", "Treefrog");
            Property           prop2      = new StringProperty("Name", "Amphibian");

            collection.Add(prop1);
            collection.Add(prop2);
        }
コード例 #12
0
        public void AddDuplicateNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            Property prop1 = new StringProperty("Name", "Treefrog");
            Property prop2 = new StringProperty("Name", "Amphibian");

            collection.Add(prop1);
            collection.Add(prop2);
        }
コード例 #13
0
        private String getDropList(int val)
        {
            PropertyCollection plist = new PropertyCollection();

            plist.Add(new PropertyItem(lang("title"), 1));
            plist.Add(new PropertyItem(lang("author"), 2));

            return(Html.DropList(plist, "qtype", "Name", "Value", val));
        }
コード例 #14
0
        public static StructProperty ToRotatorStructProperty(this CIVector3 vector, string propName = null)
        {
            var pc = new PropertyCollection();

            pc.Add(new IntProperty(vector.X, "X"));
            pc.Add(new IntProperty(vector.Y, "Y"));
            pc.Add(new IntProperty(vector.Z, "Z"));
            return(new StructProperty("Rotator", pc, propName, true));
        }
コード例 #15
0
        public static PropertyCollection getDefaultStructValue(string className, bool stripTransients)
        {
            bool isImmutable = UnrealObjectInfo.IsImmutable(className, MEGame.ME1);

            if (Structs.ContainsKey(className))
            {
                ClassInfo info = Structs[className];
                try
                {
                    PropertyCollection structProps = new PropertyCollection();
                    ClassInfo          tempInfo    = info;
                    while (tempInfo != null)
                    {
                        foreach ((string propName, PropertyInfo propInfo) in tempInfo.properties)
                        {
                            if (stripTransients && propInfo.Transient)
                            {
                                continue;
                            }
                            if (getDefaultProperty(propName, propInfo, stripTransients, isImmutable) is UProperty uProp)
                            {
                                structProps.Add(uProp);
                            }
                        }
                        if (!Structs.TryGetValue(tempInfo.baseClass, out tempInfo))
                        {
                            tempInfo = null;
                        }
                    }
                    structProps.Add(new NoneProperty());

                    string filepath = Path.Combine(ME1Directory.gamePath, "BioGame", info.pccPath);
                    if (File.Exists(info.pccPath))
                    {
                        filepath = info.pccPath; //Used for dynamic lookup
                    }
                    if (File.Exists(filepath))
                    {
                        IMEPackage         importPCC    = MEPackageHandler.OpenME1Package(filepath);
                        var                exportToRead = importPCC.getUExport(info.exportIndex);
                        byte[]             buff         = exportToRead.Data.Skip(0x30).ToArray();
                        PropertyCollection defaults     = PropertyCollection.ReadProps(exportToRead, new MemoryStream(buff), className);
                        foreach (var prop in defaults)
                        {
                            structProps.TryReplaceProp(prop);
                        }
                    }
                    return(structProps);
                }
                catch
                {
                    return(null);
                }
            }
            return(null);
        }
コード例 #16
0
        public static StructProperty ToFourPartIntStruct(string structType, bool isImmutable, int val1, int val2, int val3, int val4, string name1, string name2, string name3, string name4, string structname = null)
        {
            PropertyCollection props = new PropertyCollection();

            props.Add(new IntProperty(val1, name1));
            props.Add(new IntProperty(val2, name2));
            props.Add(new IntProperty(val3, name3));
            props.Add(new IntProperty(val4, name4));
            return(new StructProperty(structType, props, structname, isImmutable));
        }
コード例 #17
0
        internal StructProperty ToStructProperty(string xName, string yName, string zName, string propName = null, bool isImmutable = true)
        {
            PropertyCollection props = new PropertyCollection();

            props.Add(new FloatProperty(X, xName));
            props.Add(new FloatProperty(Y, yName));
            props.Add(new FloatProperty(Z, zName));

            return(new StructProperty("Vector", props, propName, isImmutable));
        }
コード例 #18
0
        protected PropertyCollection makeData(Object btn_color, Object btn_size, String btn_caption, String btn_url = "")
        {
            PropertyCollection data = new PropertyCollection();

            data.Add(nameof(btn_color), btn_color);
            data.Add(nameof(btn_size), btn_size);
            data.Add(nameof(btn_caption), btn_caption);
            data.Add(nameof(btn_url), btn_url);
            data.Add("c", converterInsert);
            return(data);
        }
コード例 #19
0
        internal StructProperty ToStructProperty()
        {
            PropertyCollection props = new PropertyCollection();

            props.Add(new FloatProperty(InVal, "InVal"));
            props.Add(OutVal.ToStructProperty("X", "Y", "Z", "OutVal"));
            props.Add(ArriveTangent.ToStructProperty("X", "Y", "Z", "ArriveTangent"));
            props.Add(LeaveTangent.ToStructProperty("X", "Y", "Z", "LeaveTangent"));
            props.Add(new EnumProperty(InterpMode.ToString(), "EInterpCurveMode", MERFileSystem.Game, "InterpMode"));
            return(new StructProperty("nterpCurvePointVector", props));
        }
コード例 #20
0
        public void RenameDuplicateNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            Property           prop1      = new StringProperty("Author", "Treefrog");
            Property           prop2      = new StringProperty("Developer", "Justin");

            collection.Add(prop1);
            collection.Add(prop2);

            prop1.Name = "Developer";
        }
コード例 #21
0
        public void SetUp()
        {
            _injector = new Injector();

            _properties = new PropertyCollection();
            _properties.Add(new Property("scriptkey1", "scriptvalue1"));
            _properties.Add(new Property("foo", "scriptbar"));
            _properties.Add(new Property("thing", "key1"));
            _properties.Add(new Property("foo", "globalbar"));
            _properties.Add(new Property("globalkey1", "globalvalue1"));
        }
コード例 #22
0
        private static PropertyCollection getOptions()
        {
            PropertyCollection p = new PropertyCollection();

            p.Add(new PropertyItem(lang.get("privacySelf"), 0));
            p.Add(new PropertyItem(lang.get("privacyFriend"), 1));
            p.Add(new PropertyItem(lang.get("privacyLoggedUser"), 2));
            p.Add(new PropertyItem(lang.get("privacyEveryone"), 3));

            return(p);
        }
コード例 #23
0
        private static void InstallDynamicAnimSetRefForSkeletalMesh(ExportEntry export, RBioEvtSysTrackGesture.Gesture gesture)
        {
            // We have parent sequence data
            var skmDynamicAnimSets = export.GetProperty <ArrayProperty <ObjectProperty> >("AnimSets") ?? new ArrayProperty <ObjectProperty>("AnimSets");

            // Check to see if there is any item that uses our bioanimset
            var bioAnimSet = gesture.GetBioAnimSet(export.FileRef);

            if (bioAnimSet != null)
            {
                ExportEntry skmBioDynamicAnimSet = null;
                foreach (var skmDynAnimSet in skmDynamicAnimSets)
                {
                    var kEntry        = skmDynAnimSet.ResolveToEntry(export.FileRef) as ExportEntry; // I don't think these can be imports as they're part of the seq
                    var associatedset = kEntry.GetProperty <ObjectProperty>("m_pBioAnimSetData").ResolveToEntry(export.FileRef);
                    if (associatedset == bioAnimSet)
                    {
                        // It's this one
                        skmBioDynamicAnimSet = kEntry;
                        break;
                    }
                }

                if (skmBioDynamicAnimSet == null)
                {
                    // We need to generate a new one
                    PropertyCollection props = new PropertyCollection();
                    props.Add(new NameProperty(gesture.GestureSet, "m_nmOrigSetName"));
                    props.Add(new ArrayProperty <ObjectProperty>("Sequences"));
                    props.Add(new ObjectProperty(bioAnimSet, "m_pBioAnimSetData"));
                    skmBioDynamicAnimSet = ExportCreator.CreateExport(export.FileRef, $"BioDynamicAnimSet", "BioDynamicAnimSet", export);

                    // Write a blank count of 0 - we will update this in subsequent call
                    // This must be here to ensure parser can read it
                    skmBioDynamicAnimSet.WritePropertiesAndBinary(props, new byte[4]);
                    skmDynamicAnimSets.Add(new ObjectProperty(skmBioDynamicAnimSet)); // Add new export to sequence's list of biodynamicanimsets
                    export.WriteProperty(skmDynamicAnimSets);
                }

                var currentObjs = skmBioDynamicAnimSet.GetProperty <ArrayProperty <ObjectProperty> >("Sequences");
                if (currentObjs.All(x => x.Value != gesture.Entry.UIndex))
                {
                    // We need to add our item to it
                    currentObjs.Add(new ObjectProperty(gesture.Entry));
                    var bin = ObjectBinary.From <BioDynamicAnimSet>(skmBioDynamicAnimSet);
                    bin.SequenceNamesToUnkMap[gesture.GestureAnim] = 1; // Not sure what the value should be, or if game actually reads this
                    // FIX IT IF WE EVER FIGURE IT OUT!
                    skmBioDynamicAnimSet.WriteProperty(currentObjs);
                    skmBioDynamicAnimSet.WriteBinary(bin);
                }
            }
        }
コード例 #24
0
        public int VerifyEmployee(string name, string passWord)
        {
            PropertyCollection _fields = new PropertyCollection();

            _fields.Add("name", name);
            _fields.Add("passWord", passWord);

            ExecuteDelete("JNyulu.VerifyEmployee", _fields);

            int _id = (int)_fields["id"];

            return(_id);
        }
コード例 #25
0
        public static void SetRotation(ExportEntry export, float newDirectionDegrees)
        {
            StructProperty prop = export.GetProperty <StructProperty>("rotation");

            if (prop == null)
            {
                PropertyCollection p = new PropertyCollection();
                p.Add(new IntProperty(0, "Pitch"));
                p.Add(new IntProperty(0, "Yaw"));
                p.Add(new IntProperty(0, "Roll"));
                prop = new StructProperty("Rotator", p, "Rotation", true);
            }
            SetRotation(prop, newDirectionDegrees);
            export.WriteProperty(prop);
        }
コード例 #26
0
        public void AddReservedNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[] { "Name" });
            Property           prop       = new StringProperty("Name", "Treefrog");

            collection.Add(prop);
        }
コード例 #27
0
        /// <summary>
        /// Adds or replaces values of existing with values from data. Overwrite is off if <c>skipExistingKeys</c> is TRUE
        /// </summary>
        /// <param name="existing">Collection to modify</param>
        /// <param name="data">input data</param>
        /// <param name="skipExistingKeys">on TRUE it will not replace existing values</param>
        /// <returns>Number of newly added key/value pairs. -1 if <c>data</c> is <c>null</c></returns>
        /// \ingroup_disabled ace_ext_collections
        public static Int32 AddRange(this PropertyCollection existing, PropertyCollection data, Boolean skipExistingKeys = false)
        {
            Int32 c = 0;

            if (data == null)
            {
                return(-1);
            }
            if (existing == data)
            {
                return(-1);
            }
            foreach (DictionaryEntry input in data)
            {
                if (existing.ContainsKey(input.Key))
                {
                    if (!skipExistingKeys)
                    {
                        //c++;
                        existing[input.Key] = input.Value;
                    }
                }
                else
                {
                    c++;
                    existing.Add(input.Key, input.Value);
                }
            }
            return(c);
        }
コード例 #28
0
        public void ModifyPropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);

            AttachEvents(collection);

            StringProperty prop = new StringProperty("test", "orange");

            collection.PropertyModified += (s, e) =>
            {
                Assert.AreSame(prop, e.Property);
                Assert.AreEqual(1, collection.Count);
                Assert.IsTrue(collection.Contains("test"));
                Assert.IsTrue(collection.Contains(prop));
                Assert.AreEqual("blue", e.Property.ToString());
            };

            collection.Add(prop);

            _eventsFired = EventFlags.None;

            prop.Value = "blue";

            Assert.AreEqual(EventFlags.PropertyModified | EventFlags.Modified, _eventsFired);
        }
コード例 #29
0
#pragma warning disable CS1574 // XML comment has cref attribute 'isKeyValueColumn(imbSCI.Data.collection.PropertyEntryColumn)' that could not be resolved
        /// <summary>
        /// Get all non value (<see cref="aceCommonTypes.extensions.data.PropertyEntryColumnExtensions.isKeyValueColumn(imbSCI.Data.collection.PropertyEntryColumn)"/> columns into <see cref="PropertyCollection"/>
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public PropertyCollection GetMetaForKey(Object key)
#pragma warning restore CS1574 // XML comment has cref attribute 'isKeyValueColumn(imbSCI.Data.collection.PropertyEntryColumn)' that could not be resolved
        {
            var                pe     = entries[key];
            Object             input  = null;
            PropertyCollection output = new PropertyCollection();

            foreach (DictionaryEntry pair in pe)
            {
                input = pair.Value;
                Boolean copyOk = true;
                if (input is PropertyEntryColumn)
                {
                    PropertyEntryColumn input_PropertyEntryColumn = (PropertyEntryColumn)input;
                    if (input_PropertyEntryColumn.isKeyValueColumn())
                    {
                        copyOk = false;
                    }
                }
                if (copyOk)
                {
                    output.Add(pair.Key, pair.Value);
                }
            }
            return(output);
        }
コード例 #30
0
        public override string ToString()
        {
            if (DisplayableStyles.Contains(Style))
            {
                PropertyCollection.Add(Style.ToString());
            }
            if (DisplayableSpaceVariations.Contains(Spacing))
            {
                PropertyCollection.Add(Spacing.ToString());
            }
            if (DisplayableAlignments.Contains(Alignment))
            {
                Attributes.Add(AlignmentAttributeKey, Alignment.ToString());
            }

            if (MakeSmall)
            {
                PropertyCollection.Add(SmallPropertyText);
            }
            if (IsVertical)
            {
                PropertyCollection.Add(VerticalPropertyText);
            }

            return(base.ToString());
        }
コード例 #31
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            _editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (_editorService != null)
            {
                if (context.Instance != null)
                {
                    // CR modifying to accomodate PropertyBag
                    Type   instanceType = null;
                    object objinfo      = null;
                    ContextHelper.GetContextInstanceObject(context, ref objinfo, ref instanceType);
                    var propInfo = instanceType.GetProperty("FindMethodsParameters");
                    var propColl = (PropertyCollection)propInfo.GetValue(objinfo, null);

                    var obj      = (CslaObjectInfo)objinfo;
                    var itemType = obj.ItemType;
                    if (!string.IsNullOrEmpty(itemType))
                    {
                        var info = GeneratorController.Current.CurrentUnit.CslaObjects.Find(itemType);
                        if (info != null)
                        {
                            var valueProps = info.ValueProperties;
                            if (valueProps.Count > 0)
                            {
                                _lstProperties.Items.Clear();
                                _lstProperties.Items.Add(new DictionaryEntry("(None)", new ValueProperty()));
                                for (int i = 0; i < valueProps.Count; i++)
                                {
                                    _lstProperties.Items.Add(new DictionaryEntry(valueProps[i].Name, valueProps[i]));
                                }
                                _lstProperties.Sorted = true;

                                foreach (var parentProp in propColl)
                                {
                                    _lstProperties.SelectedItems.Add(new DictionaryEntry(parentProp.Name, parentProp));
                                }

                                _lstProperties.SelectedIndexChanged += LstPropertiesSelectedIndexChanged;
                                _editorService.DropDownControl(_lstProperties);
                                _lstProperties.SelectedIndexChanged -= LstPropertiesSelectedIndexChanged;

                                if (_lstProperties.SelectedItems.Count > 0)
                                {
                                    var prop = new PropertyCollection();
                                    foreach (var item in _lstProperties.SelectedItems)
                                    {
                                        prop.Add((Property)((DictionaryEntry)item).Value);
                                    }
                                    return(prop);
                                }

                                return(new PropertyCollection());
                            }
                        }
                    }
                }
            }

            return(value);
        }
コード例 #32
0
        public void RenamePropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);

            AttachEvents(collection);

            StringProperty prop = new StringProperty("test", "orange");

            collection.PropertyRenamed += (s, e) =>
            {
                Assert.AreEqual("test", e.OldName);
                Assert.AreEqual("two", e.NewName);
                Assert.AreEqual(1, collection.Count);
                Assert.IsFalse(collection.Contains("test"));
                Assert.IsTrue(collection.Contains("two"));
                Assert.IsTrue(collection.Contains(prop));
            };

            collection.Add(prop);

            _eventsFired = EventFlags.None;

            prop.Name = "two";

            Assert.AreEqual(EventFlags.PropertyRenamed | EventFlags.Modified, _eventsFired);
        }
コード例 #33
0
            protected override IDataSetLexer HandleProperty(string propertyName, JsonReader reader)
            {
                var value = _serializer.Deserialize(reader);

                _properties.Add(propertyName, value);
                return(null);
            }
コード例 #34
0
 private static void AddBooleanProperty(string propertyName, bool value, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
 {
     PropertyDescriptor<bool> propertyDescriptor = propertyDescriptors[propertyName] as PropertyDescriptor<bool>;
     if (propertyDescriptor != null)
     {
         properties.Add(new BooleanProperty(propertyDescriptor, value));
     }
 }
コード例 #35
0
 private static void LoadBooleanProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
 {
     bool flag;
     if (bool.TryParse(propertyNode.InnerText, out flag))
     {
         PropertyDescriptor<bool> propertyDescriptor = propertyDescriptors[propertyName] as PropertyDescriptor<bool>;
         if (propertyDescriptor != null)
         {
             properties.Add(new BooleanProperty(propertyDescriptor, flag));
         }
     }
 }
コード例 #36
0
        public void AddPropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            Property prop = new StringProperty("test", "orange");

            collection.PropertyAdded += (s, e) =>
            {
                Assert.AreSame(prop, e.Property);
                Assert.AreEqual(1, collection.Count);
                Assert.IsTrue(collection.Contains("test"));
                Assert.IsTrue(collection.Contains(prop));
            };

            collection.Add(prop);

            Assert.AreEqual(EventFlags.PropertyAdded | EventFlags.Modified, _eventsFired);
        }
コード例 #37
0
 private static void LoadStringProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
 {
     PropertyDescriptor<string> propertyDescriptor = propertyDescriptors[propertyName] as PropertyDescriptor<string>;
     properties.Add(new StringProperty(propertyDescriptor, propertyNode.InnerText));
 }
コード例 #38
0
 private static void LoadIntProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
 {
     int num;
     if (int.TryParse(propertyNode.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out num))
     {
         PropertyDescriptor<int> propertyDescriptor = propertyDescriptors[propertyName] as PropertyDescriptor<int>;
         properties.Add(new IntProperty(propertyDescriptor, num));
     }
 }
コード例 #39
0
 private static void LoadCollectionProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
 {
     List<string> innerCollection = new List<string>();
     XmlNodeList list2 = propertyNode.SelectNodes("Value");
     if ((list2 != null) && (list2.Count > 0))
     {
         foreach (XmlNode node in list2)
         {
             if (!string.IsNullOrEmpty(node.InnerText))
             {
                 innerCollection.Add(node.InnerText);
             }
         }
     }
     if (innerCollection.Count > 0)
     {
         CollectionPropertyDescriptor propertyDescriptor = propertyDescriptors[propertyName] as CollectionPropertyDescriptor;
         CollectionProperty property = new CollectionProperty(propertyDescriptor, innerCollection);
         properties.Add(property);
     }
 }
コード例 #40
0
        private void readProperties(PropertyCollection properties, Type ownerType)
        {
            int count = _reader.ReadNumber();
            for (int i = 0; i < count; i++)
            {
                byte elementId = _reader.ReadElementId();

                string propertyName = _reader.ReadName();

                // estimating the propertyInfo
                PropertyInfo subPropertyInfo = ownerType.GetProperty(propertyName);

                Property subProperty = deserialize(elementId, propertyName, subPropertyInfo.PropertyType);
                properties.Add(subProperty);
            }
        }
コード例 #41
0
ファイル: TrackGenerator.cs プロジェクト: GarethIW/TriRace
        public static void Generate(Map gameMap)
        {
            const float deviation = 40f;

            List<Point> trackLine = new List<Point>();
            List<Point> innerTrack = new List<Point>();
            List<Point> outerTrack = new List<Point>();

            List<Point> controlPoints = new List<Point>();

            int mapWidth = gameMap.Width*gameMap.TileWidth;
            int mapHeight = gameMap.Height*gameMap.TileHeight;

            controlPoints.Add(new Point(0, mapHeight / 2) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));
            if (Helper.Random.Next(2) == 0)
                controlPoints.Add(new Point((mapWidth / 8) + Helper.Random.Next(mapWidth / 6), (mapHeight / 8) + Helper.Random.Next(mapHeight / 6)) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));
            controlPoints.Add(new Point(mapWidth/2, 0) + new Point(Helper.Random.Next((int) deviation) - ((int) deviation/2), Helper.Random.Next((int) deviation) - ((int) deviation/2)));
            if (Helper.Random.Next(2) == 0)
                controlPoints.Add(new Point(((mapWidth / 8) * 7) - Helper.Random.Next(mapWidth / 6), (mapHeight / 8) + Helper.Random.Next(mapHeight /6)) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));
            controlPoints.Add(new Point(mapWidth, mapHeight/2) + new Point(Helper.Random.Next((int) deviation) - ((int) deviation/2), Helper.Random.Next((int) deviation) - ((int) deviation/2)));
            if (Helper.Random.Next(2) == 0)
                controlPoints.Add(new Point(((mapWidth / 8) * 7) - Helper.Random.Next(mapWidth / 6), ((mapHeight / 8)*7) - Helper.Random.Next(mapHeight / 6)) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));
            controlPoints.Add(new Point(mapWidth/2, mapHeight) + new Point(Helper.Random.Next((int) deviation) - ((int) deviation/2), Helper.Random.Next((int) deviation) - ((int) deviation/2)));
            if (Helper.Random.Next(2) == 0)
                controlPoints.Add(new Point((mapWidth / 8) + Helper.Random.Next(mapWidth / 6), ((mapHeight / 8) * 7) - Helper.Random.Next(mapHeight / 6)) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));

            for (int i = 0; i < controlPoints.Count; i++)
            {
                trackLine.Add(controlPoints[i]);
                for (float d = 0.25f; d <= 0.75f; d += 0.25f)
                {
                    int nextPoint = i + 1;
                    if (nextPoint == controlPoints.Count) nextPoint = 0;
                    Vector2 newPoint = Vector2.Lerp(Helper.PtoV(controlPoints[i]), Helper.PtoV(controlPoints[nextPoint]),d);

                    newPoint.X = Helper.RandomFloat(newPoint.X - deviation, newPoint.X + deviation);
                    newPoint.Y = Helper.RandomFloat(newPoint.Y - deviation, newPoint.Y + deviation);

                    trackLine.Add(Helper.VtoP(newPoint));
                }
            }

            foreach (var p in trackLine)
            {
                float width = Helper.RandomFloat(0.8f, 0.95f);
                Point newP =  p - new Point(mapWidth/2,mapHeight/2);
                newP.X = (int)((float)newP.X * width);
                newP.Y = (int)((float)newP.Y * width);
                newP += new Point(mapWidth / 2, mapHeight / 2);
                innerTrack.Add(newP);
            }

            foreach (var p in trackLine)
            {
                float width = Helper.RandomFloat(1.05f, 1.2f);
                Point newP = p - new Point(mapWidth / 2, mapHeight / 2);
                newP.X = (int)((float)newP.X * width);
                newP.Y = (int)((float)newP.Y * width);
                newP += new Point(mapWidth / 2, mapHeight / 2);
                outerTrack.Add(newP);
            }

            var track = (MapObjectLayer)gameMap.GetLayer("Tris");
            for (int i = 0; i < trackLine.Count; i++)
            {
                float triDev = 5f;

                Vector2 start = Helper.PtoV(outerTrack[i]);
                Vector2 end = Helper.PtoV(i + 1 < outerTrack.Count ? outerTrack[i + 1] : outerTrack[0]);

                List<Point> polyPoints;

                float up = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) - MathHelper.PiOver2;
                float down = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + MathHelper.PiOver2;
                Vector2 startdownvect = Helper.PointOnCircle(start, 3f, down);
                Vector2 enddownvect = Helper.PointOnCircle(end, 3f, down);
                Vector2 startupvect = Helper.PointOnCircle(start, 3f, up);
                Vector2 endupvect = Helper.PointOnCircle(end, 3f, up);
                polyPoints = new List<Point>
                    {
                        Helper.VtoP(startdownvect),
                        Helper.VtoP(startupvect),
                        Helper.VtoP(enddownvect)
                    };
                track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                polyPoints = new List<Point>
                    {
                        Helper.VtoP(startupvect),
                        Helper.VtoP(endupvect),
                        Helper.VtoP(enddownvect)
                    };
                track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                for (float d = 0f; d <1f; d += 0.1f)
                {
                    Vector2 p1 = Vector2.Lerp(start, end, MathHelper.Clamp(d + Helper.RandomFloat(-0.3f, -0.1f), 0f, 1f));// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    Vector2 p2 = Vector2.Lerp(start, end, MathHelper.Clamp(d + Helper.RandomFloat(0.1f, 0.3f), 0f, 1f));// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    float a = (float) Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) + Helper.RandomFloat((-MathHelper.PiOver2-MathHelper.PiOver4),-MathHelper.PiOver4);
                    Vector2 off = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(10f, 60f), a);
                    off += new Vector2(Helper.RandomFloat(-triDev*5f, triDev*5f), Helper.RandomFloat(-triDev*10f, triDev*10f));

                    polyPoints = new List<Point>
                    {
                        Helper.VtoP(p1),
                        Helper.VtoP(p2),
                        Helper.VtoP(off)
                    };
                    track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat((-MathHelper.PiOver2 - MathHelper.PiOver4), -MathHelper.PiOver4);
                    p1 = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(0f, 20f), a);// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat((-MathHelper.PiOver2 - MathHelper.PiOver4), -MathHelper.PiOver4);
                    p2 = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(20f, 150f), a);// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    //p2 += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));
                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat((-MathHelper.PiOver2 - MathHelper.PiOver4), -MathHelper.PiOver4);
                    off = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(20f, 150f), a);
                    //off += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));

                    polyPoints = new List<Point>
                    {
                        Helper.VtoP(p1),
                        Helper.VtoP(p2),
                        Helper.VtoP(off)
                    };
                    //track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));
                }

                start = Helper.PtoV(innerTrack[i]);
                end = Helper.PtoV(i + 1 < innerTrack.Count ? innerTrack[i + 1] : innerTrack[0]);

                up = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) - MathHelper.PiOver2;
                down = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + MathHelper.PiOver2;
                startdownvect = Helper.PointOnCircle(start, 3f, down);
                enddownvect = Helper.PointOnCircle(end, 3f, down);
                startupvect = Helper.PointOnCircle(start, 3f, up);
                endupvect = Helper.PointOnCircle(end, 3f, up);
                polyPoints = new List<Point>
                    {
                        Helper.VtoP(startdownvect),
                        Helper.VtoP(startupvect),
                        Helper.VtoP(enddownvect)
                    };
                track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                polyPoints = new List<Point>
                    {
                        Helper.VtoP(startupvect),
                        Helper.VtoP(endupvect),
                        Helper.VtoP(enddownvect)
                    };
                track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                for (float d = 0f; d < 1f; d += 0.1f)
                {
                    Vector2 p1 = Vector2.Lerp(start, end, MathHelper.Clamp(d + Helper.RandomFloat(-0.3f, -0.1f), 0f, 1f));// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    Vector2 p2 = Vector2.Lerp(start, end, MathHelper.Clamp(d + Helper.RandomFloat(0.1f, 0.3f), 0f, 1f));// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    float a = (float)Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) + Helper.RandomFloat(MathHelper.PiOver4, MathHelper.PiOver4+MathHelper.PiOver4);
                    Vector2 off = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(10f, 60f), a);
                    off += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));

                    polyPoints = new List<Point>
                    {
                        Helper.VtoP(p1),
                        Helper.VtoP(p2),
                        Helper.VtoP(off)
                    };
                    track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat(MathHelper.PiOver2-0.1f, MathHelper.PiOver2 + 0.1f);
                    p1 = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(0f, 20f), a);// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat(MathHelper.PiOver2 - 0.1f, MathHelper.PiOver2 + 0.1f);
                    p2 = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(20f, 100f), a);// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    //p2 += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));
                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat(MathHelper.PiOver2 - 0.1f, MathHelper.PiOver2 + 0.1f);
                    off = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(20f, 100f), a);
                    //off += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));

                    polyPoints = new List<Point>
                    {
                        Helper.VtoP(p1),
                        Helper.VtoP(p2),
                        Helper.VtoP(off)
                    };
                    //track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));
                }

                //polyPoints = new List<Point>
                //{
                //    trackLine[i],
                //    trackLine[i]+new Point(2,0),
                //    i+1<trackLine.Count?trackLine[i+1]:trackLine[0]
                //};

                //track.Objects.Add(new MapObject("", "", new Rectangle(trackLine[i].X, trackLine[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                //polyPoints = new List<Point>
                //{
                //    innerTrack[i],
                //    innerTrack[i]+new Point(2,0),
                //    i+1<innerTrack.Count?innerTrack[i+1]:innerTrack[0]
                //};

                //track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                //polyPoints = new List<Point>
                //{
                //    outerTrack[i],
                //    outerTrack[i]+new Point(2,0),
                //    i+1<outerTrack.Count?outerTrack[i+1]:outerTrack[0]
                //};

                //track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));
            }

            Vector2 spawn = Vector2.Lerp(Helper.PtoV(trackLine[0]), Helper.PtoV(trackLine[1]), 0.5f);
            float spawnDir = (float)Math.Atan2(Helper.PtoV(trackLine[1]).Y - Helper.PtoV(trackLine[0]).Y, Helper.PtoV(trackLine[1]).X - Helper.PtoV(trackLine[0]).X);
            var spawnLayer = ((MapObjectLayer)gameMap.GetLayer("Spawn"));
            PropertyCollection props = new PropertyCollection();
            props.Add("rot", spawnDir.ToString());
            spawnLayer.Objects.Add(new MapObject("","",new Rectangle((int)spawn.X,(int)spawn.Y,0,0), null,null, props));
        }
コード例 #42
0
        /// <summary>
        /// Loads and stores an integer property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void LoadIntProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Skip corrupted properties.
            int value;
            if (int.TryParse(propertyNode.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
            {
                // Get the property descriptor.
                PropertyDescriptor<int> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor<int>;

                // Create and add the property.
                properties.Add(new IntProperty(descriptor, value));
            }
        }
コード例 #43
0
        public void RenameReservedNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[] { "Name" });
            Property prop = new StringProperty("Author", "Treefrog");
            collection.Add(prop);

            prop.Name = "Name";
        }
コード例 #44
0
 private static void MergeCollectionProperties(PropertyCollection mergedPropertyCollection, PropertyValue originalProperty, PropertyValue overridingProperty)
 {
     CollectionProperty property = (CollectionProperty) originalProperty;
     CollectionProperty property2 = (CollectionProperty) overridingProperty;
     CollectionProperty property3 = new CollectionProperty((CollectionPropertyDescriptor) property.PropertyDescriptor);
     mergedPropertyCollection.Add(property3);
     foreach (string str in property2.Values)
     {
         property3.Add(str);
     }
     if (property.Aggregate)
     {
         foreach (string str2 in property.Values)
         {
             if (!property3.Contains(str2))
             {
                 property3.Add(str2);
             }
         }
     }
 }
コード例 #45
0
        /// <summary>
        /// Adds a boolean property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property.
        /// </param>
        /// <param name="value">
        /// The property value.
        /// </param>
        /// <param name="properties">
        /// The collection of properties.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void AddBooleanProperty(string propertyName, bool value, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.Ignore(value);
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Get the property descriptor.
            PropertyDescriptor<bool> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor<bool>;
            if (descriptor != null)
            {
                // Create and add the property.
                properties.Add(new BooleanProperty(descriptor, value));
            }
        }
コード例 #46
0
        /// <summary>
        /// Merged two sets of property collections together.
        /// </summary>
        /// <param name="originalPropertyCollection">
        /// The original property collection.
        /// </param>
        /// <param name="overridingPropertyCollection">
        /// The overriding property collection.
        /// </param>
        /// <param name="mergedPropertyCollection">
        /// The merged property collection.
        /// </param>
        internal static void MergePropertyCollections(
            PropertyCollection originalPropertyCollection, PropertyCollection overridingPropertyCollection, PropertyCollection mergedPropertyCollection)
        {
            Param.Ignore(originalPropertyCollection);
            Param.Ignore(overridingPropertyCollection);
            Param.AssertNotNull(mergedPropertyCollection, "mergedPropertyCollection");

            // The merge is based on whether one or both files are present.
            if (originalPropertyCollection == null && overridingPropertyCollection != null)
            {
                // There are no settings in the original settings file, only settings from the overriding file.
                foreach (PropertyValue property in overridingPropertyCollection)
                {
                    mergedPropertyCollection.Add(property.Clone());
                }
            }
            else if (originalPropertyCollection != null && overridingPropertyCollection == null)
            {
                // There are no settings from the overriding settings file, only settings from the original file.
                foreach (PropertyValue property in originalPropertyCollection)
                {
                    // Only take a property from the original collection if the property is supposed to be merged.
                    if (property.PropertyDescriptor.Merge)
                    {
                        mergedPropertyCollection.Add(property.Clone());
                    }
                }
            }
            else if (originalPropertyCollection != null && overridingPropertyCollection != null)
            {
                // There are settings in both settings files. Fist, loop through each property collection 
                // in the original settings file.
                foreach (PropertyValue originalProperty in originalPropertyCollection)
                {
                    if (originalProperty.PropertyDescriptor.Merge)
                    {
                        // Try to find a corresponding property in the overriding settings file.
                        PropertyValue overridingProperty = overridingPropertyCollection[originalProperty.PropertyName];
                        if (overridingProperty == null)
                        {
                            // There is no corresponding overriding property. Just add the original property.
                            mergedPropertyCollection.Add(originalProperty.Clone());
                        }
                        else
                        {
                            // Merge the two property value collections together depending on the property type.
                            switch (originalProperty.PropertyType)
                            {
                                case PropertyType.Int:
                                case PropertyType.String:
                                case PropertyType.Boolean:
                                    mergedPropertyCollection.Add(overridingProperty.Clone());
                                    break;

                                case PropertyType.Collection:
                                    MergeCollectionProperties(mergedPropertyCollection, originalProperty, overridingProperty);
                                    break;

                                default:
                                    Debug.Fail("Unexpected property type.");
                                    break;
                            }
                        }
                    }
                }

                // Now look through each property in the overriding property collection. If there is any 
                // property here which is not contained in the merged collection, just add it directly.
                // This means that it was not present in the original collection.
                foreach (PropertyValue overridingProperty in overridingPropertyCollection)
                {
                    PropertyValue mergedProperty = mergedPropertyCollection[overridingProperty.PropertyName];
                    if (mergedProperty == null)
                    {
                        mergedPropertyCollection.Add(overridingProperty.Clone());
                    }
                }
            }

            mergedPropertyCollection.IsReadOnly = true;
        }
コード例 #47
0
        public void RenamePropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            StringProperty prop = new StringProperty("test", "orange");

            collection.PropertyRenamed += (s, e) =>
            {
                Assert.AreEqual("test", e.OldName);
                Assert.AreEqual("two", e.NewName);
                Assert.AreEqual(1, collection.Count);
                Assert.IsFalse(collection.Contains("test"));
                Assert.IsTrue(collection.Contains("two"));
                Assert.IsTrue(collection.Contains(prop));
            };

            collection.Add(prop);

            _eventsFired = EventFlags.None;

            prop.Name = "two";

            Assert.AreEqual(EventFlags.PropertyRenamed | EventFlags.Modified, _eventsFired);
        }
コード例 #48
0
 public void AddNullPropertyTest()
 {
     PropertyCollection collection = new PropertyCollection(new string[0]);
     collection.Add(null);
 }
コード例 #49
0
 public void AddReservedNameTest()
 {
     PropertyCollection collection = new PropertyCollection(new string[] { "Name" });
     Property prop = new StringProperty("Name", "Treefrog");
     collection.Add(prop);
 }
コード例 #50
0
        private void ReadProperties(PropertyCollection properties, Type ownerType)
        {
            var count = _reader.ReadNumber();
            for (var i = 0; i < count; i++) {
                var elementId = _reader.ReadElementId();

                var propertyName = _reader.ReadName();

                // estimating the propertyInfo
                var subPropertyInfo = ownerType.GetProperty(propertyName);
                var propertyType = subPropertyInfo != null ? subPropertyInfo.PropertyType : null;
                var subProperty = deserialize(elementId, propertyName, propertyType);
                properties.Add(subProperty);
            }
        }
コード例 #51
0
        /// <summary>
        /// Loads and stores a boolean property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void LoadBooleanProperty(
            string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Skip corrupted properties.
            bool value;
            if (bool.TryParse(propertyNode.InnerText, out value))
            {
                // Get the property descriptor.
                PropertyDescriptor<bool> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor<bool>;

                if (descriptor != null)
                {
                    // Create and add the property.
                    properties.Add(new BooleanProperty(descriptor, value));
                }
            }
        }
コード例 #52
0
        private void readProperties(PropertyCollection properties, Type ownerType)
        {
            foreach (string subElement in _reader.ReadSubElements())
            {
                PropertyArt propertyArt = getPropertyArtFromString(subElement);
                if (propertyArt != PropertyArt.Unknown)
                {
                    // check if the property with the name exists
                    string subPropertyName = _reader.GetAttributeAsString(Attributes.Name);
                    if (string.IsNullOrEmpty(subPropertyName)) continue;

                    // estimating the propertyInfo
                    PropertyInfo subPropertyInfo = ownerType.GetProperty(subPropertyName);
                    if (subPropertyInfo != null)
                    {
                        Property subProperty = deserialize(propertyArt, subPropertyInfo.PropertyType);
                        properties.Add(subProperty);
                    }
                }
            }
        }
コード例 #53
0
        /// <summary>
        /// Merges two collection properties together.
        /// </summary>
        /// <param name="mergedPropertyCollection">
        /// The merged property collection.
        /// </param>
        /// <param name="originalProperty">
        /// The original property to merge.
        /// </param>
        /// <param name="overridingProperty">
        /// The overriding property to merge.
        /// </param>
        private static void MergeCollectionProperties(PropertyCollection mergedPropertyCollection, PropertyValue originalProperty, PropertyValue overridingProperty)
        {
            Param.AssertNotNull(mergedPropertyCollection, "mergedPropertyCollection");
            Param.AssertNotNull(originalProperty, "originalProperty");
            Param.AssertNotNull(overridingProperty, "overridingProperty");

            CollectionProperty originalCollectionProperty = (CollectionProperty)originalProperty;
            CollectionProperty overridingCollectionProperty = (CollectionProperty)overridingProperty;

            // Create a new merged collection property.
            CollectionProperty mergedCollectionProperty = new CollectionProperty((CollectionPropertyDescriptor)originalCollectionProperty.PropertyDescriptor);
            mergedPropertyCollection.Add(mergedCollectionProperty);

            // Add each of the strings from the overriding collection.
            foreach (string value in overridingCollectionProperty.Values)
            {
                mergedCollectionProperty.Add(value);
            }

            // If necessary, also add the strings from the original collection.
            if (originalCollectionProperty.Aggregate)
            {
                foreach (string value in originalCollectionProperty.Values)
                {
                    if (!mergedCollectionProperty.Contains(value))
                    {
                        mergedCollectionProperty.Add(value);
                    }
                }
            }
        }
コード例 #54
0
ファイル: Map.cs プロジェクト: GarethIW/LDEngine
        //private Layer collisionLayer;
        // Construct a TiledLib.Map from a TmxReader.map
        public Map(ContentManager content, string mapName)
        {
            string mapPath = AppDomain.CurrentDomain.BaseDirectory +
                "Content/" +
                mapName +
                ".tmx";

            TmxMap tmx = new TmxMap(mapPath);

            Version = new Version(tmx.Version);

            switch(tmx.Orientation)
            {
                case TmxMap.OrientationType.Isometric:
                    Orientation = Orientation.Isometric;
                    break;
                case TmxMap.OrientationType.Orthogonal:
                    Orientation = Orientation.Orthogonal;
                    break;
                case TmxMap.OrientationType.Staggered:
                    throw new Exception(
                        "TiledLib doesn't support maps with Staggered " +
                        "orientation.");
            }

            Width = tmx.Width;
            Height = tmx.Height;
            TileWidth = tmx.TileWidth;
            TileHeight = tmx.TileHeight;

            Properties = new PropertyCollection();
            foreach(KeyValuePair<string, string> kvp in tmx.Properties)
            {
                Properties.Add(kvp);
            }

            // Create a list for our tiles
            List<Tile> tiles = new List<Tile>();
            Tiles = new Collection<Tile>(tiles);

            // Read in each TileSet
            foreach (TmxTileset ts in tmx.Tilesets)
            {
                string tilesetName = ts.Name;
                Texture2D texture = content.Load<Texture2D>(ts.Image.Source);

                bool collisionSet = ts.Properties.ContainsKey("CollisionSet") &&
                    ts.Properties["CollisionSet"] == "True" ?
                    true : false;

                /* TODO:  Add this intelligence to TiledSharp.
                 * If the texture is bigger than a individual tile, infer all the
                 * additional tiles that must be created.
                 */

                if (texture.Width > ts.TileWidth || texture.Height > ts.TileHeight)
                {
                    // Deconstruct tileset to individual tiles
                    int id = 0;
                    for (int y = 0; y < texture.Height / ts.TileHeight; y++)
                    {
                        for (int x = 0; x < texture.Width / ts.TileWidth; x++)
                        {
                            Rectangle source = new Rectangle(
                                x * ts.TileWidth,
                                y * ts.TileHeight,
                                ts.TileWidth,
                                ts.TileHeight
                            );

                            Color[] collisionData = null;
                            bool[] collisionBitData = null;
                            PropertyCollection props = new PropertyCollection();

                            TmxTilesetTile tsTile = ts.Tiles.Find(i => i.Id == id);
                            if(tsTile != null)
                            {
                                foreach (KeyValuePair<string, string> kvp in
                                    tsTile.Properties)
                                {
                                    props.Add(kvp);

                                    // Inherit tilesets collision
                                    bool collidable = collisionSet;
                                    if (kvp.Key == "CollisionSet")
                                    {
                                        // Allow override per tile
                                        if (kvp.Value == "True")
                                        {
                                            collidable = true;
                                        } else
                                        {
                                            collidable = false;
                                        }
                                    }
                                    if (collidable)
                                    {
                                        int numOfBytes = ts.TileWidth * ts.TileHeight;
                                        collisionData = new Color[numOfBytes];
                                        collisionBitData = new bool[numOfBytes];

                                        texture.GetData<Color>(
                                            0,
                                            source,
                                            collisionData,
                                            0,
                                            numOfBytes
                                        );

                                        for (int col = 0; col < numOfBytes; col++)
                                        {
                                            if (collisionData[col].A > 0)
                                            {
                                                collisionBitData[col] = true;
                                            }
                                        }
                                        collisionData = null;
                                    }
                                }
                            }

                            Tile t = new Tile(
                                texture,
                                source,
                                props,
                                collisionBitData
                            );

                            while (id >= tiles.Count)
                            {
                                tiles.Add(null);
                            }
                            tiles.Insert(id + ts.FirstGid, t);
                            id++;
                        }
                    }
                }
            }

            // Process Map Items (layers, objectgroups, etc.)
            List<Layer> layers = new List<Layer>();
            Layers = new Collection<Layer>(layers);

            foreach(TmxLayer l in tmx.Layers)
            {
                Layer layer = null;

                PropertyCollection props = new PropertyCollection();
                foreach(KeyValuePair<string, string> kvp in l.Properties)
                {
                    props.Add(kvp);
                }

                layer = new TileLayer(
                    l.Name,
                    tmx.Width,  // As of TiledQT always same as layer.
                    tmx.Height, // As of TiledQT always same as layer.
                    l.Visible,
                    (float) l.Opacity,
                    props,
                    this,
                    l.Tiles
                );
                layers.Add(layer);
                namedLayers.Add(l.Name, layer);
            }

            foreach(TmxObjectGroup og in tmx.ObjectGroups)
            {
                Layer layer = null;

                PropertyCollection props = new PropertyCollection();
                foreach(KeyValuePair<string, string> kvp in og.Properties)
                {
                    props.Add(kvp);
                }

                List<MapObject> objects = new List<MapObject>();

                // read in all of our objects
                foreach(TmxObjectGroup.TmxObject i in og.Objects)
                {
                    Rectangle objLoc = new Rectangle(
                        i.X,
                        i.Y,
                        i.Width,
                        i.Height
                    );

                    List<Point> objPoints = new List<Point>();
                    if (i.Points != null)
                    {
                        foreach (Tuple<int, int> tuple in i.Points)
                        {
                            objPoints.Add(new Point(tuple.Item1, tuple.Item2));
                        }
                    }

                    PropertyCollection objProps = new PropertyCollection();
                    foreach(KeyValuePair<string, string> kvp in i.Properties)
                    {
                        objProps.Add(kvp);
                    }

                    objects.Add(
                        new MapObject(
                            i.Name,
                            i.Type,
                            objLoc,
                            objPoints,
                            objProps)
                    );
                }

                layer = new MapObjectLayer(
                    og.Name,
                    tmx.Width,
                    tmx.Height,
                    og.Visible,
                    (float) og.Opacity,
                    props,
                    objects
                );

                layers.Add(layer);
                namedLayers.Add(og.Name, layer);
            }
        }
コード例 #55
0
        internal static void MergePropertyCollections(PropertyCollection originalPropertyCollection, PropertyCollection overridingPropertyCollection, PropertyCollection mergedPropertyCollection)
        {
            if ((originalPropertyCollection == null) && (overridingPropertyCollection != null))
            {
                foreach (PropertyValue value2 in overridingPropertyCollection)
                {
                    mergedPropertyCollection.Add(value2.Clone());
                }
            }
            else if ((originalPropertyCollection != null) && (overridingPropertyCollection == null))
            {
                foreach (PropertyValue value3 in originalPropertyCollection)
                {
                    if (value3.PropertyDescriptor.Merge)
                    {
                        mergedPropertyCollection.Add(value3.Clone());
                    }
                }
            }
            else if ((originalPropertyCollection != null) && (overridingPropertyCollection != null))
            {
            Label_0109:
                foreach (PropertyValue value4 in originalPropertyCollection)
                {
                    if (value4.PropertyDescriptor.Merge)
                    {
                        PropertyValue overridingProperty = overridingPropertyCollection[value4.PropertyName];
                        if (overridingProperty == null)
                        {
                            mergedPropertyCollection.Add(value4.Clone());
                        }
                        else
                        {
                            switch (value4.PropertyType)
                            {
                                case PropertyType.String:
                                case PropertyType.Boolean:
                                case PropertyType.Int:
                                    mergedPropertyCollection.Add(overridingProperty.Clone());
                                    goto Label_0109;

                                case PropertyType.Collection:
                                    MergeCollectionProperties(mergedPropertyCollection, value4, overridingProperty);
                                    goto Label_0109;
                            }
                        }
                    }
                }
                foreach (PropertyValue value6 in overridingPropertyCollection)
                {
                    if (mergedPropertyCollection[value6.PropertyName] == null)
                    {
                        mergedPropertyCollection.Add(value6.Clone());
                    }
                }
            }
            mergedPropertyCollection.IsReadOnly = true;
        }
コード例 #56
0
        public void RenameDuplicateNameTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            Property prop1 = new StringProperty("Author", "Treefrog");
            Property prop2 = new StringProperty("Developer", "Justin");
            collection.Add(prop1);
            collection.Add(prop2);

            prop1.Name = "Developer";
        }
コード例 #57
0
        /// <summary>
        /// Loads and stores a collection property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void LoadCollectionProperty(
            string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Create and load the inner property collection.
            List<string> innerCollection = new List<string>();

            // Load the value list.
            XmlNodeList valueNodes = propertyNode.SelectNodes("Value");
            if (valueNodes != null && valueNodes.Count > 0)
            {
                foreach (XmlNode valueNode in valueNodes)
                {
                    if (!string.IsNullOrEmpty(valueNode.InnerText))
                    {
                        innerCollection.Add(valueNode.InnerText);
                    }
                }
            }

            // If at least one value was loaded, save the proeprty.
            if (innerCollection.Count > 0)
            {
                // Get the property descriptor.
                CollectionPropertyDescriptor descriptor = propertyDescriptors[propertyName] as CollectionPropertyDescriptor;

                // Create the collection node and pass in the inner collection.
                CollectionProperty collectionProperty = new CollectionProperty(descriptor, innerCollection);

                // Add this property to the parent collection.
                properties.Add(collectionProperty);
            }
        }
コード例 #58
0
        public void RemovePropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            Property prop1 = new StringProperty("test", "orange");
            Property prop2 = new StringProperty("two", "number");

            collection.Add(prop1);
            collection.Add(prop2);

            collection.PropertyRemoved += (s, e) =>
            {
                Assert.AreSame(prop1, e.Property);
                Assert.AreEqual(1, collection.Count);
                Assert.IsFalse(collection.Contains("test"));
                Assert.IsTrue(collection.Contains("two"));
                Assert.IsFalse(collection.Contains(prop1));
                Assert.IsTrue(collection.Contains(prop2));
            };

            _eventsFired = EventFlags.None;

            collection.Remove(prop1);

            Assert.AreEqual(EventFlags.PropertyRemoved | EventFlags.Modified, _eventsFired);
        }
コード例 #59
0
        /// <summary>
        /// Loads and stores a string property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void LoadStringProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Get the property descriptor.
            PropertyDescriptor<string> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor<string>;

            // Create and add the property.
            properties.Add(new StringProperty(descriptor, propertyNode.InnerText));
        }
コード例 #60
0
        public void ClearPropertyTest()
        {
            PropertyCollection collection = new PropertyCollection(new string[0]);
            AttachEvents(collection);

            Property prop1 = new StringProperty("test", "orange");
            Property prop2 = new StringProperty("two", "number");

            collection.Add(prop1);
            collection.Add(prop2);

            int rmCount = 0;
            collection.PropertyRemoved += (s, e) =>
            {
                rmCount++;
            };

            _eventsFired = EventFlags.None;

            collection.Clear();

            Assert.AreEqual(EventFlags.PropertyRemoved | EventFlags.Modified, _eventsFired);
            Assert.AreEqual(2, rmCount);
            Assert.AreEqual(0, collection.Count);
        }