コード例 #1
0
ファイル: Autotiler.cs プロジェクト: david-reborn/Celeste
    private bool CheckTile(
        Autotiler.TerrainType set,
        VirtualMap <char> mapData,
        int x,
        int y,
        Rectangle forceFill,
        Autotiler.Behaviour behaviour)
    {
        if (forceFill.Contains(x, y))
        {
            return(true);
        }
        if (mapData == null)
        {
            return(behaviour.EdgesExtend);
        }
        if (x < 0 || y < 0 || x >= mapData.Columns || y >= mapData.Rows)
        {
            if (!behaviour.EdgesExtend)
            {
                return(false);
            }
            char ch = mapData[Util.Clamp(x, 0, mapData.Columns - 1), Util.Clamp(y, 0, mapData.Rows - 1)];
            return(!this.IsEmpty(ch) && !set.Ignore(ch));
        }
        char ch1 = mapData[x, y];

        return(!this.IsEmpty(ch1) && !set.Ignore(ch1));
    }
コード例 #2
0
ファイル: Tiles.cs プロジェクト: david-reborn/Celeste
        private Autotiler.Tiles TileHandler(VirtualMap <char> mapData, int x, int y, Rectangle forceFill, char forceID, Autotiler.Behaviour behaviour)
        {
            char tile = this.GetTile(mapData, x, y, forceFill, forceID, behaviour);

            if (this.IsEmpty(tile))
            {
                return(null);
            }
            Autotiler.TerrainType set = this.lookup[tile];
            bool flag1 = true;
            int  num   = 0;

            for (int index1 = -1; index1 < 2; ++index1)
            {
                for (int index2 = -1; index2 < 2; ++index2)
                {
                    bool flag2 = this.CheckTile(set, mapData, x + index2, y + index1, forceFill, behaviour);
                    if (!flag2 && behaviour.EdgesIgnoreOutOfLevel && !this.CheckForSameLevel(x, y, x + index2, y + index1))
                    {
                        flag2 = true;
                    }
                    this.adjacent[num++] = flag2 ? (byte)1 : (byte)0;
                    if (!flag2)
                    {
                        flag1 = false;
                    }
                }
            }
            if (flag1)
            {
                if ((behaviour.PaddingIgnoreOutOfLevel ? ((!this.CheckTile(set, mapData, x - 2, y, forceFill, behaviour) && this.CheckForSameLevel(x, y, x - 2, y)) || (!this.CheckTile(set, mapData, x + 2, y, forceFill, behaviour) && this.CheckForSameLevel(x, y, x + 2, y)) || (!this.CheckTile(set, mapData, x, y - 2, forceFill, behaviour) && this.CheckForSameLevel(x, y, x, y - 2)) || (!this.CheckTile(set, mapData, x, y + 2, forceFill, behaviour) && this.CheckForSameLevel(x, y, x, y + 2))) : (!this.CheckTile(set, mapData, x - 2, y, forceFill, behaviour) || !this.CheckTile(set, mapData, x + 2, y, forceFill, behaviour)) || (!this.CheckTile(set, mapData, x, y - 2, forceFill, behaviour)) || (!this.CheckTile(set, mapData, x, y + 2, forceFill, behaviour))))
                {
                    return(this.lookup[tile].Padded);
                }
                else
                {
                    return(this.lookup[tile].Center);
                }
            }
            //return  ? this.lookup[tile].Padded : this.lookup[tile].Center;
            for (int p = 0; p < set.Masked.Count; p++)
            {
                Autotiler.Masked masked = set.Masked[p];
                bool             flag2  = true;
                for (int index = 0; index < 9 & flag2; ++index)
                {
                    if (masked.Mask[index] != (byte)2 && (int)masked.Mask[index] != (int)this.adjacent[index])
                    {
                        flag2 = false;
                    }
                }
                if (flag2)
                {
                    return(masked.Tiles);
                }
            }
            return(null);
        }
コード例 #3
0
ファイル: Tiles.cs プロジェクト: david-reborn/Celeste
        public Tiles(string path)
        {
            Dictionary <char, XmlElement> dictionary = new Dictionary <char, XmlElement>();
            XmlDocument doc = new XmlDocument();

            doc.Load(path);
            foreach (XmlElement xml in doc.GetElementsByTagName("Tileset"))
            {
                char    ch                 = xml.AttrChar("id");
                Tileset tileset            = new Tileset(Gfx.Game["tilesets/" + xml.Attr("path")], 8, 8);
                Autotiler.TerrainType data = new Autotiler.TerrainType(ch);
                this.ReadInto(data, tileset, xml);
                if (xml.HasAttr("copy"))
                {
                    char key = xml.AttrChar("copy");
                    if (!dictionary.ContainsKey(key))
                    {
                        throw new Exception("Copied tilesets must be defined before the tilesets that copy them!");
                    }
                    this.ReadInto(data, tileset, dictionary[key]);
                }
                if (xml.HasAttr("ignores"))
                {
                    string str1    = xml.Attr("ignores");
                    char[] chArray = new char[1] {
                        ','
                    };
                    foreach (string str2 in str1.Split(chArray))
                    {
                        if (str2.Length > 0)
                        {
                            data.Ignores.Add(str2[0]);
                        }
                    }
                }
                dictionary.Add(ch, xml);
                this.lookup.Add(ch, data);
            }
        }
コード例 #4
0
ファイル: Tiles.cs プロジェクト: david-reborn/Celeste
 private void ReadInto(Autotiler.TerrainType data, Tileset tileset, XmlElement xml)
 {
     foreach (object obj in (XmlNode)xml)
     {
         if (!(obj is XmlComment))
         {
             XmlElement      xml1 = obj as XmlElement;
             string          str1 = xml1.Attr("mask");
             Autotiler.Tiles tiles;
             if (str1 == "center")
             {
                 tiles = data.Center;
             }
             else if (str1 == "padding")
             {
                 tiles = data.Padded;
             }
             else
             {
                 Autotiler.Masked masked = new Autotiler.Masked();
                 tiles = masked.Tiles;
                 int index = 0;
                 int num   = 0;
                 for (; index < str1.Length; ++index)
                 {
                     if (str1[index] == '0')
                     {
                         masked.Mask[num++] = (byte)0;
                     }
                     else if (str1[index] == '1')
                     {
                         masked.Mask[num++] = (byte)1;
                     }
                     else if (str1[index] == 'x' || str1[index] == 'X')
                     {
                         masked.Mask[num++] = (byte)2;
                     }
                 }
                 data.Masked.Add(masked);
             }
             string str2     = xml1.Attr("tiles");
             char[] chArray1 = new char[1] {
                 ';'
             };
             foreach (string str3 in str2.Split(chArray1))
             {
                 char[] chArray2 = new char[1] {
                     ','
                 };
                 string[] strArray = str3.Split(chArray2);
                 int      index1   = int.Parse(strArray[0]);
                 int      index2   = int.Parse(strArray[1]);
                 MTexture mtexture = tileset[index1, index2];
                 tiles.Textures.Add(mtexture);
             }
             if (xml1.HasAttr("sprites"))
             {
                 string str3     = xml1.Attr("sprites");
                 char[] chArray2 = new char[1] {
                     ','
                 };
                 foreach (string str4 in str3.Split(chArray2))
                 {
                     tiles.OverlapSprites.Add(str4);
                 }
                 tiles.HasOverlays = true;
             }
         }
     }
     data.Masked.Sort((Comparison <Autotiler.Masked>)((a, b) =>
     {
         int num1 = 0;
         int num2 = 0;
         for (int index = 0; index < 9; ++index)
         {
             if (a.Mask[index] == (byte)2)
             {
                 ++num1;
             }
             if (b.Mask[index] == (byte)2)
             {
                 ++num2;
             }
         }
         return(num1 - num2);
     }));
 }