public MainForm() { InitializeComponent(); string[] args = Environment.GetCommandLineArgs(); if (args.Length <= 1) { Reset(true); } else { _saveFileName = args[1]; try { this._emotionalAppraisalAsset = EmotionalAppraisalAsset.LoadFromFile((args[1])); Reset(false); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.ErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); Reset(true); } } }
internal ConfigStore(Platform platform = Platform.Windows) { Platform = platform; ConfigValues = new Dictionary <ConfigKey, float>(); var configText = Templates.ResourceManager.GetString("config"); var contractResolver = new PrivatePropertyResolver(); var settings = new JsonSerializerSettings { ContractResolver = contractResolver }; ConfigValues = JsonConvert.DeserializeObject <Dictionary <ConfigKey, float> >(configText, settings); foreach (var key in (ConfigKey[])Enum.GetValues(typeof(ConfigKey))) { if (!ConfigValues.ContainsKey(key)) { throw new Exception("Config key " + key + " not included in config!"); } } BoatTypes = new Dictionary <string, List <Position> >(); var boatText = Templates.ResourceManager.GetString("boat_config"); BoatTypes = JsonConvert.DeserializeObject <Dictionary <string, List <Position> > >(boatText); GameConfig = new GameConfig().GetConfig(); NameConfig = new NameConfig().GetConfig(); Avatar.Config = new AvatarGeneratorConfig().GetConfig(); AssetManager.Instance.Bridge = new TemplateBridge(); RolePlayCharacter = RolePlayCharacterAsset.LoadFromFile("template_rpc"); EmotionalAppraisal = EmotionalAppraisalAsset.LoadFromFile("template_ea"); EmotionalDecisionMaking = EmotionalDecisionMakingAsset.LoadFromFile("template_edm"); SocialImportance = SocialImportanceAsset.LoadFromFile("template_si"); IntegratedAuthoringTool = IntegratedAuthoringToolAsset.LoadFromFile("template_iat"); switch (Platform) { case Platform.Android: AssetManager.Instance.Bridge = new AndroidBaseBridge(); break; case Platform.iOS: AssetManager.Instance.Bridge = new IOSBaseBridge(); break; case Platform.Windows: AssetManager.Instance.Bridge = new BaseBridge(); break; } }
//This is a small console program to exemplify the main functionality of the Emotional Appraisal Asset static void Main(string[] args) { var kickEvent = Name.BuildName("Event(Action-End, John, *, *)"); EmotionalAppraisalAsset ea = EmotionalAppraisalAsset.LoadFromFile("../../../Examples/EA-Tutorial/EATest.ea"); //The following lines add an appraisal rule that will make the kickEvent be perceived as undesirable //Normally, these rules should be authored using the AuthoringTool provided with the asset but they can also be added dynamically /* var rule = new AppraisalRuleDTO {EventMatchingTemplate = (Name)"Event(Action-End, [s], *, *)", Desirability = (Name)"4"}; * ea.AddOrUpdateAppraisalRule(rule); */ var am = new AM(); var kb = new KB((Name)"John"); kb.Tell(Name.BuildName("Likes(Mary)"), Name.BuildName("John"), Name.BuildName("SELF")); var emotionalState = new ConcreteEmotionalState(); //Emotions are generated by the appraisal of the events that occur in the game world ea.AppraiseEvents(new[] { kickEvent }, emotionalState, am, kb); Console.WriteLine("\nMood on tick '" + am.Tick + "': " + emotionalState.Mood); Console.WriteLine("Active Emotions: " + string.Concat(emotionalState.GetAllEmotions().Select(e => e.EmotionType + "-" + e.Intensity + " "))); //Each event that is appraised will be stored in the autobiographical memory that was passed as a parameter Console.WriteLine("\nEvents occured so far: " + string.Concat(am.RecallAllEvents().Select(e => "\nId: " + e.Id + " Event: " + e.EventName.ToString()))); //The update function will increase the current tick by 1. Each active emotion will decay to 0 and the mood will slowly return to 0 for (int i = 0; i < 3; i++) { am.Tick++; emotionalState.Decay(am.Tick); Console.WriteLine("\nMood on tick '" + am.Tick + "': " + emotionalState.Mood); Console.WriteLine("Active Emotions: " + string.Concat(emotionalState.GetAllEmotions().Select(e => e.EmotionType + "-" + e.Intensity + " "))); } //The asset can also be loaded from an existing file using the following method: ea = EmotionalAppraisalAsset.LoadFromFile("../../../Examples/EA-Tutorial/EATest.ea"); Console.ReadKey(); }
private void buttonSetEmotionalAppraisalSource_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { try { var ea = EmotionalAppraisalAsset.LoadFromFile(ofd.FileName); _rpcAsset.EmotionalAppraisalAssetSource = ofd.FileName; textBoxEmotionalAppraisalSource.Text = ofd.FileName; } catch (Exception ex) { MessageBox.Show(ex.Message + "-" + ex.StackTrace, Resources.ErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { try { _emotionalAppraisalAsset = EmotionalAppraisalAsset.LoadFromFile(ofd.FileName); _saveFileName = ofd.FileName; Reset(false); } catch (Exception ex) { MessageBox.Show(ex.Message + "-" + ex.StackTrace, Resources.ErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static RolePlayCharacterAsset LoadFromFile(string filename) { RolePlayCharacterAsset rpc; using (var f = File.Open(filename, FileMode.Open, FileAccess.Read)) { var serializer = new JSONSerializer(); rpc = serializer.Deserialize <RolePlayCharacterAsset>(f); } if (!string.IsNullOrEmpty(rpc.EmotionalAppraisalAssetSource)) { try { rpc._emotionalAppraisalAsset = EmotionalAppraisalAsset.LoadFromFile(rpc.EmotionalAppraisalAssetSource); } catch (Exception ex) { rpc.ErrorOnLoad = "Unable to load the Emotional Appraisal Asset at " + rpc.EmotionalAppraisalAssetSource + ". Check if the path is correct."; return(rpc); } if (!string.IsNullOrEmpty(rpc.EmotionalDecisionMakingSource)) { try { rpc._emotionalDecisionMakingAsset = EmotionalDecisionMakingAsset.LoadFromFile(rpc.EmotionalDecisionMakingSource); } catch (Exception ex) { rpc.ErrorOnLoad = "Unable to load the Emotional Decision Making Asset at " + rpc.EmotionalAppraisalAssetSource + ". Check if the path is correct."; return(rpc); } rpc._emotionalDecisionMakingAsset.RegisterEmotionalAppraisalAsset(rpc._emotionalAppraisalAsset); } } return(rpc); }
protected override void OnAssetDataLoaded(RolePlayCharacterAsset asset) { textBoxCharacterName.Text = asset.CharacterName == null ? string.Empty : asset.CharacterName.ToString(); textBoxCharacterBody.Text = asset.BodyName; textBoxCharacterVoice.Text = asset.VoiceName; _emotionalStateVM = new EmotionalStateVM(this); _autobiographicalMemoryVM = new AutobiographicalMemoryVM(this); this.moodValueLabel.Text = Math.Round(_emotionalStateVM.Mood).ToString(MOOD_FORMAT); this.moodTrackBar.Value = (int)float.Parse(this.moodValueLabel.Text); this.StartTickField.Value = _emotionalStateVM.Start; this.emotionsDataGridView.DataSource = _emotionalStateVM.Emotions; this.dataGridViewAM.DataSource = _autobiographicalMemoryVM.Events; //EA ASSET if (string.IsNullOrEmpty(asset.EmotionalAppraisalAssetSource)) { _eaForm.Hide(); } else { this.pathTextBoxEA.Text = LoadableAsset <EmotionalDecisionMakingAsset> .ToRelativePath(LoadedAsset.AssetFilePath, asset.EmotionalAppraisalAssetSource); var ea = EmotionalAppraisalAsset.LoadFromFile(asset.EmotionalAppraisalAssetSource); _eaForm.LoadedAsset = ea; FormHelper.ShowFormInContainerControl(this.panelEA, _eaForm); } //EDM ASSET if (string.IsNullOrEmpty(asset.EmotionalDecisionMakingSource)) { _edmForm.Hide(); } else { this.textBoxPathEDM.Text = LoadableAsset <EmotionalDecisionMakingAsset> .ToRelativePath(LoadedAsset.AssetFilePath, asset.EmotionalDecisionMakingSource); var edm = EmotionalDecisionMakingAsset.LoadFromFile(asset.EmotionalDecisionMakingSource); _edmForm.LoadedAsset = edm; FormHelper.ShowFormInContainerControl(this.panelEDM, _edmForm); } //SI ASSET if (string.IsNullOrEmpty(asset.SocialImportanceAssetSource)) { _siForm.Hide(); } else { this.textBoxPathSI.Text = LoadableAsset <EmotionalDecisionMakingAsset> .ToRelativePath(LoadedAsset.AssetFilePath, asset.SocialImportanceAssetSource); var si = SocialImportanceAsset.LoadFromFile(asset.SocialImportanceAssetSource); _siForm.LoadedAsset = si; FormHelper.ShowFormInContainerControl(this.panelSI, _siForm); } //CIF ASSET if (string.IsNullOrEmpty(asset.CommeillFautAssetSource)) { _cifForm.Hide(); } else { this.textBoxPathCIF.Text = LoadableAsset <EmotionalDecisionMakingAsset> .ToRelativePath(LoadedAsset.AssetFilePath, asset.CommeillFautAssetSource); var cif = CommeillFautAsset.LoadFromFile(asset.CommeillFautAssetSource); _cifForm.LoadedAsset = cif; FormHelper.ShowFormInContainerControl(this.panelCIF, _cifForm); } //KB _knowledgeBaseVM = new KnowledgeBaseVM(this); dataGridViewBeliefs.DataSource = _knowledgeBaseVM.Beliefs; }