private List <string> getCodes(JSONNode json) { List <string> rv = new List <string>(); JSONArray codes = json["codes"].AsArray; IEnumerator enumerator = codes.GetEnumerator(); while (enumerator.MoveNext()) { rv.Add(((JSONData)(enumerator.Current)).Value); } // TODO: Get codes from the server // hack { List <string> errors = getErrors(json); if (errors != null) { errors.ForEach(e => { if (e.Length >= 42 && e.Substring(0, 42) == "User does not have enough to pay entry fee") { rv.Add(ArbiterErrorCodes.INSUFFICIENT_FUNDS); } }); } // } hack return(rv); }
// Parses the Tournament.Users JSON array returned from the server and converts each item into a c# TournamentUser public static List <Arbiter.TournamentUser> ParseUsers(JSONNode usersNode) { List <Arbiter.TournamentUser> rv = new List <Arbiter.TournamentUser>(); JSONArray rawUsers = usersNode.AsArray; IEnumerator enumerator = rawUsers.GetEnumerator(); while (enumerator.MoveNext()) { JSONClass userNode = enumerator.Current as JSONClass; string id = userNode["id"]; string username = userNode["username"]; bool paid = userNode["paid"].AsBool; string score = userNode["score"]; // TODO: Parse if the user has viewed this tournament. For now assume they have not bool viewed = false; Arbiter.TournamentUser user = new Arbiter.TournamentUser(id); user.Paid = paid; user.Username = username; user.Viewed = viewed; if (score != null && score != "null" && score != "<null>") { user.Score = int.Parse(score); } rv.Add(user); } return(rv); }
private List <string> getDescriptions(JSONNode json) { List <string> rv = new List <string>(); JSONArray errors = json["descriptions"].AsArray; IEnumerator enumerator = errors.GetEnumerator(); while (enumerator.MoveNext()) { rv.Add(((JSONData)(enumerator.Current)).Value); } return(rv); }
public void MetadataArrayUI(JSONArray j, string key) { int n = 0; JSONNode.Enumerator iter = j.GetEnumerator(); while (iter.MoveNext()) { JSONNode N = (JSONNode)iter.Current; if (N.AsArray != null && N.AsArray.Count != 0) { if (N.AsArray.Count == 3 && N.AsArray [0].Value != "XYZ") { MetadataVector3UI(N.AsArray, n.ToString()); n++; continue; } string name = key + n.ToString(); if (!ShowPosition.ContainsKey(name)) { ShowPosition.Add(name, true); } ShowPosition [name] = EditorGUILayout.Foldout(ShowPosition [name], name); if (ShowPosition [name] == true) { EditorGUI.indentLevel++; MetadataArrayUI(N.AsArray, name); EditorGUI.indentLevel--; } n++; continue; } if (N.AsObject != null && N.AsObject.Count != 0) { string name = key + n.ToString(); if (!ShowPosition.ContainsKey(name)) { ShowPosition.Add(name, true); } ShowPosition [name] = EditorGUILayout.Foldout(ShowPosition [name], name); if (ShowPosition [name] == true) { EditorGUI.indentLevel++; MetadataObjectUI(N.AsObject); EditorGUI.indentLevel--; } n++; continue; } EditorGUILayout.LabelField(n.ToString(), N.Value.ToString()); n++; } }
public static List <Arbiter.Tournament> ParseTournaments(JSONNode tournamentsNode) { List <Arbiter.Tournament> rv = new List <Arbiter.Tournament>(); JSONArray rawTournaments = tournamentsNode.AsArray; IEnumerator enumerator = rawTournaments.GetEnumerator(); while (enumerator.MoveNext()) { JSONClass tournament = enumerator.Current as JSONClass; rv.Add(ParseTournament(tournament)); } return(rv); }
private void CustomRestore(JSONArray currentStorables) { Dictionary <string, bool> dictionary = new Dictionary <string, bool>(); IEnumerator enumerator = currentStorables.GetEnumerator(); try { while (enumerator.MoveNext()) { JSONClass jSONClass = (JSONClass)enumerator.Current; string id = jSONClass["id"]; if (id == "geometry" || id == "textures") { JSONStorable storable = containingAtom.GetStorableByID(id); if (!dictionary.ContainsKey(id)) { dictionary.Add(id, value: true); } continue; } JSONStorable value = containingAtom.GetStorableByID(id); if (value != null) { value.RestoreFromJSON(jSONClass, false, true, null); if (!dictionary.ContainsKey(id)) { dictionary.Add(id, value: true); } } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } JSONStorable[] array = containingAtom.GetStorableIDs().Select((id) => containingAtom.GetStorableByID(id)).ToArray(); JSONStorable[] array2 = array; foreach (JSONStorable jSONStorable in array2) { if (!jSONStorable.exclude && !dictionary.ContainsKey(jSONStorable.storeId) && (!jSONStorable.onlyStoreIfActive || jSONStorable.gameObject.activeInHierarchy)) { JSONClass jc2 = new JSONClass(); jSONStorable.RestoreFromJSON(jc2, false, true); } } }
// I'm sure the is a more elegant way of converting items in the JSON array in a c# list of strings, but this solves the type casting issue for now public static List <string> ParseWinners(JSONNode winnersNode) { List <string> winners = new List <string>(); if (winnersNode != null) { JSONArray rawNode = winnersNode.AsArray; IEnumerator enumerator = rawNode.GetEnumerator(); while (enumerator.MoveNext()) { JSONData winnerId = enumerator.Current as JSONData; winners.Add(winnerId.Value); } } return(winners); }