Beispiel #1
0
    public void VerifFormule()
    {
        iField = focusHandler.getCurrentFormule();
        output = focusHandler.getCurrentVerif();

        if (string.IsNullOrEmpty(iField.text))
        {
            return;
        }
        try
        {
            Formule     formule = FormuleFactory.parse(iField.text);
            Jardin      jardin  = terrainHandler.getJardin();
            Communicate comm    = new Communicate(SCRIPT_PYTHON, jardin);
            foreach (Element el in jardin.GetElements())
            {
                Debug.Log(el);
            }


            //lance le script
            comm.GetSource().Execute(comm.GetScope());
            object pythonForm = comm.HandleForm(formule);
            Func <Jardin, object> unity_my_interp_formul = comm.GetScope().GetVariable <Func <Jardin, object> >("unity_my_interp_formul");
            object pythonJardin = unity_my_interp_formul(jardin);
            Func <object, object, object> unity_eval_one_form = comm.GetScope().GetVariable <Func <object, object, object> >("unity_eval_one_form");
            var res = unity_eval_one_form(pythonJardin, pythonForm);
            Debug.Log("res=" + res);

            //Affiche résultat
            if ((bool)res == true)
            {
                output.color = Color.green;
                output.text  = "Vrai";
            }
            else
            {
                output.color = Color.red;
                output.text  = "Faux";
            }
        }
        catch (ParserLogException)
        {
            output.color = Color.red;
            output.text  = "Erreur";
            Debug.Log("Erreur formule");
        }
        catch (ValueErrorException)
        {
            output.color = new Color32(255, 128, 0, 255);
            output.text  = "Var libre";
        }
        catch (Exception)
        {
            output.color = Color.red;
            output.text  = "Erreur imprévue";
        }
    }
Beispiel #2
0
    void OnMouseDown()
    {
        // Debug.Log("tile: " + x + " : " + y + " CLICK");
        if (_flower)
        {
            TerrainHandler            terrain = this.transform.parent.gameObject.GetComponent <TerrainHandler>();
            TerrainHandler.ToggleType mode    = terrain.getMode();

            if (mode == TerrainHandler.ToggleType.Create)
            {
                _flower.setXY((float)x, (float)y);
                terrain.getJardin().Add(_flower.copyToElement());
            }
            if (mode == TerrainHandler.ToggleType.Delete)
            {
                if (_flower.isAttribuate())
                {
                    _flower.setXY(-42, -42);
                    _flower.destroyFlower(terrain.getJardin());
                }
            }
        }
    }
Beispiel #3
0
    void save()
    {
        /*JARDIN*/
        Jardin jardin = terrainHandler.getJardin();
        string path   = fName.text;

        if (path.Length == 0)
        {
            /* Invalid path */
            Debug.Log("Invalid path");
            return;
        }

        try
        {
            StreamWriter sw = new StreamWriter(@path);

            /*Write formules */
            sw.WriteLine("#FORMULES");
            for (int i = 1; i <= NB_FORMULE; i++)
            {
                InputField iField = (InputField)GameObject.Find(FORMULE_PATH + "Form_" + i).GetComponent <InputField>();
                if (iField.text.Length == 0)
                {
                    continue;
                }
                sw.WriteLine(iField.text);
            }

            /*Write jardin*/
            sw.WriteLine("#JARDIN");
            foreach (Element elem in jardin.GetElements())
            {
                sw.WriteLine(elem.ToString());
            }

            Debug.Log("sauvegarder dans : " + path);
            sw.Close();
            ClosePanel();
        }
        catch (Exception)
        {
            Debug.Log("Error while writing file path=" + path);
            fName.text = "Dossier \"" + path + "\" introuvable !";
            return;
        }
    }
Beispiel #4
0
    public void VerifFormule()
    {
        Jardin      jardin = terrainHandler.getJardin();
        Communicate comm   = new Communicate(SCRIPT_PYTHON, jardin);

        //lance le script
        comm.GetSource().Execute(comm.GetScope());
        for (int i = 1; i <= NB_FORMULE; i++)
        {
            iField = (InputField)GameObject.Find(PATH + "Form_" + i).GetComponent <InputField>();
            output = (Text)GameObject.Find(PATH + "VerifPan_" + i + "/verif_resultat_" + i).GetComponent <Text>();

            if (iField.text == "")
            {
                continue;
            }
            try
            {
                Formule formule = FormuleFactory.parse(iField.text);


                foreach (Element el in jardin.GetElements())
                {
                    Debug.Log(el);
                }

                object pythonForm = comm.HandleForm(formule);
                Func <Jardin, object> unity_my_interp_formul = comm.GetScope().GetVariable <Func <Jardin, object> >("unity_my_interp_formul");
                object pythonJardin = unity_my_interp_formul(jardin);
                Func <object, object, object> unity_eval_one_form = comm.GetScope().GetVariable <Func <object, object, object> >("unity_eval_one_form");
                var res = unity_eval_one_form(pythonJardin, pythonForm);

                //Affiche résultat
                if ((bool)res == true)
                {
                    output.color = Color.green;
                    output.text  = "Vrai";
                }
                else
                {
                    output.color = Color.red;
                    output.text  = "Faux";
                }
            }
            catch (ParserLogException)
            {
                output.color = Color.red;
                output.text  = "Erreur";
                Debug.Log("Erreur formule");
            }
            catch (ValueErrorException)
            {
                output.color = new Color32(255, 128, 0, 255);
                output.text  = "Var libre";
            }
            catch (Exception)
            {
                output.color = Color.red;
                output.text  = "Erreur imprévue";
            }
        }
    }