new public string ReadEnumLiteral() { Instruction instruction = (Instruction)pop(); byte value = pop(); string typeString = instruction.ToString(); if (typeString.StartsWith("ENUM")) { EnumRepesentation enumRepesentation = EnumRepesentation.EnumLookup(typeString); return(enumRepesentation.getName((int)value)); } else { throw new UnexpectedByteException("Expected enum, got " + typeString); } }
public void Dropdown(bool active, ReturnType type = ReturnType.NONE) { dropdown.gameObject.SetActive(active); submitSelectionButton.gameObject.SetActive(active); // set appropriate dropdown options with ReturnType List <string> options; // handling for enums string typeString = type.ToString(); if (typeString.StartsWith("ENUM")) { EnumRepesentation enumRepesentation = EnumRepesentation.EnumLookup(typeString); options = enumRepesentation.getNames().ToList(); } else if (type == ReturnType.ROOT_EFFECT) { options = EffectData.GetAllRootEffects() .Select(effect => effect.name).ToList(); } else { options = EffectData.Effects .Where(effect => effect.returnType == type && effect.type != "primitive") .Select(effect => effect.name).ToList(); } // need to check all ancestors for potential placeholders dropdown.ClearOptions(); if (options.Count > 0) { dropdown.AddOptions(options); } else { dropdown.gameObject.SetActive(false); submitSelectionButton.gameObject.SetActive(false); } }
public void SubmitSelection() { string selection = dropdown.options[dropdown.value].text; EffectData data = EffectData.GetEffectDataByName(selection); EffectBuilderItem newNode = data != null ? new EffectBuilderItem(data) : null; // handling for enums if (currentCompilerNode != null) { string typeString = currentFieldData.returnType.ToString(); if (typeString.StartsWith("ENUM")) { EnumRepesentation enumRepesentation = EnumRepesentation.EnumLookup(typeString); Instruction enumInstruction = enumRepesentation.getInstruction(); EffectData effectDataForEnumInstruction = EffectData.GetEffectDataByInstruction(enumInstruction); EffectBuilderItem compilerNode = new EffectBuilderItem(effectDataForEnumInstruction); currentCompilerNode.Add(compilerNode); byte enumValue = (byte)enumRepesentation.getIndex(selection); compilerNode.Add(new EffectBuilderItem(new List <byte> { enumValue })); Next(); return; } else if (newNode != null) { currentCompilerNode.Add(newNode); } } if (newNode != null) { currentCompilerNode = newNode; } Next(); }
public string PrintNext() { Instruction instruction = (Instruction)peek(); try { if (Array.IndexOf(enumInstructions, instruction) != -1) { byte b = ReadEnumLiteral(); return($"enum:{b}"); } switch (instruction) { case Instruction.INT: { int n = ReadIntLiteral(readAccessorFirst); return($"{instruction.ToString()}({n})"); } case Instruction.STRING: { string s = ReadStringLiteral(readAccessorFirst); return($"{instruction.ToString()}({s})"); } case Instruction.BOOL: { bool b = ReadBoolLiteral(readAccessorFirst); return($"{instruction.ToString()}({b})"); } case Instruction.PLAYER: { int player = ReadPlayerLiteral(readAccessorFirst); return($"{instruction.ToString()}({player})"); } case Instruction.CARD: { string card = ReadCardLiteral(readAccessorFirst); return($"{instruction.ToString()}({card})"); } case Instruction.LIST: { // pop head and ENUM_LIST_TYPE head pop(); byte type = ReadEnumLiteral(); int size = ReadIntLiteral(readAccessorFirst); push(LiteralFactory.CreateIntLiteral(size)); push(LiteralFactory.CreateEnumLiteral(type, Instruction.ENUM_LIST_TYPE)); push((byte)Instruction.LIST); ReadList(readAccessorFirst); string typeName = EnumRepesentation.EnumLookup("ENUM_LIST_TYPE").getName((int)type); return($"{instruction.ToString()}(size:{size},type:{typeName})"); } case Instruction.IF: case Instruction.UNLESS: case Instruction.LOOP: case Instruction.FOR_LOOP: case Instruction.ENDIF: case Instruction.ENDLOOP: { pop(); int id = ReadIntLiteral(readAccessorFirst); return($"{instruction.ToString()}(id:{id})"); } case Instruction.PLACEHOLDER: { pop(); int id = ReadIntLiteral(readAccessorFirst); return($"{instruction.ToString()}(id:{id})"); } case Instruction.ADD_TO_REGISTER: { pop(); int id = ReadIntLiteral(readAccessorFirst); int size = ReadIntLiteral(readAccessorFirst); return($"{instruction.ToString()}(at:{id}, size:{size})"); } default: { pop(); return(instruction.ToString()); } } } catch (UnexpectedByteException e) { Debug.LogError($"Printer jam! ({instruction}) --- {e}"); return("#" + ((byte)instruction).ToString()); } catch (StackFullException e) { Debug.LogError($"Printer jam! ({instruction}) --- {e}"); return("#" + ((byte)instruction).ToString()); } catch (StackEmptyException e) { Debug.LogError($"Printer jam! ({instruction}) --- {e}"); return("#" + ((byte)instruction).ToString()); } }