A personality is a combination of scripts used to respond to specific events
        public CopyPersonalityWindow(Personality personality)
        {
            InitializeComponent();
            DataContext = this;

            this.personality = personality;
        }
        public ConfigurationWindow()
        {
            InitializeComponent();
            DataContext = this;

            ObservableCollection<Personality> personalities = new ObservableCollection<Personality>();
            // Add our default personality
            personalities.Add(Personality.Default());
            foreach (Personality personality in Personality.AllFromDirectory())
            {
                personalities.Add(personality);
            }
            // Add local personalities
            foreach (Personality personality in personalities)
            {
                Logging.Debug("Found personality " + personality.Name);
            }
            Personalities = personalities;

            SpeechResponderConfiguration configuration = SpeechResponderConfiguration.FromFile();

            foreach (Personality personality in Personalities)
            {
                if (personality.Name == configuration.Personality)
                {
                    Personality = personality;
                    break;
                }
            }
        }
 private void deletePersonalityClicked(object sender, RoutedEventArgs e)
 {
     string messageBoxText = "Are you sure you want to delete the \"" + Personality.Name + "\" personality?";
     string caption = "Delete Personality";
     MessageBoxResult result = MessageBox.Show(messageBoxText, caption, MessageBoxButton.YesNo, MessageBoxImage.Warning);
     switch (result)
     {
         case MessageBoxResult.Yes:
             // Remove the personality from the list and the local filesystem
             Personality oldPersonality = Personality;
             Personalities.Remove(oldPersonality);
             Personality = Personalities[0];
             oldPersonality.RemoveFile();
             break;
     }
 }
 private void copyPersonalityClicked(object sender, RoutedEventArgs e)
 {
     CopyPersonalityWindow window = new CopyPersonalityWindow(Personality);
     if (window.ShowDialog() == true)
     {
         string PersonalityName = window.PersonalityName == null ? null : window.PersonalityName.Trim();
         string PersonalityDescription = window.PersonalityDescription == null ? null : window.PersonalityDescription.Trim();
         Personality newPersonality = Personality.Copy(PersonalityName, PersonalityDescription);
         Personalities.Add(newPersonality);
         Personality = newPersonality;
     }
 }
コード例 #5
0
        /// <summary>
        /// Fix up the personality information to ensure that it contains the correct event
        /// </summary>
        private static void fixPersonalityInfo(Personality personality)
        {
            // Default personality for reference scripts
            Personality defaultPersonality = personality.IsDefault ? null : Default();

            Dictionary <string, Script> fixedScripts = new Dictionary <string, Script>();
            // Ensure that every required event is present
            List <string> missingScripts = new List <string>();

            foreach (KeyValuePair <string, string> defaultEvent in Events.DESCRIPTIONS)
            {
                personality.Scripts.TryGetValue(defaultEvent.Key, out Script script);
                Script defaultScript = null;
                defaultPersonality?.Scripts?.TryGetValue(defaultEvent.Key, out defaultScript);
                script = UpgradeScript(script, defaultScript);
                if (script == null)
                {
                    missingScripts.Add(defaultEvent.Key);
                }
                else
                {
                    fixedScripts.Add(defaultEvent.Key, script);
                }
            }
            foreach (KeyValuePair <string, Script> kv in personality.Scripts)
            {
                if (!fixedScripts.ContainsKey(kv.Key))
                {
                    Script defaultScript = null;
                    defaultPersonality?.Scripts?.TryGetValue(kv.Key, out defaultScript);
                    Script script = UpgradeScript(kv.Value, defaultScript);
                    fixedScripts.Add(kv.Key, script);
                }
            }
            if (!personality.IsDefault)
            {
                // Remove deprecated scripts from the list
                List <string> scriptHolder = new List <string>();
                foreach (KeyValuePair <string, Script> kv in fixedScripts)
                {
                    if (kv.Key == "Jumping") // Replaced by "FSD engaged" script
                    {
                        scriptHolder.Add(kv.Key);
                    }
                    else if (kv.Value.Name == "Crew member role change") // This name is mismatched to the key (should be "changed"),
                    // so EDDI couldn't match the script name to the .json key correctly. The default script has been corrected.
                    {
                        scriptHolder.Add(kv.Key);
                    }
                    else if (kv.Value.Name == "Ship low fuel") // Accidental duplicate. The real event is called 'Low fuel'
                    {
                        scriptHolder.Add(kv.Key);
                    }
                }
                foreach (string script in scriptHolder)
                {
                    fixedScripts.Remove(script);
                }
                // Also add any secondary scripts in the default personality that aren't present in the list
                if (defaultPersonality?.Scripts != null)
                {
                    foreach (KeyValuePair <string, Script> kv in defaultPersonality?.Scripts)
                    {
                        if (!fixedScripts.ContainsKey(kv.Key))
                        {
                            fixedScripts.Add(kv.Key, kv.Value);
                        }
                    }
                }
            }

            // Report missing scripts, except those we have specifically named
            /// `Belt scanned` is a useless event, only exists so that the count on nav beacon scans comes out right
            /// `Jumping` is a deprecated event
            /// `Status` and `Unhandled event` are events which shares updates with monitors / responders but are not intended to be user facing
            string[] ignoredEventKeys = { "Belt scanned", "Jumping", "Status", "Unhandled event" };
            missingScripts.RemoveAll(t => t == "Belt scanned" || t == "Jumping" || t == "Status" || t == "Unhandled event");
            if (missingScripts.Count > 0)
            {
                Logging.Info("Failed to find scripts" + string.Join(";", missingScripts));
            }

            // Re-order the scripts by name
            fixedScripts = fixedScripts.OrderBy(s => s.Key).ToDictionary(s => s.Key, s => s.Value);

            personality.Scripts = fixedScripts;
        }
コード例 #6
0
ファイル: Personality.cs プロジェクト: klightspeed/EDDI
        /// <summary>
        /// Fix up the personality information to ensure that it contains the correct event
        /// </summary>
        private static void fixPersonalityInfo(Personality personality)
        {
            // Default personality for reference scripts
            Personality defaultPersonality = personality.IsDefault ? null : Default();

            Dictionary <string, Script> fixedScripts = new Dictionary <string, Script>();
            // Ensure that every required event is present
            List <string> missingScripts = new List <string>();

            foreach (KeyValuePair <string, string> defaultEvent in Events.DESCRIPTIONS)
            {
                personality.Scripts.TryGetValue(defaultEvent.Key, out Script script);
                Script defaultScript = null;
                defaultPersonality?.Scripts?.TryGetValue(defaultEvent.Key, out defaultScript);
                script = UpgradeScript(script, defaultScript);
                if (script == null)
                {
                    missingScripts.Add(defaultEvent.Key);
                }
                else
                {
                    fixedScripts.Add(defaultEvent.Key, script);
                }
            }
            foreach (KeyValuePair <string, Script> kv in personality.Scripts)
            {
                if (!fixedScripts.ContainsKey(kv.Key))
                {
                    Script defaultScript = null;
                    defaultPersonality?.Scripts?.TryGetValue(kv.Key, out defaultScript);
                    Script script = UpgradeScript(kv.Value, defaultScript);
                    fixedScripts.Add(kv.Key, script);
                }
            }
            if (!personality.IsDefault)
            {
                // Remove deprecated scripts from the list
                List <string> scriptHolder = new List <string>();
                foreach (KeyValuePair <string, Script> kv in fixedScripts)
                {
                    if (kv.Key == "Jumping") // Replaced by "FSD engaged" script
                    {
                        scriptHolder.Add(kv.Key);
                    }
                    else if (kv.Value.Name == "Crew member role change") // This name is mismatched to the key (should be "changed"),
                                                                         // so EDDI couldn't match the script name to the .json key correctly. The default script has been corrected.
                    {
                        scriptHolder.Add(kv.Key);
                    }
                    else if (kv.Value.Name == "Ship low fuel") // Accidental duplicate. The real event is called 'Low fuel'
                    {
                        scriptHolder.Add(kv.Key);
                    }
                    else if (kv.Value.Name == "Modification applied") // Event deprecated by FDev, no longer written.
                    {
                        scriptHolder.Add(kv.Key);
                    }
                }
                foreach (string script in scriptHolder)
                {
                    fixedScripts.Remove(script);
                }
                // Also add any secondary scripts in the default personality that aren't present in the list
                if (defaultPersonality?.Scripts != null)
                {
                    foreach (KeyValuePair <string, Script> kv in defaultPersonality?.Scripts)
                    {
                        if (!fixedScripts.ContainsKey(kv.Key))
                        {
                            fixedScripts.Add(kv.Key, kv.Value);
                        }
                    }
                }
            }

            // Report missing scripts, except those we have specifically named
            string[] ignoredEventKeys =
            {
                // Deprecated events
                "Belt scanned",
                "Jumping",
                "Modification applied",
                "Status",

                // Shares updates with monitors / responders but are not intended to be user facing
                "Cargo",
                "Market",
                "Missions",
                "Outfitting",
                "Shipyard",
                "Squadron startup",
                "Stored ships",
                "Stored modules",
                "Unhandled event"
            };

            Array.Sort(ignoredEventKeys);
            bool isIgnoredEvent(string t) => Array.BinarySearch(ignoredEventKeys, t) >= 0;

            missingScripts.RemoveAll(isIgnoredEvent);
            if (missingScripts.Count > 0)
            {
                Logging.Info("Failed to find scripts" + string.Join(";", missingScripts));
            }

            // Re-order the scripts by name
            fixedScripts = fixedScripts.OrderBy(s => s.Key).ToDictionary(s => s.Key, s => s.Value);

            personality.Scripts = fixedScripts;
        }
コード例 #7
0
 /// <summary>
 /// Fix up the personality information to ensure that it contains the correct event
 /// </summary>
 private static void fixPersonalityInfo(Personality personality)
 {
     Dictionary<string, Script> fixedScripts = new Dictionary<string, Script>();
     // Ensure that every required event is present
     foreach (KeyValuePair<string, string> defaultEvent in Events.DESCRIPTIONS)
     {
         Script script;
         personality.Scripts.TryGetValue(defaultEvent.Key, out script);
         if (script == null)
         {
             // The personality doesn't have this event; create a default
             string defaultScript = Events.DefaultByName(defaultEvent.Key);
             script = new Script(defaultEvent.Key, defaultEvent.Value, true, defaultScript);
         }
         else if (script.Description != defaultEvent.Value)
         {
             // The description has been updated
             script = new Script(defaultEvent.Key, defaultEvent.Value, true, script.Value, script.Priority);
         }
         fixedScripts.Add(defaultEvent.Key, script);
     }
     foreach (KeyValuePair<string, Script> kv in personality.Scripts)
     {
         if (!fixedScripts.ContainsKey(kv.Key))
         {
             fixedScripts.Add(kv.Key, kv.Value);
         }
     }
     personality.Scripts = fixedScripts;
 }