public void CreateCell(CellType type, Vector3 position) { var cellPrefab = cellPrefabs.Find(x => x.type == type); if (cellPrefab == null) return; Instantiate(cellPrefab.prefab, position, Quaternion.identity); }
public void init(CellType _cellType,BombType _cellBombType,CellColor _cellColor) { string spritePath = _cellType.ToString() +_cellBombType.ToString()+ _cellColor.ToString(); Sprite newSprite = Resources.Load("Sprite/Cells/"+spritePath,typeof(Sprite)) as Sprite; GetComponent<SpriteRenderer>().sprite = newSprite; }
public MemberFieldData(string def) { string[] strSplit = def.Split(':'); if (strSplit.Length > 1) { string typedef = strSplit[1]; if (string.Compare(typedef, "integer") == 0) type = CellType.Int; else if (string.Compare(typedef, "string") == 0) type = CellType.String; else if (string.Compare(typedef, "float") == 0) type = CellType.Float; else if (string.Compare(typedef, "double") == 0) type = CellType.Double; else if (string.Compare(typedef, "enum") == 0) type = CellType.Enum; else if (string.Compare(typedef, "bool") == 0) type = CellType.Bool; else { type = CellType.Undefined; Debug.LogError("Wrong cell type is defined: " + typedef); } } else type = CellType.Undefined; name = strSplit[0]; }
public virtual FrameworkElement CreateCell(DataGrid grid, CellType cellType, CellRange rng) { // cell border var bdr = CreateCellBorder(grid, cellType, rng); // bottom right cells have no content if (!rng.IsValid) { return bdr; } // bind/customize cell by type switch (cellType) { case CellType.Cell: CreateCellContent(grid, bdr, rng); break; case CellType.ColumnHeader: CreateColumnHeaderContent(grid, bdr, rng); break; } // done return bdr; }
public sCell(GameObject cell) { if (cell == null) { type = CellType.Null; return; } pos = new sVector3(cell.transform.position); value = cell.GetComponent<CellValue>().Value; switch (cell.tag) { case "Dragon": type = CellType.Dragon; break; case "Hero": type = CellType.Hero; break; case "Monster": type = CellType.Monster; break; case "Sword": type = CellType.Sword; break; } }
/// <summary> /// Creates a GameField object from the given string /// </summary> /// <param name="fieldData">The field data.</param> /// <returns></returns> public static GameField FromString(string fieldData) { var rows = fieldData.Split(new[] {";"}, StringSplitOptions.RemoveEmptyEntries); var rowList = new List<CellType[]>(); foreach (var row in rows) { var rowData = row .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(ToCellType) .ToArray(); rowList.Add(rowData); } int width = rowList.First().Length; int heigth = rows.Length; // Construct and Initialize Grid var gridData = new CellType[heigth][]; for (int y = 0; y < heigth; y++) { gridData[y] = new CellType[width]; for (int x = 0; x < width; x++) { gridData[y][x] = CellType.Empty; } } return new GameField(new Size(width, heigth), gridData); }
public void SetCell(int x, int y, CellType c) { if (x < 0 || x >= cells.GetLength(0) || y < 0 || y >= cells.GetLength(1)) return; switch (c) { case CellType.Passable: case CellType.Impassable: if ((StartX == x && StartY == y) || (FinishX == x && FinishY == y)) return; break; case CellType.Start: if (cells[x, y] == -2 || cells[x, y] == -4) // don't change if its impassable or "finish" return; cells[StartX, StartY] = -1; StartX = x; StartY = y; break; case CellType.Finish: if (cells[x, y] == -2 || cells[x, y] == -3) // don't change if its impassable or "start" return; cells[FinishX, FinishY] = -1; FinishX = x; FinishY = y; break; } cells[x, y] = -(int)c - 1; }
public IEnumerable<CellCost> Calculate(CellType[,] grid, int horizontalPosition, int verticalPosition) { var output = new List<CellCost>(); if (horizontalPosition > 0) { var left = horizontalPosition - 1; var leftCell = grid[verticalPosition, left]; output.Add( new CellCost(verticalPosition, left, GetCost(leftCell))); } if (horizontalPosition < grid.GetLength(1) - 1) { var right = horizontalPosition + 1; var leftCell = grid[verticalPosition, right]; output.Add( new CellCost(verticalPosition, right, GetCost(leftCell))); } if (verticalPosition > 0) { var down = verticalPosition - 1; var leftCell = grid[down, horizontalPosition]; output.Add( new CellCost(down, horizontalPosition, GetCost(leftCell))); } if (verticalPosition < grid.GetLength(0) - 1) { var up = verticalPosition + 1; var leftCell = grid[up, horizontalPosition]; output.Add( new CellCost(up, horizontalPosition, GetCost(leftCell))); } return output; }
//internal CMap(MapRepresent_ProD representMap) //{ // colCount = representMap.ColCount; // rowCount = representMap.RowCount; // mx = new CCell[colCount, rowCount]; // for (int i = 0; i < colCount; i++) // for (int j = 0; j < rowCount; j++) // { // var cell = new CCell(i, j, representMap[i, j]); // mx[i, j] = cell; // if (cell.IsWall) wall.Add(cell); // else // switch (cell.Type) // { // case CellType.Entrance: // entranceCell = cell; // break; // case CellType.Exit: // exitCell = cell; // break; // case CellType.Door: // doorCells.Add(cell); // break; // } // } //} internal CMap(CellType[,] cellMatrix) { colCount = cellMatrix.GetLength(0); rowCount = cellMatrix.GetLength(1); mx = new CCell[colCount, rowCount]; for (int i = 0; i < colCount; i++) for (int j = 0; j < rowCount; j++) { var cell = new CCell(i, j, cellMatrix[i, j]); mx[i, j] = cell; if (cell.IsWall) wall.Add(cell); else switch (cell.Type) { case CellType.Entrance: entranceCell = cell; break; case CellType.Exit: exitCell = cell; break; case CellType.Door: doorCells.Add(cell); break; } } }
public Map(string filename) { var lines = File.ReadAllLines(filename); var heroPos = lines[0].Split().Select(int.Parse).ToArray(); Hero = new Location(heroPos[0], heroPos[1]); cells = new CellType[lines.Length, lines[0].Length]; foreach (var y in lines.Indices()) foreach (var x in lines[0]) { CellType cellType; switch (lines[y][x]) { case '.': cellType = CellType.Empty; break; case '#': cellType = CellType.Wall; break; case '@': cellType = CellType.Swamp; break; default: throw new NotSupportedException(lines[y][x].ToString()); } cells[y, x] = cellType; } }
public PawnType(Tag tag) { if (tag.name == "_") { type_ = CellType.None; tag_ = null; } else if (tag.name == "Float") { type_ = CellType.Float; tag_ = null; } else if (tag.name == "bool") { type_ = CellType.Bool; tag_ = null; } else if (SourcePawn.OpcodeHelpers.IsFunctionTag(tag)) { type_ = CellType.Function; tag_ = null; } else { type_ = CellType.Tag; tag_ = tag; } }
public void SetValue(ValueEval value) { Type cls = value.GetType(); if (cls == typeof(NumberEval)) { _cellType = CellType.NUMERIC; _numberValue = ((NumberEval)value).NumberValue; return; } if (cls == typeof(StringEval)) { _cellType = CellType.STRING; _stringValue = ((StringEval)value).StringValue; return; } if (cls == typeof(BoolEval)) { _cellType = CellType.BOOLEAN; _boolValue = ((BoolEval)value).BooleanValue; return; } if (cls == typeof(ErrorEval)) { _cellType = CellType.ERROR; _errorValue = ((ErrorEval)value).ErrorCode; return; } if (cls == typeof(BlankEval)) { _cellType = CellType.BLANK; return; } throw new ArgumentException("Unexpected value class (" + cls.Name + ")"); }
public static CellType[] GenerateGround(string seed, int islandSize, int seedBase, float noiseSize, float falloffExponent, float threshold) { var cells = new CellType[islandSize * islandSize]; var seedHash = seedBase + seed.GetHashCode(); // These weird nubers are 'random' prime numbers var seedX = seedHash % 65521; var seedY = (seedHash * 45949) % 31147; var spacing = noiseSize / islandSize; var offset = (spacing - noiseSize) * 0.5f; var center = islandSize * 0.5f; var radius = islandSize * Mathf.Sqrt(0.5f); for (var row = 0; row < islandSize; ++row) { for (var column = 0; column < islandSize; ++column) { if (row == 0 || column == 0 || row == islandSize - 1 || column == islandSize - 1) { cells[row * islandSize + column] = CellType.Water; } else { var x = seedX + offset + row * spacing; var y = seedY + offset + column * spacing; var distanceToCenter = Vector2.Distance( new Vector2(row, column), new Vector2(center, center)) / radius; var sample = Mathf.PerlinNoise(x, y) * (1.0f - Mathf.Pow(distanceToCenter, falloffExponent)); cells[row * islandSize + column] = sample > threshold ? CellType.Ground : CellType.Water; } } } return cells; }
public Cell(int newID, int newType, Vector3 loc, Vector3 size) { id = newID; type = (CellType)newType; location = loc; bounds = new Bounds(loc,size); }
/*/// <summary> /// Surface molecular pattern of the cell. An array of bits each of which represents a nucleotide. /// </summary> public MolecularPattern Pattern { get { return pattern; } }*/ #endregion #region Public Methods /*public Cell(CellType type, ITissue parent, MolecularPattern initialPattern) { Type = type; Parent = parent; pattern = initialPattern; maturationLevel = CellMaturationLevel.Immature; Start(); }*/ public Cell(CellType type, ITissue parent) { Type = type; Parent = parent; maturationLevel = CellMaturationLevel.Immature; Start(); }
/// <summary> /// Cell factory implementation. /// </summary> /// <param name="cellType">Cell type.</param> /// <returns>Required cell.</returns> public static ICell CreateCell(CellType cellType) { //// Uses "lazy initialization". ICell cell; switch (cellType) { case CellType.EmptyCell: cell = new EmptyCell(); cell.CellView = CellView.Empty; break; case CellType.Bomb: int bombSize = RandomGenerator.GetRandomNumber(MIN_BOMB_SIZE, MAX_BOMB_SIZE); cell = new BombCell(bombSize); cell.CellView = (CellView)bombSize + ASCII_VIEW_OFFSET; break; case CellType.BlownCell: cell = new BlownCell(); cell.CellView = CellView.Blown; break; default: throw new ArgumentException("Invalid cell type give to the cell factory"); } return cell; }
public World(int moveIndex, int width, int height, Player[] players, Trooper[] troopers, Bonus[] bonuses, CellType[][] cells, bool[] cellVisibilities) { this.moveIndex = moveIndex; this.width = width; this.height = height; this.players = new Player[players.Length]; Array.Copy(players, this.players, players.Length); this.troopers = new Trooper[troopers.Length]; Array.Copy(troopers, this.troopers, troopers.Length); this.bonuses = new Bonus[bonuses.Length]; Array.Copy(bonuses, this.bonuses, bonuses.Length); this.cells = new CellType[width][]; for (int x = 0; x < width; ++x) { this.cells[x] = new CellType[cells[x].Length]; Array.Copy(cells[x], this.cells[x], cells[x].Length); } this.cellVisibilities = cellVisibilities; }
public Sprite GetSpriteForCellType(CellType type) { switch (type) { case CellType.PATH_FLOOR: return pathFloor; case CellType.ROOM_FLOOR: return roomFloor; case CellType.ROOM_N_WALL: return roomNWall; case CellType.ROOM_NE_WALL: return roomNEWall; case CellType.ROOM_NW_WALL: return roomNWWall; case CellType.ROOM_S_WALL: return roomSWall; case CellType.ROOM_SE_WALL: return roomSEWall; case CellType.ROOM_SW_WALL: return roomSWWall; case CellType.ROOM_W_WALL: return roomWWall; case CellType.OPENDOOR: return openDoor; case CellType.CLOSEDDOOR: return closedDoor; case CellType.ROOM_E_WALL: return roomEWall; default: Debug.LogError (SCRIPT_NAME + ": texture not found"); return null; } }
public CellRange GetMergedRange(C1FlexGrid grid, CellType cellType, CellRange rg) { // we are only interested in data cells // (not merging row or column headers) if (cellType == CellType.Cell) { // expand left/right for (int i = rg.Column; i < grid.Columns.Count - 1; i++) { if (GetDataDisplay(grid, rg.Row, i) != GetDataDisplay(grid, rg.Row, i + 1)) break; rg.Column2 = i + 1; } for (int i = rg.Column; i > 0; i--) { if (GetDataDisplay(grid, rg.Row, i) != GetDataDisplay(grid, rg.Row, i - 1)) break; rg.Column = i - 1; } // expand up/down for (int i = rg.Row; i < grid.Rows.Count - 1; i++) { if (GetDataDisplay(grid, i, rg.Column) != GetDataDisplay(grid, i + 1, rg.Column)) break; rg.Row2 = i + 1; } for (int i = rg.Row; i > 0; i--) { if (GetDataDisplay(grid, i, rg.Column) != GetDataDisplay(grid, i - 1, rg.Column)) break; rg.Row = i - 1; } } // done return rg; }
/// <summary> /// Gets a <see cref="T:C1.WPF.FlexGrid.CellRange" /> that specifies the merged extent of a cell /// in a <see cref="T:C1.WPF.FlexGrid.GridPanel" />. /// </summary> /// <param name="grid"> /// <see cref="T:C1.WPF.FlexGrid.C1FlexGrid" /> that contains the merged cell. /// </param> /// <param name="cellType"> /// <see cref="T:C1.WPF.FlexGrid.CellType" /> that specifies the type of the merged cell. /// </param> /// <param name="rng">A <see cref="T:C1.WPF.FlexGrid.CellRange" /> that specifies the coordinates of the cell to be merged.</param> /// <returns> /// A <see cref="T:C1.WPF.FlexGrid.CellRange" /> that expands the given <paramref name="rng" /> over a merged /// range. /// </returns> /// <remarks> /// This method expands ranges by comparing the cell contents with the content of neighboring /// cells and merging cells that have the same content. /// </remarks> public virtual CellRange GetMergedRange(C1FlexGrid grid, CellType cellType, CellRange rng) { switch (cellType) { case CellType.Cell: { if (grid.ActiveEditor != null && grid.EditorRange.Contains(rng)) { return grid.EditorRange; } if (grid.GetChildItemsPropertyInfo() != null) { return rng; } return GetMergedRange(grid, grid.Cells, rng); } case CellType.ColumnHeader: { return GetMergedRange(grid, grid.ColumnHeaders, rng); } case CellType.RowHeader: { return GetMergedRange(grid, grid.RowHeaders, rng); } case CellType.TopLeft: { return GetMergedRange(grid, grid.TopLeftCells, rng); } } return rng; }
public TerrainChunk(CellType fill) { cells = new CellType[ChunkWidth * ChunkHeight]; for(int i = 0; i < cells.Length; i++) cells[i] = fill; }
public DBCFileComparer(string oldFile, string newFile, int testAmount, CellType[] knownColumnStructure) { oldReader = new DBCReader(oldFile); newReader = new DBCReader(newFile); this.knownColumnStructure = knownColumnStructure; this.testAmount = testAmount; }
public Cell(int y, int x, CellType cellType) { Gold = 0; Y = y; X = x; CellType = cellType; }
public PFCell(CellType type, int col, int row) { this.type = type; this.row = row; this.col = col; this.center = new Vector2((col + 0.5f) * GameConst.UNITS_PER_CELL, (row + 0.5f) * GameConst.UNITS_PER_CELL); }
/// <summary> /// Initializes a new instance of the <see cref="Cell"/> class. /// </summary> /// <param name="Where">The <see cref="Location"/>.</param> /// <param name="Type">The <see cref="CellType"/>.</param> /// <param name="Value">The number that is there.</param> /// <param name="Pencils">A <see cref="bool"/> array of values representing the pencil marks; true for present, false for clear. /// Note that the array contains values for 0-9 even though a pencil mark for 0 (clear) doesn't make sense. This just makes the handling easier.</param> public Cell(Location Where, CellType Type, int Value, bool[] Pencils) { this.Where = Where; this.Value = Value; this.Type = Type; _pencilMarks = new bool[10]; Pencils.CopyTo(_pencilMarks,0); }
public void ChangeSprite() { if (_cellType != Cell.Type) { //SpriteRenderer.sprite = SnakeSpritesHelper.Instance.GetSprite(Cell.Type); _cellType = Cell.Type; } }
// override horizontal alignment to make ticker cell stretch and fill the column width public override void ApplyCellStyles(C1FlexGrid grid, CellType cellType, CellRange range, Border bdr) { var ticker = bdr.Child as StockTicker; if (ticker != null) { ticker.HorizontalAlignment = HorizontalAlignment.Stretch; } }
protected bool PerimeterCanReplace(CellType type) { if (type == CellType.Blocked || type == CellType.StairsPerimeter || type == CellType.Perimeter || type == CellType.Entrance) { return false; } return true; }
/// <summary> /// Create a new Cell of the given <see cref="CellType"/>, with the given value and format. For some common formats, see <see cref="BuiltInCellFormat"/>. /// You can also implicitly create a cell from a string or number. /// </summary> /// <param name="type"> </param> /// <param name="value"> </param> /// <param name="format"> </param> public Cell(CellType type, object value, string format) { _xlsxCellStyle = new XlsxCellStyle(); _xlsxCellStyle.Format = format; Value = value; CellType = type; }
public void SetData(Cell cell) { Type = cell.Type; CurrentDirection = cell.CurrentDirection; PreviousDirection = cell.PreviousDirection; Coorditanes[0] = cell.Coorditanes[0]; Coorditanes[1] = cell.Coorditanes[1]; }
internal Size MeasureCell(MapGraphics g, int fontSizeReducedBy, Font legendAutoFont, Size singleWCharacterSize) { if (cachedCellSizeFontReducedBy == fontSizeReducedBy && !cachedCellSize.IsEmpty) { return(cachedCellSize); } Size result = Size.Empty; bool disposeFont = false; Font cellFont = GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont); if (CellType == LegendCellType.Symbol) { result.Width = (int)((float)(Math.Abs(SymbolSize.Width) * singleWCharacterSize.Width) / 100f); result.Height = (int)((float)(Math.Abs(SymbolSize.Height) * singleWCharacterSize.Height) / 100f); result.Width = (int)Math.Round((double)result.Width * 1.1); result.Height = (int)Math.Round((double)result.Height * 1.25); } else if (CellType == LegendCellType.Image) { if (ImageSize.IsEmpty && !string.IsNullOrEmpty(Image)) { Image image = GetLegend().Common.ImageLoader.LoadImage(Image); result.Width = image.Width; result.Height = image.Height; } else { result.Width = (int)((float)(Math.Abs(ImageSize.Width) * singleWCharacterSize.Width) / 100f); result.Height = (int)((float)(Math.Abs(ImageSize.Height) * singleWCharacterSize.Height) / 100f); } } else { if (CellType != 0) { throw new InvalidOperationException("Unknown Legend Cell Type: " + CellType.ToString(CultureInfo.CurrentCulture)); } string cellText = GetCellText(); result = g.MeasureStringAbs(cellText + "I", cellFont); } result.Width += (int)((float)((Margins.Left + Margins.Right) * singleWCharacterSize.Width) / 100f); result.Height += (int)((float)((Margins.Top + Margins.Bottom) * singleWCharacterSize.Height) / 100f); if (GetLegend() != null && legendItem != null && legendItem.Separator != 0) { result.Height += GetLegend().GetSeparatorSize(g, legendItem.Separator).Height; } if (disposeFont) { cellFont.Dispose(); cellFont = null; } cachedCellSize = result; cachedCellSizeFontReducedBy = fontSizeReducedBy; return(result); }
/// <summary> /// Copy cell value, formula and style, from srcCell per cell copy policy /// If srcCell is null, clears the cell value and cell style per cell copy policy /// /// This does not shift references in formulas. Use {@link XSSFRowShifter} to shift references in formulas. /// </summary> /// <param name="srcCell">The cell to take value, formula and style from</param> /// <param name="policy">The policy for copying the information, see {@link CellCopyPolicy}</param> /// <exception cref="ArgumentException">if copy cell style and srcCell is from a different workbook</exception> public void CopyCellFrom(ICell srcCell, CellCopyPolicy policy) { // Copy cell value (cell type is updated implicitly) if (policy.IsCopyCellValue) { if (srcCell != null) { CellType copyCellType = srcCell.CellType; if (copyCellType == CellType.Formula && !policy.IsCopyCellFormula) { // Copy formula result as value // FIXME: Cached value may be stale copyCellType = srcCell.CachedFormulaResultType; } switch (copyCellType) { case CellType.Boolean: SetCellValue(srcCell.BooleanCellValue); break; case CellType.Error: SetCellErrorValue(srcCell.ErrorCellValue); break; case CellType.Formula: SetCellFormula(srcCell.CellFormula); break; case CellType.Numeric: // DataFormat is not copied unless policy.isCopyCellStyle is true if (DateUtil.IsCellDateFormatted(srcCell)) { SetCellValue(srcCell.DateCellValue); } else { SetCellValue(srcCell.NumericCellValue); } break; case CellType.String: SetCellValue(srcCell.StringCellValue); break; case CellType.Blank: SetBlankInternal(); break; default: throw new ArgumentException("Invalid cell type " + srcCell.CellType); } } else { //srcCell is null SetBlankInternal(); } } // Copy CellStyle if (policy.IsCopyCellStyle) { if (srcCell != null) { CellStyle = (srcCell.CellStyle); } else { // clear cell style CellStyle = (null); } } if (policy.IsMergeHyperlink) { // if srcCell doesn't have a hyperlink and destCell has a hyperlink, don't clear destCell's hyperlink IHyperlink srcHyperlink = srcCell.Hyperlink; if (srcHyperlink != null) { Hyperlink = new XSSFHyperlink(srcHyperlink); } } else if (policy.IsCopyHyperlink) { // overwrite the hyperlink at dest cell with srcCell's hyperlink // if srcCell doesn't have a hyperlink, clear the hyperlink (if one exists) at destCell IHyperlink srcHyperlink = srcCell.Hyperlink; if (srcHyperlink == null) { Hyperlink = (null); } else { Hyperlink = new XSSFHyperlink(srcHyperlink); } } }
public void setCellType(CellType cellType) { this.cellType = cellType; }
public static bool IsCellPassable(CellType cellType) { return(cellType != CellType.Wall); }
internal void Paint(ChartGraphics chartGraph, int fontSizeReducedBy, Font legendAutoFont, Size singleWCharacterSize, PointF animationLocationAdjustment) { if (cellPosition.Width <= 0 || cellPosition.Height <= 0) { return; } if (GetLegend().Common.ProcessModePaint) { Color cellBackColor = GetCellBackColor(); RectangleF relativeRectangle = chartGraph.GetRelativeRectangle(cellPositionWithMargins); if (!cellBackColor.IsEmpty) { chartGraph.FillRectangleRel(relativeRectangle, cellBackColor, ChartHatchStyle.None, string.Empty, ChartImageWrapMode.Tile, Color.Empty, ChartImageAlign.Center, GradientType.None, Color.Empty, Color.Empty, 0, ChartDashStyle.NotSet, Color.Empty, 0, PenAlignment.Inset); } GetLegend().Common.EventsManager.OnBackPaint(this, new ChartPaintEventArgs(chartGraph, GetLegend().Common, new ElementPosition(relativeRectangle.X, relativeRectangle.Y, relativeRectangle.Width, relativeRectangle.Height))); switch (CellType) { case LegendCellType.Text: PaintCellText(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize, animationLocationAdjustment); break; case LegendCellType.Image: PaintCellImage(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize, animationLocationAdjustment); break; case LegendCellType.SeriesSymbol: PaintCellSeriesSymbol(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize, animationLocationAdjustment); break; default: throw new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(CellType.ToString())); } GetLegend().Common.EventsManager.OnPaint(this, new ChartPaintEventArgs(chartGraph, GetLegend().Common, new ElementPosition(relativeRectangle.X, relativeRectangle.Y, relativeRectangle.Width, relativeRectangle.Height))); } if (GetLegend().Common.ProcessModeRegions) { GetLegend().Common.HotRegionsList.AddHotRegion(chartGraph, chartGraph.GetRelativeRectangle(cellPositionWithMargins), GetCellToolTip(), GetCellHref(), GetCellMapAreaAttributes(), legendItem, this, ChartElementType.LegendItem, legendItem.SeriesName); } }
/** * Compute width of a single cell * * @param cell the cell whose width is to be calculated * @param defaultCharWidth the width of a single character * @param formatter formatter used to prepare the text to be measured * @param useMergedCells whether to use merged cells * @return the width in pixels or -1 if cell is empty */ public static double GetCellWidth(ICell cell, int defaultCharWidth, DataFormatter formatter, bool useMergedCells) { ISheet sheet = cell.Sheet; IWorkbook wb = sheet.Workbook; IRow row = cell.Row; int column = cell.ColumnIndex; int colspan = 1; for (int i = 0; i < sheet.NumMergedRegions; i++) { CellRangeAddress region = sheet.GetMergedRegion(i); if (ContainsCell(region, row.RowNum, column)) { if (!useMergedCells) { // If we're not using merged cells, skip this one and move on to the next. return(-1); } cell = row.GetCell(region.FirstColumn); colspan = 1 + region.LastColumn - region.FirstColumn; } } ICellStyle style = cell.CellStyle; CellType cellType = cell.CellType; IFont defaultFont = wb.GetFontAt((short)0); Font windowsFont = IFont2Font(defaultFont); // for formula cells we compute the cell width for the cached formula result if (cellType == CellType.Formula) { cellType = cell.CachedFormulaResultType; } IFont font = wb.GetFontAt(style.FontIndex); double width = -1; { if (cellType == CellType.String) { IRichTextString rt = cell.RichStringCellValue; String[] lines = rt.String.Split("\n".ToCharArray()); for (int i = 0; i < lines.Length; i++) { String txt = lines[i] + defaultChar; //AttributedString str = new AttributedString(txt); //copyAttributes(font, str, 0, txt.length()); windowsFont = IFont2Font(font); if (rt.NumFormattingRuns > 0) { // TODO: support rich text fragments } width = GetCellWidth(defaultCharWidth, colspan, style, width, txt, windowsFont, cell); } } else { String sval = null; if (cellType == CellType.Numeric) { // Try to get it formatted to look the same as excel try { sval = formatter.FormatCellValue(cell, dummyEvaluator); } catch (Exception) { sval = cell.NumericCellValue.ToString(); } } else if (cellType == CellType.Boolean) { sval = cell.BooleanCellValue.ToString().ToUpper(); } if (sval != null) { String txt = sval + defaultChar; //str = new AttributedString(txt); //copyAttributes(font, str, 0, txt.length()); windowsFont = IFont2Font(font); width = GetCellWidth(defaultCharWidth, colspan, style, width, txt, windowsFont, cell); } } } return(width); }
/// <summary> /// Writes the terrain to the specified stream. /// </summary> /// <param name="stream">The destination stream.</param> public void Write(Stream stream) { BinaryWriter writer = new BinaryWriter(stream); if (Version > 0) { writer.Write(0x52524554u); // 'TERR' if (Version < 4) { writer.Write(0x00000003u); // version } else { writer.Write(Version); // version } writer.Write(GridMinX); writer.Write(GridMinZ); writer.Write(GridMaxX); writer.Write(GridMaxZ); } for (int y = 0; y < this.Height; y += CLUSTER_SIZE) { for (int x = 0; x < this.Width; x += CLUSTER_SIZE) { bool haveHeight = true; bool haveColor = true; bool haveAlpha1 = true; bool haveAlpha2 = true; bool haveAlpha3 = true; bool haveCell = true; if (Version >= 5) { haveHeight = false; haveColor = false; haveAlpha1 = false; haveAlpha2 = false; haveAlpha3 = false; haveCell = false; float height = this.HeightMapFloat[x, y]; RGB color = this.ColorMap[x, y]; byte alpha1 = this.AlphaMap1[x, y]; byte alpha2 = this.AlphaMap2[x, y]; byte alpha3 = this.AlphaMap3[x, y]; CellType cell = this.CellMap[x, y]; for (int cy = 0; cy < CLUSTER_SIZE; cy++) { if (!haveHeight) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { if (height != this.HeightMapFloat[x + cx, y + cy]) { haveHeight = true; break; } } } } for (int cy = 0; cy < CLUSTER_SIZE; cy++) { if (!haveColor) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { if (color.R != this.ColorMap[x + cx, y + cy].R || color.G != this.ColorMap[x + cx, y + cy].G || color.B != this.ColorMap[x + cx, y + cy].B) { haveColor = true; break; } } } } for (int cy = 0; cy < CLUSTER_SIZE; cy++) { if (!haveAlpha1) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { if (alpha1 != this.AlphaMap1[x + cx, y + cy]) { haveAlpha1 = true; break; } } } } for (int cy = 0; cy < CLUSTER_SIZE; cy++) { if (!haveAlpha2) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { if (alpha2 != this.AlphaMap2[x + cx, y + cy]) { haveAlpha2 = true; break; } } } } for (int cy = 0; cy < CLUSTER_SIZE; cy++) { if (!haveAlpha3) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { if (alpha3 != this.AlphaMap3[x + cx, y + cy]) { haveAlpha3 = true; break; } } } } for (int cy = 0; cy < CLUSTER_SIZE; cy++) { if (!haveCell) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { if (cell != this.CellMap[x + cx, y + cy]) { haveCell = true; break; } } } } byte Compression = 0; if (haveHeight) { Compression += 1; } if (haveColor) { Compression += (1 << 1); } if (haveAlpha1) { Compression += (1 << 2); } if (haveAlpha2) { Compression += (1 << 3); } if (haveAlpha3) { Compression += (1 << 4); } if (haveCell) { Compression += (1 << 5); } writer.Write(Compression); } if (Version < 3) { for (int cy = 0; cy < (CLUSTER_SIZE + 1); cy++) { for (int cx = 0; cx < (CLUSTER_SIZE + 1); cx++) { int _cx = cx; int _cy = cy; if ((x + cx) == this.Width) { _cx--; } if ((x + cy) == this.Width) { _cy--; } writer.Write(this.HeightMap[x + _cx, y + _cy]); } } } else if (Version < 4) { // height map for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { writer.Write(this.HeightMap[x + cx, y + cy]); } } } else { // height map if (haveHeight) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { writer.Write(this.HeightMapFloat[x + cx, y + cy]); } } } else { writer.Write(this.HeightMapFloat[x, y]); } } if (Version < 3) { for (int cy = 0; cy < (CLUSTER_SIZE + 1); cy++) { for (int cx = 0; cx < (CLUSTER_SIZE + 1); cx++) { int _cx = cx; int _cy = cy; if ((x + cx) == this.Width) { _cx--; } if ((x + cy) == this.Width) { _cy--; } writer.Write(this.NormalMap[x + _cx, y + _cy]); } } } else if (Version < 4) { // normal map for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { writer.Write(this.NormalMap[x + cx, y + cy]); } } } // color map if (Version < 3) { for (int cy = 0; cy < (CLUSTER_SIZE + 1); cy++) { for (int cx = 0; cx < (CLUSTER_SIZE + 1); cx++) { int _cx = cx; int _cy = cy; if ((x + cx) == this.Width) { _cx--; } if ((x + cy) == this.Width) { _cy--; } writer.Write(this.ColorMap[x + _cx, y + _cy].R); writer.Write(this.ColorMap[x + _cx, y + _cy].G); writer.Write(this.ColorMap[x + _cx, y + _cy].B); } } } else //if (Version < 4) { if (haveColor) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { writer.Write(this.ColorMap[x + cx, y + cy].R); writer.Write(this.ColorMap[x + cx, y + cy].G); writer.Write(this.ColorMap[x + cx, y + cy].B); } } } else { writer.Write(this.ColorMap[x, y].R); writer.Write(this.ColorMap[x, y].G); writer.Write(this.ColorMap[x, y].B); } } // alpha map 1 if (Version < 3) { for (int cy = 0; cy < (CLUSTER_SIZE + 1); cy++) { for (int cx = 0; cx < (CLUSTER_SIZE + 1); cx++) { int _cx = cx; int _cy = cy; if ((x + cx) == this.Width) { _cx--; } if ((x + cy) == this.Width) { _cy--; } writer.Write(this.AlphaMap1[x + _cx, y + _cy]); } } } else //if (Version < 4) { if (haveAlpha1) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { writer.Write(this.AlphaMap1[x + cx, y + cy]); } } } else { writer.Write(this.AlphaMap1[x, y]); } } // alpha map 2 if (Version < 3) { for (int cy = 0; cy < (CLUSTER_SIZE + 1); cy++) { for (int cx = 0; cx < (CLUSTER_SIZE + 1); cx++) { int _cx = cx; int _cy = cy; if ((x + cx) == this.Width) { _cx--; } if ((x + cy) == this.Width) { _cy--; } writer.Write(this.AlphaMap2[x + _cx, y + _cy]); } } } else //if (Version < 4) { if (haveAlpha2) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { writer.Write(this.AlphaMap2[x + cx, y + cy]); } } } else { writer.Write(this.AlphaMap2[x, y]); } } // alpha map 3 if (Version < 3) { for (int cy = 0; cy < (CLUSTER_SIZE + 1); cy++) { for (int cx = 0; cx < (CLUSTER_SIZE + 1); cx++) { int _cx = cx; int _cy = cy; if ((x + cx) == this.Width) { _cx--; } if ((x + cy) == this.Width) { _cy--; } writer.Write(this.AlphaMap3[x + _cx, y + _cy]); } } } else //if (Version < 4) { if (haveAlpha3) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { writer.Write(this.AlphaMap3[x + cx, y + cy]); } } } else { writer.Write(this.AlphaMap3[x, y]); } } // cliff map if (Version < 3) { for (int cy = 0; cy < (CLUSTER_SIZE + 1); cy++) { for (int cx = 0; cx < (CLUSTER_SIZE + 1); cx++) { int _cx = cx; int _cy = cy; if ((x + cx) == this.Width) { _cx--; } if ((x + cy) == this.Width) { _cy--; } writer.Write((byte)this.CellMap[x + _cx, y + _cy]); } } } else //if (Version < 4) { if (haveCell) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { writer.Write((byte)this.CellMap[x + cx, y + cy]); } } } else { writer.Write((byte)this.CellMap[x, y]); } } // info map writer.Write(this.InfoMap[x / CLUSTER_SIZE, y / CLUSTER_SIZE]); // ??? if (Version > 0) { if (Version < 3) { for (int i = 0; i < 25; i++) { writer.Write(0x00); } } if (Version == 2) { writer.Write(0x00); } } } } }
public static List <Combination> AllMoves(List <List <ICell> > cells) { List <Combination> moves = new List <Combination>(); int size = cells.Count; for (int i = 0; i < size; i++) { int count = 0; CellType previous = CellType.Default; for (int j = 0; j < size; j++) { if (cells[i][j].Type == previous && previous != CellType.Default) { count = 2; } else { count = 1; } previous = cells[i][j].Type; if (count == 2) { if (j > 1) { if (i > 0 && cells[i - 1][j - 2].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(i - 1, j - 2)); currentMove.combination.Add(new Position(i, j - 2)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (i < size - 1 && cells[i + 1][j - 2].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(i + 1, j - 2)); currentMove.combination.Add(new Position(i, j - 2)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (j > 2 && cells[i][j - 3].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(i, j - 3)); currentMove.combination.Add(new Position(i, j - 2)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } } if (j < size - 1) { if (i > 0 && cells[i - 1][j + 1].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(i - 1, j + 1)); currentMove.combination.Add(new Position(i, j + 1)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (i < size - 1 && cells[i + 1][j + 1].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(i + 1, j + 1)); currentMove.combination.Add(new Position(i, j + 1)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (j < size - 2 && cells[i][j + 2].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(i, j + 2)); currentMove.combination.Add(new Position(i, j + 1)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } } } } previous = CellType.Default; for (int j = 0; j < size; j++) { if (cells[j][i].Type == previous && previous != CellType.Default) { count = 2; } else { count = 1; } previous = cells[j][i].Type; if (count == 2) { if (j > 1) { if (i > 0 && cells[j - 2][i - 1].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(j - 2, i - 1)); currentMove.combination.Add(new Position(j - 2, i)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (i < size - 1 && cells[j - 2][i + 1].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(j - 2, i + 1)); currentMove.combination.Add(new Position(j - 2, i)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (j > 2 && cells[j - 3][i].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(j - 3, i)); currentMove.combination.Add(new Position(j - 2, i)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } } if (j < size - 1) { if (i > 0 && cells[j + 1][i - 1].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(j + 1, i - 1)); currentMove.combination.Add(new Position(j + 1, i)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (i < size - 1 && cells[j + 1][i + 1].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(j + 1, i + 1)); currentMove.combination.Add(new Position(j + 1, i)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (j < size - 2 && cells[j + 2][i].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(j + 2, i)); currentMove.combination.Add(new Position(j + 1, i)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } } } } previous = CellType.Default; for (int j = 0; j < size - 1; j++) { if (cells[i][j + 1].Type == previous && previous != CellType.Default) { count = 2; } else { count = 1; } if (count == 2) { if (i > 0 && cells[i - 1][j].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(i - 1, j)); currentMove.combination.Add(new Position(i, j)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (i < size - 1 && cells[i + 1][j].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(i + 1, j)); currentMove.combination.Add(new Position(i, j)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } } previous = cells[i][j].Type; } previous = CellType.Default; for (int j = 0; j < size - 1; j++) { if (cells[j + 1][i].Type == previous && previous != CellType.Default) { count = 2; } else { count = 1; } if (count == 2) { if (i > 0 && cells[j][i - 1].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(j, i - 1)); currentMove.combination.Add(new Position(j, i)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } if (i < size - 1 && cells[j][i + 1].Type == previous) { Combination currentMove = new Combination(); currentMove.combination.Add(new Position(j, i + 1)); currentMove.combination.Add(new Position(j, i)); if (!moves.Contains(currentMove)) { moves.Add(currentMove); } } } previous = cells[j][i].Type; } } return(moves); }
public static bool HasMoves(List <List <ICell> > cells) { int size = cells.Count; for (int i = 0; i < size; i++) { int count = 0; CellType previous = CellType.Default; for (int j = 0; j < size; j++) { if (cells[i][j].Type == previous && previous != CellType.Default) { count = 2; } else { count = 1; } previous = cells[i][j].Type; if (count == 2) { if (j > 1) { if (i > 0 && cells[i - 1][j - 2].Type == previous) { return(true); } if (i < size - 1 && cells[i + 1][j - 2].Type == previous) { return(true); } if (j > 2 && cells[i][j - 3].Type == previous) { return(true); } } if (j < size - 1) { if (i > 0 && cells[i - 1][j + 1].Type == previous) { return(true); } if (i < size - 1 && cells[i + 1][j + 1].Type == previous) { return(true); } if (j < size - 2 && cells[i][j + 2].Type == previous) { return(true); } } } } previous = CellType.Default; for (int j = 0; j < size; j++) { if (cells[j][i].Type == previous && previous != CellType.Default) { count = 2; } else { count = 1; } previous = cells[j][i].Type; if (count == 2) { if (j > 1) { if (i > 0 && cells[j - 2][i - 1].Type == previous) { return(true); } if (i < size - 1 && cells[j - 2][i + 1].Type == previous) { return(true); } if (j > 2 && cells[j - 3][i].Type == previous) { return(true); } } if (j < size - 1) { if (i > 0 && cells[j + 1][i - 1].Type == previous) { return(true); } if (i < size - 1 && cells[j + 1][i + 1].Type == previous) { return(true); } if (j < size - 2 && cells[j + 2][i].Type == previous) { return(true); } } } } previous = CellType.Default; for (int j = 0; j < size - 1; j++) { if (cells[i][j + 1].Type == previous && previous != CellType.Default) { count = 2; } else { count = 1; } if (count == 2) { if (i > 0 && cells[i - 1][j].Type == previous) { return(true); } if (i < size - 1 && cells[i + 1][j].Type == previous) { return(true); } } previous = cells[i][j].Type; } previous = CellType.Default; for (int j = 0; j < size - 1; j++) { if (cells[j + 1][i].Type == previous && previous != CellType.Default) { count = 2; } else { count = 1; } if (count == 2) { if (i > 0 && cells[j][i - 1].Type == previous) { return(true); } if (i < size - 1 && cells[j][i + 1].Type == previous) { return(true); } } previous = cells[j][i].Type; } } return(false); }
/// <summary> /// Reads a terrain from a stream. /// </summary> /// <param name="stream">The data stream.</param> /// <returns></returns> public static Terrain Read(Stream stream) { int CLUSTER_SIZE = 4; BinaryReader reader = new BinaryReader(stream); bool version0 = false; if (reader.ReadUInt32() != 0x52524554u) // 'TERR' { reader.BaseStream.Seek(0, SeekOrigin.Begin); version0 = true; //throw new Exception("Invalid magic number."); } UInt32 version = 0; if (!version0) { version = reader.ReadUInt32(); } if (version < 0 || version > 5) { throw new NotSupportedException(string.Format("Version {0} is not supported.", version)); } if (version >= 4) { CLUSTER_SIZE = 16; } Int16 gridMinX = 0; Int16 gridMinZ = 0; Int16 gridMaxX = 0; Int16 gridMaxZ = 0; if (version > 0) { gridMinX = reader.ReadInt16(); gridMinZ = reader.ReadInt16(); gridMaxX = reader.ReadInt16(); gridMaxZ = reader.ReadInt16(); } else { long ClusterCount = (stream.Length / 0xfd); ClusterCount = (long)Math.Sqrt(ClusterCount); gridMinX = (Int16)(-ClusterCount / 2); gridMinZ = (Int16)(-ClusterCount / 2); gridMaxX = (Int16)(ClusterCount / 2); gridMaxZ = (Int16)(ClusterCount / 2); } int width = gridMaxX - gridMinX; int height = gridMaxZ - gridMinZ; Terrain terrain = new Terrain(version, gridMinX, gridMinZ, gridMaxX, gridMaxZ); for (int y = 0; y < height; y += CLUSTER_SIZE) { for (int x = 0; x < width; x += CLUSTER_SIZE) { bool haveHeight = true; bool haveColor = true; bool haveAlpha1 = true; bool haveAlpha2 = true; bool haveAlpha3 = true; bool haveCell = true; if (version >= 5) { byte CompressionData = reader.ReadByte(); haveHeight = (CompressionData & 1) != 0; haveColor = (CompressionData & (1 << 1)) != 0; haveAlpha1 = (CompressionData & (1 << 2)) != 0; haveAlpha2 = (CompressionData & (1 << 3)) != 0; haveAlpha3 = (CompressionData & (1 << 4)) != 0; haveCell = (CompressionData & (1 << 5)) != 0; } // height map if (version < 4) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { short value = reader.ReadInt16(); terrain.HeightMap[x + cx, y + cy] = value; if (value < terrain.heightMapMin) { terrain.heightMapMin = value; } if (value > terrain.heightMapMax) { terrain.heightMapMax = value; } } if (version < 3) { reader.ReadInt16(); // 5th vertex (from next cluster) } } if (version < 3) { reader.ReadBytes(10); // 5th row of vertecies (from next cluster) } } else { if (haveHeight) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { Single value = reader.ReadSingle(); terrain.HeightMapFloat[x + cx, y + cy] = value; if (value < terrain.heightMapFloatMin) { terrain.heightMapFloatMin = value; } if (value > terrain.heightMapFloatMax) { terrain.heightMapFloatMax = value; } } } } else { Single value = reader.ReadSingle(); for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { terrain.HeightMapFloat[x + cx, y + cy] = value; } } if (value < terrain.heightMapFloatMin) { terrain.heightMapFloatMin = value; } if (value > terrain.heightMapFloatMax) { terrain.heightMapFloatMax = value; } } } // normal map if (version < 4) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { byte value = reader.ReadByte(); terrain.NormalMap[x + cx, y + cy] = value; } if (version < 3) { reader.ReadByte(); // 5th vertex (from next cluster) } } if (version < 3) { reader.ReadBytes(5); // 5th row of vertecies (from next cluster) } } // color map if (haveColor) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { byte R = reader.ReadByte(); byte G = reader.ReadByte(); byte B = reader.ReadByte(); terrain.ColorMap[x + cx, y + cy].R = R; terrain.ColorMap[x + cx, y + cy].G = G; terrain.ColorMap[x + cx, y + cy].B = B; } if (version < 3) { reader.ReadBytes(3); // 5th vertex (from next cluster) } } if (version < 3) { reader.ReadBytes(15); // 5th row of vertecies (from next cluster) } } else { byte R = reader.ReadByte(); byte G = reader.ReadByte(); byte B = reader.ReadByte(); for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { terrain.ColorMap[x + cx, y + cy].R = R; terrain.ColorMap[x + cx, y + cy].G = G; terrain.ColorMap[x + cx, y + cy].B = B; } } } // alpha map 1 if (haveAlpha1) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { byte value = reader.ReadByte(); terrain.AlphaMap1[x + cx, y + cy] = value; } if (version < 3) { reader.ReadByte(); // 5th vertex (from next cluster) } } if (version < 3) { reader.ReadBytes(5); // 5th row of vertecies (from next cluster) } } else { byte value = reader.ReadByte(); for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { terrain.AlphaMap1[x + cx, y + cy] = value; } } } // alpha map 2 if (haveAlpha2) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { byte value = reader.ReadByte(); terrain.AlphaMap2[x + cx, y + cy] = value; } if (version < 3) { reader.ReadByte(); // 5th vertex (from next cluster) } } if (version < 3) { reader.ReadBytes(5); // 5th row of vertecies (from next cluster) } } else { byte value = reader.ReadByte(); for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { terrain.AlphaMap2[x + cx, y + cy] = value; } } } // alpha map 3 if (haveAlpha3) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { byte value = reader.ReadByte(); terrain.AlphaMap3[x + cx, y + cy] = value; } if (version < 3) { reader.ReadByte(); // 5th vertex (from next cluster) } } if (version < 3) { reader.ReadBytes(5); // 5th row of vertecies (from next cluster) } } else { byte value = reader.ReadByte(); for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { terrain.AlphaMap3[x + cx, y + cy] = value; } } } // cliff map if (haveCell) { for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { CellType value = (CellType)reader.ReadByte(); terrain.CellMap[x + cx, y + cy] = value; } if (version < 3) { reader.ReadByte(); // 5th vertex (from next cluster) } } if (version < 3) { reader.ReadBytes(5); // 5th row of vertecies (from next cluster) } } else { CellType value = (CellType)reader.ReadByte(); for (int cy = 0; cy < CLUSTER_SIZE; cy++) { for (int cx = 0; cx < CLUSTER_SIZE; cx++) { terrain.CellMap[x + cx, y + cy] = value; } } } // info map { UInt32 value = reader.ReadUInt32(); terrain.InfoMap[x / CLUSTER_SIZE, y / CLUSTER_SIZE] = value; } // ??? if (version > 0) { if (version < 3) { reader.ReadBytes(25); } if (version == 2) { reader.ReadByte(); } } } } return(terrain); }
// Update is called once per frame void Update() { RotateLookingObject(); if (Physics.Raycast(_camera.transform.position, _camera.transform.forward, out var hit)) { var ctrl = hit.transform.gameObject.GetComponent <Focusable>(); if (ctrl) { if (ctrl.CanFocus) { BlurAll(); ctrl.Focus(); } _focused = ctrl; } else { BlurAll(); } } var down = Input.GetAxis("Vertical") < -0.0001f; if (!_downPressedDown && down) { _downPressedDown = true; Focus(Math.Min(_focusedIndex + 1, CurrentStageItems().Length - 1)); } if (!down && _downPressedDown) { _downPressedDown = false; } var up = Input.GetAxis("Vertical") > 0.0001f; if (!_upPressedDown && up) { _upPressedDown = true; Focus(Math.Max(_focusedIndex - 1, 0)); } if (!up && _upPressedDown) { _upPressedDown = false; } var left = Input.GetAxis("Horizontal") < -0.0001f; if (!_leftPressedDown && left) { _leftPressedDown = true; if (_focused.TryGetComponent <SliderItemController>(out var slider)) { slider.Decrement(); if (slider.gameObject.name == "BoardSize") { _size = slider.value; _toWin.SetMax(slider.value); } } } if (!left && _leftPressedDown) { _leftPressedDown = false; } var right = Input.GetAxis("Horizontal") > 0.0001f; if (!_rightPressedDown && right) { _rightPressedDown = true; if (_focused.TryGetComponent <SliderItemController>(out var slider)) { slider.Increment(); if (slider.gameObject.name == "BoardSize") { _size = slider.value; _toWin.SetMax(slider.value); } } } if (!right && _rightPressedDown) { _rightPressedDown = false; } var click = Math.Abs(Input.GetAxis("Fire1")) > 0.0001f || Input.GetKey(KeyCode.Return); if (!_clickPressedDown && click && _focused && _focused.TryGetComponent <ButtonController>(out var btn)) { _clickPressedDown = true; switch (btn.id) { case "exit": Application.Quit(); break; case "new-game": SetStage(2); break; case "start-game-x": case "start-game-o": _gameCellType = btn.id == "start-game-x" ? CellType.X : CellType.O; SceneManager.LoadScene("MainScene"); break; } } if (!click && _clickPressedDown) { _clickPressedDown = false; } }
/// <summary> /// Changes the type of the cell. /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="cellType">Cell type.</param> public void ChangeCellType(int x, int y, CellType cellType) { GetCellAt(x, y).cellType = cellType; }
public void CreateCell(int Cc, CellType TypeO) { CurrentCol = Cc; CurrentCell = CurrentIRow.CreateCell(CurrentCol); }
public static Cell[,] TransformBoolToCell(bool[,] map, CellType trueCell = CellType.Empty, CellType falseCell = CellType.Empty) { if (trueCell == CellType.Empty && falseCell == CellType.Empty) { Debug.LogError("Both cell types are CellType.Empty."); return(null); } Cell[,] cellMap = new Cell[map.GetLength(0), map.GetLength(1)]; for (int z = 0; z < map.GetLength(1); z++) { for (int x = 0; x < map.GetLength(0); x++) { if (trueCell != CellType.Empty && map[x, z]) { cellMap[x, z] = Cell.CreateCell(trueCell); } if (falseCell != CellType.Empty && !map[x, z]) { cellMap[x, z] = Cell.CreateCell(falseCell); } } } return(cellMap); }
public Cell(string viewText, CellType type) { ViewText = viewText; Type = type; }
public Position(int x, int y, CellType value) { this.X = x; this.Y = y; this.Value = value; }
internal Size MeasureCell(ChartGraphics graph, int fontSizeReducedBy, Font legendAutoFont, Size singleWCharacterSize) { if (cachedCellSizeFontReducedBy == fontSizeReducedBy && !cachedCellSize.IsEmpty) { return(cachedCellSize); } Size result = Size.Empty; bool disposeFont = false; Font cellFont = GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont); if (CellType == LegendCellType.SeriesSymbol) { result.Width = (int)((float)(Math.Abs(SeriesSymbolSize.Width) * singleWCharacterSize.Width) / 100f); result.Height = (int)((float)(Math.Abs(SeriesSymbolSize.Height) * singleWCharacterSize.Height) / 100f); } else if (CellType == LegendCellType.Image) { if (ImageSize.IsEmpty && Image.Length > 0) { SizeF size = default(SizeF); if (GetLegend().Common.ImageLoader.GetAdjustedImageSize(Image, graph.Graphics, ref size)) { result.Width = (int)size.Width; result.Height = (int)size.Height; } } else { result.Width = (int)((float)(Math.Abs(ImageSize.Width) * singleWCharacterSize.Width) / 100f); result.Height = (int)((float)(Math.Abs(ImageSize.Height) * singleWCharacterSize.Height) / 100f); } } else { if (CellType != 0) { throw new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(CellType.ToString())); } string cellText = GetCellText(); result = graph.MeasureStringAbs(cellText + "I", cellFont); } result.Width += (int)((float)((Margins.Left + Margins.Right) * singleWCharacterSize.Width) / 100f); result.Height += (int)((float)((Margins.Top + Margins.Bottom) * singleWCharacterSize.Height) / 100f); if (GetLegend() != null && legendItem != null && legendItem.Separator != 0) { result.Height += GetLegend().GetSeparatorSize(graph, legendItem.Separator).Height; } if (disposeFont) { cellFont.Dispose(); cellFont = null; } cachedCellSize = result; cachedCellSizeFontReducedBy = fontSizeReducedBy; return(result); }
/// <summary> /// Set the cells type (numeric, formula or string) /// </summary> /// <param name="cellType"></param> public void SetCellType(CellType cellType) { CellType prevType = CellType; if (IsPartOfArrayFormulaGroup) { NotifyArrayFormulaChanging(); } if (prevType == CellType.FORMULA && cellType != CellType.FORMULA) { ((XSSFWorkbook)Sheet.Workbook).OnDeleteFormula(this); } switch (cellType) { case CellType.BLANK: SetBlank(); break; case CellType.BOOLEAN: String newVal = ConvertCellValueToBoolean() ? TRUE_AS_STRING : FALSE_AS_STRING; _cell.t = (ST_CellType.b); _cell.v = (newVal); break; case CellType.NUMERIC: _cell.t = (ST_CellType.n); break; case CellType.ERROR: _cell.t = (ST_CellType.e); break; case CellType.STRING: if (prevType != CellType.STRING) { String str = ConvertCellValueToString(); XSSFRichTextString rt = new XSSFRichTextString(str); rt.SetStylesTableReference(_stylesSource); int sRef = _sharedStringSource.AddEntry(rt.GetCTRst()); _cell.v = sRef.ToString(); } _cell.t = (ST_CellType.s); break; case CellType.FORMULA: if (!_cell.IsSetF()) { CT_CellFormula f = new CT_CellFormula(); f.Value = "0"; _cell.f = (f); if (_cell.IsSetT()) { _cell.unsetT(); } } break; default: throw new ArgumentException("Illegal cell type: " + cellType); } if (cellType != CellType.FORMULA && _cell.IsSetF()) { _cell.unsetF(); } }
protected Cell(CellType cellType) { CellType = cellType; }
public static Texture2D GetTextureTile(CellType type) => _texturesTile[type];
public DynamicExcelBuilder InsertCell(int rowIndex, int columnIndex, string columnValue, CellType cellType = CellType.String, bool isReplace = false) { var sheet = _excelContext.Sheet; var row = sheet.GetRow(rowIndex); if (isReplace) { var originCell = row.GetCell(columnIndex); originCell.SetCellValue(columnValue); } else { var cell = row.CreateCell(columnIndex, cellType); cell?.SetCellValue(columnValue); } return(this); }
MultidimensionalArray Compute_OrthonormalizationTrafo(int j0, int Len, int Degree) { // init // ==== int iKref = this.m_Owner.iGeomCells.GetRefElementIndex(j0); PolynomialList Polys = this.GetOrthonormalPolynomials(Degree)[iKref]; int N = Polys.Count; CellType cellType = this.m_Owner.iGeomCells.GetCellType(j0); #if DEBUG // checking for (int j = 1; j < Len; j++) { int jCell = j + j0; if (this.m_Owner.iGeomCells.GetCellType(jCell) != cellType) { throw new NotSupportedException("All cells in chunk must have same type."); } } #endif // storage for result MultidimensionalArray NonlinOrtho = MultidimensionalArray.Create(Len, N, N); if (m_Owner.iGeomCells.IsCellAffineLinear(j0)) { // affine-linear branch // ++++++++++++++++++++ MultidimensionalArray scl = this.Scaling; for (int j = 0; j < Len; j++) { int jCell = j + j0; double scl_j = scl[jCell]; for (int n = 0; n < N; n++) { NonlinOrtho[j, n, n] = scl_j; } } } else { // nonlinear cells branch // ++++++++++++++++++++++ // init // ==== var Kref = m_Owner.iGeomCells.GetRefElement(j0); int deg; // polynomial degree of integrand: Degree of Jacobi determinat + 2* degree of basis polynomials in ref.-space. { int D = m_Owner.SpatialDimension; deg = Kref.GetInterpolationDegree(cellType); if (deg > 1) { deg -= 1; } deg *= D; deg += 2 * Degree; } var qr = Kref.GetQuadratureRule((int)deg); int K = qr.NoOfNodes; // evaluate basis polys in ref space // ================================= MultidimensionalArray BasisValues = this.EvaluateBasis(qr.Nodes, Degree); Debug.Assert(BasisValues.GetLength(0) == K); if (BasisValues.GetLength(0) > N) { BasisValues = BasisValues.ExtractSubArrayShallow(new int[] { 0, 0 }, new int[] { K - 1, N - 1 }); } // compute \f$ A_{k n m} = \phi_{k n} \phi_{k m} w_{k} \f$ // (cell-INdependentd part of mass matrix computation) // ================================================================== MultidimensionalArray A = MultidimensionalArray.Create(K, N, N); A.Multiply(1.0, qr.Weights, BasisValues, BasisValues, 0.0, "knm", "k", "kn", "km"); // Determine mass matrix \f$ M \f$ in all cells by quadrature // \f$ M_{n m} = \sum_{k} J_k A_{k n m} \f$ // ===================================================== MultidimensionalArray J = m_Owner.JacobianDeterminat.GetValue_Cell(qr.Nodes, j0, Len); // store mass-matrix in 'NonlinOrtho' to save mem alloc NonlinOrtho.Multiply(1.0, A, J, 0.0, "jmn", "knm", "jk"); // Compute change-of-basis for all cells // (invese of cholesky) // ===================================== for (int j = 0; j < Len; j++) { MultidimensionalArray Mj = NonlinOrtho.ExtractSubArrayShallow(j, -1, -1); // mass-matrix of basis on refrence element in cell j+j0 #if DEBUG MultidimensionalArray MjClone = Mj.CloneAs(); #endif //Mj.InvertSymmetrical(); Mj.SymmetricLDLInversion(Mj, null); // clear lower triangular part // Debug.Assert(Mj.NoOfCols == N); for (int n = 1; n < N; n++) { for (int m = 0; m < n; m++) { Mj[n, m] = 0.0; } } #if DEBUG MultidimensionalArray B = NonlinOrtho.ExtractSubArrayShallow(j, -1, -1); MultidimensionalArray Bt = B.Transpose(); double MjNorm = MjClone.InfNorm(); double Bnorm = B.InfNorm(); MultidimensionalArray check = IMatrixExtensions.GEMM(Bt, MjClone, B); check.AccEye(-1.0); double checkNorm = check.InfNorm(); double RelErr = checkNorm / Math.Max(MjNorm, Bnorm); Debug.Assert(RelErr < 1.0e-5, "Fatal error in numerical orthonomalization on nonlinear cell."); #endif } } // return // ========= return(NonlinOrtho); }
public MemberFieldData() { name = ""; type = CellType.Undefined; }
public ContinuumElement3DNonLinear CreateNonLinearElement(CellType cellType, IReadOnlyList <Node> nodes, IContinuumMaterial3D commonMaterial, DynamicMaterial commonDynamicProperties) { return(new ContinuumElement3DNonLinear(nodes, commonMaterial, integrationsForStiffness[cellType], interpolations[cellType])); }
public ContinuumElement3D CreateElement(CellType cellType, IReadOnlyList <Node> nodes) { return(CreateElement(cellType, nodes, commonMaterial, commonDynamicProperties)); }
/// <summary> /// Sets the cell type. The SetValue flag indicates whether to bother about /// trying to preserve the current value in the new record if one is Created. /// The SetCellValue method will call this method with false in SetValue /// since it will overWrite the cell value later /// </summary> /// <param name="cellType">Type of the cell.</param> /// <param name="setValue">if set to <c>true</c> [set value].</param> /// <param name="row">The row.</param> /// <param name="col">The col.</param> /// <param name="styleIndex">Index of the style.</param> private void SetCellType(CellType cellType, bool setValue, int row, int col, short styleIndex) { if (cellType > CellType.Error) { throw new Exception("I have no idea what type that Is!"); } switch (cellType) { case CellType.Formula: FormulaRecordAggregate frec = null; if (cellType != this.cellType) { frec = _sheet.Sheet.RowsAggregate.CreateFormula(row, col); } else { frec = (FormulaRecordAggregate)_record; } frec.Column = col; if (setValue) { frec.FormulaRecord.Value = NumericCellValue; } frec.XFIndex = styleIndex; frec.Row = row; _record = frec; break; case CellType.Numeric: NumberRecord nrec = null; if (cellType != this.cellType) { nrec = new NumberRecord(); } else { nrec = (NumberRecord)_record; } nrec.Column = col; if (setValue) { nrec.Value = NumericCellValue; } nrec.XFIndex = styleIndex; nrec.Row = row; _record = nrec; break; case CellType.String: LabelSSTRecord lrec = null; if (cellType != this.cellType) { lrec = new LabelSSTRecord(); } else { lrec = (LabelSSTRecord)_record; } lrec.Column = col; lrec.Row = row; lrec.XFIndex = styleIndex; if (setValue) { String str = ConvertCellValueToString(); int sstIndex = book.Workbook.AddSSTString(new UnicodeString(str)); lrec.SSTIndex = (sstIndex); UnicodeString us = book.Workbook.GetSSTString(sstIndex); stringValue = new HSSFRichTextString(); stringValue.UnicodeString = us; } _record = lrec; break; case CellType.Blank: BlankRecord brec = null; if (cellType != this.cellType) { brec = new BlankRecord(); } else { brec = (BlankRecord)_record; } brec.Column = col; // During construction the cellStyle may be null for a Blank cell. brec.XFIndex = styleIndex; brec.Row = row; _record = brec; break; case CellType.Boolean: BoolErrRecord boolRec = null; if (cellType != this.cellType) { boolRec = new BoolErrRecord(); } else { boolRec = (BoolErrRecord)_record; } boolRec.Column = col; if (setValue) { boolRec.SetValue(ConvertCellValueToBoolean()); } boolRec.XFIndex = styleIndex; boolRec.Row = row; _record = boolRec; break; case CellType.Error: BoolErrRecord errRec = null; if (cellType != this.cellType) { errRec = new BoolErrRecord(); } else { errRec = (BoolErrRecord)_record; } errRec.Column = col; if (setValue) { errRec.SetValue((byte)HSSFErrorConstants.ERROR_VALUE); } errRec.XFIndex = styleIndex; errRec.Row = row; _record = errRec; break; } if (cellType != this.cellType && this.cellType != CellType.Unknown) // Special Value to indicate an Uninitialized Cell { _sheet.Sheet.ReplaceValueRecord(_record); } this.cellType = cellType; }
internal void Paint(MapGraphics chartGraph, int fontSizeReducedBy, Font legendAutoFont, Size singleWCharacterSize) { if (cellPosition.Width <= 0 || cellPosition.Height <= 0 || !GetLegend().Common.ProcessModePaint) { return; } Color cellBackColor = GetCellBackColor(); if (!cellBackColor.IsEmpty) { chartGraph.FillRectangleRel(chartGraph.GetRelativeRectangle(cellPositionWithMargins), cellBackColor, MapHatchStyle.None, string.Empty, MapImageWrapMode.Tile, Color.Empty, MapImageAlign.Center, GradientType.None, Color.Empty, Color.Empty, 0, MapDashStyle.None, Color.Empty, 0, PenAlignment.Inset); } if (GetLegend().Common.ProcessModePaint) { switch (CellType) { case LegendCellType.Text: PaintCellText(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize); break; case LegendCellType.Image: PaintCellImage(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize); break; case LegendCellType.Symbol: PaintCellSeriesSymbol(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize); break; default: throw new InvalidOperationException("Unknown legend cell type: '" + CellType.ToString(CultureInfo.CurrentCulture) + "'."); } } }
public void SetValue(CellType cellType) { this.cellType = cellType; }
public CellValueParser(CellType cellTypeToUse, WorkbookPart workbookPartToUse) { this.cell = cellTypeToUse; this.workbookPart = workbookPartToUse; }
#pragma warning disable 1570 /// <summary> /// Method to merge a list of footprints to one result footprint. /// This method finds the CellTypes for the resultFootprint. /// /// Merge each cell individually: /// The cells of all other footprints are checked. /// If in a cell of all footprints with a pound sign occurs, /// then a hash mark character is also entered in the cell of the result Footprint. /// {CellState of a list of Footprints} -> Result footprint /// {#,#,#} -> # /// {->,#,#} -> -> /// {#,<-,#} -> <- /// {#,->,<-,#} -> || /// </summary> #pragma warning restore 1570 /// <param name="footprintList">A list of ComparingFootprint's</param> /// <autor>Andrej Albrecht</autor> internal void MergeFootprints(List <ComparingFootprint> footprintList) { AddEventHeader(footprintList); ResultMatrix = new CellType[HeaderWithEventNames.Count, HeaderWithEventNames.Count]; //Two loops, to go through each cell from a virtual table. for (int row = 0; row < HeaderWithEventNames.Count; row++) { for (int column = 0; column < HeaderWithEventNames.Count; column++) { int countSharp = 0; int countLeft = 0; int countRight = 0; int countParallel = 0; int countLoop = 0; //go over all footprints and find the best CellTypes foreach (ComparingFootprint footprint in footprintList) { switch (footprint.GetFootprintCellState(HeaderWithEventNames[row], HeaderWithEventNames[column])) { case CellType.Nothing: countSharp++; break; case CellType.Left: countLeft++; break; case CellType.Right: countRight++; break; case CellType.Parallel: countParallel++; break; case CellType.Loop: countLoop++; break; } } //# if (footprintList.Count == countSharp) { ResultMatrix[row, column] = CellType.Nothing; // # } // || else if (footprintList.Count == countParallel || countParallel > 0 && countRight == 0 && countLeft == 0 || countRight > 0 && countLeft > 0) { ResultMatrix[row, column] = CellType.Parallel; // || } // -> else if (footprintList.Count == countRight || countRight > 0 && countLeft == 0) { ResultMatrix[row, column] = CellType.Right; // -> } // <- else if (footprintList.Count == countLeft || countLeft > 0 && countRight == 0) { ResultMatrix[row, column] = CellType.Left; // <- } // @ else if (footprintList.Count == countLoop || countLoop > 0) { ResultMatrix[row, column] = CellType.Loop; // @ } else { throw new NotImplementedException("countFootprint:" + footprintList.Count + " countSharp:" + countSharp + " countLeft:" + countLeft + " countRight:" + countRight + " countParallel:" + countParallel); } } } }