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 Decision Making Asset static void Main(string[] args) { //First we construct a new instance of the EmotionalDecisionMakingAsset class var edm = new EmotionalDecisionMakingAsset(); //Then, we have to register an existing knowledge base to the asset so it can check for //beliefs are true var kb = new KB((Name)"John"); kb.Tell((Name)"LikesToFight(SELF)", (Name)"True"); edm.RegisterKnowledgeBase(kb); //create an action rule var actionRule = new ActionRuleDTO { Action = Name.BuildName("Kick"), Priority = Name.BuildName("4"), Target = (Name)"Player" }; //add the reaction rule var id = edm.AddActionRule(actionRule); edm.AddRuleCondition(id, "LikesToFight(SELF) = True"); var actions = edm.Decide(Name.UNIVERSAL_SYMBOL); Console.WriteLine("Decisions: "); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } //this is how you can load the asset from a file Console.WriteLine("Loading From File: "); edm = EmotionalDecisionMakingAsset.LoadFromFile("../../../Examples/EDM-Tutorial/EDMTest.edm"); edm.RegisterKnowledgeBase(kb); actions = edm.Decide(Name.UNIVERSAL_SYMBOL); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } Console.WriteLine("Decisions: "); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } Console.ReadKey(); }
private void buttonSetEmotionalDecisionMakingSource_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { try { var edm = EmotionalDecisionMakingAsset.LoadFromFile(ofd.FileName); _rpcAsset.EmotionalDecisionMakingSource = ofd.FileName; textBoxEmotionalDecisionMakingSource.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 { _edmAsset = EmotionalDecisionMakingAsset.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); }
public MainForm() { InitializeComponent(); string[] args = Environment.GetCommandLineArgs(); if (args.Length <= 1) { Reset(true); } else { _saveFileName = args[1]; try { _edmAsset = EmotionalDecisionMakingAsset.LoadFromFile(_saveFileName); Reset(false); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.ErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); Reset(true); } } }
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; }