Initial commit
This commit is contained in:
commit
ef3b7d68fb
30 changed files with 1568 additions and 0 deletions
51
Domain/GridSection.cs
Normal file
51
Domain/GridSection.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
namespace StitchATon2.Domain;
|
||||
|
||||
public class GridSection
|
||||
{
|
||||
public TileManager TileManager { get; }
|
||||
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
public int OffsetX { get; }
|
||||
public int OffsetY { get; }
|
||||
|
||||
public Tile Origin { get; }
|
||||
|
||||
public GridSection(
|
||||
TileManager tileManager,
|
||||
string coordinatePair,
|
||||
float cropX,
|
||||
float cropY,
|
||||
float cropWidth,
|
||||
float cropHeight)
|
||||
{
|
||||
TileManager = tileManager;
|
||||
var config = tileManager.Configuration;
|
||||
|
||||
var (tile0, tile1) = tileManager.GetTilePair(coordinatePair);
|
||||
|
||||
var (col0, col1) = tile0.Column < tile1.Column
|
||||
? (tile0.Column, tile1.Column)
|
||||
: (tile1.Column, tile0.Column);
|
||||
|
||||
var (row0, row1) = tile0.Row < tile1.Row
|
||||
? (tile0.Row, tile1.Row)
|
||||
: (tile1.Row, tile0.Row);
|
||||
|
||||
var gridWidth = (col1 - col0 + 1) * config.Width;
|
||||
var gridHeight = (row1 - row0 + 1) * config.Height;
|
||||
|
||||
var x0 = (int)(gridWidth * cropX);
|
||||
var y0 = (int)(gridHeight * cropY);
|
||||
var x1 = (int)(gridWidth * (cropWidth + cropX));
|
||||
var y1 = (int)(gridHeight * (cropHeight + cropY));
|
||||
|
||||
Width = x1 - x0;
|
||||
Height = y1 - y0;
|
||||
|
||||
(var columnOffset, OffsetX) = Math.DivRem(x0, config.Width);
|
||||
(var rowOffset, OffsetY) = Math.DivRem(y0, config.Height);
|
||||
|
||||
Origin = tileManager.GetTile(col0 + columnOffset, row0 + rowOffset);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue