Example #1
0
    public override void Execute()
    {
        Variable variable = LevelManager.instance.variablePlayerHolding;

        if (variable == null)
        {
            statusDisplay.SetText("Not holding variable", true);
            return;
        }

        if (variable.type.Name != "Int32")
        {
            statusDisplay.SetText("Variable must be an integer", true);
            return;
        }

        if (!operand1Exists)
        {
            operand1       = (int)variable.GetValue();
            operand1Exists = true;
            return;
        }

        if (!operand2Exists)
        {
            operand2       = (int)variable.GetValue();
            operand2Exists = true;
            return;
        }

        LevelManager.instance.variablePlayerHolding.SetValue(Evaluate());
    }
Example #2
0
        private bool ExecuteExpression()
        {
            if (String.IsNullOrEmpty(ifCondition.Expression))
            {
                throw new ArgumentNullException(nameof(ifCondition.Expression));
            }
            // 分析表达式
            // 分析逻辑表达式的情况
            var    expressions   = ifCondition.Expression.Split(new string[] { ">", "<", "==", ">=", "<=", "!=" }, StringSplitOptions.RemoveEmptyEntries);
            string newExpression = ifCondition.Expression;

            if (expressions.Length == 2)
            {
                var expre_left = expressions[0];
                var key_value  = expre_left.Split('.');
                if (key_value.Length == 2)
                {
                    Variable variable = null;
                    switch (key_value[0])
                    {
                    case "Locals":
                        variable = Locals[key_value[1]];
                        break;

                    case "Parameters":
                        variable = Parameters[key_value[1]];
                        break;

                    default:
                        break;
                    }
                    if (variable == null)
                    {
                        throw new ArgumentNullException(expre_left);
                    }
                    switch (variable.VariableType.Name)
                    {
                    case nameof(Int32):
                        newExpression = newExpression.Replace(expre_left, variable.GetValue <Int32>().ToString());
                        break;

                    case nameof(String):
                        newExpression = newExpression.Replace(expre_left, "\"" + variable.GetValueString() + "\"");
                        break;

                    case nameof(Boolean):
                        newExpression = newExpression.Replace(expre_left, variable.GetValue <Boolean>().ToString());
                        break;

                    default:
                        break;
                    }
                }
            }
            return(MyEvaluator.EvaluateToBool(newExpression));
        }
Example #3
0
            public List <Object> GetEntities()
            {
                String        selectorString  = CastString(selector.GetValue()).GetTypedValue();
                bool          resolvedIsGroup = false;
                Block         bt       = blockType.HasValue ? blockType.Value : ResolveType(selectorString, out resolvedIsGroup);
                bool          useGroup = isGroup || resolvedIsGroup;
                List <object> entities = useGroup ? BlockHandlerRegistry.GetBlocksInGroup(bt, selectorString) : BlockHandlerRegistry.GetBlocks(bt, block => block.CustomName.Equals(selectorString));

                return(entities);
            }
    public void In()
    {
        GameObject parent = Parent.GetValue <GameObject>();

        if (parent != null)
        {
            Child.Value = EB.Util.GetObjectExactMatch(Parent.GetValue <GameObject>(), Name);
        }

        Out.Invoke();
    }
Example #5
0
            public Primitive GetValue()
            {
                var list   = CastList(expectedList.GetValue()).GetTypedValue();
                var values = GetIndexValues()
                             .Select(p => list.GetValue(p))
                             .ToList();

                if (values.Count == 0)
                {
                    return(new ListPrimitive(list));
                }
                return(values.Count == 1 ? values[0].GetValue() : new ListPrimitive(new KeyedList(values.ToArray())));
            }
 //Adds the value to the List and also adds it to the linked UI element to display the output to the user
 public void Output(Variable output)
 {
     if (clearOutputs)
     {
         outputText.text = "Outputs:";
         clearOutputs    = false;
     }
     outputList.Add(output.GetValue());
     if (outputText != null)
     {
         ObjectiveManager.AddToTMP(outputText, output.GetValue());
     }
 }
Example #7
0
            public Primitive GetValue()
            {
                Primitive       comparison = comparisonValue.GetValue();
                List <Variable> list       = CastList(expectedList.GetValue()).GetTypedValue().GetValues();

                return(new BooleanPrimitive(Evaluate(list.Count, list.Where(v => comparator.compare(v.GetValue(), comparison)).Count(), aggregationMode)));
            }
 public void Start()
 {
     this.Activate();
     _remaining = Interval.GetValue <float>();
     _running   = true;
     _pause     = false;
 }
Example #9
0
        public Array GetArray(Tensor x)
        {
            Variable xvar = In(x);
            Value    v    = null;

            if (xvar.IsOutput)
            {
                var f = xvar.ToFunction();

                var plist = f.Parameters();
                Dictionary <Variable, Value> inputs  = new Dictionary <Variable, Value>();
                Dictionary <Variable, Value> outputs = new Dictionary <Variable, Value>()
                {
                    { f, null }
                };

                f.Evaluate(inputs, outputs, DeviceManager.Current);
                v = outputs.FirstOrDefault().Value;
            }
            else
            {
                v = new Value(xvar.GetValue());
            }

            return(v.GetDenseData <float>(xvar)[0].ToArray());
        }
Example #10
0
            public List <Object> GetEntities()
            {
                String        selectorString = CastString(selector.GetValue()).GetStringValue();
                List <object> entities       = isGroup ? BlockHandlerRegistry.GROUP_BLOCK_PROVIDER(blockType, selectorString) : BlockHandlerRegistry.BLOCK_PROVIDER(blockType, selectorString);

                return(entities);
            }
Example #11
0
            public List <object> GetEntities()
            {
                List <object> entities         = provider.GetEntities();
                List <object> selectedEntities = new List <Object>();
                BlockHandler  b = BlockHandlerRegistry.GetBlockHandler(GetBlockType());

                var indexes = CastList(index.GetValue()).GetTypedValue().GetValues()
                              .Select(v => v.GetValue()).ToList();

                foreach (Primitive p in indexes)
                {
                    //Return empty list if index > Count
                    if (p.GetPrimitiveType() == Return.NUMERIC)
                    {
                        int i = (int)CastNumber(p).GetTypedValue();
                        if (i < entities.Count)
                        {
                            selectedEntities.Add(entities[i]);
                        }
                    }
                    if (p.GetPrimitiveType() == Return.STRING)
                    {
                        var entityName = CastString(p).GetTypedValue();
                        selectedEntities.AddRange(entities.Where(o => entityName == b.GetName(o)));
                    }
                    //Other Index types not supported
                }
                return(selectedEntities);
            }
        public void TestVariableDefaultValue()
        {
            IVariable variableObject  = new Variable <Car>("car", new Car(), "input", false, VariableValue.Null);
            IVariable variableInt     = new Variable <int>("id", 1, false, 0);
            IVariable variableString  = new Variable <string>("name", "name", false, "n");
            IVariable variableFloat   = new Variable <float>("value", 100F, false, 0);
            IVariable variableBoolean = new Variable <bool>("active", true, false, false);
            IVariable variableID      = new Variable <object>("id", 2, "ID", false, 0, Format.FormatID);

            Assert.AreEqual("$car:input=null", variableObject.GetKeyParam());
            Assert.AreEqual("$id:Int=0", variableInt.GetKeyParam());
            Assert.AreEqual("$name:String=n", variableString.GetKeyParam());
            Assert.AreEqual("$value:Float=0", variableFloat.GetKeyParam());
            Assert.AreEqual("$active:Boolean=false", variableBoolean.GetKeyParam());
            Assert.AreEqual("$id:ID=0", variableID.GetKeyParam());

            Assert.AreEqual("input", variableObject.Convert());
            Assert.AreEqual(variableObject.Value, variableObject.GetValue());

            Assert.IsInstanceOfType(variableInt.VariableType.Type, typeof(int).GetType());
            Assert.IsInstanceOfType(variableString.VariableType.Type, typeof(string).GetType());
            Assert.IsInstanceOfType(variableFloat.VariableType.Type, typeof(float).GetType());
            Assert.IsInstanceOfType(variableBoolean.VariableType.Type, typeof(bool).GetType());
            Assert.IsInstanceOfType(variableID.VariableType.Type, typeof(object).GetType());
        }
Example #13
0
 public Loop(int initialIndex, Variable iterationVariable)
 {
     this.initialIndex      = initialIndex;
     this.finalIndex        = initialIndex;
     this.iterationVariable = iterationVariable;
     this.numberIterations  = iterationVariable.GetValue();
 }
        public void IGoToTheVSMCSite()
        {
            // get url from variable
            var url = Variable.GetValue("p_vsmc_url");

            _driver.Navigate().GoToUrl(url);
        }
Example #15
0
        protected byte[] VariablesToBytes(List <DatabaseVariable> ltVariables, int iLength)
        {
            byte[] abBuffer, abReturn = new byte[Crc24.ciCrc24Length + iLength];
            int    iFrom, iTo = Crc24.ciCrc24Length;
            Crc24  Crc24Computed;

            foreach (DatabaseVariable Variable in ltVariables)
            {
                abReturn[iTo++] = Variable.bTag;
                abBuffer        = Variable.GetValue();
                for (iFrom = 0; iFrom < Variable.iLength; iFrom++)
                {
                    abReturn[iTo++] = abBuffer[iFrom];
                }
            }

            if (iTo == Crc24.ciCrc24Length + iLength)
            {
                Crc24Computed = new Crc24(abReturn, Crc24.ciCrc24Length);
                abReturn[0]   = (byte)((Crc24Computed.iCrc24 >> 16) & 0xff);
                abReturn[1]   = (byte)((Crc24Computed.iCrc24 >> 8) & 0xff);
                abReturn[2]   = (byte)(Crc24Computed.iCrc24 & 0xff);
                return(abReturn);
            }
            else
            {
                throw new FormatException("Failed to complete EncryptedDatabase.VariablesToBytes().");
            }
        }
            public override bool Execute()
            {
                switch (controlType)
                {
                case ControlType.STOP:
                    RUNNING_COMMANDS = null; STATE = ProgramState.STOPPED; break;

                case ControlType.PARSE:
                    RUNNING_COMMANDS = null; ParseCommands(); STATE = ProgramState.STOPPED; break;

                case ControlType.START:
                    RUNNING_COMMANDS = null; STATE = ProgramState.RUNNING; break;

                case ControlType.RESTART:
                    RUNNING_COMMANDS.Reset(); RUNNING_COMMANDS.Loop(1); STATE = ProgramState.RUNNING; break;

                case ControlType.PAUSE:
                    STATE = ProgramState.PAUSED; break;

                case ControlType.RESUME:
                    STATE = ProgramState.RUNNING; break;

                case ControlType.LOOP:
                    float loops = CastNumber(loopAmount.GetValue()).GetNumericValue();
                    RUNNING_COMMANDS.Loop((int)loops); STATE = ProgramState.RUNNING; break;

                default: throw new Exception("Unsupported Control Type");
                }
                return(true);
            }
            public override bool Execute()
            {
                Variable value = useReference ? variable : new StaticVariable(variable.GetValue());

                Program.memoryVariables[variableName] = value;
                return(true);
            }
Example #18
0
            public Primitive GetValue()
            {
                switch (operand)
                {
                case OperandType.ADD: return(a.GetValue().Plus(b.GetValue()));

                case OperandType.SUBTACT: return(a.GetValue().Minus(b.GetValue()));

                case OperandType.MULTIPLY: return(a.GetValue().Multiply(b.GetValue()));

                case OperandType.DIVIDE: return(a.GetValue().Divide(b.GetValue()));

                case OperandType.MOD: return(a.GetValue().Mod(b.GetValue()));

                default: throw new Exception("Unknown Operand type: " + operand);
                }
            }
 protected void SetVariable(Variable var1, Variable var2)
 {
     //Ensures values are not null to prevent throwing an exception
     if (var1 != null && var2 != null)
     {
         var1.SetValue(var2.GetValue());
     }
 }
 public override bool Execute()
 {
     if (ticksLeft < 0)
     {
         ticksLeft = getTicks(CastNumber(waitInterval.GetValue()).GetTypedValue(), units);
     }
     Debug("Waiting for " + ticksLeft + " ticks");
     return(ticksLeft-- <= 0);
 }
Example #21
0
        private void Update(EvaluationContext context)
        {
            string variableName = Variable.GetValue(context);

            if (context.FloatVariables.TryGetValue(variableName, out float value))
            {
                // Log.Debug($"{variableName} : {value}");
                Result.Value = value;
            }
        }
 private bool EvaluateCondition()
 {
     if ((!isExecuting && alwaysEvaluate) || !evaluated)
     {
         Trace("Evaluating Value");
         evaluatedValue = CastBoolean(Condition.GetValue()).GetBooleanValue(); evaluated = true;
     }
     Debug("Evaluated Value: " + evaluatedValue);
     return(evaluatedValue);
 }
Example #23
0
    public void Spawn()
    {
        var locator = Where.GetValue <GameObject>();

        if (!locator)
        {
            EB.Debug.LogError("Missing locator!");
        }

        Spawned.Value = (GameObject)Object.Instantiate(Prefab, locator.transform.position, locator.transform.rotation);

        Finished.Invoke();
    }
            public override bool Execute()
            {
                if (from.GetBlockType() != Block.CARGO || to.GetBlockType() != Block.CARGO)
                {
                    throw new Exception("Transfers can only be executed on cargo block types");
                }

                BlockHandler blockHandler = BlockHandlerRegistry.GetBlockHandler(Block.CARGO);

                var filter = PROGRAM.AnyItem(PROGRAM.GetItemFilters(CastString((second ?? first).GetValue()).GetTypedValue()));
                var items  = new List <MyInventoryItem>();

                var toInventories   = to.GetEntities().Select(i => (IMyInventory)i).Where(i => !i.IsFull).ToList();
                var fromInventories = from.GetEntities().Select(i => (IMyInventory)i)
                                      .Where(i => toInventories.TrueForAll(to => i.Owner.EntityId != to.Owner.EntityId)) //Don't transfer to yourself
                                      .ToList();

                MyFixedPoint amountLeft = MyFixedPoint.MaxValue;

                if (second != null)
                {
                    amountLeft = (MyFixedPoint)CastNumber(first.GetValue()).GetTypedValue();
                }

                int transfers = 0;

                foreach (IMyInventory fromInventory in fromInventories)
                {
                    fromInventory.GetItems(items, filter);
                    for (int i = 0; i < toInventories.Count; i++)
                    {
                        foreach (MyInventoryItem item in items)
                        {
                            var destinationInventory = toInventories[i];
                            var startMass            = fromInventory.CurrentMass;
                            fromInventory.TransferItemTo(destinationInventory, item, amountLeft);
                            amountLeft -= (startMass - fromInventory.CurrentMass);
                            if (amountLeft <= MyFixedPoint.Zero || ++transfers >= PROGRAM.maxItemTransfers)
                            {
                                return(true);
                            }
                            if (destinationInventory.IsFull)
                            {
                                toInventories.RemoveAt(i--);
                                break;
                            }
                        }
                    }
                }
                return(true);
            }
Example #25
0
        protected override TaskResult OnUpdate()
        {
            var leftValue  = leftVariable.GetValue(this) as IComparable;
            var rightValue = rightVariable.GetValue(this) as IComparable;

            if (leftValue == null || rightValue == null)
            {
                LogError("{0}: Failed to get value from variables. Left: {0} = {1}, Right: {2} = {3}",
                         leftVariable, leftValue, rightVariable, rightValue);
                return(TaskResult.Failure);
            }

            return(description.Op.Match(leftValue.CompareTo(rightValue)) ? TaskResult.Success : TaskResult.Failure);
        }
Example #26
0
        private void Update(EvaluationContext context)
        {
            string variableName = Variable.GetValue(context);
            float  end          = End.GetValue(context);

            for (float i = 0f; i < end; i += 1.0f)
            {
                context.FloatVariables[variableName] = i;

                DirtyFlag.InvalidationRefFrame++;
                Command.Invalidate();
                Command.GetValue(context);
            }
        }
            public override bool Execute()
            {
                Variable value = useReference ? variable : new StaticVariable(variable.GetValue().DeepCopy());

                if (isGlobal)
                {
                    PROGRAM.SetGlobalVariable(variableName, value);
                }
                else
                {
                    PROGRAM.GetCurrentThread().threadVariables[variableName] = value;
                }
                return(true);
            }
Example #28
0
            public Primitive GetValue()
            {
                ListPrimitive list = CastList(expectedIndex.GetValue());

                if (list.GetTypedValue().GetValues().Count == 1)
                {
                    Primitive onlyValue = list.GetTypedValue().GetValue(ResolvePrimitive(0)).GetValue();
                    if (onlyValue.GetPrimitiveType() == Return.LIST)
                    {
                        list = CastList(onlyValue);
                    }
                }
                return(list);
            }
            public override bool Execute()
            {
                if (currentCommands == null || currentCommands.Count == 0)
                {
                    currentCommands = commandsToExecute.Select(c => c.Copy()).ToList();//Deep Copy
                    if (loopsLeft == 0)
                    {
                        loopsLeft = (int)Math.Round(CastNumber(loopCount.GetValue()).GetNumericValue());
                    }
                    loopsLeft -= 1;
                }

                Debug("Commands left: " + currentCommands.Count);
                Debug("Loops Left: " + loopsLeft);

                int commandIndex = 0;

                while (currentCommands != null && commandIndex < currentCommands.Count)
                {
                    Command nextCommand = currentCommands[commandIndex];

                    bool handled = nextCommand.Execute();
                    if (handled && currentCommands != null)
                    {
                        currentCommands.RemoveAt(commandIndex);
                    }
                    else
                    {
                        commandIndex++;
                    }
                    if (!nextCommand.Async)
                    {
                        break;
                    }
                    Debug("Command is async, continuing to command at index: " + commandIndex);
                }

                if (currentCommands != null && currentCommands.Count > 0)
                {
                    return(false);
                }
                if (loopsLeft == 0)
                {
                    return(true);
                }

                Reset();
                return(false);
            }
Example #30
0
            public List <object> GetEntities()
            {
                List <object> entities         = provider.GetEntities();
                List <object> selectedEntities = new List <Object>();

                //Return empty list if index > Count
                int i = (int)CastNumber(index.GetValue()).GetNumericValue();

                if (i < entities.Count)
                {
                    selectedEntities.Add(entities[i]);
                }

                return(selectedEntities);
            }
Example #31
0
 private static IEnumerable<IHasState> GetLHSSatisfiers(
     IEnumerable<IHasState> scope,
     RuleName rule,
     IHasState Y)
 {
     Variable X = new Variable();
     foreach (bool l2 in RuleDefs.RuleFunc(rule)(scope, X, Y))
         yield return X.GetValue<IHasState>();
 }
Example #32
0
 private static IEnumerable<Tuple<IHasState, IHasState>> GetRuleSatisfiers(
     IEnumerable<IHasState> scope,
     RuleName rule)
 {
     Variable X = new Variable();
     Variable Y = new Variable();
     foreach (bool l2 in RuleDefs.RuleFunc(rule)(scope, X, Y))
         yield return new Tuple<IHasState, IHasState>(
             X.GetValue<IHasState>(),
             Y.GetValue<IHasState>());
 }