A personality holds anything that defines the personality.
Inheritance: IKeyed
Example #1
0
		public void AddPersonality(Personality p)
		{
			if (!ReferenceEquals(p.VM, VM))
			{
				// ToDo : Error
				Logger.Log(null, Logger.Level.Error, "Tried to add a personality with a different VM then the controller!");
			}
			// ToDo :
			personality = p;
		}
Example #2
0
		public void AssignPersonality(Personality p)
		{
			log = new Logger("PersonalityControl");
			this.p = p;

			if (p != null)
				txtID.Text = p.ID;
			attach(".name", txtName);
			attach(".eye", comboEyeColor);

			Enabled = p != null;
		}
Example #3
0
		public void Append(Personality p, string message)
		{
			message = System.Security.SecurityElement.Escape(message);

			textBox.AppendText("\n");
			//if (lastPersona != p)
			//{
			//	lastPersona = p;
			var name = System.Security.SecurityElement.Escape(p.Name);
			//	textBox.AppendText(name);
			//	textBox.AppendText(" Says:\n");
			//}
			//textBox.AppendText("    ");
			textBox.AppendText(name);
			textBox.AppendText(" Says: ");
			textBox.AppendText(message);

			textBox.Select(textBox.TextLength - 1, 0);
		}
Example #4
0
		public void Validate()
		{
			var log = new Logger("Validator");
			using (new LogTimed(log, "Starting", "Finished"))
			{
				// dummy variables used to run scripts without effecting user data.
				var p = new Personality(this, "tmpValidator", "tmpValidator");
				var c = new Controller(this, "DUMMY");
				c.AddPersonality(p);
				var output = new StringBuilder();
				var vars = new Dictionary<string, Variable>();


				personControlLock.EnterReadLock();
				try
				{
					if (personalities.Count == 0)
						log.Error(StringsScripting.No_personalities);
					if (inputReplace == null || inputReplace.Count == 0)
						log.Warning(StringsScripting.No_input_replace);
				}
				finally
				{ personControlLock.ExitReadLock(); }



				if (allscripts.IsEmpty)
					log.Error(StringsScripting.No_scripts);


				// validate startup scripts.
				scriptsLock.EnterReadLock();
				try
				{
					foreach (var s in setupPersonality)
						validateScript(c, s, vars, output);
					foreach (var s in setupController)
						validateScript(c, s, vars, output);
				}
				finally
				{ scriptsLock.ExitReadLock(); }

				// validate all other scripts.
				foreach (var s in allscripts.GetAll())
					if (s.IsSet)
						validateScript(c, s, vars, output);
			}
			// ToDo 2: Scripts can change inbetwen here and validation, so we could be dirty but dirty being false.
			Dirty = false;
		}
Example #5
0
		/// <summary> Runs all setup scripts on the personality. </summary>
		private void runAllSetupOn(Personality p, StringBuilder sb)
		{
			var c = new Controller(this, "DUMMY");
			c.AddPersonality(p);
			scriptsLock.EnterReadLock();
			try
			{
				foreach (var s in setupPersonality)
					runThroughScript(c, s, sb);
			}
			finally
			{ scriptsLock.ExitReadLock(); }
		}
Example #6
0
		public Personality[] GetPersonalities()
		{
			var p = personalities.Values.ToArray();
			var result = new Personality[p.Length];
			for (int i = 0; i < result.Length; ++i)
				result[i] = p[i].Value;
			return result;
		}
Example #7
0
		public bool ChangePersonalityID(Personality p, string newID)
		{
			newID = KeyClean(newID);
			if (personalities.ContainsKey(newID))
				return false;
			Dirty = true;
			Variable<Personality> var;
			if (personalities.TryRemove(p.ID, out var))
				personalities[newID] = var;
			else
				personalities[newID] = new Variable<Personality>(p);
			p.ID = newID;
			return true;
		}
Example #8
0
		public bool TryGetPersonality(string name, out Personality p)
		{
			Variable<Personality> vP = null;
			if (personalities.TryGetValue(KeyClean(name), out vP) && vP.IsSet)
			{
				p = vP.Value;
				return true;
			}
			p = null;
			return false;
		}
Example #9
0
		/// <summary>
		/// Craete a new personality with given name.
		/// </summary>
		/// <param name="name"></param>
		/// <returns>New Personality or null if name already exits.</returns>
		public Personality CreatePersonality(string name)
		{
			var id = KeyClean(name);
			Dirty = true;
			// If personality with id already exists, add number.
			if (personalities.ContainsKey(id))
			{
				int num = 1;
				while (personalities.ContainsKey(id + (++num)))
				{ }
				id = id + num;
			}

			var p = new Personality(this, name, id);
			personalities[id] = new Variable<Personality>(p);
			return p;
		}
Example #10
0
		public bool Contains(Personality p)
		{
			return ReferenceEquals(p, personality);
		}
Example #11
0
		public void Input(Personality p, string text)
		{
			var shorthand = VM.InputToShorthand(text);

			// ToDo 8: If Debugging
			//OnOutput?.Invoke(p, shorthand);
			// else
			OnOutput?.Invoke(p, text);

			var script = VM.GetScriptResponse(shorthand);
			if (script != null)
				Add(script);
		}