public void CheckCellInitialzer() { CellCoordinate cell = new CellCoordinate(); Assert.Equal(0, cell.row); Assert.Equal(0, cell.column); }
public void CheckCellInitialzerWithValues() { CellCoordinate cell = new CellCoordinate(3, 4); Assert.Equal(3, cell.row); Assert.Equal(4, cell.column); }
/// <summary> /// Initializes a new instance of the <see cref="ActionRecord"/> class /// </summary> /// <param name="unit">Unit that acted</param> /// <param name="source">Source cell of the action</param> /// <param name="action">Action type</param> /// <param name="targetUnit">Target unit of the action</param> /// <param name="targetCell">Target cell of the action</param> private ActionRecord(Unit unit, CellCoordinate source, ActionType action, Unit targetUnit, CellCoordinate targetCell) { this.Unit = unit; this.Source = source; this.Action = action; this.TargetCell = targetCell; this.TargetUnit = targetUnit; }
public void CheckCellMoveInGridWrap() { CellCoordinate cell = new CellCoordinate(3, 8); Assert.True(cell.MoveToNextCellInGrid()); Assert.Equal(4, cell.row); Assert.Equal(0, cell.column); }
/// <summary> /// Adds a cell to the specified row /// </summary> /// <param name="rowIndex"></param> /// <param name="cell"></param> public void AddCell(int rowIndex, Interop.IHTMLTableCell cell) { ArrayList currentRow; int row; int colSpan; int colIndex; int rowSpanCount; ArrayList cellList; currentRow = (ArrayList)this._rows[rowIndex]; row = 0; while (row < currentRow.Count && currentRow[row] != null) { row++; } colSpan = 0; while (colSpan < cell.colSpan) { colIndex = row + colSpan; this.EnsureIndex(currentRow, colIndex); currentRow[colIndex] = cell; if (!(this._cells.Contains(cell))) { this._cells[cell] = new Pair(rowIndex, colIndex); } rowSpanCount = 1; while (rowSpanCount < cell.rowSpan) { if (rowIndex + 1 >= this._rows.Count) { this._rows.Add(new ArrayList()); } cellList = (ArrayList)this._rows[rowIndex + rowSpanCount]; this.EnsureIndex(cellList, colIndex); cellList[colIndex] = cell; if (!(this._cells.Contains(cell))) { this._cells[cell] = new Pair(rowIndex + rowSpanCount, colIndex); } rowSpanCount++; } colSpan++; } CellCoordinate cc = new CellCoordinate(); cc.row = (int)((Pair)this._cells[cell]).First; cc.col = (int)((Pair)this._cells[cell]).Second; cc.x = ((Interop.IHTMLElement)cell).GetOffsetLeft(); cc.y = ((Interop.IHTMLElement)cell).GetOffsetTop(); cc.w = ((Interop.IHTMLElement)cell).GetOffsetWidth(); cc.h = ((Interop.IHTMLElement)cell).GetOffsetHeight(); cc.r = cc.x + cc.w; cc.b = cc.y + cc.h; this.CellCoordinates.Add(cc); }
private GameObject GenerateCell(bool open, CellCoordinate coord) { var prefab = open == true ? OpenPrefab : FilledPrefab; var gameObject = Instantiate(prefab, transform); gameObject.transform.localPosition = new Vector3(coord.X * 2, coord.Floor * 2, coord.Y * 2); //gameObject.GetComponent<MeshRenderer>().material.color = open ? Color.red : Color.blue; return(gameObject); }
public static void AppendValue(this IWorkSheet sheet, CellCoordinate coordinate, object value) { var cellVal = sheet[coordinate.RowIndex][coordinate.CellIndex]; var str = cellVal == null ? string.Empty : cellVal.ToString(); if (string.IsNullOrEmpty(str)) { str = " "; } sheet[coordinate.RowIndex][coordinate.CellIndex] = str + value; }
public void OnCellChanged(CellCoordinate coord, Cell old, Cell next) { //Debug.Log("Need to change " + coord.X + " , " + coord.Y + " to " + next.Status); //throw new NotImplementedException(); // destroy old object var oldGameObject = _objects[coord]; Destroy(oldGameObject); // add the new one var nextGameObject = GenerateCell(next.Status == CellStatus.OPEN, coord); _objects[coord] = nextGameObject; }
public static void SetValue(this IWorkSheet sheet, CellCoordinate coordinate, object value) { bool canAssign; if (value is string str) { canAssign = !string.IsNullOrEmpty(str); } else { canAssign = value != null; } if (canAssign) { sheet[coordinate.RowIndex][coordinate.CellIndex] = value; } }
/// <summary> /// Writes data to the cells of a worksheet. /// </summary> /// <param name="worksheet">The worksheet to write into.</param> /// <param name="cellCoordinate">The cell coordinates to start writting to.</param> private void WriteCellData(ExcelWorksheet worksheet, CellCoordinate cellCoordinate) { foreach (var d in Data.Items) { foreach (var c in Columns) { var value = d.GetValue(c.PropertyName); if (c.Format == null && value is DateTime) { worksheet.Cells[cellCoordinate.Row, cellCoordinate.Column].Style.Numberformat.Format = "dd.mm.yyyy"; } if (c.Format != null) { worksheet.Cells[cellCoordinate.Row, cellCoordinate.Column].Style.Numberformat.Format = c.Format; } if (c.ColSpan.HasValue) { var cells = worksheet.Cells[cellCoordinate.Row, cellCoordinate.Column, cellCoordinate.Row, cellCoordinate.Column + c.ColSpan.Value]; cells.Merge = true; cellCoordinate.Column += c.ColSpan.Value; c.Render(value, cells); } else { c.Render(value, worksheet.Cells[cellCoordinate.Row, cellCoordinate.Column]); } worksheet.Column(cellCoordinate.Column).AutoFit(); cellCoordinate.Column++; } cellCoordinate.Column = 1; cellCoordinate.Row++; } }
public async Task <ValuesRange> GetAsync(string sheetId, SpreadsheetGetRequest getRequest, CancellationToken cancellationToken) { (CellCoordinate cellCoordinate, _) = CellCoordinate.ParseRange(getRequest.CellsRange); SpreadsheetsResource.ValuesResource.GetRequest request = _clientService.Spreadsheets.Values.Get(sheetId, $"{getRequest.Sheet}!{getRequest.CellsRange}"); request.ValueRenderOption = SpreadsheetsResource.ValuesResource.GetRequest.ValueRenderOptionEnum.UNFORMATTEDVALUE; ValueRange response = await request.ExecuteAsync(cancellationToken); IList <IList <object> > values = response.Values; IEnumerable <Cell> cells = values.Select((x, row) => x.Select((y, coll) => new Cell { Coordinate = new CellCoordinate { Row = row + cellCoordinate.Row, Column = Column.FromNumber(coll) + cellCoordinate.Column, }, Value = y as string })).SelectMany(x => x); var result = new ValuesRange(cells); return(result); }
public Cell(CellCoordinate coordinate, string value) { Coordinate = coordinate; Value = value; }
public void CheckCellMoveInGridLastCell() { CellCoordinate cell = new CellCoordinate(8, 8); Assert.False(cell.MoveToNextCellInGrid()); }
/// <summary> /// Creates a record for movement /// </summary> /// <param name="unit">Unit that moved</param> /// <param name="source">Where it moved from</param> /// <param name="destination">Where it moved to</param> /// <returns>Action record for movement</returns> public static ActionRecord MoveAction(Unit unit, CellCoordinate source, CellCoordinate destination) { return(new ActionRecord(unit, source, ActionType.Move, null, destination)); }
public Choice(CellCoordinate coordinate, double mineProbability) { Coordinate = coordinate; MineProbability = mineProbability; }
/// <summary> /// Creates a record for attack /// </summary> /// <param name="unit">Unit that attacked</param> /// <param name="source">Where it attacked from</param> /// <param name="targetUnit">Unit it attacked</param> /// <param name="targetCell">Cell it attacked</param> /// <returns>Action record for attack</returns> public static ActionRecord AttackAction(Unit unit, CellCoordinate source, Unit targetUnit, CellCoordinate targetCell) { return(new ActionRecord(unit, source, ActionType.Attack, targetUnit, targetCell)); }
/// <summary> /// Creates the columns in a package sheet using the current sheet's configuration. /// </summary> /// <param name="worksheet">The worksheet to add columns on.</param> /// <returns>The cell coordinates.</returns> private CellCoordinate CreateColumns(ExcelWorksheet worksheet) { if (Columns.Count == 0 && Data.Count > 0) { foreach (var p in Data[0].Properties) { Columns.Add(new ExcelColumn { PropertyName = p }); } } var cell = new CellCoordinate { Row = 1, Column = 1 }; if (HeaderColumns.Any()) { foreach (var headerColumn in HeaderColumns) { var colSpan = headerColumn.HeaderColSpan ?? headerColumn.ColSpan; if (colSpan.HasValue) { var cells = worksheet.Cells[cell.Row, cell.Column, cell.Row, cell.Column + colSpan.Value]; cells.Merge = true; cell.Column += colSpan.Value; HeaderRenderer(headerColumn.DisplayName, cells); headerColumn.Render(headerColumn.DisplayName, cells); } else { HeaderRenderer(headerColumn.DisplayName, worksheet.Cells[cell.Row, cell.Column]); headerColumn.Renderer(headerColumn.DisplayName, worksheet.Cells[cell.Row, cell.Column]); } cell.Column++; } cell.Column = 1; cell.Row++; } var hasHeader = Columns.Any(el => !String.IsNullOrEmpty(el.DisplayName)); if (hasHeader) { foreach (var c in Columns) { var colSpan = c.HeaderColSpan ?? c.ColSpan; if (colSpan.HasValue) { var cells = worksheet.Cells[cell.Row, cell.Column, cell.Row, cell.Column + colSpan.Value]; cells.Merge = true; cell.Column += colSpan.Value; HeaderRenderer(c.DisplayName, cells); c.Renderer(c.DisplayName, cells); } else { HeaderRenderer(c.DisplayName, worksheet.Cells[cell.Row, cell.Column]); c.Renderer(c.DisplayName, worksheet.Cells[cell.Row, cell.Column]); } cell.Column++; } cell.Column = 1; cell.Row++; } foreach (var rowHeight in RowHeights) { worksheet.Row(rowHeight.Row).Height = ExcelHelper.Pixel2RowHeight(rowHeight.Height); } foreach (var imageContent in Images) { DrawImage(worksheet, imageContent); } return(cell); }