Exemple #1
0
        private void buttVariable_Click(object sender, EventArgs e)
        {
            if (Editor.Instance.curGame.MyVariable.Count == 0)
            {
                MessageBox.Show("You need to have atleast 1 variable before you can use this");
                return;
            }

            SetVariable sv = new SetVariable(_toAdd, _forRefresh);
            sv.ShowDialog();
        }
        public void SetVariable_Get_Set()
        {
            var variable = new SetVariable
            {
                VariablesReference = 0ul,
                Name  = "test-variable",
                Value = "value"
            };

            Assert.Equal(0ul, variable.VariablesReference);
            Assert.Equal("test-variable", variable.Name);
            Assert.Equal("value", variable.Value);
        }
Exemple #3
0
        private void OnBridgeCallId(CmdBase command, CommandReply reply)
        {
            GetVariableReply gvr = (GetVariableReply)reply;

            if (!gvr.Success)
            {
                Debug.WriteLine("OnBridgeCallId " + reply.ErrorMessage);
            }

            string      otherChannelId = (string)command.ContextData;
            SetVariable sv             = new SetVariable(otherChannelId, "gate_callid", gvr.Value);

            sv.ReplyReceived += OnCallIdReply;
            _eventMgr.Send(sv);
            command.ReplyReceived -= OnBridgeCallId;
        }
Exemple #4
0
        public bool UnsetReferencingVariables(String ClassName, long InstanceID)
        {
            bool Result = true;

            foreach (EXEReferencingVariable Variable in this.ReferencingVariables)
            {
                if (Variable.ClassName == ClassName && Variable.ReferencedInstanceId == InstanceID)
                {
                    Variable.ReferencedInstanceId = -1;
                }
            }
            foreach (EXEReferencingSetVariable SetVariable in this.SetReferencingVariables)
            {
                SetVariable.UnsetVariables(InstanceID);
            }
            if (this.SuperScope != null)
            {
                Result &= this.SuperScope.UnsetReferencingVariables(ClassName, InstanceID);
            }

            return(Result);
        }
Exemple #5
0
 public override void Initialize(Invert.IOC.UFrameContainer container)
 {
     container.AddItem <RequireReference>();
     container.AddTypeItem <OutputsChildItem>();
     container.AddTypeItem <InputsChildItem>();
     container.AddTypeItem <VariablesChildItem>();
     container.AddTypeItem <PropertiesChildItem>();
     container.AddTypeItem <CollectionsChildItem>();
     container.AddItem <BranchesChildItem>();
     CustomAction = container.AddNode <CustomActionNode, CustomActionNodeViewModel, CustomActionNodeDrawer>("CustomAction");
     CustomAction.Color(NodeColor.Gray);
     Data = container.AddGraph <DataGraph, DataNode>("DataGraph");
     Data.Color(NodeColor.Yellow);
     Data.HasSubNode <GroupNode>();
     Data.HasSubNode <EventNode>();
     Data.HasSubNode <ComponentNode>();
     Library = container.AddGraph <LibraryGraph, LibraryNode>("LibraryGraph");
     Library.Color(NodeColor.Yellow);
     Library.HasSubNode <GroupNode>();
     Library.HasSubNode <EventNode>();
     Library.HasSubNode <CustomActionNode>();
     Library.HasSubNode <ComponentNode>();
     Null = container.AddNode <NullNode, NullNodeViewModel, NullNodeDrawer>("Null");
     Null.Color(NodeColor.Purple);
     StringLiteral = container.AddNode <StringLiteralNode, StringLiteralNodeViewModel, StringLiteralNodeDrawer>("StringLiteral");
     StringLiteral.Color(NodeColor.Gray);
     Property = container.AddNode <PropertyNode, PropertyNodeViewModel, PropertyNodeDrawer>("Property");
     Property.Color(NodeColor.Blue);
     String = container.AddNode <StringNode, StringNodeViewModel, StringNodeDrawer>("String");
     String.Color(NodeColor.Purple);
     ActionGroup = container.AddNode <ActionGroupNode, ActionGroupNodeViewModel, ActionGroupNodeDrawer>("ActionGroup");
     ActionGroup.Color(NodeColor.Red);
     Function = container.AddNode <FunctionNode, FunctionNodeViewModel, FunctionNodeDrawer>("Function");
     Function.Color(NodeColor.Lightgoldenrod4);
     Bool = container.AddNode <BoolNode, BoolNodeViewModel, BoolNodeDrawer>("Bool");
     Bool.Color(NodeColor.Purple);
     Module = container.AddGraph <ModuleGraph, ModuleNode>("ModuleGraph");
     Module.Color(NodeColor.Black);
     Module.HasSubNode <EventNode>();
     Module.HasSubNode <ComponentNode>();
     Module.HasSubNode <CustomActionNode>();
     Module.HasSubNode <SystemNode>();
     Module.HasSubNode <GroupNode>();
     StopTimer = container.AddNode <StopTimerNode, StopTimerNodeViewModel, StopTimerNodeDrawer>("StopTimer");
     StopTimer.Color(NodeColor.Gray);
     AllFalse = container.AddNode <AllFalseNode, AllFalseNodeViewModel, AllFalseNodeDrawer>("AllFalse");
     AllFalse.Color(NodeColor.Orange);
     CodeAction = container.AddNode <CodeActionNode, CodeActionNodeViewModel, CodeActionNodeDrawer>("CodeAction");
     CodeAction.Color(NodeColor.Green);
     BoolExpression = container.AddNode <BoolExpressionNode, BoolExpressionNodeViewModel, BoolExpressionNodeDrawer>("BoolExpression");
     BoolExpression.Color(NodeColor.Gray);
     Float = container.AddNode <FloatNode, FloatNodeViewModel, FloatNodeDrawer>("Float");
     Float.Color(NodeColor.Purple);
     UserMethod = container.AddNode <UserMethodNode, UserMethodNodeViewModel, UserMethodNodeDrawer>("UserMethod");
     UserMethod.Color(NodeColor.Blue);
     LoopCollection = container.AddNode <LoopCollectionNode, LoopCollectionNodeViewModel, LoopCollectionNodeDrawer>("LoopCollection");
     LoopCollection.Color(NodeColor.LightGray);
     AnyFalse = container.AddNode <AnyFalseNode, AnyFalseNodeViewModel, AnyFalseNodeDrawer>("AnyFalse");
     AnyFalse.Color(NodeColor.Orange);
     ComponentCreated = container.AddNode <ComponentCreatedNode, ComponentCreatedNodeViewModel, ComponentCreatedNodeDrawer>("ComponentCreated");
     ComponentCreated.Color(NodeColor.Indianred4);
     SetVariable = container.AddNode <SetVariableNode, SetVariableNodeViewModel, SetVariableNodeDrawer>("SetVariable");
     SetVariable.Color(NodeColor.Gray);
     CollectionItemRemoved = container.AddNode <CollectionItemRemovedNode, CollectionItemRemovedNodeViewModel, CollectionItemRemovedNodeDrawer>("CollectionItemRemoved");
     CollectionItemRemoved.Color(NodeColor.Indianred4);
     CollectionModifiedHandler = container.AddNode <CollectionModifiedHandlerNode, CollectionModifiedHandlerNodeViewModel, CollectionModifiedHandlerNodeDrawer>("CollectionModifiedHandler");
     CollectionModifiedHandler.Color(NodeColor.Red);
     Object = container.AddNode <ObjectNode, ObjectNodeViewModel, ObjectNodeDrawer>("Object");
     Object.Color(NodeColor.Purple);
     PropertyChanged = container.AddNode <PropertyChangedNode, PropertyChangedNodeViewModel, PropertyChangedNodeDrawer>("PropertyChanged");
     PropertyChanged.Color(NodeColor.Indianred4);
     Variable = container.AddNode <VariableNode, VariableNodeViewModel, VariableNodeDrawer>("Variable");
     Variable.Color(NodeColor.Gray);
     Group = container.AddNode <GroupNode, GroupNodeViewModel, GroupNodeDrawer>("Group");
     Group.Color(NodeColor.SgiLightBlue);
     Group.HasSubNode <Vector3Node>();
     Group.HasSubNode <Vector2Node>();
     Group.HasSubNode <ConditionNode>();
     Group.HasSubNode <AnyFalseNode>();
     Group.HasSubNode <AnyTrueNode>();
     Group.HasSubNode <BoolExpressionNode>();
     Group.HasSubNode <PropertyNode>();
     Group.HasSubNode <AllTrueNode>();
     Group.HasSubNode <AllFalseNode>();
     Group.HasSubNode <FloatNode>();
     Group.HasSubNode <StringNode>();
     Group.HasSubNode <IntNode>();
     Group.HasSubNode <BoolNode>();
     Descriptor = container.AddNode <DescriptorNode, DescriptorNodeViewModel, DescriptorNodeDrawer>("Descriptor");
     Descriptor.Color(NodeColor.Indianred2);
     Vector3 = container.AddNode <Vector3Node, Vector3NodeViewModel, Vector3NodeDrawer>("Vector3");
     Vector3.Color(NodeColor.Purple);
     Event = container.AddNode <EventNode, EventNodeViewModel, EventNodeDrawer>("Event");
     Event.Inheritable();
     Event.Color(NodeColor.Gold3);
     Literal = container.AddNode <LiteralNode, LiteralNodeViewModel, LiteralNodeDrawer>("Literal");
     Literal.Color(NodeColor.Purple);
     Component = container.AddNode <ComponentNode, ComponentNodeViewModel, ComponentNodeDrawer>("Component");
     Component.Inheritable();
     Component.Color(NodeColor.Darkolivegreen4);
     Int = container.AddNode <IntNode, IntNodeViewModel, IntNodeDrawer>("Int");
     Int.Color(NodeColor.Purple);
     CollectionItemAdded = container.AddNode <CollectionItemAddedNode, CollectionItemAddedNodeViewModel, CollectionItemAddedNodeDrawer>("CollectionItemAdded");
     CollectionItemAdded.Color(NodeColor.Indianred4);
     ComponentDestroyed = container.AddNode <ComponentDestroyedNode, ComponentDestroyedNodeViewModel, ComponentDestroyedNodeDrawer>("ComponentDestroyed");
     ComponentDestroyed.Color(NodeColor.Indianred4);
     Vector2 = container.AddNode <Vector2Node, Vector2NodeViewModel, Vector2NodeDrawer>("Vector2");
     Vector2.Color(NodeColor.Purple);
     SequenceContainer = container.AddNode <SequenceContainerNode, SequenceContainerNodeViewModel, SequenceContainerNodeDrawer>("SequenceContainer");
     SequenceContainer.Color(NodeColor.Red);
     AllTrue = container.AddNode <AllTrueNode, AllTrueNodeViewModel, AllTrueNodeDrawer>("AllTrue");
     AllTrue.Color(NodeColor.Orange);
     StartTimer = container.AddNode <StartTimerNode, StartTimerNodeViewModel, StartTimerNodeDrawer>("StartTimer");
     StartTimer.Color(NodeColor.Gray);
     Condition = container.AddNode <ConditionNode, ConditionNodeViewModel, ConditionNodeDrawer>("Condition");
     Condition.Color(NodeColor.Orange);
     Action = container.AddNode <ActionNode, ActionNodeViewModel, ActionNodeDrawer>("Action");
     Action.Color(NodeColor.Green);
     Handler = container.AddGraph <HandlerGraph, HandlerNode>("HandlerGraph");
     Handler.Color(NodeColor.Indianred4);
     Handler.HasSubNode <SetVariableNode>();
     Handler.HasSubNode <ActionGroupNode>();
     Handler.HasSubNode <ActionNode>();
     Handler.HasSubNode <ComponentNode>();
     Handler.HasSubNode <ObjectNode>();
     Handler.HasSubNode <LoopCollectionNode>();
     Handler.HasSubNode <IntNode>();
     Handler.HasSubNode <PropertyNode>();
     Handler.HasSubNode <EnumValueNode>();
     Handler.HasSubNode <Vector2Node>();
     Handler.HasSubNode <FloatNode>();
     Handler.HasSubNode <NullNode>();
     Handler.HasSubNode <BoolNode>();
     Handler.HasSubNode <SequenceItemNode>();
     Handler.HasSubNode <Vector3Node>();
     Handler.HasSubNode <StringNode>();
     System = container.AddGraph <SystemGraph, SystemNode>("SystemGraph");
     System.Color(NodeColor.Blue);
     System.HasSubNode <CollectionItemAddedNode>();
     System.HasSubNode <ComponentNode>();
     System.HasSubNode <PropertyChangedNode>();
     System.HasSubNode <ComponentCreatedNode>();
     System.HasSubNode <CustomActionNode>();
     System.HasSubNode <HandlerNode>();
     System.HasSubNode <DescriptorNode>();
     System.HasSubNode <EventNode>();
     System.HasSubNode <GroupNode>();
     System.HasSubNode <ComponentDestroyedNode>();
     System.HasSubNode <CollectionItemRemovedNode>();
     Entity = container.AddNode <EntityNode, EntityNodeViewModel, EntityNodeDrawer>("Entity");
     Entity.Color(NodeColor.Gray);
     Color = container.AddNode <ColorNode, ColorNodeViewModel, ColorNodeDrawer>("Color");
     Color.Color(NodeColor.Purple);
     EnumValue = container.AddNode <EnumValueNode, EnumValueNodeViewModel, EnumValueNodeDrawer>("EnumValue");
     EnumValue.Color(NodeColor.Purple);
     AnyTrue = container.AddNode <AnyTrueNode, AnyTrueNodeViewModel, AnyTrueNodeDrawer>("AnyTrue");
     AnyTrue.Color(NodeColor.Orange);
     SequenceItem = container.AddNode <SequenceItemNode, SequenceItemNodeViewModel, SequenceItemNodeDrawer>("SequenceItem");
     SequenceItem.Color(NodeColor.Green);
     container.Connectable <BoolExpressionNode, Expressions>();
     container.Connectable <BoolExpressionNode, GroupNode>();
     container.Connectable <ComponentNode, RequireReference>();
     container.Connectable <ActionNode, ActionNode>();
     container.Connectable <HandlerNode, SequenceItemNode>();
     container.Connectable <SequenceItemNode, SequenceItemNode>();
 }
Exemple #6
0
        public static InstructionCollection Parse(Stream input, long instructionsPosition)
        {
            var instructions = new SortedList <int, InstructionBase>();

            using (var helper = new InstructionParseHelper(input, instructionsPosition))
            {
                var reader = helper.GetReader();
                while (helper.CanParse(instructions))
                {
                    //now reader the instructions
                    var instructionPosition = helper.CurrentPosition;
                    var type             = reader.ReadByteAsEnum <InstructionType>();
                    var requireAlignment = InstructionAlignment.IsAligned(type);

                    if (requireAlignment)
                    {
                        reader.Align(4);
                    }

                    InstructionBase instruction = null;
                    var             parameters  = new List <Value>();

                    switch (type)
                    {
                    case InstructionType.ToNumber:
                        instruction = new ToNumber();
                        break;

                    case InstructionType.NextFrame:
                        instruction = new NextFrame();
                        break;

                    case InstructionType.Play:
                        instruction = new Play();
                        break;

                    case InstructionType.Stop:
                        instruction = new Stop();
                        break;

                    case InstructionType.Add:
                        instruction = new Add();
                        break;

                    case InstructionType.Subtract:
                        instruction = new Subtract();
                        break;

                    case InstructionType.Multiply:
                        instruction = new Multiply();
                        break;

                    case InstructionType.Divide:
                        instruction = new Divide();
                        break;

                    case InstructionType.Not:
                        instruction = new Not();
                        break;

                    case InstructionType.StringEquals:
                        instruction = new StringEquals();
                        break;

                    case InstructionType.Pop:
                        instruction = new Pop();
                        break;

                    case InstructionType.ToInteger:
                        instruction = new ToInteger();
                        break;

                    case InstructionType.GetVariable:
                        instruction = new GetVariable();
                        break;

                    case InstructionType.SetVariable:
                        instruction = new SetVariable();
                        break;

                    case InstructionType.StringConcat:
                        instruction = new StringConcat();
                        break;

                    case InstructionType.GetProperty:
                        instruction = new GetProperty();
                        break;

                    case InstructionType.SetProperty:
                        instruction = new SetProperty();
                        break;

                    case InstructionType.Trace:
                        instruction = new Trace();
                        break;

                    case InstructionType.Random:
                        instruction = new RandomNumber();
                        break;

                    case InstructionType.Delete:
                        instruction = new Delete();
                        break;

                    case InstructionType.Delete2:
                        instruction = new Delete2();
                        break;

                    case InstructionType.DefineLocal:
                        instruction = new DefineLocal();
                        break;

                    case InstructionType.CallFunction:
                        instruction = new CallFunction();
                        break;

                    case InstructionType.Return:
                        instruction = new Return();
                        break;

                    case InstructionType.Modulo:
                        instruction = new Modulo();
                        break;

                    case InstructionType.NewObject:
                        instruction = new NewObject();
                        break;

                    case InstructionType.InitArray:
                        instruction = new InitArray();
                        break;

                    case InstructionType.InitObject:
                        instruction = new InitObject();
                        break;

                    case InstructionType.TypeOf:
                        instruction = new TypeOf();
                        break;

                    case InstructionType.Add2:
                        instruction = new Add2();
                        break;

                    case InstructionType.LessThan2:
                        instruction = new LessThan2();
                        break;

                    case InstructionType.Equals2:
                        instruction = new Equals2();
                        break;

                    case InstructionType.ToString:
                        instruction = new ToString();
                        break;

                    case InstructionType.PushDuplicate:
                        instruction = new PushDuplicate();
                        break;

                    case InstructionType.GetMember:
                        instruction = new GetMember();
                        break;

                    case InstructionType.SetMember:
                        instruction = new SetMember();
                        break;

                    case InstructionType.Increment:
                        instruction = new Increment();
                        break;

                    case InstructionType.Decrement:
                        instruction = new Decrement();
                        break;

                    case InstructionType.CallMethod:
                        instruction = new CallMethod();
                        break;

                    case InstructionType.Enumerate2:
                        instruction = new Enumerate2();
                        break;

                    case InstructionType.EA_PushThis:
                        instruction = new PushThis();
                        break;

                    case InstructionType.EA_PushZero:
                        instruction = new PushZero();
                        break;

                    case InstructionType.EA_PushOne:
                        instruction = new PushOne();
                        break;

                    case InstructionType.EA_CallFunc:
                        instruction = new CallFunc();
                        break;

                    case InstructionType.EA_CallMethodPop:
                        instruction = new CallMethodPop();
                        break;

                    case InstructionType.BitwiseXOr:
                        instruction = new BitwiseXOr();
                        break;

                    case InstructionType.Greater:
                        instruction = new Greater();
                        break;

                    case InstructionType.EA_PushThisVar:
                        instruction = new PushThisVar();
                        break;

                    case InstructionType.EA_PushGlobalVar:
                        instruction = new PushGlobalVar();
                        break;

                    case InstructionType.EA_ZeroVar:
                        instruction = new ZeroVar();
                        break;

                    case InstructionType.EA_PushTrue:
                        instruction = new PushTrue();
                        break;

                    case InstructionType.EA_PushFalse:
                        instruction = new PushFalse();
                        break;

                    case InstructionType.EA_PushNull:
                        instruction = new PushNull();
                        break;

                    case InstructionType.EA_PushUndefined:
                        instruction = new PushUndefined();
                        break;

                    case InstructionType.GotoFrame:
                        instruction = new GotoFrame();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.GetURL:
                        instruction = new GetUrl();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.SetRegister:
                        instruction = new SetRegister();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.ConstantPool:
                    {
                        instruction = new ConstantPool();
                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.GotoLabel:
                        instruction = new GotoLabel();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.DefineFunction2:
                    {
                        instruction = new DefineFunction2();
                        var name       = reader.ReadStringAtOffset();
                        var nParams    = reader.ReadUInt32();
                        var nRegisters = reader.ReadByte();
                        var flags      = reader.ReadUInt24();

                        //list of parameter strings
                        var paramList = reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                            {
                                Register  = reader.ReadInt32(),
                                Parameter = reader.ReadStringAtOffset(),
                            }, nParams);

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger((int)nParams));
                        parameters.Add(Value.FromInteger((int)nRegisters));
                        parameters.Add(Value.FromInteger((int)flags));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromInteger(param.Register));
                            parameters.Add(Value.FromString(param.Parameter));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.PushData:
                    {
                        instruction = new PushData();

                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.BranchAlways:
                    {
                        instruction = new BranchAlways();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GetURL2:
                        instruction = new GetUrl2();
                        break;

                    case InstructionType.DefineFunction:
                    {
                        instruction = new DefineFunction();
                        var name = reader.ReadStringAtOffset();
                        //list of parameter strings
                        var paramList = reader.ReadListAtOffset <string>(() => reader.ReadStringAtOffset());

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger(paramList.Count));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromString(param));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.BranchIfTrue:
                    {
                        instruction = new BranchIfTrue();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GotoFrame2:
                        instruction = new GotoFrame2();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.EA_PushString:
                        instruction = new PushString();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushConstantByte:
                        instruction = new PushConstantByte();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetStringVar:
                        instruction = new GetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringVar:
                        instruction = new SetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_GetStringMember:
                        instruction = new GetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringMember:
                        instruction = new SetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushValueOfVar:
                        instruction = new PushValueOfVar();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetNamedMember:
                        instruction = new GetNamedMember();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFuncPop:
                        instruction = new CallNamedFuncPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFunc:
                        instruction = new CallNamedFunc();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedMethodPop:
                        instruction = new CallNamedMethodPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushFloat:
                        instruction = new PushFloat();
                        parameters.Add(Value.FromFloat(reader.ReadSingle()));
                        break;

                    case InstructionType.EA_PushByte:
                        instruction = new PushByte();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushShort:
                        instruction = new PushShort();
                        parameters.Add(Value.FromInteger(reader.ReadUInt16()));
                        break;

                    case InstructionType.End:
                        instruction = new End();
                        break;

                    case InstructionType.EA_CallNamedMethod:
                        instruction = new CallNamedMethod();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.Var:
                        instruction = new Var();
                        break;

                    case InstructionType.EA_PushRegister:
                        instruction = new PushRegister();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushConstantWord:
                        instruction = new PushConstantWord();
                        parameters.Add(Value.FromConstant(reader.ReadUInt16()));
                        break;

                    case InstructionType.EA_CallFuncPop:
                        instruction = new CallFunctionPop();
                        break;

                    case InstructionType.StrictEqual:
                        instruction = new StrictEquals();
                        break;

                    default:
                        throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                    }

                    if (instruction != null)
                    {
                        instruction.Parameters = parameters;
                        instructions.Add(instructionPosition, instruction);
                    }
                }
            }

            return(new InstructionCollection(instructions));
        }
Exemple #7
0
        public void Parse()
        {
            var current = _reader.BaseStream.Position;

            _reader.BaseStream.Seek(_offset, SeekOrigin.Begin);
            bool parsing     = true;
            bool branched    = false;
            int  branchBytes = 0;

            while (parsing)
            {
                //now reader the instructions
                var type    = _reader.ReadByteAsEnum <InstructionType>();
                var aligned = InstructionAlignment.IsAligned(type);

                if (aligned)
                {
                    var padding = _reader.Align(4);
                    if (padding > 0)
                    {
                        Items.Add(new Padding(padding));
                        if (branched)
                        {
                            branchBytes -= (int)padding;

                            if (branchBytes <= 0)
                            {
                                branched    = false;
                                branchBytes = 0;
                            }
                        }
                    }
                }

                InstructionBase instruction = null;
                List <Value>    parameters  = new List <Value>();

                switch (type)
                {
                case InstructionType.ToNumber:
                    instruction = new ToNumber();
                    break;

                case InstructionType.NextFrame:
                    instruction = new NextFrame();
                    break;

                case InstructionType.Play:
                    instruction = new Play();
                    break;

                case InstructionType.Stop:
                    instruction = new Stop();
                    break;

                case InstructionType.Add:
                    instruction = new Add();
                    break;

                case InstructionType.Subtract:
                    instruction = new Subtract();
                    break;

                case InstructionType.Multiply:
                    instruction = new Multiply();
                    break;

                case InstructionType.Divide:
                    instruction = new Divide();
                    break;

                case InstructionType.Not:
                    instruction = new Not();
                    break;

                case InstructionType.StringEquals:
                    instruction = new StringEquals();
                    break;

                case InstructionType.Pop:
                    instruction = new Pop();
                    break;

                case InstructionType.ToInteger:
                    instruction = new ToInteger();
                    break;

                case InstructionType.GetVariable:
                    instruction = new GetVariable();
                    break;

                case InstructionType.SetVariable:
                    instruction = new SetVariable();
                    break;

                case InstructionType.StringConcat:
                    instruction = new StringConcat();
                    break;

                case InstructionType.GetProperty:
                    instruction = new GetProperty();
                    break;

                case InstructionType.SetProperty:
                    instruction = new SetProperty();
                    break;

                case InstructionType.Trace:
                    instruction = new Trace();
                    break;

                case InstructionType.Delete:
                    instruction = new Delete();
                    break;

                case InstructionType.Delete2:
                    instruction = new Delete2();
                    break;

                case InstructionType.DefineLocal:
                    instruction = new DefineLocal();
                    break;

                case InstructionType.CallFunction:
                    instruction = new CallFunction();
                    break;

                case InstructionType.Return:
                    instruction = new Return();
                    break;

                case InstructionType.NewObject:
                    instruction = new NewObject();
                    break;

                case InstructionType.InitArray:
                    instruction = new InitArray();
                    break;

                case InstructionType.InitObject:
                    instruction = new InitObject();
                    break;

                case InstructionType.TypeOf:
                    instruction = new InitObject();
                    break;

                case InstructionType.Add2:
                    instruction = new Add2();
                    break;

                case InstructionType.LessThan2:
                    instruction = new LessThan2();
                    break;

                case InstructionType.Equals2:
                    instruction = new Equals2();
                    break;

                case InstructionType.ToString:
                    instruction = new ToString();
                    break;

                case InstructionType.PushDuplicate:
                    instruction = new PushDuplicate();
                    break;

                case InstructionType.GetMember:
                    instruction = new GetMember();
                    break;

                case InstructionType.SetMember:
                    instruction = new SetMember();
                    break;

                case InstructionType.Increment:
                    instruction = new Increment();
                    break;

                case InstructionType.Decrement:
                    instruction = new Decrement();
                    break;

                case InstructionType.CallMethod:
                    instruction = new CallMethod();
                    break;

                case InstructionType.Enumerate2:
                    instruction = new Enumerate2();
                    break;

                case InstructionType.EA_PushThis:
                    instruction = new PushThis();
                    break;

                case InstructionType.EA_PushZero:
                    instruction = new PushZero();
                    break;

                case InstructionType.EA_PushOne:
                    instruction = new PushOne();
                    break;

                case InstructionType.EA_CallFunc:
                    instruction = new CallFunc();
                    break;

                case InstructionType.EA_CallMethodPop:
                    instruction = new CallMethodPop();
                    break;

                case InstructionType.BitwiseXOr:
                    instruction = new BitwiseXOr();
                    break;

                case InstructionType.Greater:
                    instruction = new Greater();
                    break;

                case InstructionType.EA_PushThisVar:
                    instruction = new PushThisVar();
                    break;

                case InstructionType.EA_PushGlobalVar:
                    instruction = new PushGlobalVar();
                    break;

                case InstructionType.EA_ZeroVar:
                    instruction = new ZeroVar();
                    break;

                case InstructionType.EA_PushTrue:
                    instruction = new PushTrue();
                    break;

                case InstructionType.EA_PushFalse:
                    instruction = new PushFalse();
                    break;

                case InstructionType.EA_PushNull:
                    instruction = new PushNull();
                    break;

                case InstructionType.EA_PushUndefined:
                    instruction = new PushUndefined();
                    break;

                case InstructionType.GotoFrame:
                    instruction = new GotoFrame();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.GetURL:
                    instruction = new GetUrl();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.SetRegister:
                    instruction = new SetRegister();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.ConstantPool:
                {
                    instruction = new ConstantPool();
                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.GotoLabel:
                    instruction = new GotoLabel();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.DefineFunction2:
                {
                    instruction = new DefineFunction2();
                    var name       = _reader.ReadStringAtOffset();
                    var nParams    = _reader.ReadUInt32();
                    var nRegisters = _reader.ReadByte();
                    var flags      = _reader.ReadUInt24();

                    //list of parameter strings
                    var paramList = _reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                        {
                            Register  = _reader.ReadInt32(),
                            Parameter = _reader.ReadStringAtOffset(),
                        }, nParams);

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger((int)nParams));
                    parameters.Add(Value.FromInteger((int)nRegisters));
                    parameters.Add(Value.FromInteger((int)flags));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromInteger(param.Register));
                        parameters.Add(Value.FromString(param.Parameter));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.PushData:
                {
                    instruction = new PushData();

                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.BranchAlways:
                    instruction = new BranchAlways();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GetURL2:
                    instruction = new GetUrl2();
                    break;

                case InstructionType.DefineFunction:
                {
                    instruction = new DefineFunction();
                    var name = _reader.ReadStringAtOffset();
                    //list of parameter strings
                    var paramList = _reader.ReadListAtOffset <string>(() => _reader.ReadStringAtOffset());

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger(paramList.Count));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromString(param));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.BranchIfTrue:
                    instruction = new BranchIfTrue();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GotoFrame2:
                    instruction = new GotoFrame2();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushString:
                    instruction = new PushString();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushConstantByte:
                    instruction = new PushConstantByte();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetStringVar:
                    instruction = new GetStringVar();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringVar:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_GetStringMember:
                    instruction = new GetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringMember:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushValueOfVar:
                    instruction = new PushValueOfVar();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetNamedMember:
                    instruction = new GetNamedMember();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFuncPop:
                    instruction = new CallNamedFuncPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFunc:
                    instruction = new CallNamedFunc();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedMethodPop:
                    instruction = new CallNamedMethodPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushFloat:
                    instruction = new PushFloat();
                    parameters.Add(Value.FromFloat(_reader.ReadSingle()));
                    break;

                case InstructionType.EA_PushByte:
                    instruction = new PushByte();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushShort:
                    instruction = new PushShort();
                    parameters.Add(Value.FromInteger(_reader.ReadUInt16()));
                    break;

                case InstructionType.End:
                    instruction = new End();

                    if (!branched)
                    {
                        parsing = false;
                    }
                    break;

                case InstructionType.EA_CallNamedMethod:
                    instruction = new CallNamedMethod();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.Var:
                    instruction = new Var();

                    break;

                default:
                    throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                }

                if (instruction != null)
                {
                    instruction.Parameters = parameters;
                    Items.Add(instruction);
                }

                if (branched)
                {
                    branchBytes -= (int)instruction.Size + 1;

                    if (branchBytes <= 0)
                    {
                        branched = false;
                    }
                }
            }
            _reader.BaseStream.Seek(current, SeekOrigin.Begin);
        }
Exemple #8
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            SetVariable t = target as SetVariable;

            var flowchart = (Flowchart)t.GetFlowchart();

            if (flowchart == null)
            {
                return;
            }

            // Select Variable
            EditorGUILayout.PropertyField(variableProp);

            if (variableProp.objectReferenceValue == null)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }

            // Get selected variable
            Variable selectedVariable = variableProp.objectReferenceValue as Variable;

            System.Type variableType = selectedVariable.GetType();

            // Get operators for the variable
            SetOperator[] setOperators = SetVariable.operatorsByVariableType[variableType];

            // Create operator list
            List <GUIContent> operatorsList = new List <GUIContent>();

            foreach (var setOperator in setOperators)
            {
                switch (setOperator)
                {
                case SetOperator.Assign:
                    operatorsList.Add(new GUIContent("="));
                    break;

                case SetOperator.Negate:
                    operatorsList.Add(new GUIContent("=!"));
                    break;

                case SetOperator.Add:
                    operatorsList.Add(new GUIContent("+="));
                    break;

                case SetOperator.Subtract:
                    operatorsList.Add(new GUIContent("-="));
                    break;

                case SetOperator.Multiply:
                    operatorsList.Add(new GUIContent("*="));
                    break;

                case SetOperator.Divide:
                    operatorsList.Add(new GUIContent("\\="));
                    break;

                default:
                    Debug.LogError("The " + setOperator.ToString() + " operator has no matching GUIContent.");
                    break;
                }
            }

            // Get previously selected operator
            int selectedIndex = System.Array.IndexOf(setOperators, t._SetOperator);

            if (selectedIndex < 0)
            {
                // Default to first index if the operator is not found in the available operators list
                // This can occur when changing between variable types
                selectedIndex = 0;
            }

            // Get next selected operator
            selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());


            setOperatorProp.enumValueIndex = (int)setOperators[selectedIndex];


            VariablePropertyInfo propertyInfo = propertyInfoByVariableType[variableType];

            EditorGUILayout.PropertyField(propertyInfo.dataProp, new GUIContent(propertyInfo.name));


            serializedObject.ApplyModifiedProperties();
        }
Exemple #9
0
        static TestData()
        {
            //MainViewModel.MainViewModelStatic.ItemClasses.Add(Editor.ObjectTypes.ItemClass.GetBaseItemClass());
            TestScript = new Script();
            TestScript.ScriptLines.Clear();
            TestScript.ScriptLines.Add(new Comment {
                CommentText = "test comment"
            });
            TestScript.ScriptLines.Add(new Comment {
                CommentText = "another test comment"
            });
            TestCondition1 = new Conditional(TestScript);
            TestCondition1.ThenStatement.AddBeforeSelected(new Comment {
                CommentText = "Test Conditional Comment"
            });
            TestCondition1.ElseStatement.AddBeforeSelected(new Comment {
                CommentText = "Test Else Comment"
            });
            TestConditionNested = new Conditional(TestScript);
            TestConditionChild  = new Conditional(TestScript);
            TestConditionChild.ThenStatement.AddBeforeSelected(new Comment {
                CommentText = "Another comment"
            });
            TestConditionChild.ElseStatement.AddBeforeSelected(new Comment {
                CommentText = "Another else comment"
            });
            TestConditionNested.ThenStatement.AddBeforeSelected(TestConditionChild);
            TestConditionChild = new Conditional(TestScript);
            TestScript.ScriptLines.Add(TestCondition1);
            TestScript.ScriptLines.Add(TestConditionNested);
            TestScript.ScriptLines.Add(new Blank());
            TestComment = new Comment {
                CommentText = "This is my comment."
            };
            TestDisplayText = new DisplayText {
                Text = "The room is dark and reeks of old milk.\n\nThere is an unlit chandalier."
            };
            TestAddText = new AddText {
                Text = "A fresh, crisp, tasty looking apple."
            };
            TestRoom                         = new Room();
            TestRoom.RoomName                = "Test Room";
            TestRoom.Description             = "Test Room Description";
            TestRoom.HasPlaintextDescription = false;
            TestRoom.RoomID                  = new Guid("{1CF2C7E6-276C-4678-951C-2D1B1F239620}");
            TestRoom.RoomDescriptionScript   = TestScript;

            TestScriptRoom                         = new Room();
            TestScriptRoom.RoomName                = "Test Room";
            TestScriptRoom.Description             = "Test Room Description";
            TestScriptRoom.HasPlaintextDescription = true;
            TestScriptRoom.RoomID                  = new Guid("{1CF2C7E6-276C-4678-951C-2D1B1F239620}");
            TestScriptRoom.RoomDescriptionScript   = TestScript;

            TestInteractable = new Interactable();

            TestInteractable.InteractableName      = "Bookshelf";
            TestInteractable.DefaultDisplayName    = "Old Bookshelf";
            TestInteractable.CanExamine            = true;
            TestInteractable.CanExamineUsesScript  = true;
            TestInteractable.CanInteract           = true;
            TestInteractable.CanInteractUsesScript = false;
            Script testIntCanExScript = new Script();

            testIntCanExScript.AddBeforeSelected(new Comment {
                CommentText = "Test Can Examine Script"
            });
            Script testIntCanInScript = new Script();

            testIntCanInScript.AddBeforeSelected(new Comment {
                CommentText = "Test Can Interact Script"
            });
            Script testIntExScript = new Script();

            testIntExScript.AddBeforeSelected(new Comment {
                CommentText = "Test Examine Script"
            });
            Script testIntInScript = new Script();

            testIntInScript.AddBeforeSelected(new Comment {
                CommentText = "Test Interaction Script"
            });
            TestInteractable.ExamineScript     = testIntExScript;
            TestInteractable.InteractScript    = testIntInScript;
            TestInteractable.CanInteractScript = testIntCanInScript;
            TestInteractable.CanExamineScript  = testIntCanExScript;
            TestInteractable.GroupName         = "Furniture";

            TestInteractableGroup = MainViewModel.MainViewModelStatic.InteractableGroups.FirstOrDefault();

            TestRoom.DefaultInteractables.Add(new InteractableRef(TestInteractable.InteractableID));

            TestDateTimeVariable                 = new Variable();
            TestDateTimeVariable.IsDateTime      = true;
            TestDateTimeVariable.DefaultDateTime = new DateTime(2015, 1, 30, 10, 20, 5);
            TestDateTimeVariable.Name            = "Test Date Time";

            TestStringVariable               = new Variable();
            TestStringVariable.IsString      = true;
            TestStringVariable.DefaultString = "Test Data";
            TestStringVariable.Name          = "Test String";

            TestNumberVariable               = new Variable();
            TestNumberVariable.IsNumber      = true;
            TestNumberVariable.DefaultNumber = 5;
            TestNumberVariable.Name          = "Test Number";

            TestSetVariable = new SetVariable();
            TestSetVariable.SelectedVariable = new VarRef(TestNumberVariable.Id);
            //var testParent = new ItemClass() { Name = "Item" };
            //MainViewModel.MainViewModelStatic.ItemClasses.Add(TestItemClass);
            TestItemClass = new ItemClass {
                Name = "Clothing", ParentClass = ItemClass.GetBaseItemClass()
            };
            TestItemClass.ItemProperties.Add(new Variable {
                Name = "Slot", IsString = true, DefaultString = "Body"
            });
            TestItemClass.ItemProperties.Add(new Variable {
                Name = "Weight", IsNumber = true, DefaultNumber = 40
            });
            //MainViewModel.MainViewModelStatic.ItemClasses.Add(TestItemClass);
            var testChild1 = new ItemClass()
            {
                Name = "Shirts", ParentClass = TestItemClass
            };
            var testChild2 = new ItemClass()
            {
                Name = "Pants", ParentClass = TestItemClass
            };
            var testChild3 = new ItemClass()
            {
                Name = "Underwear", ParentClass = TestItemClass
            };
            var testChild4 = new ItemClass()
            {
                Name = "Food", ParentClass = TestItemClass
            };

            testChild4.ParentClass = TestItemClass.ParentClass;
            var testItem = new Item()
            {
                ItemClassParent = TestItemClass, DefaultName = "Helmet"
            };

            var testItem2 = new Item()
            {
                ItemClassParent = TestItemClass, DefaultName = "Bracers"
            };
            var testItem3 = new Item()
            {
                ItemClassParent = TestItemClass, DefaultName = "Apple"
            };

            testItem3.ItemClassParent = TestItemClass.ParentClass;

            TestItemClass.SelectedProperty = TestItemClass.ItemProperties.First();
            testItem2.ItemName             = "BasicBracers";
            testItem2.IsEquipment          = true;

            testItem2.SelectedProperty = testItem.ItemProperties.First();
            TestItem = testItem2;

            TestAddItem = new AddItemToInventory {
                ItemReference = new ItemRef(testItem.ItemID)
            };

            TestGetProperty = new GetItemProperty {
                VarRef = new VarRef(TestStringVariable.Id), SelectedItemClass = TestItemClass
            };
            TestGetProperty.SelectedProperty = TestGetProperty.SelectedItemClass.ItemProperties.First();
            TestSetProperty = new SetItemProperty {
                VarRef = new VarRef(TestStringVariable.Id), SelectedItemClass = TestItemClass
            };
            TestSetProperty.SelectedProperty = TestSetProperty.SelectedItemClass.ItemProperties.First();

            Settings1 = new PlayerSettings();
            Settings1.PlayerDescription.AddBeforeSelected(new AddText {
                Text = "You are a {{Age}} year old {{Gender}}"
            });
            PlayerStatistic testHunger = new PlayerStatistic {
                Label = "Hunger"
            };

            testHunger.DisplayCondition.AddBeforeSelected(new ReturnFalse());
            testHunger.AssociatedVariable        = new VarRef(TestNumberVariable.Id);
            testHunger.IsProgressBar             = true;
            testHunger.HighWarning               = false;
            testHunger.LowWarning                = true;
            testHunger.MaximumValueVariable      = true;
            testHunger.MaximumValueVariableValue = new VarRef(TestNumberVariable.Id);
            PlayerStatistic testSpecies = new PlayerStatistic {
                Label = "Species"
            };

            testSpecies.Label = "Species";
            testSpecies.AssociatedVariable = new VarRef(TestNumberVariable.Id);
            testSpecies.IsPlaintext        = true;

            Settings1.PlayerStatistics.Add(testHunger);
            Settings1.PlayerStatistics.Add(testSpecies);
            Settings1.SelectedStatistic = testHunger;
            Settings1.EquipmentSlots.Add(new EquipmentSlot {
                Name = "Body"
            });
            Settings1.EquipmentSlots.Add(new EquipmentSlot {
                Name = "Legs"
            });
            Settings1.EquipmentSlots.Add(new EquipmentSlot {
                Name = "Wrists"
            });
            Settings1.EquipmentSlots.Add(new EquipmentSlot {
                Name = "Feet"
            });
            Settings1.EquipmentSlots.Add(new EquipmentSlot {
                Name = "Head"
            });
            Settings1.SelectedEquipmentSlot = Settings1.EquipmentSlots.First();
            testItem2.EquipmentRef.OccupiesSlots.Add(Settings1.SelectedEquipmentSlot);
            TestCommonEvent = new CommonEvent();
            //TestCommonEvent.Name = "Test";
            //TestCommonEvent.EventType = CommonEvent.CommonEventTypes.First();


            TestConversation               = new Conversation();
            TestConversation.Name          = "Test";
            TestConversation.StartingStage = 10;
            ConversationStage TestStage1 = new ConversationStage();

            TestStage1.StageName = "Test Intro Point";
            TestStage1.StageAction.AddBeforeSelected(new DisplayText {
                Text = "Test Stuff"
            });
            TestStage1.StageId = 10;
            TestStage1.Choices.Add(new ConversationChoice()
            {
                ChoiceText = "Choice 1", Target = 20
            });
            TestStage1.Choices.Add(new ConversationChoice()
            {
                ChoiceText = "Choice 2", Target = 30
            });
            ConversationStage TestStage2 = new ConversationStage();

            TestStage2.StageName = "Stage #2";
            ConversationStage TestStage3 = new ConversationStage();

            TestStage3.StageName = "Stage #3";
            TestStage2.StageId   = 20;
            TestStage3.StageId   = 30;

            TestConversation.Stages.Add(TestStage1);
            TestConversation.Stages.Add(TestStage2);
            TestConversation.SelectedStage = TestStage1;
            TestConversation.Stages.Add(TestStage3);
            TestStage1.SelectedChoice = TestStage1.Choices.First();
            TestStage1.SelectedChoice.ChoiceVisibility.AddBeforeSelected(new ReturnTrue());


            //var tempRooms = new System.Collections.ObjectModel.ObservableCollection<Room>();
            //tempRooms.Add(TestData.TestRoom);
            //MainViewModel.MainViewModelStatic.Zones.Add(new Zone { ZoneName = "Test", Rooms = tempRooms });

            //TestArray.IsNumber = true;
            //TestArray.Name = "Test";
            //TestArray.Group = "Test Group";
            TestStatusEffect      = new StatusEffect();
            TestStatusEffect.Name = "Sample Status Effect";
            TestStatusEffect.OnInitialize.AddBeforeSelected(new Comment {
                CommentText = "On Initialize Script"
            });
            TestStatusEffect.OnMove.AddBeforeSelected(new Comment {
                CommentText = "On Move Script"
            });
            TestStatusEffect.OnStack.AddBeforeSelected(new Comment {
                CommentText = "On Stack Script"
            });
            TestStatusEffect.OnFinish.AddBeforeSelected(new Comment {
                CommentText = "On Finish Script"
            });
            TestStatusEffect.CheckIfCleared.AddBeforeSelected(new Comment {
                CommentText = "Check If Cleared Script"
            });
            TestStatusEffect.CanOccurMultipleTimes = false;
            TestStatusEffect.Arguments.Add(new StatusEffectValue {
                Name = "Duration", IsNumber = true
            });
            TestStatusEffect.Arguments.Add(new StatusEffectValue {
                Name = "Text Test", IsString = true
            });
            TestStatusEffect.SelectedArgument = TestStatusEffect.Arguments.Last();

            //AddStatusEffectTest = new AddStatusEffect();
            //AddStatusEffectTest.AssociatedEffect = new GenericRef<StatusEffect>((id) => TestStatusEffect, (statusEffect) => TestStatusEffect.Id) { Ref = TestStatusEffect.Id };
            //AddStatusEffect.UpdateAllArguments(TestStatusEffect);
        }
Exemple #10
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            SetVariable t = target as SetVariable;

            var flowchart = (Flowchart)t.GetFlowchart();

            if (flowchart == null)
            {
                return;
            }

            EditorGUILayout.PropertyField(variableProp);

            if (variableProp.objectReferenceValue == null)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }

            Variable selectedVariable = variableProp.objectReferenceValue as Variable;

            System.Type variableType = selectedVariable.GetType();

            List <GUIContent> operatorsList = new List <GUIContent>();

            operatorsList.Add(new GUIContent("="));
            if (variableType == typeof(BooleanVariable))
            {
                operatorsList.Add(new GUIContent("=!"));
            }
            else if (variableType == typeof(IntegerVariable) ||
                     variableType == typeof(FloatVariable))
            {
                operatorsList.Add(new GUIContent("+="));
                operatorsList.Add(new GUIContent("-="));
                operatorsList.Add(new GUIContent("*="));
                operatorsList.Add(new GUIContent("/="));
            }

            int selectedIndex = 0;

            switch (t._SetOperator)
            {
            default:
            case SetOperator.Assign:
                selectedIndex = 0;
                break;

            case SetOperator.Negate:
                selectedIndex = 1;
                break;

            case SetOperator.Add:
                selectedIndex = 1;
                break;

            case SetOperator.Subtract:
                selectedIndex = 2;
                break;

            case SetOperator.Multiply:
                selectedIndex = 3;
                break;

            case SetOperator.Divide:
                selectedIndex = 4;
                break;
            }

            selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());

            SetOperator setOperator = SetOperator.Assign;

            if (variableType == typeof(BooleanVariable) ||
                variableType == typeof(StringVariable))
            {
                switch (selectedIndex)
                {
                default:
                case 0:
                    setOperator = SetOperator.Assign;
                    break;

                case 1:
                    setOperator = SetOperator.Negate;
                    break;
                }
            }
            else if (variableType == typeof(IntegerVariable) ||
                     variableType == typeof(FloatVariable))
            {
                switch (selectedIndex)
                {
                default:
                case 0:
                    setOperator = SetOperator.Assign;
                    break;

                case 1:
                    setOperator = SetOperator.Add;
                    break;

                case 2:
                    setOperator = SetOperator.Subtract;
                    break;

                case 3:
                    setOperator = SetOperator.Multiply;
                    break;

                case 4:
                    setOperator = SetOperator.Divide;
                    break;
                }
            }

            setOperatorProp.enumValueIndex = (int)setOperator;

            if (variableType == typeof(BooleanVariable))
            {
                EditorGUILayout.PropertyField(booleanDataProp, new GUIContent("Boolean"));
            }
            else if (variableType == typeof(IntegerVariable))
            {
                EditorGUILayout.PropertyField(integerDataProp, new GUIContent("Integer"));
            }
            else if (variableType == typeof(FloatVariable))
            {
                EditorGUILayout.PropertyField(floatDataProp, new GUIContent("Float"));
            }
            else if (variableType == typeof(StringVariable))
            {
                EditorGUILayout.PropertyField(stringDataProp, new GUIContent("String"));
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemple #11
0
 public SetVariableWrapper(SetVariable sv)
 {
     line = sv;
 }
        /// <summary>
        /// a DTMF was pressed. Validate it towards the queue
        /// </summary>
        /// <param name="digit"></param>
        /// <returns>true if it can be processed, false if not.</returns>
        public bool GotDtmf(char digit)
        {
            bool isValid = true;

            lock (_items)
            {
                // dequeue all play commands if correct digit is pressed.
                while (_items.Count > 0)
                {
                    if (_items.Peek().GetType() == typeof(SetVariable))
                    {
                        Console.WriteLine("Is SetVariable");
                        SetVariable var    = (SetVariable)_items.Peek();
                        string      digits = string.Empty;
                        digits += digit;
                        if (var.Name == "playback_terminators")
                        {
                            if (var.Value.Contains(digits))
                            {
                                _items.Dequeue();
                                if (_items.Count > 0 && _items.Peek().GetType() == typeof(PlaybackCmd))
                                {
                                    _items.Dequeue();
                                }
                            }
                            else
                            {
                                isValid = false; //digit was not one of the terminators. skip it.
                            }
                        }
                    }
                    else if (_items.Peek().GetType() == typeof(PlaybackCmd))
                    {
                        Console.WriteLine("Is PlaybackCmd");
                        PlaybackCmd cmd    = (PlaybackCmd)_items.Peek();
                        string      digits = string.Empty;
                        digits += digit;
                        if (cmd.DtmfAbort.Contains(digits))
                        {
                            _items.Dequeue();
                        }
                        else
                        {
                            isValid = false; //digit was not one of the terminators, skip it.
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // and dequeue the dtmf command.
                if (_items.Count > 0 && _items.Peek().GetType() == typeof(PrivateWaitDtmf))
                {
                    ((PrivateWaitDtmf)_items.Dequeue()).Dispose();
                }
            }

            return(isValid);
        }
    public void CreateAssignment(Parser.AssignmentStatement ass, Block block, Dictionary <string, Yarn.Parser.Node> nodes, Dictionary <string, Block> blocks)
    {
        SetVariable setVar        = currentFlowchartObj.AddComponent <SetVariable>();
        Flowchart   currFlowchart = currentFlowchartObj.GetComponent <Flowchart>();

        switch (ass.operation)
        {
        case Yarn.TokenType.EqualToOrAssign:
            setVar.SetSetOperator(Fungus.SetOperator.Assign);
            break;

        case Yarn.TokenType.AddAssign:
            setVar.SetSetOperator(Fungus.SetOperator.Add);
            break;

        case Yarn.TokenType.MinusAssign:
            setVar.SetSetOperator(SetOperator.Subtract);
            break;

        case Yarn.TokenType.DivideAssign:
            setVar.SetSetOperator(SetOperator.Divide);
            break;

        case Yarn.TokenType.MultiplyAssign:
            setVar.SetSetOperator(SetOperator.Multiply);
            break;

        default:
            Debug.LogError("Unknown Operator");
            break;
        }
        switch (ass.valueExpression.value.value.type)
        {
        case Value.Type.String:
            StringDataMulti sdm = new StringDataMulti(ass.valueExpression.value.value.AsString);
            setVar.SetStringData(sdm);
            StringVariable sv = null;
            if (currFlowchart.GetVariable <StringVariable>(ass.destinationVariableName) == null)
            {
                sv       = currentFlowchartObj.AddComponent <StringVariable>();
                sv.Scope = VariableScope.Public;
                sv.Key   = ass.destinationVariableName;
                sv.Value = "";
                currFlowchart.AddVariable(sv);
                currFlowchart.SetStringVariable(sv.Key, sv.Value);
            }
            else
            {
                sv = currFlowchart.GetVariable <StringVariable>(ass.destinationVariableName);
                currFlowchart.SetStringVariable(sv.Key, sv.Value);
            }
            setVar.SetAffectedVariable(sv);
            break;

        case Value.Type.Number:
            FloatData fd = new FloatData(ass.valueExpression.value.value.AsNumber);
            setVar.SetFloatData(fd);
            FloatVariable fv = null;
            if (currFlowchart.GetVariable <FloatVariable>(ass.destinationVariableName) == null)
            {
                fv       = currentFlowchartObj.AddComponent <FloatVariable>();
                fv.Scope = VariableScope.Public;
                fv.Key   = ass.destinationVariableName;
                fv.Value = 0;
                currFlowchart.AddVariable(fv);
                currFlowchart.SetFloatVariable(fv.Key, fv.Value);
            }
            else
            {
                fv = currFlowchart.GetVariable <FloatVariable>(ass.destinationVariableName);
                currFlowchart.SetFloatVariable(fv.Key, fv.Value);
            }
            setVar.SetAffectedVariable(fv);
            break;

        case Value.Type.Bool:
            BooleanData bd = new BooleanData(ass.valueExpression.value.value.AsBool);
            setVar.SetBooleanData(bd);
            BooleanVariable bv = null;
            if (currFlowchart.GetVariable <BooleanVariable>(ass.destinationVariableName) == null)
            {
                bv       = currentFlowchartObj.AddComponent <BooleanVariable>();
                bv.Scope = VariableScope.Public;
                bv.Key   = ass.destinationVariableName;
                bv.Value = false;
                currFlowchart.AddVariable(bv);
                currFlowchart.SetBooleanVariable(bv.Key, bv.Value);
            }
            else
            {
                bv = currFlowchart.GetVariable <BooleanVariable>(ass.destinationVariableName);
                currFlowchart.SetBooleanVariable(bv.Key, bv.Value);
            }
            setVar.SetAffectedVariable(bv);
            break;

        default:
            Debug.LogError("Unknown type");
            break;
        }

        block.CommandList.Add(setVar);
    }
Exemple #14
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            SetVariable t = target as SetVariable;

            var flowchart = (Flowchart)t.GetFlowchart();

            if (flowchart == null)
            {
                return;
            }

            // Select Variable
            EditorGUILayout.PropertyField(anyVarProp, true);

            //fetching every draw to ensure we don't have stale data based on types that have changed by user selection,
            //  without us noticing.

            // Get selected variable
            Variable          selectedVariable = anyVarProp.FindPropertyRelative("variable").objectReferenceValue as Variable;
            List <GUIContent> operatorsList    = new List <GUIContent>();

            if (selectedVariable != null)
            {
                if (selectedVariable.IsArithmeticSupported(SetOperator.Assign))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Assign)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Negate))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Negate)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Add))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Add)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Subtract))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Subtract)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Multiply))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Multiply)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Divide))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Divide)));
                }
            }
            else
            {
                operatorsList.Add(VariableConditionEditor.None);
            }

            // Get previously selected operator
            int selectedIndex = (int)t._SetOperator;

            if (selectedIndex < 0)
            {
                // Default to first index if the operator is not found in the available operators list
                // This can occur when changing between variable types
                selectedIndex = 0;
            }

            // Get next selected operator
            selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());

            if (selectedVariable != null)
            {
                setOperatorProp.enumValueIndex = selectedIndex;
            }

            serializedObject.ApplyModifiedProperties();
        }