private Node GetNodeFrom(CustomBlockNode block)
        {
            CustomBlocks.Remove(block);

            var node = new Node(Grammar.CUSTOM_BLOCK_RULE_NAME, new LocalOptions {
                IsLand = true
            });

            node.AddLastChild(block.Start);
            node.AddLastChild(block.End);

            return(node);
        }
Esempio n. 2
0
    private void Init()
    {
#if BLOCK_MODEL || BLOCK_EDITOR
        string persistentPath = Application.persistentDataPath;
#else
        string persistentPath = PTUGame.persistentDataPath;
#endif

        var modelDatPath    = isApp?Path.Combine(persistentPath, MODEL_DATA_PATH_APP):MODEL_DATA_PATH;
        var prefabDataPath  = isApp?Path.Combine(persistentPath, Prefab_DATA_PATH_APP):Prefab_DATA_PATH;
        var colorDataPath   = isApp?Path.Combine(persistentPath, COLOR_DATA_PATH_APP):COLOR_DATA_PATH;
        var partNumDataPath = isApp?Path.Combine(persistentPath, PARTNUM_DATA_PATH_APP):PARTNUM_DATA_PATH;
        var textureDataPath = isApp?Path.Combine(persistentPath, TEXTURE_DATA_PATH_APP):TEXTURE_DATA_PATH;
        var stickerDataPath = isApp?Path.Combine(persistentPath, STICKER_DATA_PATH_APP):STICKER_DATA_PATH;
        var matDataPath     = isApp?Path.Combine(persistentPath, MAT_DATA_PATH_APP):MAT_DATA_PATH;

        blockModelDatas = LitJson.JsonMapper.ToObject <List <BlockModelData> >(File.ReadAllText(modelDatPath));
        PTDebug.LogWarning("{0} 解析完成。", modelDatPath);

        blockPrefabDatas = LitJson.JsonMapper.ToObject <List <BlockPrefabData> >(File.ReadAllText(prefabDataPath));
        PTDebug.LogWarning("{0} 解析完成。", prefabDataPath);

        blockColorDatas = LitJson.JsonMapper.ToObject <List <BlockColorData> >(File.ReadAllText(colorDataPath));
        PTDebug.LogWarning("{0} 解析完成。", colorDataPath);

        textureDatas = LitJson.JsonMapper.ToObject <List <PBTextureData> >(File.ReadAllText(textureDataPath));
        PTDebug.LogWarning("{0} 解析完成。", textureDataPath);

        stickerDatas = LitJson.JsonMapper.ToObject <List <StickerData> >(File.ReadAllText(stickerDataPath));
        PTDebug.LogWarning("{0} 解析完成。", stickerDataPath);

        matDatas = JsonUtility.FromJson <MaterialInfos>(File.ReadAllText(matDataPath)).materialInfos;

        if (!isApp)
        {
            CustomBlocks.GetCustomConfig(blockModelDatas);
            partNumDatas = LitJson.JsonMapper.ToObject <List <PartNumData> >(File.ReadAllText(partNumDataPath));
        }
        GenerateBlockDatas();
        mIsInitialize = true;
    }
        public override void Visit(Node root)
        {
            Root = root;

            if (root.Type == Grammar.ANY_TOKEN_NAME)
            {
                ProcessAny(root, CustomBlocks);
            }
            else
            {
                var outerBlocks = CustomBlocks.Where(b => b.Location.Includes(Root.Location)).ToList();

                Visit(Root, CustomBlocks.Except(outerBlocks).ToList());

                foreach (var block in outerBlocks)
                {
                    var newNode = GetNodeFrom(block);
                    newNode.InsertChild(Root, 1);

                    Root = newNode;
                }
            }
        }
Esempio n. 4
0
        private void SlabsCustoms()
        {
            int xAxis = 10;
            int yAxis = 5;

            remainingPb = xAxis * yAxis;

            int pbHeight = (int)(Height * 0.3) / yAxis;
            int pbWidth  = (Width - (xAxis - 5)) / xAxis;

            cpb = new CustomBlocks[yAxis, xAxis];

            for (int i = 0; i < yAxis; i++)
            {
                for (int j = 0; j < xAxis; j++)
                {
                    cpb[i, j] = new CustomBlocks();

                    if (i == 4)
                    {
                        cpb[i, j].Hits = 2;
                    }
                    else
                    {
                        cpb[i, j].Hits = 1;
                    }

                    //tamano
                    cpb[i, j].Height = pbHeight;
                    cpb[i, j].Width  = pbWidth;

                    //Posicion left  y posicion top
                    cpb[i, j].Left = j * pbWidth;
                    cpb[i, j].Top  = i * pbHeight + Score.Height + 1;
                    //cpb[i, j].BackgroundImage = Image.FromFile("../../../Sprites/" + GR() + ".png");


                    int imageBack;
                    if (i % 2 == 1 && j % 2 != 1)
                    {
                        imageBack = 4;
                    }
                    else if (i % 2 == 1 && j % 3 != 0)
                    {
                        imageBack = 3;
                    }
                    else if (i % 2 == 1 && j % 2 != 0)
                    {
                        imageBack = 3;
                    }
                    else
                    {
                        imageBack = 6;
                    }

                    if (i == 4)
                    {
                        cpb[i, j].BackgroundImage = Image.FromFile("../../../Sprites/blinded.png");
                        cpb[i, j].Tag             = "blinded";
                    }
                    else
                    {
                        cpb[i, j].BackgroundImage = Image.FromFile("../../../Sprites/" + imageBack + ".png");
                        cpb[i, j].Tag             = "tileTag";
                    }

                    cpb[i, j].BackgroundImageLayout = ImageLayout.Stretch;

                    Controls.Add(cpb[i, j]);
                }
            }
        }
Esempio n. 5
0
        public override IToken GetNextToken()
        {
            switch (CurrentTokenDirection)
            {
            case Direction.Down:
                PairStack.Push(OpenedPair);
                OpenedPair = null;
                break;

            case Direction.Up:
                PairStack.Pop();
                break;
            }

            CurrentTokenDirection = Direction.Forward;

            var token = base.GetNextToken();

            if (CustomBlockDefinition != null &&
                CustomBlockDefinition.BaseToken == token.Name)
            {
                if (CustomBlockDefinition.IsStartLexem(token.Text))
                {
                    var newBlock = new CustomBlockNode
                    {
                        Location = new SegmentLocation {
                            Start = token.Location.Start
                        },
                        Start = new Node(token.Name, new LocalOptions {
                            ExactMatch = true, Priority = LocalOptions.BASE_PRIORITY
                        })
                    };

                    newBlock.Start.SetLocation(token.Location.Start, token.Location.End);
                    newBlock.Start.SetValue(CustomBlockDefinition.GetName(token.Text));

                    CustomBlockStack.Push(newBlock);
                }
                else if (CustomBlockDefinition.IsEndLexem(token.Text))
                {
                    /// Отлавливаем ситуацию, когда количество закрытий блока не совпадает с количеством открытий
                    if (CustomBlockStack.Count == 0)
                    {
                        Log.Add(Message.Error(
                                    $"Неожиданная закрывающая конструкция {this.GetTokenInfoForMessage(token)} для пользовательского блока",
                                    token.Location.Start
                                    ));
                    }
                    else
                    {
                        var currentBlock = CustomBlockStack.Pop();

                        currentBlock.End = new Node(token.Name);
                        currentBlock.End.SetLocation(token.Location.Start, token.Location.End);
                        currentBlock.Location.End = token.Location.End;

                        CustomBlocks.Add(currentBlock);
                    }
                }
            }

            /// Предполагается, что токен может быть началом ровно одной пары, или концом ровно одной пары,
            /// или одновременно началом и концом ровно одной пары
            var closed = GrammarObject.Pairs.FirstOrDefault(p => p.Value.Right.Contains(token.Name));

            /// Если текущий токен закрывает некоторую конструкцию
            if (closed.Value != null)
            {
                /// и при этом не открывает её же
                if (!closed.Value.Left.Contains(token.Name))
                {
                    /// проверяем, есть ли на стеке то, что можно этой конструкцией закрыть
                    if (PairStack.Count == 0)
                    {
                        Log.Add(Message.Error(
                                    $"Отсутствует открывающая конструкция для парной закрывающей {this.GetTokenInfoForMessage(token)}",
                                    token.Location.Start
                                    ));

                        return(Lexer.CreateToken(Grammar.ERROR_TOKEN_NAME));
                    }
                    else if (PairStack.Peek() != closed.Value)
                    {
                        Log.Add(Message.Error(
                                    $"Неожиданная закрывающая конструкция {this.GetTokenInfoForMessage(token)}, ожидается {String.Join("или ", PairStack.Peek().Right.Select(e => GrammarObject.Userify(e)))} для открывающей конструкции {String.Join("или ", PairStack.Peek().Left.Select(e => GrammarObject.Userify(e)))}",
                                    token.Location.Start
                                    ));

                        return(Lexer.CreateToken(Grammar.ERROR_TOKEN_NAME));
                    }
                    else
                    {
                        CurrentTokenDirection = Direction.Up;
                    }
                }
                /// иначе, если текущий токен одновременно открывающий и закрывающий
                else
                {
                    /// и есть что закрыть, закрываем
                    if (PairStack.Count > 0 && PairStack.Peek() == closed.Value)
                    {
                        CurrentTokenDirection = Direction.Up;
                    }
                    else
                    {
                        CurrentTokenDirection = Direction.Down;
                        OpenedPair            = closed.Value;
                    }
                }
            }
            else
            {
                var opened = GrammarObject.Pairs.FirstOrDefault(p => p.Value.Left.Contains(token.Name));

                if (opened.Value != null)
                {
                    CurrentTokenDirection = Direction.Down;
                    OpenedPair            = opened.Value;
                }
            }

            return(token);
        }