Beispiel #1
0
        public bool StartProcess(KontrolSystemProcess process, Vessel vessel)
        {
            switch (process.State)
            {
            case KontrolSystemProcessState.Available:
                KSPContext context    = new KSPContext(consoleBuffer);
                Entrypoint entrypoint = process.EntrypointFor(HighLogic.LoadedScene, context);
                if (entrypoint == null)
                {
                    return(false);
                }
                CorouttineAdapter adapter = new CorouttineAdapter(entrypoint(vessel), context,
                                                                  message => OnProcessDone(process, message));
                process.MarkRunning(context);

                Coroutine coroutine = StartCoroutine(adapter);

                if (coroutines.ContainsKey(process.id))
                {
                    StopCoroutine(coroutines[process.id]);
                    coroutines[process.id] = coroutine;
                }
                else
                {
                    coroutines.Add(process.id, coroutine);
                }

                return(true);

            default:
                return(false);
            }
        }
Beispiel #2
0
        private void OnProcessDone(KontrolSystemProcess process, string message)
        {
            if (process.State == KontrolSystemProcessState.Outdated)
            {
                processes.Remove(process);
            }

            process.MarkDone(message);
            coroutines.Remove(process.id);
        }
Beispiel #3
0
        public void TriggerBoot(Vessel vessel)
        {
            GameScenes current = HighLogic.LoadedScene;

            KontrolSystemProcess bootProcess = processes?.FirstOrDefault(p => p.IsBootFor(current, vessel));

            if (bootProcess?.State != KontrolSystemProcessState.Available)
            {
                return;
            }

            StartProcess(bootProcess, vessel);
        }
Beispiel #4
0
        public bool StopProcess(KontrolSystemProcess process)
        {
            switch (process.State)
            {
            case KontrolSystemProcessState.Running:
            case KontrolSystemProcessState.Outdated:
                if (coroutines.ContainsKey(process.id))
                {
                    StopCoroutine(coroutines[process.id]);
                    OnProcessDone(process, "Aborted by pilot");
                }

                return(true);

            default:
                return(false);
            }
        }