Copy() public method

Copy a JSONObject. This could probably work better
public Copy ( ) : JSONObject,
return JSONObject,
Exemplo n.º 1
0
    private IEnumerator _hurt(int dmg)
    {
        print($"{gameObject.name} hurt for {dmg}");
        health -= dmg;
        if (health <= 0)
        {
            GameRound.Instance.EndGame(gameObject.name);
        }

        JSONObject jSonObject = HurtMsgFormat.Copy();

        jSonObject["playerName"].str = gameObject.name;
        jSonObject["health"].n       = health;
        jSonObject["dmg"].n          = dmg;
        _eventManager.InvokeEvent("playerHurt", jSonObject);
        yield return(null);
    }
Exemplo n.º 2
0
        public void Change(string docId, JSONObject fields, JSONObject cleared)
        {
            JSONObject jsonDocument = DocumentToJSONObject(documents[docId]);

            DocType oldDocument = default(DocType);

            if (OnChanged != null)
            {
                oldDocument = JSONObjectToDocument(jsonDocument.Copy());
            }

            if (fields != null)
            {
                foreach (string field in fields.keys)
                {
                    jsonDocument.SetField(field, fields[field]);
                }
            }

            if (cleared != null)
            {
                foreach (JSONObject field in cleared.list)
                {
                    jsonDocument.RemoveField(field.str);
                }
            }

            DocType newDocument = JSONObjectToDocument(jsonDocument);

            if (OnChanged != null)
            {
                OnChanged(oldDocument, newDocument);
            }

            documents[docId] = newDocument;
        }
Exemplo n.º 3
0
    private IEnumerator ParseDataFile()
    {
        // Construct a JSONObject from the output.txt file.
        Dictionary <string, string> fileInfo = new Dictionary <string, string>(); // info from output.txt comes here in key/value pairs.

        fileInfo.Clear();

        string filePath = System.IO.Path.Combine(SkydataPath, "unityData.txt");

        //Debug.Log("Trying to get " + filePath);

        if (filePath.Contains("://"))
        {
            // Mostly WebGL path...
            Debug.Log("Reading data via WebRequest: " + filePath);
            UnityWebRequest www = UnityWebRequest.Get(filePath);
            yield return(www.SendWebRequest());

            string text;
            Debug.Log("Asked for text file at URL:" + www.url);
            if (www.isNetworkError || www.isHttpError)
            {
                Debug.LogWarning(message: "CANNOT RETRIEVE TEXT!" + www.error);
            }
            else
            {
                // Show results as text
                Debug.Log(www.downloadHandler.text);

                // Or retrieve results as binary data
                //byte[] results = www.downloadHandler.data;
            }
            text = www.downloadHandler.text;
            // TODO: Parse into fileInfo dictionary
            try
            {
                // Create an instance of StringReader to read from the returned text.
                // The using statement also closes the StringReader.
                using (StringReader sr = new StringReader(text))
                {
                    String line;
                    // Read and display lines from the file until end of string.
                    while ((line = sr.ReadLine()) != null)
                    {
                        //Debug.Log(line);
                        String[] keyValPair = line.Split(new Char[] { ':' }, 2);
                        //Debug.Log(keyValPair);
                        if (keyValPair.Length == 2)
                        {
                            fileInfo.Add(keyValPair[0], keyValPair[1]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Debug.LogWarning("The www.text string could not be parsed:" + e.Message);
            }
            // At this point all data from the URL path have been read.
        }
        else
        {
            // LOCAL FILE
            //Debug.Log("Reading data from local file " + filePath);
            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(filePath))
                {
                    String line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        //Debug.Log(line);
                        String[] keyValPair = line.Split(new Char[] { ':' }, 2);
                        //Debug.Log(keyValPair);
                        if (keyValPair.Length == 2)
                        {
                            fileInfo.Add(keyValPair[0], keyValPair[1]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Debug.LogWarning("The file could not be read:" + e.Message);
            }
            // At this point all data have been read.
            // Prepare the light info object. They are currently not used, but maybe later?
        }

        jsonLightInfo = new JSONObject();
        jsonSunInfo   = new JSONObject();
        jsonMoonInfo  = new JSONObject();
        jsonVenusInfo = new JSONObject();
        try
        {
            jsonSunInfo.AddField("name", "Sun");
            jsonSunInfo.AddField("altitude", float.Parse(fileInfo["Sun Altitude"]));
            jsonSunInfo.AddField("azimuth", float.Parse(fileInfo["Sun Azimuth"]));
            jsonSunInfo.AddField("vmag", float.Parse(fileInfo["Sun Magnitude"]));
            jsonSunInfo.AddField("vmage", float.Parse(fileInfo["Sun Magnitude (after extinction)"]));
            jsonSunInfo.AddField("elong", float.Parse(fileInfo["Sun Longitude"]));
            if (fileInfo.ContainsKey("Sun Size"))
            {
                jsonSunInfo.AddField("diameter", float.Parse(fileInfo["Sun Size"]));
            }
            else
            {
                jsonSunInfo.AddField("diameter", 0.5f);
            }
            jsonMoonInfo.AddField("name", "Moon");
            jsonMoonInfo.AddField("altitude", float.Parse(fileInfo["Moon Altitude"]));
            jsonMoonInfo.AddField("azimuth", float.Parse(fileInfo["Moon Azimuth"]));
            jsonMoonInfo.AddField("illumination", float.Parse(fileInfo["Moon illumination"]));
            jsonMoonInfo.AddField("vmag", float.Parse(fileInfo["Moon Magnitude"]));
            jsonMoonInfo.AddField("vmage", float.Parse(fileInfo["Moon Magnitude (after extinction)"]));
            //jsonMoonInfo.AddField("elong",  float.Parse(fileInfo["Moon Longitude"]));
            if (fileInfo.ContainsKey("Moon Size"))
            {
                jsonMoonInfo.AddField("diameter", float.Parse(fileInfo["Moon Size"]));
            }
            else
            {
                jsonMoonInfo.AddField("diameter", 0.5f);
            }
            jsonVenusInfo.AddField("name", "Venus");
            jsonVenusInfo.AddField("altitude", float.Parse(fileInfo["Venus Altitude"]));
            jsonVenusInfo.AddField("azimuth", float.Parse(fileInfo["Venus Azimuth"]));
            jsonVenusInfo.AddField("vmag", float.Parse(fileInfo["Venus Magnitude"]));
            jsonVenusInfo.AddField("vmage", float.Parse(fileInfo["Venus Magnitude (after extinction)"]));
            //jsonVenusInfo.AddField("elong", fileInfo["Venus Longitude"]);
            jsonVenusInfo.AddField("diameter", 0.0f); // For the naked eye, we assume point source (to switch off the impostor sphere!)
            // The following field can only be in the file with Stellarium r9130+ (2017-02-05).
            if (fileInfo.ContainsKey("Landscape Brightness"))
            {
                jsonSunInfo.AddField("ambientInt", float.Parse(fileInfo["Landscape Brightness"]));
                jsonMoonInfo.AddField("ambientInt", float.Parse(fileInfo["Landscape Brightness"]));
                jsonVenusInfo.AddField("ambientInt", float.Parse(fileInfo["Landscape Brightness"]));
            }


            if (float.Parse(fileInfo["Sun Altitude"]) > -3.0f)
            {
                jsonLightInfo = jsonSunInfo.Copy();
            }
            else if (float.Parse(fileInfo["Moon Altitude"]) > 0.0f)
            {
                jsonLightInfo = jsonMoonInfo.Copy();
            }
            else if (float.Parse(fileInfo["Venus Altitude"]) > 0.0f)
            {
                jsonLightInfo = jsonVenusInfo.Copy();
            }
            else
            {
                jsonLightInfo.AddField("name", "none");
                // The following field can only be in the file with Stellarium r9130+ (2017-02-05).
                if (fileInfo.ContainsKey("Landscape Brightness"))
                {
                    jsonLightInfo.AddField("ambientInt", float.Parse(fileInfo["Landscape Brightness"]));
                }
                else
                {
                    jsonLightInfo.AddField("ambientInt", 0.05f);
                }
            }
        }
        catch (Exception e)
        {
            // Let the user know what went wrong.
            Debug.LogWarning("info lookup failed:" + e.Message);
            jsonLightInfo.AddField("name", "none");
            jsonLightInfo.AddField("ambientInt", 0.05f);
            //jsonLightInfo.AddField("landscape-brt", "0.05");
        }

        jsonTime = new JSONObject();
        //jsonTime.Clear();
        jsonTime.AddField("jday", float.Parse(fileInfo["JD"])); //current Julian day
        jsonTime.AddField("deltaT", "unknown");                 //current deltaT as determined by the current dT algorithm  --> TODO: Make float! Or fix in skybox.ssc
        jsonTime.AddField("gmtShift", "unknown");               //the timezone shift to GMT                                 --> TODO: Make float! Or fix in skybox.ssc
        jsonTime.AddField("timeZone", "unknown");               //the timezone name                                         --> TODO: Fix in skybox.ssc and retrieve as string
        jsonTime.AddField("utc", fileInfo["Date (UTC)"]);       //the time in UTC time zone as ISO8601 time string
        jsonTime.AddField("local", fileInfo["Date"]);           //the time in local time zone as ISO8601 time string
        jsonTime.AddField("isTimeNow", false);                  //if true, the Stellarium time equals the current real-world time
        jsonTime.AddField("timerate", 0.0f);                    //the current time rate (in secs). Obviously 0 for a static skybox...
    }