//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);
    }
    //Load the values of eache reagent, putting it into a Dictionary
    private static Dictionary <string, string> LoadReagentValues(JSONEditor jsonEditor, int i)
    {
        Dictionary <string, string> reagentValues = new Dictionary <string, string> ();

        reagentValues.Add("formula", jsonEditor.GetString(i, "formula"));
        reagentValues.Add("description", jsonEditor.GetString(i, "description"));

        return(reagentValues);
    }
    /*public static void AddJournalUIItem(JournalUIItem journalItem,int expo){
     *      Dictionary<int, JournalUIItem> JournalItems = JournalSaver.LoadJournalUIItems (expo);
     *      if(JournalItems.ContainsKey(journalItem.index))
     *         JournalItems.Remove(journalItem.index);
     *      JournalItems.Add (journalItem.index
     *                        , journalItem);
     *      //SaveJournalUIItems (JournalItems,expo);
     * }*/

    //Saves the reactions from a dictionary to the text file

    /*public static void SaveJournalUIItems(Dictionary<int, JournalUIItem> JournalItems,int expo)
     * {
     *      text = new TextEdit("Assets/Resources/journalItems"+expo.ToString()+".txt");
     *      text.ClearFile ();
     *      text.SetInt ("numberOfJournalItems", JournalItems.Count);
     *
     *      int counter = 0;
     *      foreach (JournalUIItem JournalItem in JournalItems.Values)
     *      {
     *              text.SetInt("index" + counter.ToString(), counter);
     *              text.SetString("name" + counter.ToString(), JournalItem.name);
     *              text.SetBool("isDone" + counter.ToString(),JournalItem.isDone);
     *              text.SetInt("numberOfPrerequisites" + counter.ToString() , JournalItem.prerequisites.Count);
     *              for(int i = 0; i < JournalItem.prerequisites.Count;i++){
     *                      Debug.Log("indexPrerequisiteOf" + counter.ToString()+"_"+i.ToString()+"= "+JournalItem.prerequisites[i]);
     *                      text.SetInt("indexPrerequisiteOf" + counter.ToString()+"_"+i.ToString(), JournalItem.prerequisites[i]);
     *              }
     *              counter++;
     *      }
     * }*/
    //Loads the reactions from a file, and returns a dictionary

    public static Dictionary <int, JournalUIItem> LoadJournalUIItems(int expo)
    {
        json = new JSONEditor("journalItems" + expo.ToString());

        int numberOfJournalItems = json.NumberOfFields(0);

        Dictionary <int, JournalUIItem> journalUIItems = new Dictionary <int, JournalUIItem>();

        if (numberOfJournalItems > 0)
        {
            for (int i = 0; i < numberOfJournalItems; i++)
            {
                JournalUIItem journalItem = new JournalUIItem();

                journalItem.index = json.GetInt(i, "index");

                journalItem.name   = json.GetString(i, "name");
                journalItem.isDone = json.GetBool(i, "isDone");
                journalItem.prerequisites.Clear();
                for (int n = 0; n < json.GetInt(i, "numberOfPrerequisites"); n++)
                {
                    int indexOfPre = int.Parse(json.GetSubValue(i, "indexPrerequisiteOf", n));
                    journalItem.prerequisites.Add(indexOfPre);
                }
                journalItem.prerequisitesDone = false;

                if (!journalUIItems.ContainsKey(journalItem.index))
                {
                    journalUIItems.Add(journalItem.index, journalItem);
                }
            }
        }
        return(journalUIItems);
    }
Example #4
0
    //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);
    }
    /* -------------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);
    }
Example #8
0
    /*public static Dictionary<int, Dictionary<string, string>> ProcessPhases(JSONEditor jsonEditor) {
     * }*/

    //Load the step, putting it into a Dictionary
    private static Dictionary <string, string> LoadStep(JSONEditor jsonEditor, int i)
    {
        Dictionary <string, string> step = new Dictionary <string, string> ();

        step.Add("typeOfStep", jsonEditor.GetString(i, "typeOfStep"));

        switch (step ["typeOfStep"])
        {
        case "1":
            step.Add("option1", jsonEditor.GetString(i, "option1"));
            step.Add("option2", jsonEditor.GetString(i, "option2"));
            step.Add("option3", jsonEditor.GetString(i, "option3"));
            step.Add("option4", jsonEditor.GetString(i, "option4"));
            step.Add("option5", jsonEditor.GetString(i, "option5"));
            step.Add("correctAnswer", jsonEditor.GetString(i, "correctAnswer"));
            break;

        case "2":
            step.Add("compoundFormula", jsonEditor.GetString(i, "compoundFormula"));             //Compound Formula
            break;

        case "3":
            step.Add("compoundFormula", jsonEditor.GetString(i, "compoundFormula"));
            step.Add("molarity", jsonEditor.GetString(i, "molarity"));             //Molarity
            step.Add("maxError", jsonEditor.GetString(i, "maxError"));
            break;

        case "4":
            step.Add("compoundFormula", jsonEditor.GetString(i, "compoundFormula"));
            step.Add("molarity", jsonEditor.GetString(i, "molarity"));
            step.Add("minVolume", jsonEditor.GetString(i, "minVolume"));
            step.Add("maxError", jsonEditor.GetString(i, "maxError"));
            break;
        }

        return(step);
    }