private void InsertTable(InjectionContext injectionContext)
        {
            var markerPosition = injectionContext.MarkerRange.StartMarker.Position;
            var table          = (injectionContext.Injection as TableInjection).Resource.Object;
            var sheet          = injectionContext.Workbook.Worksheet(markerPosition.SheetIndex);
            var topLeftCell    = sheet.Cell(markerPosition.RowIndex, markerPosition.CellIndex);

            var rowCount    = table.Count;
            var columnCount = rowCount == 0
                ? 0
                : table[0].Count;

            //удаляем маркер
            if (rowCount == 0 || columnCount == 0)
            {
                topLeftCell.Clear(XLClearOptions.Contents);
            }

            var mergedRowsEnumerator = CellUtils.EnumerateMergedRows(topLeftCell).GetEnumerator();

            table.ForEach(dataRow =>
            {
                mergedRowsEnumerator.MoveNext();
                var excelRow = mergedRowsEnumerator.Current;

                var firstCellOfRow        = sheet.Cell(excelRow.FirstCell().Address.RowNumber, topLeftCell.Address.ColumnNumber);
                var mergedCellsEnumerator = CellUtils.EnumerateMergedCells(firstCellOfRow).GetEnumerator();

                dataRow.ForEach(dataValue =>
                {
                    mergedCellsEnumerator.MoveNext();
                    CellUtils.SetDynamicCellValue(mergedCellsEnumerator.Current, dataValue);
                });
            });
        }
Esempio n. 2
0
    void Init_Cells()
    {
        cells = new Cell[8, 8];

        if (SceneManager.GetActiveScene().name == "Game")
        {
            Debug.Log("Game");
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    GetCells()[i < 2 ? i : i + 4, j] = i < 2 ? Cell.WhiteFigure : Cell.BlackFigure;
                }
            }

            GetCells()[0, 4] |= Cell.King;
            GetCells()[7, 4] |= Cell.King;
        }
        // FOR_TEST Scene.
        else
        {
            Debug.Log("FOR_TEST");
            CellUtils.UpdateCells();
        }
    }
Esempio n. 3
0
 public virtual void RefreshCoordinates()
 {
     PlacedPosition = Pivot + PosOffset;
     if (SubCellFlags != SubCellFlags.Free)
     {
         CellBlocking = CellUtils.Combine(SubCellFlags, CellBlocking, transform);
     }
 }
Esempio n. 4
0
 internal static object GetIdentifier(RecordIdentifierContext context)
 {
     if (CellUtils.IsInterior(context.record))
     {
         return(CellUtils.GetName(context.record));
     }
     else
     {
         return(CellUtils.GetGridKey(context.record));
     }
 }
Esempio n. 5
0
        public CellWrapper GetCellFor(Vector3 position)
        {
            var cellLocation = Vector3Int.FloorToInt(position / Configs.CellSideSize);
            var cellName     = CellUtils.CreateCellName(cellLocation);

            if (cellsByName.ContainsKey(cellName))
            {
                return(cellsByName[cellName]);
            }

            return(null);
        }
Esempio n. 6
0
    public bool Update(ValueWithNeighbors <Chunk> chunkWithNeighbors, int2 cellPosition, Random random)
    {
        Cell?GetCellAtOffset(int2 offset)
        {
            return(CellUtils.GetCellAtPosition(chunkWithNeighbors, cellPosition + offset));
        }

        bool MoveTo(int2 offset)
        {
            return(CellUtils.SwitchCells(chunkWithNeighbors, cellPosition, offset));
        }

        var randomDirection = random.NextBool() ? -1 : 1;

        {
            var cellType = GetCellAtOffset(int2(0, -1))?.type;

            if (cellType == CellType.None || cellType == CellType.Water)
            {
                return(MoveTo(int2(0, -1)));
            }
        }

        {
            var cellType = GetCellAtOffset(int2(randomDirection, -1))?.type;

            if (cellType == CellType.None || cellType == CellType.Water)
            {
                return(MoveTo(int2(randomDirection, -1)));
            }
        }

        {
            var cellType = GetCellAtOffset(int2(-randomDirection, -1))?.type;

            if (cellType == CellType.None || cellType == CellType.Water)
            {
                return(MoveTo(int2(-randomDirection, -1)));
            }
        }

        return(false);
    }
    void OnGUI()
    {
        if (EditorApplication.isPlaying && Board.Instance.GetCells() != null)
        {
            if (GUILayout.Button("Update the Cells") || update)
            {
                CellUtils.UpdateCells();
                update = false;
            }

            DisplayCells();

            // Display amount of chessmen after cells.
            GUILayout.Label("WhiteChessmen: " + Board.Instance.WhiteChessmen.Count);
            GUILayout.Label("BlackChessmen: " + Board.Instance.BlackChessmen.Count);
        }
        else
        {
            update = true;
        }
    }
Esempio n. 8
0
    private bool WantMove()
    {
        if (Settings.monsterMoveOnGround)
        {
            var map     = Game.Map;
            var cell    = map.WorldToCell(transform.position);
            var surface = CellUtils.Combine(SubCellFlags.HasFloor, transform);

            if ((map.GetCellBlocking(cell + Vector2Int.down) & surface) != 0)
            {
                if (map.IsXNearNextCell(transform.position.x, desiredDirection))
                {
                    if ((map.GetCellBlocking(cell + new Vector2Int(desiredDirection, -1)) & surface) == 0
                        /*|| (map.GetCellBlocking(cell + new Vector2Int(desiredDirection, 0), placeable) & fullBlock) != 0*/)
                    {
                        return(false);
                    }
                }
            }
        }

        return(true);
    }
        IEnumerator <Marker> IEnumerable <Marker> .GetEnumerator()
        {
            foreach (var sheet in _sheets)
            {
                var rangeUsed = sheet.RangeUsed();
                if (rangeUsed == null)
                {
                    continue;
                }

                foreach (var row in rangeUsed.Rows())
                {
                    foreach (var cell in row.CellsUsed())
                    {
                        if (CellUtils.IsMarkedCell(cell, _markerOptions))
                        {
                            var markerId    = CellUtils.ExtractMarkerValue(cell, _markerOptions);
                            var isEndMarker = markerId.Substring(0, _markerOptions.Terminator.Length) == _markerOptions.Terminator;
                            var marker      = new Marker
                            {
                                Id = isEndMarker
                                    ? markerId.Substring(_markerOptions.Terminator.Length)
                                    : markerId,
                                Position = new MarkerPosition
                                {
                                    SheetIndex = SheetUtils.SheetIndex(sheet),
                                    RowIndex   = row.FirstCell().Address.RowNumber,
                                    CellIndex  = cell.Address.ColumnNumber
                                },
                                MarkerType = isEndMarker ? MarkerType.End : MarkerType.Start
                            };
                            yield return(marker);
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        public void Generate()
        {
            var grid       = GetComponent <Grid>();
            var sideLength = (int)Math.Sqrt(Configs.WorldCellCount);

            var worldBounds = new BoundsInt(Vector3Int.zero, new Vector3Int(sideLength, sideLength, 1));
            var cellBounds  = new BoundsInt(Vector3Int.zero, Configs.CellDimensions);

            foreach (var worldPosition in worldBounds.allPositionsWithin)
            {
                if (worldPosition.z > 0)
                {
                    break;
                }

                var writer = new Writer();
                foreach (Transform child in grid.transform)
                {
                    foreach (var position in cellBounds.allPositionsWithin)
                    {
                        if (position.z > 0)
                        {
                            break;
                        }

                        writer.WriteTile(GenerateRandomTile(), position);
                    }

                    writer.WriteTileMap();
                }

                writer.Save(CellUtils.CreateCellName(worldPosition));
            }

            Debug.Log("Done mofo!");
        }
Esempio n. 11
0
 public Bounds GetCellBounds(string cellName, float offset)
 {
     return(new Bounds(CellUtils.GetWorldCellCenter(cellName),
                       new Vector3(Configs.CellSideSize * offset, Configs.CellSideSize * offset,
                                   Configs.CellSideSize * offset)));
 }
Esempio n. 12
0
        private void lineRTtoLB79_Click(object sender, RoutedEventArgs e)
        {
            MaxCount += 50;
            //统一坐标系
            UInt32 x   = 0;
            UInt32 y   = 0;
            UInt32 w   = 25;
            UInt32 h   = 25;
            var    pen = CellUtils.RandomPen();

            //x,y为起始点
            Action <DrawingContext, uint> drawLine = (dc, count) =>
            {
                CellUtils.DrawPen = pen;
                CellUtils.Width   = w;
                CellUtils.Height  = h;
                CellUtils.Dc      = dc;

                //count是奇数,count项分两部分:
                //一部分竖排,一部分横排(往回)
                //中间项属于第一部分
                uint mid = (count + 1) / 2;
                for (uint i = 1; i <= mid; i++)//第一部分[1,mid]
                {
                    CellUtils.LocX = x;
                    CellUtils.LocY = y;
                    CellUtils.DrawCell();
                    y += h;
                }
                //第二部分[mid+1,count]
                y -= h;
                for (uint i = mid + 1; i <= count; i++)
                {
                    x -= w;
                    CellUtils.LocX = x;
                    CellUtils.LocY = y;
                    CellUtils.DrawCell();
                }
            };

            var target = page01;

            //target.Width = 79 * w;
            //target.Height = 79 * h;

            System.Threading.Thread thread = new System.Threading.Thread(() =>
            {
                Color[] colors = new Color[(MaxCount - 1) / 2 + 1];
                for (int taskCount = 1, k = 0; taskCount <= MaxCount; taskCount += 2, k++)
                {
                    colors[k] = CellUtils.RandomColor();
                    int temp  = taskCount;
                    Dispatcher.Invoke(() =>
                    {
                        target._DrawAction = () =>
                        {
                            for (uint i = 1, j = 0; i <= temp; i += 2, j++)
                            {
                                pen = CellUtils.ThePen(colors[j]);
                                x   = 10 + j * w;
                                y   = 10;
                                drawLine(page01._DrawHandle, i);
                            }
                        };
                        target.InvalidateVisual();
                    });
                    //System.Threading.Thread.Sleep(250);
                }
            });
            thread.Start();
        }
Esempio n. 13
0
        public void Load(ModFile modFile)
        {
            if (modFiles.ContainsKey(modFile.Name))
            {
                throw new ArgumentException($"Mod file already loaded: {modFile.Name}");
            }

            // Cache mod file.
            modFiles.Add(modFile.Name, modFile);

            // Create Record <-> TES3GameItem relationship.
            var regItems = new List <Tuple <Record, TES3GameItem> >();

            recordItemRegistry.Add(modFile.Name, regItems);


            DialogueTopic currentTopic = null;
            IDictionary <string, DialogueResponse> currentResponses = null;

            foreach (var record in modFile)
            {
                // Create Item
                TES3GameItem item;
                if (record.Name == "CELL")
                {
                    if (CellUtils.IsInterior(record))
                    {
                        item = new InteriorCell(record);
                    }
                    else
                    {
                        item = new ExteriorCell(record);
                    }
                }
                else
                {
                    if (!GameItemConstructors.ContainsKey(record.Name))
                    {
                        throw new ArgumentException($"Unrecognized record type: {record.Name}");
                    }

                    var constructor = GameItemConstructors[record.Name];
                    item = (TES3GameItem)constructor.Invoke(new Record[] { record });
                }


                // Cache individual Record <-> TES3GameItem relationship.
                regItems.Add(new Tuple <Record, TES3GameItem>(record, item));

                if (item.GetType() == typeof(DialogueTopic))
                {
                    if (currentTopic != null)
                    {
                        var dialogue = new Dialogue(modFile.Name, currentTopic, currentResponses, OnAddDialogueResponse, OnRemoveDialogueResponse);
                        dialogueVersionsById[currentTopic.Name].Add(new GameItemVersion <Dialogue>(modFile.Name, dialogue));
                        dialogueByModFile[modFile.Name].Add(dialogue);
                        dialogueByIdAndFile.Add(new GameItemKey(modFile.Name, currentTopic.Name), new Tuple <Record, Dialogue>(record, dialogue));
                    }

                    currentTopic     = (DialogueTopic)item;
                    currentResponses = new Dictionary <string, DialogueResponse>();
                    item.IdChanged  += OnIdChange;
                }
                else if (item.GetType() == typeof(DialogueResponse))
                {
                    if (currentTopic == null)
                    {
                        throw new InvalidOperationException();
                    }

                    var dialogueItem = (DialogueResponse)item;
                    currentResponses.Add(dialogueItem.Identifier, dialogueItem);
                }
                else
                {
                    if (currentTopic != null)
                    {
                        var dialogue = new Dialogue(modFile.Name, currentTopic, currentResponses, OnAddDialogueResponse, OnRemoveDialogueResponse);
                        dialogueVersionsById[currentTopic.Name].Add(new GameItemVersion <Dialogue>(modFile.Name, dialogue));
                        dialogueByModFile[modFile.Name].Add(dialogue);
                        dialogueByIdAndFile.Add(new GameItemKey(modFile.Name, currentTopic.Name), new Tuple <Record, Dialogue>(record, dialogue));
                        currentTopic     = null;
                        currentResponses = null;
                    }

                    // Handle common caching.
                    HandleCommonCache(modFile.Name, item);
                }
            }
        }
Esempio n. 14
0
    public bool Update(ValueWithNeighbors <Chunk> chunkWithNeighbors, int2 cellPosition, Random random)
    {
        Cell?GetCellAtOffset(int2 offset)
        {
            return(CellUtils.GetCellAtPosition(chunkWithNeighbors, cellPosition + offset));
        }

        bool MoveTo(int2 offset)
        {
            return(CellUtils.SwitchCells(chunkWithNeighbors, cellPosition, offset));
        }

        var randomDirection = random.NextBool() ? -1 : 1;

        if (GetCellAtOffset(int2(0, -1))?.type == CellType.None)
        {
            return(MoveTo(int2(0, -1)));
        }
        else if (GetCellAtOffset(int2(randomDirection, -1))?.type == CellType.None)
        {
            if (GetCellAtOffset(int2(randomDirection * 2, -2))?.type == CellType.None)
            {
                return(MoveTo(int2(randomDirection * 2, -2)));
            }
            else
            {
                return(MoveTo(int2(randomDirection, -1)));
            }
        }
        else if (GetCellAtOffset(int2(-randomDirection, -1))?.type == CellType.None)
        {
            if (GetCellAtOffset(int2(-randomDirection * 2, -2))?.type == CellType.None)
            {
                return(MoveTo(int2(-randomDirection * 2, -2)));
            }
            else
            {
                return(MoveTo(int2(-randomDirection, -1)));
            }
        }
        else if (GetCellAtOffset(int2(randomDirection, 0))?.type == CellType.None)
        {
            if (GetCellAtOffset(int2(randomDirection * 2, 0))?.type == CellType.None)
            {
                return(MoveTo(int2(randomDirection * 2, 0)));
            }
            else
            {
                return(MoveTo(int2(randomDirection, 0)));
            }
        }
        else if (GetCellAtOffset(int2(-randomDirection, 0))?.type == CellType.None)
        {
            if (GetCellAtOffset(int2(-randomDirection * 2, 0))?.type == CellType.None)
            {
                return(MoveTo(int2(-randomDirection * 2, 0)));
            }
            else
            {
                return(MoveTo(int2(-randomDirection, 0)));
            }
        }

        // return
        //     TryMoveTo(math.int2(0, -1)) ||
        //     TryMoveTo(math.int2(randomDirection * 2, -1)) ||
        //     TryMoveTo(math.int2(-randomDirection * 2, -1)) ||
        //     TryMoveTo(math.int2(randomDirection * 2, 0)) ||
        //     TryMoveTo(math.int2(-randomDirection * 2, 0)) ||
        //     TryMoveTo(math.int2(randomDirection, -1)) ||
        //     TryMoveTo(math.int2(-randomDirection, -1)) ||
        //     TryMoveTo(math.int2(randomDirection, 0)) ||
        //     TryMoveTo(math.int2(-randomDirection, 0));

        return(false);
    }
Esempio n. 15
0
    private void TryPlaceArm(int index)
    {
        var  map         = Game.Map;
        bool otherPlaced = ArmCatched;
        var  center      = ArmSphere.transform.position.XY();
        var  center3d    = ArmSphere.transform.position + new Vector3(0, 0, Settings.legZ[index]);

        var radius2 = new Vector2(ArmSphere.radius, ArmSphere.radius);

        map.Get(placeables, center - radius2, 2 * radius2, Ksid.Catch);

        foreach (var p in placeables)
        {
            var pos = p.GetClosestPoint(center3d);
            if (!otherPlaced || Vector2.Dot(desiredVelocity, pos - center3d) >= 0)
            {
                if (Physics.Raycast(center3d, pos - center3d, out var hitInfo, ArmSphere.radius, Settings.armCatchLayerMask))
                {
                    if ((hitInfo.point - pos).sqrMagnitude < 0.001 && ConnectLabel(index, ref hitInfo, p))
                    {
                        PlaceLeg3d(index, ref hitInfo, Catch);
                        placeables.Clear();
                        return;
                    }
                }
            }
        }

        placeables.Clear();

        var c  = map.WorldToCell(ArmSphere.transform.position.XY());
        var c1 = c - Settings.ArmCellRadius;
        var c2 = c + Settings.ArmCellRadius + Vector2Int.one;

        var blocking = CellUtils.Combine(SubCellFlags.Full, transform);

        for (int y = c1.y; y < c2.y; y++)
        {
            for (int x = c1.x; x < c.x; x++)
            {
                if ((map.GetCellBlocking(new Vector2Int(x, y)) & blocking) == blocking &&
                    (map.GetCellBlocking(new Vector2Int(x + 1, y)) & blocking) != blocking &&
                    (map.GetCellBlocking(new Vector2Int(x + 1, y + 1)) & blocking) != blocking &&
                    (map.GetCellBlocking(new Vector2Int(x, y + 1)) & blocking) != blocking)
                {
                    armCandidates.Add(map.CellToWorld(new Vector2Int(x + 1, y + 1)));
                }
            }
            for (int x = c.x + 1; x < c2.x; x++)
            {
                if ((map.GetCellBlocking(new Vector2Int(x, y)) & blocking) == blocking &&
                    (map.GetCellBlocking(new Vector2Int(x - 1, y)) & blocking) != blocking &&
                    (map.GetCellBlocking(new Vector2Int(x - 1, y + 1)) & blocking) != blocking &&
                    (map.GetCellBlocking(new Vector2Int(x, y + 1)) & blocking) != blocking)
                {
                    armCandidates.Add(map.CellToWorld(new Vector2Int(x, y + 1)));
                }
            }
        }

        foreach (var pos in armCandidates)
        {
            if (!otherPlaced || Vector2.Dot(desiredVelocity, pos - center) >= 0)
            {
                if (RayCastArm(index, new Vector3(pos.x, pos.y, ArmSphere.transform.position.z), ArmSphere.radius))
                {
                    break;
                }
            }
        }

        armCandidates.Clear();
    }