public JSONObject Copy() { //return JSONParser.parse(print()); //this is slower than your grandma JSONObject xCopy = new JSONObject(type); xCopy.Merge(this); //simple, eh. but a 100 times faster because it won't torture the f****n' garbage collector! return(xCopy); }
private static List <KeyValuePair <string, string> > GetGameSettings(List <JSONObject> messages) { List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >(); JSONObject settingsJSON = JSONObject.obj; (from m in messages select m.asCustom("Settings", (JSONObject e) => e, () => null) into m where m != null select m).Reverse().ToList().ForEach(delegate(JSONObject m) { settingsJSON.Merge(m); }); if (settingsJSON.list.Count() > 0) { list.Add(new KeyValuePair <string, string>("Settings", settingsJSON.ToString())); } return(list); }
// This must be called after Start() to retrieve an update to the state changes of Stellarium into the json state. // changes: json, actionId, propertyId // TODO: Change to using UWR private IEnumerator UpdateStelJson() { #if !UNITY_WEBGL if (connectToStellarium && spoutMode) // Esp time updates are not useful while in skybox mode! { //Debug.Log("UpdateStelJson()..."); // retrieve deltas string url = "http://localhost:" + stelPort + "/api/main/status?actionId=" + actionId + "&propId=" + propertyId; WWW www = new WWW(url); yield return(www); //Debug.Log("WWW answer (JSON update):" + www.text); // Parse JSON answer! JSONObject json2 = new JSONObject(www.text); // this should be a rather short JSON with only the changed actions/properties. if (json && json.Count > 0 && json2 && json2.Count > 0) { json.Merge(json2); jsonActions = json.GetField("actionChanges"); if (jsonActions && jsonActions.HasField("id")) { jsonActions.GetField(ref actionId, "id"); } jsonProperties = json.GetField("propertyChanges"); if (jsonProperties && jsonProperties.HasField("id")) { jsonProperties.GetField(ref propertyId, "id"); } jsonTime = json.GetField("time"); //Debug.Log("Json now: " + json.Print(true)); } else { Debug.LogWarning("StelController::UpdateStelJson(): json invalid. Setting to Deltas. Things may break from now!"); json = json2; connectToStellarium = false; spoutMode = false; jsonTime = streamingSkybox.GetJsonTime(); StartCoroutine(QueryObjectInfo("Sun")); StartCoroutine(QueryObjectInfo("Moon")); StartCoroutine(QueryObjectInfo("Venus")); } } else { #endif //Debug.Log(message: "StelController::UpdateStelJson(): getting jsonTime from streaming Skybox..."); jsonTime = streamingSkybox.GetJsonTime(); StartCoroutine(QueryObjectInfo("Sun")); StartCoroutine(QueryObjectInfo("Moon")); StartCoroutine(QueryObjectInfo("Venus")); #if !UNITY_WEBGL } //Debug.Log("JSON updated. actionId=" + actionId + " propId=" + propertyId); //Debug.Log("jsonTime: " + jsonTime.Print(true)); //string utcString =""; //jsonTime.GetField(ref utcString, "utc"); //Debug.Log("jsonTime: utc=" + utcString); //Debug.Log("UpdateStelJson()...DONE"); #endif UpdateTimeGUI(); #if UNITY_WEBGL // just to fulfill return type. yield break; #endif }
public void GetStatus(int actionId = default(int), int propId = default(int)) { Dictionary <string, string> parameters = new Dictionary <string, string>(); if (actionId != default(int)) { parameters.Add("actionId", actionId.ToString()); } if (propId != default(int)) { parameters.Add("propId", propId.ToString()); } Stellarium.GET(Path, "status", parameters, (result, error) => { if (error != null) { Debug.LogError(string.Format("[{0}] {1}", Identifier, error)); return; } JSONObject json = new JSONObject(result); if (statusJSON) { statusJSON.Merge(json); } else { statusJSON = json; } Status status = JsonUtility.FromJson <Status>(result); if (statusJSON.HasField("actionChanges")) { Dictionary <string, string> jsonActionChanges = statusJSON.GetField("actionChanges").GetField("changes").ToDictionary(); status.actionChanges.changes = new Changes(); foreach (KeyValuePair <string, string> change in jsonActionChanges) { bool changed; if (bool.TryParse(change.Value, out changed)) { status.actionChanges.changes.Add(change.Key, changed); } } } else { status.actionChanges.changes = new Changes(); } if (statusJSON.HasField("propertyChanges")) { Dictionary <string, string> jsonPropertyChanges = statusJSON.GetField("propertyChanges").GetField("changes").ToDictionary(); status.propertyChanges.changes = new Changes(); foreach (KeyValuePair <string, string> change in jsonPropertyChanges) { bool changed; if (bool.TryParse(change.Value, out changed)) { status.propertyChanges.changes.Add(change.Key, changed); } } } else { status.propertyChanges.changes = new Changes(); } if (OnGotStatus != null) { OnGotStatus(status); } }); }
public JSONObject Copy() { //return JSONParser.parse(print()); //this is slower than your grandma JSONObject xCopy=new JSONObject(type); xCopy.Merge(this); //simple, eh. but a 100 times faster because it won't torture the f****n' garbage collector! return xCopy; }