public static IPropertyCollection AddOrReplace(this IPropertyCollection t, string key, string value)
        {
            if (!t.ContainsKey(key))
            {
                t.Add(key, value);
            }
            else
            {
                t[key] = value;
            }

            return(t);
        }
예제 #2
0
 private static void MapProperties(BinaryWriter writer, Actions remove, Actions set, byte[] preface, IPropertyCollection source, IPropertyCollection target)
 {
     foreach (var item in source)
     {
         if (!target.ContainsKey(item.Key))
         {
             writer.Write((byte)remove);
             writer.Write(preface);
             writer.WriteTiny(item.Key);
         }
         else if (!target[item.Key].ToString().Equals(item.Value.ToString()))
         {
             writer.Write((byte)set);
             writer.Write(preface);
             writer.WriteTiny(item.Key);
             writer.Write((string)item.Value);
         }
     }
 }
예제 #3
0
        public static IPropertyCollection GetDifference(IPropertyCollection a, IPropertyCollection b, bool overwriteConflicting = true, bool nullIfEmpty = true)
        {
            if (b == null)
            {
                return(a);
            }

            IPropertyCollection properties = new PropertyCollection();

            foreach (var property in a)
            {
                // Only add it if it's not in the vanilla map properties or we changed the value.
                // This way we only set things we actually changed.
                // Need to do ToString() otherwise comparison always fails.
                if (!b.ContainsKey(property.Key) ||
                    (overwriteConflicting && b[property.Key].ToString() != property.Value.ToString()))
                {
                    properties.Add(property.Key, property.Value);
                }
            }
            return((properties.Count > 0 || !nullIfEmpty) ? properties : null);
        }
예제 #4
0
        public bool ContainsKey(string key)
        {
            IPropertyCollection tilesheetProperties = m_tileSheet.Properties;

            return(tilesheetProperties.ContainsKey(IndexKey(key)));
        }
        private void LocationEvents_CurrentLocationChanged(object sender, EventArgsCurrentLocationChanged e)
        {
            locationSetup();


            Map map = Game1.currentLocation.map;

            Layer layer = map.GetLayer("Interactive");

            if (layer == null)
            {
                return;
            }

            IPropertyCollection LayerProperties = layer.Properties;

            for (int x = 0; x < map.Layers[0].LayerWidth; x++)
            {
                for (int y = 0; y < map.Layers[0].LayerHeight; y++)
                {
                    Tile tile = layer.PickTile(new Location(x * Game1.tileSize, y * Game1.tileSize), Game1.viewport.Size);

                    if (tile == null)
                    {
                        continue;
                    }
                    IPropertyCollection tileProperties = tile.Properties;

                    if (tileProperties.Count > 0)
                    {
                        if (tileProperties.ContainsKey("REPEATACTION") && tileProperties["REPEATACTION"] != null)
                        {
                            string condition = "";
                            string action    = tileProperties["REPEATACTION"].ToString().ToLower();;
                            if (tileProperties.ContainsKey("CONDITION"))
                            {
                                condition = tileProperties["CONDITION"].ToString().ToLower();
                            }
                            if (!repeatActions.ContainsKey(new Vector2(x, y)))
                            {
                                Dictionary <string, string> repeatActionData = new Dictionary <string, string>();
                                repeatActionData.Add(condition, action);
                                repeatActions.Add(new Vector2(x, y), repeatActionData);
                            }
                        }

                        if (tileProperties.ContainsKey("TYPE") && tileProperties["TYPE"] != null && tileProperties["TYPE"].ToString().ToLower() == "switch")
                        {
                            string[] switchID = tileProperties["ID"].ToString().ToLower().Split(' ');

                            if (tileProperties["LAYER"] != null)
                            {
                                dynamic switchTile = new { layer = tileProperties["LAYER"].ToString(), position = new Vector2(x, y) };
                                if (!switchTiles.ContainsKey(tileProperties["ID"]))
                                {
                                    switchTiles.Add(switchID[0] + " " + switchID[1], switchTile);
                                }
                            }

                            if (!switches.ContainsKey(switchID[0]))
                            {
                                switches.Add(switchID[0], new Dictionary <string, bool>());
                            }

                            if (!switches[switchID[0]].ContainsKey(switchID[1]))
                            {
                                switches[switchID[0]].Add(switchID[1], false);
                            }
                        }

                        interactiveProperties.Add(new Vector2(x, y), tileProperties);
                    }
                }
            }
        }