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
...
 
@@ -33,3 +33,6 @@ namespace DesertPaintLab
 
	{
 
        public string Name { get; private set; }
 
        public string Name
 
        {
 
            get; private set;
 
        }
 
		string directory;
...
 
@@ -50,4 +53,6 @@ namespace DesertPaintLab
 
        Settings settings = new Settings();
 
        public Settings ProfileSettings { 
 
            get { 
 
        public Settings ProfileSettings
 
        {
 
            get
 
            {
 
                return settings;
...
 
@@ -60,3 +65,4 @@ namespace DesertPaintLab
 
        {
 
            get {
 
            get
 
            {
 
                return current;
...
 
@@ -65,3 +71,6 @@ namespace DesertPaintLab
 

	
 
        public string LastError { get; private set; }
 
        public string LastError
 
        {
 
            get; private set;
 
        }
 
		
...
 
@@ -88,3 +97,4 @@ namespace DesertPaintLab
 
        {
 
            get {
 
            get
 
            {
 
                return this.directory;
...
 
@@ -95,3 +105,4 @@ namespace DesertPaintLab
 
        {
 
            get {
 
            get
 
            {
 
                return this.reactions;
...
 
@@ -102,3 +113,4 @@ namespace DesertPaintLab
 
        {
 
            get {
 
            get
 
            {
 
                return this.reagentFile;
...
 
@@ -109,3 +121,4 @@ namespace DesertPaintLab
 
        {
 
            get {
 
            get
 
            {
 
                return this.recipes;
...
 
@@ -116,3 +129,4 @@ namespace DesertPaintLab
 
        {
 
            get {
 
            get
 
            {
 
                return this.ribbonRecipes;
...
 
@@ -123,3 +137,4 @@ namespace DesertPaintLab
 
        {
 
            get {
 
            get
 
            {
 
                int count = 0;
...
 
@@ -138,3 +153,4 @@ namespace DesertPaintLab
 
        {
 
            get {
 
            get
 
            {
 
                int count = 0;
...
 
@@ -181,2 +197,15 @@ 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)
...
 
@@ -190,38 +219,29 @@ namespace DesertPaintLab
 
                	{
 
						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;	
...
 
@@ -366,6 +386,14 @@ namespace DesertPaintLab
 
               	{
 
					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)