private IEnumerator MainLoop() { Debug.Log("Initializing wvw data..."); string url = "https://api.guildwars2.com/v2/worlds?ids=all"; yield return(StartCoroutine(RestCache.Get(mWorldPath, url))); mWorlds = JsonConvert.DeserializeObject <List <Gw2World> >(RestCache.mJsonData); mWorlds.Sort((x, y) => x.name.CompareTo(y.name)); Debug.Log("Servers: " + mWorlds.Count); RefreshDropDown(); url = "https://api.guildwars2.com/v2/wvw/objectives?ids=all"; yield return(StartCoroutine(RestCache.Get(mObjectivesPath, url))); mObjectivesList = JsonConvert.DeserializeObject <List <Gw2Objective> >(RestCache.mJsonData); mObjectiveMap = new Dictionary <string, Gw2Objective>(); Debug.Log("Objectives: " + mObjectivesList.Count); foreach (var objective in mObjectivesList) { mObjectiveMap[objective.id] = objective; } url = "https://api.guildwars2.com/v2/maps?ids=38,95,96,1099"; yield return(StartCoroutine(RestCache.Get(mMapsPath, url))); var maps = JsonConvert.DeserializeObject <List <Gw2Map> >(RestCache.mJsonData); foreach (var map in maps) { mMapTable[map.id] = map; } Debug.Log("Maps: " + mMapTable.Count); url = "https://api.guildwars2.com/v2/wvw/matches?world=" + Config.Instance.worldId; yield return(StartCoroutine(RestCache.Get(mMatchesPath, url))); mMatch = JsonConvert.DeserializeObject <Gw2Match>(RestCache.mJsonData); fullyLoaded = !RestCache.mCached; if (RestCache.mCached) { StartCoroutine(UpdateMatch()); } int limiter = 0; while (isInWvwMap && isActiveAndEnabled) { if (++limiter > 5) { StartCoroutine(UpdateMatch()); limiter = 0; } Gw2MatchMap mapItem = mMatch.maps.Find(x => x.id == mMapId); if (mapItem != null) { RefreshMap(mapItem); } yield return(new WaitForSeconds(1.0f)); } mainLoop = null; }
private void RefreshMap(Gw2MatchMap mapItem) { int index = 0; SetAppIconColor(); float[][] cr = mMapTable[mapItem.id].continent_rect; var rect = new Rect(cr[0][0], cr[0][1], cr[1][0] - cr[0][0], cr[1][1] - cr[0][1]); foreach (var objective in mapItem.objectives) { var objectiveItem = mObjectiveMap[objective.id]; if (objectiveItem == null || objectiveItem.coord == null || objectiveItem.coord.Length < 3) { //Debug.Log("Couldn't find objective lookup for id: " + objective.id); continue; } index++; } ArrayExpander.Expand(transform, index); index = 0; foreach (var objective in mapItem.objectives) { var objectiveItem = mObjectiveMap[objective.id]; if (objectiveItem == null || objectiveItem.coord == null || objectiveItem.coord.Length < 3) { //Debug.Log("Couldn't find objective lookup for id: " + objective.id); continue; } var wvwItem = transform.GetChild(index).GetComponent <WvWItem>(); float[] eventcoord = objectiveItem.coord; float x = (eventcoord[0] - rect.center.x) * worldScale; float z = (rect.center.y - eventcoord[1]) * worldScale; float y = eventcoord[2] * heightScale + heightOffset; //Debug.Log(objectiveItem.name + " " + x + " " + z); wvwItem.transform.position = new Vector3(x, y, z); wvwItem.image.sprite = GetSprite(objectiveItem.type); wvwItem.image.color = fullyLoaded ? objective.GetColor() : Color.white; wvwItem.title.text = objectiveItem.name; wvwItem.title.color = wvwItem.image.color; wvwItem.gameObject.name = objectiveItem.name; wvwItem.gameObject.SetActive(true); string ri = fullyLoaded ? GetRI(objective.last_flipped) : null; wvwItem.riLabel.gameObject.SetActive(ri != null); if (ri != null) { wvwItem.riLabel.text = ri; } index++; } }