コード例 #1
0
        protected override void OnGeneralSimInitialize(object sender, JsonRpcMethodEventArgs e)
        {
            LogToScreen("Received request: general/simInitialize");

            if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage))
            {
                var requestObject = JsonRpcHelper.TranslateAsRequest(e.ParsedRequestObject);
                var param0        = requestObject.Params[0];

                Debug.Assert(param0 != null, nameof(param0) + " != null");

                var param0Object = param0.ToObject <GeneralSimInitializeRequestParams>();

                var selectedFormat = SelectFormat(param0Object.SupportedFormats);

                var responseResult = new GeneralSimInitializeResponseResult {
                    SelectedFormat = selectedFormat
                };

                e.Context.RpcOk(responseResult);
            }
            else
            {
                Debug.Print(errorMessage);
                e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage);
            }
        }
コード例 #2
0
        protected override void OnPreviewPause(object sender, JsonRpcMethodEventArgs e)
        {
            LogToScreen("Received request: preview/pause");

            if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage))
            {
                var syncTimer = _communication.Game.FindSingleElement <SyncTimer>();

                if (syncTimer == null)
                {
                    e.Context.RpcError(JsonRpcErrorCodes.InternalError, "Cannot find the " + nameof(SyncTimer) + " component.", statusCode: HttpStatusCode.InternalServerError);
                    return;
                }

                syncTimer.Pause();

                e.Context.RpcOk();

                _communication.Client.SendPausedNotification();
            }
            else
            {
                Debug.Print(errorMessage);
                e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage);
            }
        }
コード例 #3
0
        protected override void OnGeneralSimLaunched(object sender, JsonRpcMethodEventArgs e)
        {
            if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage))
            {
                var requestObject = JsonRpcHelper.TranslateAsRequest(e.ParsedRequestObject);
                var param0        = requestObject.Params[0];

                Debug.Assert(param0 != null, nameof(param0) + " != null");

                var param0Object = param0.ToObject <GeneralSimLaunchedNotificationParams>();

                var simulatorServerUri = new Uri(param0Object.SimulatorServerUri);

                _communication.SimulatorLifeCycleStage = LifeCycleStage.Launched;
                _communication.SimulatorServerUri      = simulatorServerUri;

                e.Context.RpcOk();

                _communication.Client.SendSimInitializeRequest();
            }
            else
            {
                Debug.Print(errorMessage);
                e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage);
            }
        }
コード例 #4
0
 protected override void OnPreviewStopped(object sender, JsonRpcMethodEventArgs e)
 {
     if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage))
     {
         e.Context.RpcOk();
     }
     else
     {
         Debug.Print(errorMessage);
         e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage);
     }
 }
コード例 #5
0
 protected override void OnEditReloaded(object sender, JsonRpcMethodEventArgs e)
 {
     if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage))
     {
         _communication.SimulatorLifeCycleStage = LifeCycleStage.Reloaded;
         e.Context.RpcOk();
     }
     else
     {
         Debug.Print(errorMessage);
         e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage);
     }
 }
コード例 #6
0
        protected override void OnPreviewGetPlaybackState(object sender, JsonRpcMethodEventArgs e)
        {
            LogToScreen("Received request: preview/getPlaybackState");

            if (JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage))
            {
                e.Context.RpcOk();
            }
            else
            {
                Debug.Print(errorMessage);
                e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage);
            }
        }
コード例 #7
0
        protected override void OnEditReload(object sender, JsonRpcMethodEventArgs e)
        {
            LogToScreen("Received request: edit/reload");

            if (!JsonRpcHelper.IsRequestValid(e.ParsedRequestObject, out string errorMessage))
            {
                Debug.Print(errorMessage);
                e.Context.RpcError(JsonRpcErrorCodes.InvalidRequest, errorMessage);

                return;
            }

            var beatmapLoader = _communication.Game.FindSingleElement <BeatmapLoader>();

            if (beatmapLoader == null)
            {
                e.Context.RpcError(JsonRpcErrorCodes.InternalError, "Cannot find the " + nameof(BeatmapLoader) + " component.", statusCode: HttpStatusCode.InternalServerError);
                return;
            }

            var requestObject = JsonRpcHelper.TranslateAsRequest(e.ParsedRequestObject);
            var param0        = requestObject.Params[0];

            Debug.Assert(param0 != null, nameof(param0) + " != null");

            var param0Object = param0.ToObject <EditReloadRequestParams>();

            if (!string.IsNullOrEmpty(param0Object.BeatmapFile))
            {
                if (File.Exists(param0Object.BeatmapFile))
                {
                    var backgroundMusic = _communication.Game.FindSingleElement <BackgroundMusic>();

                    if (!string.IsNullOrEmpty(param0Object.BackgroundMusicFile))
                    {
                        if (backgroundMusic == null)
                        {
                            e.Context.RpcError(JsonRpcErrorCodes.InternalError, "Cannot find the " + nameof(BackgroundMusic) + " component.", statusCode: HttpStatusCode.InternalServerError);
                            return;
                        }

                        backgroundMusic.LoadMusic(param0Object.BackgroundMusicFile);
                    }
                    else
                    {
                        backgroundMusic?.LoadMusic(null);
                    }

                    beatmapLoader.Load(param0Object.BeatmapFile);
                }
                else
                {
                    LogToScreen($"Not found: {param0Object.BeatmapFile}");
                }
            }

            e.Context.RpcOk();

            // DO NOT await
            _communication.Client.SendReloadedNotification();
        }