Ejemplo n.º 1
0
        public void ScriptingTick()
        {
            if (_playerScripts == null)
            {
                return;
            }

            if (!Active)
            {
                return;
            }

            foreach (var coroutine in _activeCoroutines)
            {
                var result = coroutine.Execute(_executionContext);
                if (result is ActionResult.ActionFinished)
                {
                    _finishedCoroutines.Add(coroutine);
                }
            }

            foreach (var coroutine in _finishedCoroutines)
            {
                _activeCoroutines.Remove(coroutine);
            }

            foreach (var playerScripts in _playerScripts)
            {
                playerScripts.Execute(_executionContext);
            }

            OnUpdateFinished?.Invoke(this, this);

            Timers.Update();
        }
Ejemplo n.º 2
0
        public async Task CheckForUpdatesAsync()
        {
            // TODO: use string resources here
            Logger.Info("Checking for updates...");

            try {
                using (HttpClient client = new HttpClient()) {
                    client.BaseAddress = new Uri(ConfigurationManager.AppSettings["updateHost"]);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage response = await client.GetAsync("Launcher/Updates").ConfigureAwait(false);

                    await Task.Delay(1000).ConfigureAwait(false);

                    if (response.IsSuccessStatusCode)
                    {
                        List <UpdateContract> updates;
                        using (Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) {
                            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List <UpdateContract>));
                            updates = (List <UpdateContract>)serializer.ReadObject(stream);
                        }

                        Logger.Debug($"Read updates: {string.Join(",", (object[])updates.ToArray())}");

                        //// TODO: check the updates and then update!

                        UpdateStatus = "Up to date!";
                        OnUpdateFinished?.Invoke(this, new UpdateFinishedEventArgs()
                        {
                            Success = true,
                        });
                    }
                    else
                    {
                        UpdateStatus = $"Error contacting update server: {response.ReasonPhrase}";
                        OnUpdateFinished?.Invoke(this, new UpdateFinishedEventArgs()
                        {
                            Success = false,
                        });
                    }
                }
            } catch (Exception e) {
                UpdateStatus = $"Error contacting update server: {e.Message}";
                OnUpdateFinished?.Invoke(this, new UpdateFinishedEventArgs()
                {
                    Success = false,
                });
            }
        }
Ejemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            if (_mapScripts == null)
            {
                return;
            }

            // TODO: Remove this hack when we have separate update and render loops.
            _30hzHack = !_30hzHack;
            if (_30hzHack)
            {
                return;
            }

            if (!Active)
            {
                return;
            }

            foreach (var coroutine in _activeCoroutines)
            {
                var result = coroutine.Execute(_executionContext);
                if (result is ActionResult.ActionFinished)
                {
                    _finishedCoroutines.Add(coroutine);
                }
            }

            foreach (var coroutine in _finishedCoroutines)
            {
                _activeCoroutines.Remove(coroutine);
            }

            _mapScripts.Execute(_executionContext);

            OnUpdateFinished?.Invoke(this, this);

            Timers.Update();

            Frame++;
        }
Ejemplo n.º 4
0
        public void ScriptingTick()
        {
            if (Game.Scene3D?.PlayerScripts?.ScriptLists == null)
            {
                return;
            }

            if (!Active)
            {
                return;
            }

            foreach (var playerScripts in Game.Scene3D.PlayerScripts.ScriptLists)
            {
                playerScripts?.Execute(_executionContext);
            }

            OnUpdateFinished?.Invoke(this, this);

            Timers.Update();

            UpdateCameraFadeOverlay();
        }
        public Task UpdateMappingDataTask()
        {
            return(new Task(() => {
                RefreshTimer.Stop();
                OnUpdate?.Invoke();
                JsonTextReader jReader;
                using (var client = new WebClient()) {
                    var data = Encoding.UTF8.GetString(client.DownloadData(Properties.Settings.Default.VersionJsonUrl));
                    jReader = new JsonTextReader(new StringReader(data));
                }

                MappingData.Clear();
                VersionJson jsonInput = VersionJson.Init;
                string keyVersion = null;
                MappingType keyMapType = MappingType.Snapshot;

                while (jReader.Read())
                {
                    var value = jReader.Value;
                    if (jReader.Value != null)
                    {
                        switch (jsonInput)
                        {
                        case VersionJson.MCVersion:
                            MappingData[keyVersion = (string)value] = new Dictionary <MappingType, SortedSet <int> >();
                            break;

                        case VersionJson.MapType:
                            if (!Enum.TryParse((string)value, true, out keyMapType))
                            {
                                throw new InvalidDataException("Expected Mapping type.");
                            }
                            break;

                        case VersionJson.Version:
                            if (!MappingData[keyVersion].ContainsKey(keyMapType))
                            {
                                MappingData[keyVersion][keyMapType] = new SortedSet <int>();
                            }
                            MappingData[keyVersion][keyMapType].Add((int)(long)value);
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        if (jReader.TokenType == JsonToken.StartObject)
                        {
                            jsonInput += 1;
                        }
                        else if (jReader.TokenType == JsonToken.StartArray)
                        {
                            jsonInput += 1;
                        }
                        else if (jReader.TokenType == JsonToken.EndObject)
                        {
                            jsonInput -= 1;
                        }
                        else if (jReader.TokenType == JsonToken.EndArray)
                        {
                            jsonInput -= 1;
                        }
                    }
                }

                Dispatcher.Invoke(() => {
                    var versions = new List <string>(MappingData.Keys);
                    versions.Sort(MCVersionComparer.Comparer);
                    versions.Reverse();
                    versions.Insert(0, "Semi-Live");
                    versions.Add("Custom");
                    MCVersionDropDown.ItemsSource = versions;
                });

                RefreshTimer.Start();
                OnUpdateFinished?.Invoke();
                IsUpdating = false;
            }));
        }