示例#1
0
        /// <summary>
        /// Change the personality for the speech responder
        /// </summary>
        /// <returns>true if the speech responder is now using the new personality, otherwise false</returns>
        public bool SetPersonality(string newPersonality)
        {
            SpeechResponderConfiguration configuration = SpeechResponderConfiguration.FromFile();

            if (newPersonality == configuration.Personality)
            {
                // Already set to this personality
                return(true);
            }

            // Ensure that this personality exists
            Personality personality = Personality.FromName(newPersonality);

            if (personality != null)
            {
                // Yes it does; use it
                configuration.Personality = newPersonality;
                configuration.ToFile();
                scriptResolver = new Service.ScriptResolver(personality.Scripts);
                Logging.Debug("Changed personality to " + newPersonality);
                return(true);
            }
            else
            {
                // No it does not; ignore it
                return(false);
            }
        }
示例#2
0
        public void Reload()
        {
            SpeechResponderConfiguration configuration = SpeechResponderConfiguration.FromFile();
            Personality personality = Personality.FromName(configuration.Personality);

            if (personality == null)
            {
                Logging.Warn("Failed to find named personality; falling back to default");
                personality = Personality.Default();
                configuration.Personality = personality.Name;
                configuration.ToFile();
            }
            scriptResolver = new Service.ScriptResolver(personality.Scripts);
            subtitles      = configuration.Subtitles;
            subtitlesOnly  = configuration.SubtitlesOnly;
            Logging.Debug($"Reloaded {ResponderName()}");
        }
示例#3
0
        public SpeechResponder()
        {
            SpeechResponderConfiguration configuration = SpeechResponderConfiguration.FromFile();
            Personality personality = null;

            if (configuration != null && configuration.Personality != null)
            {
                personality = Personality.FromName(configuration.Personality);
            }
            if (personality == null)
            {
                personality = Personality.Default();
            }
            scriptResolver = new Service.ScriptResolver(personality?.Scripts);
            subtitles      = configuration?.Subtitles ?? false;
            subtitlesOnly  = configuration?.SubtitlesOnly ?? false;
            Logging.Info($"Initialized {ResponderName()}");
        }
示例#4
0
        // Say something with a custom resolver
        public void Say(Service.ScriptResolver resolver, Ship ship, string scriptName, Event theEvent = null, int?priority = null, string voice = null, bool sayOutLoud = true, bool invokedFromVA = false)
        {
            Dictionary <string, Cottle.Value> dict = resolver.createVariables(theEvent);
            string speech = resolver.resolveFromName(scriptName, dict, true);

            if (speech != null)
            {
                if (subtitles)
                {
                    // Log a tidied version of the speech
                    string tidiedSpeech = Regex.Replace(speech, "<.*?>", string.Empty).Trim();
                    if (!string.IsNullOrEmpty(tidiedSpeech))
                    {
                        log(tidiedSpeech);
                    }
                }
                if (sayOutLoud && !(subtitles && subtitlesOnly))
                {
                    SpeechService.Instance.Say(ship, speech, (priority == null ? resolver.priority(scriptName) : (int)priority), voice, false, theEvent?.type, invokedFromVA);
                }
            }
        }
示例#5
0
        // Create Cottle variables from the EDDI information
        protected internal Dictionary <string, Cottle.Value> createVariables(Event theEvent = null)
        {
            Dictionary <string, Cottle.Value> dict = new Dictionary <string, Cottle.Value>
            {
                ["capi_active"]         = CompanionAppService.Instance?.active ?? false,
                ["destinationdistance"] = EDDI.Instance.DestinationDistanceLy,
                ["environment"]         = EDDI.Instance.Environment,
                ["horizons"]            = EDDI.Instance.inHorizons,
                ["odyssey"]             = EDDI.Instance.inOdyssey,
                ["va_active"]           = App.FromVA,
                ["vehicle"]             = EDDI.Instance.Vehicle,
                ["icao_active"]         = SpeechService.Instance.Configuration.EnableIcao,
                ["ipa_active"]          = !SpeechService.Instance.Configuration.DisableIpa,
            };

            // Boolean constants
            dict["true"]  = true;
            dict["false"] = false;

            if (EDDI.Instance.Cmdr != null)
            {
                dict["cmdr"] = new ReflectionValue(EDDI.Instance.Cmdr);
            }

            if (EDDI.Instance.HomeStarSystem != null)
            {
                dict["homesystem"] = new ReflectionValue(EDDI.Instance.HomeStarSystem);
            }

            if (EDDI.Instance.HomeStation != null)
            {
                dict["homestation"] = new ReflectionValue(EDDI.Instance.HomeStation);
            }

            if (EDDI.Instance.SquadronStarSystem != null)
            {
                dict["squadronsystem"] = new ReflectionValue(EDDI.Instance.SquadronStarSystem);
            }

            if (EDDI.Instance.CurrentStarSystem != null)
            {
                dict["system"] = new ReflectionValue(EDDI.Instance.CurrentStarSystem);
            }

            if (EDDI.Instance.LastStarSystem != null)
            {
                dict["lastsystem"] = new ReflectionValue(EDDI.Instance.LastStarSystem);
            }

            if (EDDI.Instance.NextStarSystem != null)
            {
                dict["nextsystem"] = new ReflectionValue(EDDI.Instance.NextStarSystem);
            }

            if (EDDI.Instance.DestinationStarSystem != null)
            {
                dict["destinationsystem"] = new ReflectionValue(EDDI.Instance.DestinationStarSystem);
            }

            if (EDDI.Instance.DestinationStation != null)
            {
                dict["destinationstation"] = new ReflectionValue(EDDI.Instance.DestinationStation);
            }

            if (EDDI.Instance.CurrentStation != null)
            {
                dict["station"] = new ReflectionValue(EDDI.Instance.CurrentStation);
            }

            if (EDDI.Instance.CurrentStellarBody != null)
            {
                dict["body"] = new ReflectionValue(EDDI.Instance.CurrentStellarBody);
            }

            if (((StatusMonitor)EDDI.Instance.ObtainMonitor("Status monitor"))?.currentStatus != null)
            {
                dict["status"] = new ReflectionValue(((StatusMonitor)EDDI.Instance.ObtainMonitor("Status monitor"))?.currentStatus);
            }

            if (theEvent != null)
            {
                dict["event"] = new ReflectionValue(theEvent);
            }

            if (EDDI.Instance.State != null)
            {
                dict["state"] = ScriptResolver.buildState();
                Logging.Debug("State is " + JsonConvert.SerializeObject(EDDI.Instance.State));
            }

            // Obtain additional variables from each monitor
            foreach (EDDIMonitor monitor in EDDI.Instance.monitors)
            {
                IDictionary <string, object> monitorVariables = monitor.GetVariables();
                if (monitorVariables != null)
                {
                    foreach (string key in monitorVariables.Keys)
                    {
                        if (monitorVariables[key] == null)
                        {
                            dict.Remove(key);
                        }
                        else
                        {
                            dict[key] = new ReflectionValue(monitorVariables[key]);
                        }
                    }
                }
            }

            return(dict);
        }