Esempio n. 1
0
        public override bool Initialize()
        {
            this.scriptFile = EUtils.ProjectFiles(Application.dataPath)
                              .FirstOrDefault <FileInfo>((Func <FileInfo, bool>)(x => x.Name == "ItemID.cs"));
            DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(Application.dataPath, "Generated Scriptes"));

            if (this.scriptFile == null || !this.scriptFile.Exists)
            {
                if (!directoryInfo.Exists)
                {
                    directoryInfo.Create();
                }
                this.scriptFile = new FileInfo(Path.Combine(directoryInfo.FullName, "ItemID.cs"));
                using (StreamWriter text = this.scriptFile.CreateText())
                    text.Write(
                        "// Auto Generated script. Use \"Berry Panel > Item IDs\" to edit it.\npublic enum ItemID {\n    coin = 0,\n    life = 1,\n    lifeslot = 2,\n    extramoves = 10,\n    paint = 11,\n    surprise = 12,\n    ring = 13,\n    needle = 100,\n    flower = 101,\n    shuffle = 102,\n    happylife = 200\n}");
                this.code =
                    "// Auto Generated script. Use \"Berry Panel > Item IDs\" to edit it.\npublic enum ItemID {\n    coin = 0,\n    life = 1,\n    lifeslot = 2,\n    extramoves = 10,\n    paint = 11,\n    surprise = 12,\n    ring = 13,\n    needle = 100,\n    flower = 101,\n    shuffle = 102,\n    happylife = 200\n}";
            }
            else
            {
                this.code = File.ReadAllText(this.scriptFile.FullName);
            }

            if (!this.scriptFile.Exists)
            {
                return(false);
            }
            Regex regex = new Regex("^\\/\\/.*\\s*public enum ItemID \\{(?<ids>(?:\\s*\\w+\\s*=\\s*\\d+,?)*)\\s*\\}");

            if (!regex.IsMatch(this.code))
            {
                this.code =
                    "// Auto Generated script. Use \"Berry Panel > Item IDs\" to edit it.\npublic enum ItemID {\n    coin = 0,\n    life = 1,\n    lifeslot = 2,\n    extramoves = 10,\n    paint = 11,\n    surprise = 12,\n    ring = 13,\n    needle = 100,\n    flower = 101,\n    shuffle = 102,\n    happylife = 200\n}";
            }
            Match match1 = regex.Match(this.code);

            if (!match1.Success)
            {
                return(false);
            }
            this.ids.Clear();
            foreach (Match match2 in new Regex("(?<id>\\w+)\\s*=\\s*(?<num>\\d+)").Matches(match1.Groups["ids"].Value))
            {
                this.ids.Set <string, int>(match2.Groups["id"].Value, int.Parse(match2.Groups["num"].Value));
            }
            this._num = Mathf.Max(10, this.ids.Values.Max() + 1);
            this._id  = "";
            return(true);
        }
Esempio n. 2
0
        public static List <FileInfo> SearchFiles(string directoryPath)
        {
            List <FileInfo> fileInfoList  = new List <FileInfo>();
            DirectoryInfo   directoryInfo = new DirectoryInfo(directoryPath);

            if (directoryInfo.Exists)
            {
                fileInfoList.AddRange((IEnumerable <FileInfo>)((IEnumerable <FileInfo>)directoryInfo.GetFiles()).ToList <FileInfo>());
                foreach (DirectoryInfo directory in directoryInfo.GetDirectories())
                {
                    fileInfoList.AddRange((IEnumerable <FileInfo>)EUtils.SearchFiles(directory.FullName));
                }
            }
            return(fileInfoList);
        }
Esempio n. 3
0
        public static IEnumerable <FileInfo> ProjectFiles(DirectoryInfo directory)
        {
            FileInfo[] fileInfoArray = directory.GetFiles();
            int        index;

            for (index = 0; index < fileInfoArray.Length; ++index)
            {
                yield return(fileInfoArray[index]);
            }
            fileInfoArray = (FileInfo[])null;
            DirectoryInfo[] directoryInfoArray = directory.GetDirectories();
            for (index = 0; index < directoryInfoArray.Length; ++index)
            {
                foreach (FileInfo projectFile in EUtils.ProjectFiles(directoryInfoArray[index]))
                {
                    yield return(projectFile);
                }
            }
            directoryInfoArray = (DirectoryInfo[])null;
        }
Esempio n. 4
0
        public override bool Initialize()
        {
            this.scriptFile = EUtils.ProjectFiles(Application.dataPath)
                              .FirstOrDefault <FileInfo>((Func <FileInfo, bool>)(x => x.Name == "ItemColor.cs"));
            DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(Application.dataPath, "Generated Scriptes"));

            if (this.scriptFile == null || !this.scriptFile.Exists)
            {
                if (!directoryInfo.Exists)
                {
                    directoryInfo.Create();
                }
                this.scriptFile = new FileInfo(Path.Combine(directoryInfo.FullName, "ItemColor.cs"));
                using (StreamWriter text = this.scriptFile.CreateText())
                    text.Write(
                        "// Auto Generated script. Use \"Berry Panel > Item Colors\" to edit it.\nusing UnityEngine;\nusing System.Collections;\nusing System.Collections.Generic;\r\n\r\npublic enum ItemColor {\n    Red = 0,\n    Green = 1,\n    Blue = 2,\n    Yellow = 3,\n    Purple = 4,\n    Orange = 5,\n    Unknown = 100,\n    Uncolored = 101,\n    Universal = 102\n}\n\npublic static class RealColors {\r\n\r\n    static Dictionary<ItemColor, Color> colors = new Dictionary<ItemColor, Color>() {\n        {ItemColor.Red, new Color(1.00f, 0.50f, 0.50f, 1.00f)},\n        {ItemColor.Green, new Color(0.50f, 1.00f, 0.60f, 1.00f)},\n        {ItemColor.Blue, new Color(0.40f, 0.80f, 1.00f, 1.00f)},\n        {ItemColor.Yellow, new Color(1.00f, 0.90f, 0.30f, 1.00f)},\n        {ItemColor.Purple, new Color(0.80f, 0.40f, 1.00f, 1.00f)},\n        {ItemColor.Orange, new Color(1.00f, 0.70f, 0.00f, 1.00f)}\n    };\r\n\r\n    public static Color Get(ItemColor color) {\n        try {\r\n            if (color.IsPhysicalColor())\n                return colors[color];\n        } catch (System.Exception) {\r\n        }\n        return Color.white;\n    }\n}");
                this.code =
                    "// Auto Generated script. Use \"Berry Panel > Item Colors\" to edit it.\nusing UnityEngine;\nusing System.Collections;\nusing System.Collections.Generic;\r\n\r\npublic enum ItemColor {\n    Red = 0,\n    Green = 1,\n    Blue = 2,\n    Yellow = 3,\n    Purple = 4,\n    Orange = 5,\n    Unknown = 100,\n    Uncolored = 101,\n    Universal = 102\n}\n\npublic static class RealColors {\r\n\r\n    static Dictionary<ItemColor, Color> colors = new Dictionary<ItemColor, Color>() {\n        {ItemColor.Red, new Color(1.00f, 0.50f, 0.50f, 1.00f)},\n        {ItemColor.Green, new Color(0.50f, 1.00f, 0.60f, 1.00f)},\n        {ItemColor.Blue, new Color(0.40f, 0.80f, 1.00f, 1.00f)},\n        {ItemColor.Yellow, new Color(1.00f, 0.90f, 0.30f, 1.00f)},\n        {ItemColor.Purple, new Color(0.80f, 0.40f, 1.00f, 1.00f)},\n        {ItemColor.Orange, new Color(1.00f, 0.70f, 0.00f, 1.00f)}\n    };\r\n\r\n    public static Color Get(ItemColor color) {\n        try {\r\n            if (color.IsPhysicalColor())\n                return colors[color];\n        } catch (System.Exception) {\r\n        }\n        return Color.white;\n    }\n}";
            }
            else
            {
                this.code = File.ReadAllText(this.scriptFile.FullName);
            }

            if (!this.scriptFile.Exists)
            {
                return(false);
            }
            Regex regex =
                new Regex(
                    "^\\/\\/.*\\s(using\\s+[A-Za-z\\.0-1]+;\\s)*[\\s\\w]*\\{(?<ids>(?:\\s*\\w+\\s*=\\s*\\d+,?)*)\\s*\\}[\\s\\w]*\\{[\\s*\\w<,>=()]*\\{(?<colors>(?:\\s*\\{[\\w.,\\s]*\\([\\d.f,\\s]*\\)\\},?)*)\\s*\\}");

            if (!regex.IsMatch(this.code))
            {
                this.code =
                    "// Auto Generated script. Use \"Berry Panel > Item Colors\" to edit it.\nusing UnityEngine;\nusing System.Collections;\nusing System.Collections.Generic;\r\n\r\npublic enum ItemColor {\n    Red = 0,\n    Green = 1,\n    Blue = 2,\n    Yellow = 3,\n    Purple = 4,\n    Orange = 5,\n    Unknown = 100,\n    Uncolored = 101,\n    Universal = 102\n}\n\npublic static class RealColors {\r\n\r\n    static Dictionary<ItemColor, Color> colors = new Dictionary<ItemColor, Color>() {\n        {ItemColor.Red, new Color(1.00f, 0.50f, 0.50f, 1.00f)},\n        {ItemColor.Green, new Color(0.50f, 1.00f, 0.60f, 1.00f)},\n        {ItemColor.Blue, new Color(0.40f, 0.80f, 1.00f, 1.00f)},\n        {ItemColor.Yellow, new Color(1.00f, 0.90f, 0.30f, 1.00f)},\n        {ItemColor.Purple, new Color(0.80f, 0.40f, 1.00f, 1.00f)},\n        {ItemColor.Orange, new Color(1.00f, 0.70f, 0.00f, 1.00f)}\n    };\r\n\r\n    public static Color Get(ItemColor color) {\n        try {\r\n            if (color.IsPhysicalColor())\n                return colors[color];\n        } catch (System.Exception) {\r\n        }\n        return Color.white;\n    }\n}";
            }
            Match match1 = regex.Match(this.code);

            if (!match1.Success)
            {
                return(false);
            }
            this.ids.Clear();
            foreach (Match match2 in new Regex("(?<id>\\w+)\\s*=\\s*(?<num>\\d+)").Matches(match1.Groups["ids"].Value))
            {
                ItemColorEditor.ColorInfo colorInfo = new ItemColorEditor.ColorInfo();
                colorInfo.id  = match2.Groups["id"].Value;
                colorInfo.num = int.Parse(match2.Groups["num"].Value);
                this.ids.Set <string, ItemColorEditor.ColorInfo>(colorInfo.id, colorInfo);
            }

            foreach (Match match2 in new Regex(
                         "\\{ItemColor\\.(?<id>[\\w]+),\\snew\\sColor\\((?<r>\\d\\.\\d\\d)f,\\s(?<g>\\d\\.\\d\\d)f,\\s(?<b>\\d\\.\\d\\d)f,\\s(?<a>\\d\\.\\d\\d)f\\)\\}")
                     .Matches(match1.Groups["colors"].Value))
            {
                string key = match2.Groups["id"].Value;
                if (this.ids.ContainsKey(key))
                {
                    this.ids[key].color = new UnityEngine.Color?(new UnityEngine.Color(
                                                                     float.Parse(match2.Groups["r"].Value), float.Parse(match2.Groups["g"].Value),
                                                                     float.Parse(match2.Groups["b"].Value), float.Parse(match2.Groups["a"].Value)));
                }
            }

            this.ids
            .Where <KeyValuePair <string, ItemColorEditor.ColorInfo> >(
                (Func <KeyValuePair <string, ItemColorEditor.ColorInfo>, bool>)(x => !x.Value.color.HasValue))
            .ForEach <KeyValuePair <string, ItemColorEditor.ColorInfo> >(
                (Action <KeyValuePair <string, ItemColorEditor.ColorInfo> >)(x =>
                                                                             x.Value.color = new UnityEngine.Color?(UnityEngine.Color.white)));
            this.newInfo.num = this.ids.Values
                               .Where <ItemColorEditor.ColorInfo>(
                (Func <ItemColorEditor.ColorInfo, bool>)(x => x.num < 100))
                               .Max <ItemColorEditor.ColorInfo
                                     >((Func <ItemColorEditor.ColorInfo, int>)(x => x.num)) + 1;
            this.newInfo.id = "";
            return(true);
        }
Esempio n. 5
0
 public static IEnumerable <FileInfo> ProjectFiles(string directory)
 {
     return(EUtils.ProjectFiles(new DirectoryInfo(directory)));
 }