Changeset - 3154dda31272
[Not reviewed]
default
0 1 0
Jason Maltzen - 5 years ago 2019-11-02 02:23:43
jason@hiddenachievement.com
Slightly safer parsing of reaction files
1 file changed with 70 insertions and 42 deletions:
0 comments (0 inline, 0 general)
PlayerProfile.cs
Show inline comments
...
 
@@ -32,5 +32,8 @@ namespace DesertPaintLab
 
	public class PlayerProfile
 
	{
 
        public string Name { get; private set; }
 
        public string Name
 
        {
 
            get; private set;
 
        }
 
		string directory;
 
		string reactFile;
...
 
@@ -49,6 +52,8 @@ namespace DesertPaintLab
 

	
 
        Settings settings = new Settings();
 
        public Settings ProfileSettings { 
 
            get { 
 
        public Settings ProfileSettings
 
        {
 
            get
 
            {
 
                return settings;
 
            }
...
 
@@ -59,10 +64,14 @@ namespace DesertPaintLab
 
        static PlayerProfile Current
 
        {
 
            get {
 
            get
 
            {
 
                return current;
 
            }
 
        }
 

	
 
        public string LastError { get; private set; }
 
        public string LastError
 
        {
 
            get; private set;
 
        }
 
		
 
		public PlayerProfile(string name, string directory)
...
 
@@ -87,5 +96,6 @@ namespace DesertPaintLab
 
        public string Directory
 
        {
 
            get {
 
            get
 
            {
 
                return this.directory;
 
            }
...
 
@@ -94,5 +104,6 @@ namespace DesertPaintLab
 
        public ReactionSet Reactions
 
        {
 
            get {
 
            get
 
            {
 
                return this.reactions;
 
            }
...
 
@@ -101,5 +112,6 @@ namespace DesertPaintLab
 
        public string ReagentFile
 
        {
 
            get {
 
            get
 
            {
 
                return this.reagentFile;
 
            }
...
 
@@ -108,5 +120,6 @@ namespace DesertPaintLab
 
        public SortedDictionary<string, PaintRecipe> Recipes
 
        {
 
            get {
 
            get
 
            {
 
                return this.recipes;
 
            }
...
 
@@ -115,5 +128,6 @@ namespace DesertPaintLab
 
        public SortedDictionary<string, PaintRecipe> RibbonRecipes
 
        {
 
            get {
 
            get
 
            {
 
                return this.ribbonRecipes;
 
            }
...
 
@@ -122,5 +136,6 @@ namespace DesertPaintLab
 
        public int RecipeCount
 
        {
 
            get {
 
            get
 
            {
 
                int count = 0;
 
                foreach (PaintRecipe recipe in this.recipes.Values)
...
 
@@ -137,5 +152,6 @@ namespace DesertPaintLab
 
        public int RibbonCount
 
        {
 
            get {
 
            get
 
            {
 
                int count = 0;
 
                foreach (PaintRecipe recipe in this.ribbonRecipes.Values)
...
 
@@ -180,4 +196,17 @@ namespace DesertPaintLab
 
		}
 
		
 
        private void WriteReaction(StreamWriter writer, string reagent1, string reagent2, string r, string g, string b)
 
        {
 
            writer.Write(reagent1);
 
            writer.Write(" ");
 
            writer.Write(reagent2);
 
            writer.Write(" ");
 
            writer.Write(r);
 
            writer.Write(" ");
 
            writer.Write(g);
 
            writer.Write(" ");
 
            writer.WriteLine(b);
 
        }
 

	
 
		public void ConvertFromPP(string ppFile, string dpFile)
 
		{
...
 
@@ -189,40 +218,31 @@ namespace DesertPaintLab
 
					while ((line = reader.ReadLine()) != null) 
 
                	{
 
						string[] tokens = line.Split(null);
 
						if ((tokens.Length > 0) && (tokens[0] != "//"))
 
                        string[] tokens = line.Split('|');
 
                        //if ((tokens.Length > 0) && (tokens [0] != "//"))
 
                        if ((tokens.Length != 5) && (tokens[0].Trim() != "//"))
 
						{							
 
                            string reagent1 = tokens[0].Trim();
 
                            string reagent2 = tokens[1].Trim();
 
                            string colorCode = tokens[2].Trim();
 
                            string change1 = tokens[3].Trim();
 
                            string change2 = tokens[4].Trim();
 
							// Write reaction.
 
							writer.Write(tokens[0] + " " + tokens[2] + " ");
 
							switch (tokens[4])
 
                            switch (colorCode)
 
							{
 
							case "W":
 
								writer.WriteLine(tokens[6] + " " + tokens[6] + " " + tokens[6]);
 
                                WriteReaction(writer, reagent1, reagent2, change1, change1, change1);
 
                                WriteReaction(writer, reagent2, reagent1, change2, change2, change2);
 
								break;
 
							case "R":
 
								writer.WriteLine(tokens[6] + " 0 0");
 
                                WriteReaction(writer, reagent1, reagent2, change1, "0", "0");
 
                                WriteReaction(writer, reagent2, reagent1, change2, "0", "0");
 
								break;
 
							case "G":
 
								writer.WriteLine("0 " + tokens[6] + " 0");
 
                                WriteReaction(writer, reagent1, reagent2, "0", change1, "0");
 
                                WriteReaction(writer, reagent2, reagent1, "0", change2, "0");
 
								break;
 
							case "B":
 
								writer.WriteLine("0 0 " + tokens[6]);
 
								break;	
 
							}
 
							
 
							// Write reverse reaction.
 
							writer.Write(tokens[2] + " " + tokens[0] + " ");
 
							switch (tokens[4])
 
							{
 
							case "W":
 
								writer.WriteLine(tokens[8] + " " + tokens[8] + " " + tokens[8]);
 
								break;
 
							case "R":
 
								writer.WriteLine(tokens[8] + " 0 0");
 
								break;
 
							case "G":
 
								writer.WriteLine("0 " + tokens[8] + " 0");
 
								break;
 
							case "B":
 
								writer.WriteLine("0 0 " + tokens[8]);
 
                                WriteReaction(writer, reagent1, reagent2, "0", "0", change1);
 
                                WriteReaction(writer, reagent2, reagent1, "0", "0", change2);
 
								break;	
 
							}							
...
 
@@ -365,8 +385,16 @@ namespace DesertPaintLab
 
				while ((line = reader.ReadLine()) != null) 
 
               	{
 
					string[] tokens = line.Split(null);
 
                    Reagent reagent1 = ReagentManager.GetReagent(tokens[0]);
 
                    Reagent reagent2 = ReagentManager.GetReagent(tokens[1]);
 
					reactions.Set(reagent1, reagent2, new Reaction(int.Parse(tokens[2]), int.Parse(tokens[3]), int.Parse(tokens[4])));
 
                    string[] tokens = line.Split(' ');
 
                    if (tokens.Length == 5)
 
                    {
 
                        Reagent reagent1 = ReagentManager.GetReagent(tokens[0].Trim());
 
                        Reagent reagent2 = ReagentManager.GetReagent(tokens[1].Trim());
 
                        Reaction reaction = new Reaction(
 
                            int.Parse(tokens[2].Trim()),
 
                            int.Parse(tokens[3].Trim()),
 
                            int.Parse(tokens[4].Trim())
 
                            );
 
                        reactions.Set(reagent1, reagent2, reaction);
 
                    }
 
				}
 
			}
0 comments (0 inline, 0 general)