Пример #1
0
        public static CustomTileData GetData(int index, CustomType type)
        {
            CustomTileData customTileData = (CustomTileData)null;

            if (!Custom._customTilesetData[type].TryGetValue(Custom.data[type][index], out customTileData))
            {
                customTileData = Custom.LoadTileData(Custom.data[type][index], type);
            }
            return(customTileData);
        }
Пример #2
0
        public static string ApplyCustomData(CustomTileData tData, int index, CustomType type)
        {
            string key = tData.path + "@" + (object)tData.checksum + ".png";

            if (tData.texture != null)
            {
                string str = DuckFile.GetCustomDownloadDirectory(type) + key;
                if (!File.Exists(str))
                {
                    DuckFile.CreatePath(str);
                    FileStream fileStream = File.Create(str);
                    tData.texture.SaveAsPng((Stream)fileStream, tData.texture.Width, tData.texture.Height);
                    fileStream.Close();
                }
            }
            else if (tData.path == null)
            {
                return("");
            }
            Custom._customTilesetData[type][key] = tData;
            Custom.data[type][index]             = key;
            return(key);
        }
Пример #3
0
        public static CustomTileData LoadTileData(string path, CustomType type)
        {
            CustomTileData customTileData = new CustomTileData();

            if (path == "" || path == null)
            {
                return(customTileData);
            }
            Texture2D texture2D = ContentPack.LoadTexture2D(DuckFile.GetCustomDirectory(type) + path + ".png");

            if (texture2D != null)
            {
                try
                {
                    Color[] data = new Color[texture2D.Width * texture2D.Height];
                    texture2D.GetData <Color>(data);
                    for (int index1 = 0; index1 < 5; ++index1)
                    {
                        int num1 = 112;
                        int num2 = 64 + index1 * 16;
                        if (index1 == 1)
                        {
                            int num3 = num2;
                            num2 = num1;
                            num1 = num3;
                        }
                        if (index1 == 3)
                        {
                            num1 = 96;
                            num2 = 112;
                        }
                        else if (index1 == 4)
                        {
                            num1 = 112;
                            num2 = 112;
                        }
                        int num4 = -1;
                        int num5 = 0;
                        for (int index2 = 0; index2 < 16; ++index2)
                        {
                            bool flag = false;
                            for (int index3 = 0; index3 < 16; ++index3)
                            {
                                int index4 = index1 != 1 ? num1 + index3 + (num2 + index2) * texture2D.Width : num2 + index2 + (num1 + index3) * texture2D.Width;
                                if (index1 == 3 || index1 == 4 ? data[index4].a != (byte)0 : data[index4].r == (byte)0 && data[index4].g == byte.MaxValue && data[index4].b == (byte)0 && data[index4].a == byte.MaxValue)
                                {
                                    if (num4 == -1)
                                    {
                                        num4 = index3;
                                    }
                                }
                                else if (num4 != -1)
                                {
                                    num5 = index3 - num4;
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                break;
                            }
                        }
                        switch (index1)
                        {
                        case 0:
                            customTileData.verticalWidth = num5;
                            break;

                        case 1:
                            customTileData.horizontalHeight = num5;
                            break;

                        case 2:
                            customTileData.verticalWidthThick = num5;
                            break;

                        case 3:
                            customTileData.leftNubber = num5 != 0;
                            break;

                        case 4:
                            customTileData.rightNubber = num5 != 0;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    texture2D = (Texture2D)null;
                }
                customTileData.texture = texture2D;
                customTileData.path    = path;
                Custom._customTilesetData[type][path] = customTileData;
            }
            return(customTileData);
        }