//Loads the phase from a .json file, and returns a dictionary of phases public static Dictionary <int, Dictionary <string, string> > LoadPhases(string directory) { JSONEditor jsonEditor = new JSONEditor(directory); Dictionary <int, Dictionary <string, string> > phase = new Dictionary <int, Dictionary <string, string> > (); Debug.Log("Number of steps = " + jsonEditor.NumberOfObjects()); for (int i = 0; i < jsonEditor.NumberOfObjects(); i++) { phase.Add(i, PhasesSaver.LoadStep(jsonEditor, i)); Debug.Log("Adicionando step = " + phase[i]["typeOfStep"]); } return(phase); }
//Loads the reactions from a file, and returns a dictionary public static Dictionary <string, ReactionClass> LoadReactions() { JSONEditor json = new JSONEditor("reactions"); int numberOfReactions = json.NumberOfObjects(); Dictionary <string, ReactionClass> Reagents = new Dictionary <string, ReactionClass>(); if (numberOfReactions > 0) { for (int i = 0; i < numberOfReactions; i++) { ReactionClass reaction = new ReactionClass(); reaction.name = json.GetString(i, "name"); reaction.reagent1 = json.GetString(i, "aName"); reaction.reagent2 = json.GetString(i, "bName"); reaction.mainProduct = json.GetString(i, "cName"); reaction.subProduct = json.GetString(i, "dName"); reaction.stoichiometryR1 = json.GetInt(i, "aMultiply"); reaction.stoichiometryR2 = json.GetInt(i, "bMultiply"); reaction.stoichiometryMainProduct = json.GetInt(i, "cMultiply"); reaction.stoichiometrySubProduct = json.GetInt(i, "dMultiply"); Reagents.Add(reaction.name, reaction); } } return(Reagents); }
//Loads the phase from a .json file, and returns a dictionary of phases public static Dictionary <int, Dictionary <string, string> > LoadPhases() { JSONEditor jsonEditor = new JSONEditor("phases"); Dictionary <int, Dictionary <string, string> > phase = new Dictionary <int, Dictionary <string, string> > (); for (int i = 0; i < jsonEditor.NumberOfObjects(); i++) { Dictionary <string, string> stepValues = new Dictionary <string, string> (); //stepValues["typeOfStep"] = josnEdito.GetString(i, "typeOfStep"); stepValues["productFormula"] = jsonEditor.GetString(i, "productFormula"); stepValues["molarity"] = jsonEditor.GetString(i, "molarity"); stepValues["minVolume"] = jsonEditor.GetString(i, "minVolume"); stepValues["maxError"] = jsonEditor.GetString(i, "maxError"); stepValues["density"] = jsonEditor.GetString(i, "density"); stepValues["turbidity"] = jsonEditor.GetString(i, "turbidity"); stepValues["conductibility"] = jsonEditor.GetString(i, "conductibility"); phase.Add(i, stepValues); } return(phase); }
//Loads the phase from a .json file, and returns a dictionary of phases private static Dictionary <string, Dictionary <string, string> > LoadHandbook() { JSONEditor jsonEditor = new JSONEditor("handbook", true); Dictionary <string, Dictionary <string, string> > handbook = new Dictionary <string, Dictionary <string, string> > (); for (int i = 0; i < jsonEditor.NumberOfObjects(); i++) { handbook.Add(jsonEditor.GetString(i, "formula"), HandbookSaver.LoadReagentValues(jsonEditor, i)); } return(handbook); }
//Loads the phase from a .json file, and returns a dictionary of phases public static Dictionary <int, Dictionary <string, string> > LoadPhases(string directory) { JSONEditor jsonEditor = new JSONEditor(directory); Dictionary <int, Dictionary <string, string> > phase = new Dictionary <int, Dictionary <string, string> > (); for (int i = 0; i < jsonEditor.NumberOfObjects(); i++) { phase.Add(i, PhasesSaver.LoadStep(jsonEditor, i)); } return(phase); }
/* -------------PRODUCT------------- */ //! Reads/Loads the dictionary from file. public static Dictionary <string, Compound> LoadBackgroundCompounds() { JSONEditor jsonEditor = new JSONEditor("products"); Dictionary <string, Compound> products = new Dictionary <string, Compound>(); for (int i = 0; i < jsonEditor.NumberOfObjects(); i++) { Compound productAcc = new Compound(); productAcc.Name = jsonEditor.GetString(i, "name"); productAcc.Formula = jsonEditor.GetString(i, "formula"); productAcc.IsSolid = jsonEditor.GetBool(i, "isSolid" + i.ToString()); productAcc.MolarMass = jsonEditor.GetFloat(i, "molarMass"); productAcc.Purity = jsonEditor.GetFloat(i, "purity"); productAcc.Density = jsonEditor.GetFloat(i, "density"); productAcc.Polarizability = jsonEditor.GetFloat(i, "polarizability"); if (!string.IsNullOrEmpty(jsonEditor.GetString(i, "irSpecter"))) { productAcc.irSpecter = Resources.Load <Texture2D>("specter/" + jsonEditor.GetString(i, "irSpecter")); } else { productAcc.irSpecter = null; } productAcc.Conductibility = jsonEditor.GetFloat(i, "conductibility"); productAcc.Solubility = jsonEditor.GetFloat(i, "solubility"); productAcc.FumeHoodOnly = jsonEditor.GetBool(i, "fumeHoodOnly"); productAcc.compoundColor = new Color32((byte)jsonEditor.GetInt(i, "compoundColorR"), (byte)jsonEditor.GetInt(i, "compoundColorG"), (byte)jsonEditor.GetInt(i, "compoundColorB"), (byte)255); //!Gets the liquid-related variables if (!jsonEditor.GetBool(i, "isSolid")) { productAcc.PH = jsonEditor.GetFloat(i, "ph"); productAcc.Turbidity = jsonEditor.GetFloat(i, "turbidity"); productAcc.Refratometer = jsonEditor.GetFloat(i, "refratometer"); productAcc.FlameSpecter = jsonEditor.GetFloat(i, "flameSpecter"); if (!string.IsNullOrEmpty(jsonEditor.GetString(i, "uvSpecter"))) { productAcc.uvSpecter = Resources.Load <Texture2D>("specter/" + jsonEditor.GetString(i, "uvSpecter")); } else { productAcc.uvSpecter = null; } if (!string.IsNullOrEmpty(jsonEditor.GetString(i, "hplc"))) { productAcc.hplc = Resources.Load <Texture2D>("specter/" + jsonEditor.GetString(i, "hplc")); } else { productAcc.hplc = null; } } productAcc.Molarity = ((productAcc.Purity * productAcc.Density) / productAcc.MolarMass); // number of mols / volume Debug.Log(productAcc.Formula + ".Molarity = " + productAcc.Molarity); products.Add(productAcc.Formula, productAcc); } Dictionary <string, Compound> cupboard = ComponentsSaver.LoadCupboardCompounds(); foreach (string name in cupboard.Keys) { products.Add(cupboard[name].Formula, cupboard[name]); } return(products); }
//! Reads/Loads the dictionary from .json file. public static Dictionary <string, Compound> LoadCupboardCompounds() { JSONEditor jsonEditor = new JSONEditor("compounds"); Dictionary <string, Compound> reagents = new Dictionary <string, Compound>(); for (int i = 0; i < jsonEditor.NumberOfObjects(); i++) { Compound reagentAcc = new Compound(); reagentAcc.Name = jsonEditor.GetString(i, "name"); reagentAcc.Formula = jsonEditor.GetString(i, "formula"); reagentAcc.IsSolid = jsonEditor.GetBool(i, "isSolid"); reagentAcc.MolarMass = jsonEditor.GetFloat(i, "molarMass"); reagentAcc.Purity = jsonEditor.GetFloat(i, "purity"); reagentAcc.Density = jsonEditor.GetFloat(i, "density"); reagentAcc.Polarizability = jsonEditor.GetFloat(i, "polarizability"); reagentAcc.compoundColor = new Color32((byte)jsonEditor.GetInt(i, "compoundColorR"), (byte)jsonEditor.GetInt(i, "compoundColorG"), (byte)jsonEditor.GetInt(i, "compoundColorB"), (byte)255); if (!string.IsNullOrEmpty(jsonEditor.GetString(i, "irSpecter"))) { reagentAcc.irSpecter = Resources.Load <Texture2D> ("specter/" + jsonEditor.GetString(i, "irSpecter")); } else { reagentAcc.irSpecter = null; } reagentAcc.Conductibility = jsonEditor.GetFloat(i, "conductibility" + i.ToString()); reagentAcc.Solubility = jsonEditor.GetFloat(i, "solubility"); reagentAcc.FumeHoodOnly = jsonEditor.GetBool(i, "fumeHoodOnly"); //reagentAcc.color = new Color (jsonEditor.GetFloat ("colorR"+ i.ToString ()), jsonEditor.GetFloat ("colorG"+ i.ToString ()), jsonEditor.GetFloat ("colorB"+ i.ToString ()), jsonEditor.GetFloat ("colorA"+ i.ToString ())); //!Gets the liquid-related variables if (!jsonEditor.GetBool(i, "isSolid")) { reagentAcc.PH = jsonEditor.GetFloat(i, "ph"); reagentAcc.Turbidity = jsonEditor.GetFloat(i, "turbidity"); reagentAcc.Refratometer = jsonEditor.GetFloat(i, "refratometer"); reagentAcc.FlameSpecter = jsonEditor.GetFloat(i, "flameSpecter"); if (!string.IsNullOrEmpty(jsonEditor.GetString(i, "uvSpecter"))) { reagentAcc.uvSpecter = Resources.Load <Texture2D> ("specter/" + jsonEditor.GetString(i, "uvSpecter")); } else { reagentAcc.uvSpecter = null; } if (!string.IsNullOrEmpty(jsonEditor.GetString(i, "hplc"))) { reagentAcc.hplc = Resources.Load <Texture2D> ("specter/" + jsonEditor.GetString(i, "hplc")); } else { reagentAcc.hplc = null; } } reagentAcc.Molarity = ((reagentAcc.Purity * reagentAcc.Density) / reagentAcc.MolarMass) * 1000; // number of mols / volume // Debug.Log (reagentAcc.Formula + ".Molarity = " + reagentAcc.Molarity); reagents.Add(reagentAcc.Name, reagentAcc); } return(reagents); }