public List <LinkedListNode <Argument> > Contains(Argument.Type _Type, EContainsFunctionInput _What, string _EqualsTo) { var Result = new List <LinkedListNode <Argument> >(); if (_Type == Argument.Type.Unary && _What == EContainsFunctionInput.BinaryValue) { throw new ArgumentException(); } var CurrentNode = First; while (CurrentNode != null) { if (CurrentNode.Value.ArgumentType == _Type) { if ((_Type == Argument.Type.Unary && (CurrentNode.Value as UnaryArgument).Value == _EqualsTo)) { Result.Add(CurrentNode); } if (_Type == Argument.Type.Binary && ((_What == EContainsFunctionInput.UnaryValueOrBinaryKey && (CurrentNode.Value as BinaryArgument).Key == _EqualsTo) || (_What == EContainsFunctionInput.BinaryValue && (CurrentNode.Value as BinaryArgument).Value == _EqualsTo))) { Result.Add(CurrentNode); } } CurrentNode = CurrentNode.Next; } return(Result); }
public void Init(ArgumentSpec argSpec, Argument arg, CodeList codeList) { this.arg = arg; // Configure dropdown options dropdown = GetComponent <TMP_Dropdown>(); TextMeshProUGUI tm = GetComponentInChildren <TextMeshProUGUI>(); float maxPreferredWidth = 0; if (argSpec.regOnly) { for (int regNum = 0; regNum < VirtualMachine.NUM_TOTAL_REGS; ++regNum) { string regName = "R" + regNum; dropdown.options.Add(new TMP_Dropdown.OptionData(regName)); maxPreferredWidth = Mathf.Max(tm.GetPreferredValues(regName).x, maxPreferredWidth); } } else { foreach (string presetName in argSpec.presets) { dropdown.options.Add(new TMP_Dropdown.OptionData(presetName)); maxPreferredWidth = Mathf.Max(tm.GetPreferredValues(presetName).x, maxPreferredWidth); } } // Register value change handlers Argument.Type argType = argSpec.regOnly ? Argument.Type.REGISTER : Argument.Type.IMMEDIATE; dropdown.onValueChanged.AddListener((int val) => { if (selfChange.Value) { return; } arg.val = val; selfChange.Value = true; arg.BroadcastChange(); codeList.Program.BroadcastArgumentChange(); }); arg.OnChange += HandleArgChange; // Init value HandleArgChange(); // Resize to fit the max preferred width RectTransform dropdownRT = dropdown.GetComponent <RectTransform>(); RectTransform labelRT = tm.GetComponent <RectTransform>(); dropdownRT.sizeDelta = new Vector2(maxPreferredWidth - labelRT.sizeDelta.x, dropdownRT.sizeDelta.y); }
public Instruction(OpCode opCode, params Argument[] args) { this.opCode = opCode; ArgumentSpec[] argSpecs = InstructionMaps.opArgSpecMap[opCode]; this.args = new Argument[argSpecs.Length]; Array.Copy(args, this.args, Math.Min(this.args.Length, args.Length)); // Fill in any unspecified args for (int ai = args.Length; ai < this.args.Length; ++ai) { Argument.Type argType = argSpecs[ai].regOnly ? Argument.Type.REGISTER : Argument.Type.IMMEDIATE; this.args[ai] = new Argument(argType, 0); } }
public void Init(ArgumentSpec argSpec, Argument arg) { // Configure dropdown options TMP_Dropdown dropdown = GetComponent <TMP_Dropdown>(); TextMeshProUGUI tm = GetComponentInChildren <TextMeshProUGUI>(); float maxPreferredWidth = 0; if (argSpec.regOnly) { for (int regNum = 0; regNum < VirtualMachine.NUM_REGS; ++regNum) { string regName = "R" + regNum; dropdown.options.Add(new TMP_Dropdown.OptionData(regName)); maxPreferredWidth = Mathf.Max(tm.GetPreferredValues(regName).x, maxPreferredWidth); } } else { foreach (string presetName in argSpec.presets) { dropdown.options.Add(new TMP_Dropdown.OptionData(presetName)); maxPreferredWidth = Mathf.Max(tm.GetPreferredValues(presetName).x, maxPreferredWidth); } } dropdown.value = arg.val; // Register value change handler Argument.Type argType = argSpec.regOnly ? Argument.Type.REGISTER : Argument.Type.IMMEDIATE; dropdown.onValueChanged.AddListener((int val) => { arg.val = val; }); // Resize to fit the max preferred width RectTransform dropdownRT = dropdown.GetComponent <RectTransform>(); RectTransform labelRT = tm.GetComponent <RectTransform>(); dropdownRT.sizeDelta = new Vector2(maxPreferredWidth - labelRT.sizeDelta.x, dropdownRT.sizeDelta.y); }
public static Dictionary <string, HashSet <Thought> > LoadThoughts(TextAsset textAsset) { char[] nextLineChars = { '\n' }; char[] nextValueChars = { '\t' }; char[] nextSubValueChars = { ';' }; string text = textAsset.text; string[] lines = text.Split(nextLineChars); Dictionary <string, HashSet <Thought> > newThoughts = new Dictionary <string, HashSet <Thought> >(); string topic = null; Topic.Stage stage = Topic.Stage.None; string actor = null; for (int i = 1; i < lines.Length; i++) { string line = lines[i]; string[] values = line.Split(nextValueChars, 25); try { // Update running values: Topic, Stage, Actor if (!values[0].Equals("")) { topic = values[0].Trim(); } string stageText = values[1].Trim().ToLower(); if (stageMap.ContainsKey(stageText)) { stage = stageMap[stageText]; } string actorText = values[2].Trim(); if (!actorText.Equals("")) { actor = actorText; if (!newThoughts.ContainsKey(actor)) { newThoughts[actor] = new HashSet <Thought>(); } } // Read Complexity float complexity = 0f; if (!float.TryParse(values[3].Trim(), out complexity)) { Debug.Log("Failed to read: \"" + line + "\"."); continue; } // Read Text string thoughtText = values[4].Trim(); if (values[4].Equals("")) { continue; } // bruh moment (I get it, but still) if (thoughtText.Contains(",") || thoughtText.Contains("\"") && thoughtText[0] == '\"' && thoughtText[thoughtText.Length - 1] == '\"') { thoughtText = thoughtText.Substring(1, thoughtText.Length - 2); } while (thoughtText.Contains("\"\"")) { thoughtText = thoughtText.Replace("\"\"", "\""); } // Read Social Expectations Thought.Interrupt interruptStrategy = Thought.Interrupt.None; string interruptText = values[5].Trim().ToLower(); if (interruptMap.ContainsKey(interruptText)) { interruptStrategy = interruptMap[interruptText]; } Thought.Turn turnStrategy = Thought.Turn.None; string turnText = values[6].Trim().ToLower(); if (turnMap.ContainsKey(turnText)) { turnStrategy = turnMap[turnText]; } Thought.Affinity affinity = Thought.Affinity.None; string affinityText = values[7].Trim().ToLower(); if (affinityMap.ContainsKey(affinityText)) { affinity = affinityMap[affinityText]; } // Read Tangental Topics string[] tangentStrings = values[8].Trim().Split(nextSubValueChars); HashSet <string> tangents = new HashSet <string>(); foreach (var tangent in tangentStrings) { if (!tangent.Equals("")) { tangents.Add(tangent.Trim()); } } // Read Special Event Codes int eventCode = -1; int.TryParse(values[9].Trim(), out eventCode); // Read Emotional Weight Values HashSet <Emotion> emotions = new HashSet <Emotion>(); foreach (KeyValuePair <int, Emotion.Type> pair in emotionIndexMap) { int index = pair.Key; if (index > values.Length - 1) { continue; } Emotion.Type type = pair.Value; float strength = 0f; if (float.TryParse(values[index].Trim(), out strength)) { Emotion emotion = new Emotion(type, strength); emotions.Add(emotion); } } // Read Emotional Attack Values HashSet <Argument> arguments = new HashSet <Argument>(); foreach (KeyValuePair <int, Argument.Type> pair in argumentIndexMap) { int index = pair.Key; if (index > values.Length - 1) { continue; } Argument.Type type = pair.Value; float strength = 0f; if (float.TryParse(values[index].Trim(), out strength)) { Argument argument = new Argument(type, strength); arguments.Add(argument); } } Thought thought = new Thought(topic, stage, actor, complexity, thoughtText, interruptStrategy, turnStrategy, affinity, tangents, eventCode, arguments, emotions); newThoughts[actor].Add(thought); } catch (Exception e) { Debug.Log("Skipped reading: \"" + line + "\" with value count " + values.Length + ". (" + e.Message + ")"); } } foreach (KeyValuePair <string, HashSet <Thought> > pair in newThoughts) { string actorName = pair.Key; int length = pair.Value.Count; Debug.Log("Read in " + length + " thoughts for " + actorName + "."); } return(newThoughts); }
private void ModifyBelief(Argument.Type argument, float mod) { Beliefs[argument] = Mathf.Clamp(Beliefs[argument] + 0.05f * mod, -1.5f, 1.5f); }
private void DecreaseBelief(Argument.Type argument, float mod) => ModifyBelief(argument, -mod);