예제 #1
0
    private void load()
    {
        availableOps = new Dictionary <string, BotOperation> ();

        mainOp       = new CompositeOperation();
        compositeOps = new Dictionary <string, BotOperation> ();
    }
예제 #2
0
    /// <summary>
    /// Adds the operation to the active composite operation
    /// </summary>
    /// <param name="op">Op.</param>
    public void RunOperation(string op)
    {
        BotOperation operation = null;
        bool         exists    = availableOps.TryGetValue(op, out operation);

        if (exists)
        {
            if (AddToCurrentComp(operation, 0))
            {
                uiManager.AddOperationToBlock(currentComposite.name, op);
            }
        }
        else
        {
            // Maybe its a composite
            BotOperation compOp     = null;
            bool         existsComp = compositeOps.TryGetValue(op, out compOp);

            if (existsComp)
            {
                CompositeOperation comp = compOp as CompositeOperation;
                if (AddToCurrentComp(comp, 0))
                {
                    uiManager.AddOperationToBlock(currentComposite.name, op);
                }
            }
        }
    }
예제 #3
0
        public void Redo_ShouldRedoOperationsInCorrectOrder()
        {
            // Arrange
            var order = new List <IOperation>();

            var op1 = new Mock <IOperation>();

            _ = op1.Setup(op => op.Redo()).Callback(() => order.Add(op1.Object));
            var op2 = new Mock <IOperation>();

            _ = op2.Setup(op => op.Redo()).Callback(() => order.Add(op2.Object));

            var operation = new CompositeOperation()
            {
                Operations = new List <IOperation>()
                {
                    op1.Object,
                    op2.Object
                }
            };

            // Act
            operation.Redo();

            // Assert
            Assert.Equal(new[] { op1.Object, op2.Object }, order);
        }
예제 #4
0
            public virtual void ProcessCompositeOperation([CanBeNull] CompositeOperation operation)
            {
                if (ReferenceEquals(operation, CompositeOperation))
                {
                    return;
                }

                if (CompositeOperation != null)
                {
                    _statements.AddRange(CompositeOperation.Operations.SelectMany(op => _generator.Generate(op)));
                }

                CompositeOperation = operation;
            }
예제 #5
0
    IEnumerator CompositeRun(string name)
    {
        BotOperation operation;

        compositeOps.TryGetValue(name, out operation);
        CompositeOperation  compOp    = operation as CompositeOperation;
        List <BotOperation> botOpList = compOp.opList;

        if (botOpList != null)
        {
            for (int i = 0; i < botOpList.Count; i++)
            {
                BotOperation       op   = botOpList [i];
                CompositeOperation comp = op as CompositeOperation;

                if (comp != null)
                {
                    // If this operation is a composite one we need to execute it first accordingly
                    yield return(StartCoroutine(CompositeRun(comp.name)));
                }

                if (op != null && op.ValidateOperation(gameObject, levelDef))
                {
                    op.RunOperation(gameObject, levelDef);

                    if (CheckGameOver())
                    {
                        //If all the lights are on then there's no need to continue running the processes, it's game over
                        StopAllCoroutines();
                        // TextAsset load = Resources.Load<TextAsset> (listManager.chosenLevelUrl);
                        // var level = JSON.Parse (load.text);
                        // var namalvl = level["name"].Value;
                        //  if(namalvl == "1"){
                        //      SceneManager.LoadScene("Quiz1");
                        //  } else if(namalvl == "2"){
                        //      SceneManager.LoadScene("Quiz2");
                        //  }
                    }
                }

                yield return(new WaitForSeconds(operationDelay));
            }
        }

        yield return(null);
    }
            public virtual void HandleCompositeOperation([CanBeNull] CompositeOperation compositeOperation)
            {
                if (ReferenceEquals(compositeOperation, CompositeOperation))
                {
                    return;
                }

                if (CompositeOperation != null)
                {
                    foreach (var operation in CompositeOperation.Operations)
                    {
                        _statements.Add(_generator.Generate(operation));
                        _generator.DatabaseModelModifier.Modify(_generator.Database, operation);
                    }
                }

                CompositeOperation = compositeOperation;
            }
예제 #7
0
 /// <summary>
 /// Adds the operation to the available operations list
 /// </summary>
 /// <param name="operation">Operation.</param>
 /// <param name="main">If set to <c>true</c> main.</param>
 /// <param name="composite">If set to <c>true</c> composite.</param>
 /// <param name="name">Name.</param>
 public void AddOperation(BotOperation operation, bool main, bool composite, string name)
 {
     if (main)
     {
         CompositeOperation compOp = operation as CompositeOperation;
         mainOp           = compOp;
         currentComposite = compOp;
         compositeOps.Add(name, mainOp);
     }
     else if (!composite)
     {
         availableOps.Add(name, operation);
     }
     else
     {
         compositeOps.Add(name, operation);
     }
 }
예제 #8
0
        public void AsSingleUndoableOperation(Action action)
        {
            CurrentCompositeOperation = new CompositeOperation();
            CompositeOperation operation = null;

            try
            {
                action();
                operation = CurrentCompositeOperation;
            }
            finally
            {
                CurrentCompositeOperation = null;
                if (operation != null && operation.Operations.Count > 0)
                {
                    RegisterOperation(operation);
                }
            }
        }
예제 #9
0
    /// <summary>
    /// Change the composite operation to which the operations will be added
    /// </summary>
    /// <param name="name">Name.</param>
    public void ChangeCurrentComposite(string name)
    {
        BotOperation       operation = null;
        bool               exists    = compositeOps.TryGetValue(name, out operation);
        CompositeOperation compOp    = operation as CompositeOperation;

        if (compOp != null)
        {
            uiManager.DeselectBlock(currentComposite.name);
            if (indexOpSelected != -1)
            {
                uiManager.DeselectOperation(currentComposite.name, indexOpSelected);
            }

            currentComposite = compOp;
            indexOpSelected  = -1;
            uiManager.SelectBlock(currentComposite.name);
        }
    }
        public override void Visit(DropColumnOperation dropColumnOperation, Context context)
        {
            Check.NotNull(dropColumnOperation, "dropColumnOperation");
            Check.NotNull(context, "context");

            var compositeOperation = new CompositeOperation();

            var database = context.Generator.Database;
            var table    = database.GetTable(dropColumnOperation.TableName);
            var column   = table.GetColumn(dropColumnOperation.ColumnName);

            if (column.HasDefault)
            {
                compositeOperation.AddOperation(new DropDefaultConstraintOperation(table.Name, column.Name));
            }

            compositeOperation.AddOperation(dropColumnOperation);

            context.HandleCompositeOperation(compositeOperation);
        }
        public override void Visit(DropTableOperation dropTableOperation, Context context)
        {
            Check.NotNull(dropTableOperation, "dropTableOperation");
            Check.NotNull(context, "context");

            var compositeOperation = new CompositeOperation();

            var database = context.Generator.Database;
            var table    = database.GetTable(dropTableOperation.TableName);

            compositeOperation.AddOperations(
                database.Tables
                .SelectMany(t => t.ForeignKeys)
                .Where(fk => ReferenceEquals(fk.ReferencedTable, table))
                .Select(fk => new DropForeignKeyOperation(fk.Table.Name, fk.Name)));

            compositeOperation.AddOperation(dropTableOperation);

            context.HandleCompositeOperation(compositeOperation);
        }
예제 #12
0
    IEnumerator CompositeRun(string name)
    {
        BotOperation operation;

        compositeOps.TryGetValue(name, out operation);
        CompositeOperation  compOp    = operation as CompositeOperation;
        List <BotOperation> botOpList = compOp.opList;

        if (botOpList != null)
        {
            for (int i = 0; i < botOpList.Count; i++)
            {
                BotOperation       op   = botOpList [i];
                CompositeOperation comp = op as CompositeOperation;

                if (comp != null)
                {
                    // If this operation is a composite one we need to execute it first accordingly
                    yield return(StartCoroutine(CompositeRun(comp.name)));
                }

                if (op != null && op.ValidateOperation(gameObject, levelDef))
                {
                    op.RunOperation(gameObject, levelDef);

                    if (CheckGameOver())
                    {
                        // If all the lights are on then there's no need to continue running the processes, it's game over
                        StopAllCoroutines();
                    }
                }

                yield return(new WaitForSeconds(operationDelay));
            }
        }

        yield return(null);
    }
예제 #13
0
    /// <summary>
    /// Levels are defined by a JSON file, this method parses that file and loads the level information into memory
    /// </summary>
    private void LevelLoad()
    {
        BotController bController = actualBotGO.GetComponent <BotController> ();
        TextAsset     levelJson   = Resources.Load <TextAsset> (listManager.chosenLevelUrl);

        levelDefinition = new LevelDefinition();

        var levelD = JSON.Parse(levelJson.text);

        if (levelD != null)
        {
            levelDefinition.name       = levelD ["name"];
            levelDefinition.maxScore   = levelD ["maxScore"];
            levelDefinition.numRows    = levelD ["numRows"];
            levelDefinition.numColumns = levelD ["numColumns"];
            levelDefinition.botPos     = new Vector2(levelD ["botPos"] ["x"].AsInt, levelD ["botPos"] ["y"].AsInt);

            levelDefinition.board = new Tile[levelDefinition.numRows, levelDefinition.numColumns];

            for (int i = 0; i < levelDefinition.numRows; i++)
            {
                for (int j = 0; j < levelDefinition.numColumns; j++)
                {
                    Tile t = new Tile();

                    t.setInfo(levelD ["board"] [i] [j] ["height"].AsInt,
                              levelD ["board"] [i] [j] ["lightable"].AsBool,
                              new Vector2(levelD ["board"] [i] [j] ["position"] ["x"].AsInt, levelD ["board"] [i] [j] ["position"] ["y"].AsInt));

                    levelDefinition.board [i, j] = t;
                }
            }
        }

        int opAmount = levelD ["availableOps"].AsArray.Count;

        for (int i = 0; i < opAmount; i++)
        {
            var    op   = levelD ["availableOps"] [i];
            string name = op ["name"];

            switch (name)
            {
            case "FWD":
                bController.AddOperation(new ForwardOperation(), false, false, "FWD");
                uiManager.EnableOp(name);
                break;

            case "TL":
                bController.AddOperation(new TurnLeftOperation(), false, false, "TL");
                uiManager.EnableOp(name);
                break;

            case "TR":
                bController.AddOperation(new TurnRightOperation(), false, false, "TR");
                uiManager.EnableOp(name);
                break;

            case "JMP":
                bController.AddOperation(new JumpOperation(), false, false, "JMP");
                uiManager.EnableOp(name);
                break;

            case "LGHT":
                bController.AddOperation(new LightOperation(), false, false, "LGHT");
                uiManager.EnableOp(name);
                break;

            case "Main":
                CompositeOperation compOp = new CompositeOperation();
                compOp.limit = op ["limit"].AsInt;
                compOp.name  = "Main";
                bController.AddOperation(compOp, true, true, "Main");
                uiManager.EnableBlock(name, op["limit"].AsInt);
                break;

            default:
                //  If the operation is not one of the above it means that it's a function (or an unknown operation which isn't good)
                if (op ["type"].Value == "Composite")
                {
                    CompositeOperation comp = new CompositeOperation();
                    comp.limit = op ["limit"].AsInt;
                    comp.name  = op ["name"];
                    bController.AddOperation(comp, false, true, op ["name"]);
                    uiManager.EnableBlock(name, op["limit"].AsInt);
                    uiManager.EnableOp(name);
                }
                break;
            }
        }

        bController.LevelDef          = levelDefinition.Clone();
        bController.LevelDef.maxScore = levelDefinition.maxScore;

        Resources.UnloadAsset(levelJson);

        //Debug.Log (levelDefinition.ToString());
    }
예제 #14
0
 /// <summary>
 /// Sets the composite operation.
 /// </summary>
 public static void GlobalCompositeOperation(this Nvg nvg, CompositeOperation op)
 {
     nvg.stateStack.CurrentState.CompositeOperation = new CompositeOperationState(op);
 }
 public ValueTask GlobalCompositeOperationAsync(CompositeOperation type) => SetAsync("globalCompositeOperation", type);
예제 #16
0
        internal CompositeOperationState(CompositeOperation op)
        {
            BlendFactor srcFactor, dstFactor;

            switch (op)
            {
            case CompositeOperation.SourceOver:
                srcFactor = BlendFactor.One;
                dstFactor = BlendFactor.OneMinusSrcAlpha;
                break;

            case CompositeOperation.SourceIn:
                srcFactor = BlendFactor.DstAlpha;
                dstFactor = BlendFactor.Zero;
                break;

            case CompositeOperation.SourceOut:
                srcFactor = BlendFactor.OneMinusDstAlpha;
                dstFactor = BlendFactor.Zero;
                break;

            case CompositeOperation.Atop:
                srcFactor = BlendFactor.DstAlpha;
                dstFactor = BlendFactor.OneMinusSrcAlpha;
                break;

            case CompositeOperation.DestinationOver:
                srcFactor = BlendFactor.OneMinusDstAlpha;
                dstFactor = BlendFactor.One;
                break;

            case CompositeOperation.DestinationIn:
                srcFactor = BlendFactor.Zero;
                dstFactor = BlendFactor.SrcAlpha;
                break;

            case CompositeOperation.DestinationOut:
                srcFactor = BlendFactor.Zero;
                dstFactor = BlendFactor.OneMinusSrcAlpha;
                break;

            case CompositeOperation.DestinationAtop:
                srcFactor = BlendFactor.OneMinusDstAlpha;
                dstFactor = BlendFactor.SrcAlpha;
                break;

            case CompositeOperation.Lighter:
                srcFactor = BlendFactor.One;
                dstFactor = BlendFactor.One;
                break;

            case CompositeOperation.Copy:
                srcFactor = BlendFactor.One;
                dstFactor = BlendFactor.Zero;
                break;

            case CompositeOperation.XOR:
                srcFactor = BlendFactor.OneMinusDstAlpha;
                dstFactor = BlendFactor.OneMinusSrcAlpha;
                break;

            default:
                srcFactor = BlendFactor.One;
                dstFactor = BlendFactor.Zero;
                break;
            }

            SrcRgb = SrcAlpha = srcFactor;
            DstRgb = DstAlpha = dstFactor;
        }