public bool IsOrigin(Vector2Short uv) { if (uv == Vector2Short.Zero) { return(true); } var renderUV = WorldRenderXna.GetRenderUV((ushort)Id, uv.X, uv.Y); var frameSizeIx = GetFrameSizeIndex((short)renderUV.Y); var frameSize = FrameSize[frameSizeIx]; if (frameSizeIx == 0) { return(renderUV.X % ((TextureGrid.X + FrameGap.X) * frameSize.X) == 0 && renderUV.Y % ((TextureGrid.Y + FrameGap.Y) * frameSize.Y) == 0); } else { int y = 0; for (int i = 0; i < frameSizeIx; i++) { y += FrameSize[i].Y * (TextureGrid.Y + FrameGap.Y); } return(renderUV.X % ((TextureGrid.X + FrameGap.X) * frameSize.X) == 0 && renderUV.Y == y); } }
private Vector2Int32 FlipSprite(Vector2Int32 totalSize, Vector2Int32 vector, Vector2Short size, bool flipX) { var maxX = totalSize.X - 1; var maxY = totalSize.Y - 1; int bufferX; int bufferY; if (flipX) { bufferX = maxX - vector.X; bufferY = vector.Y; bufferX -= size.X - 1; } else { bufferX = vector.X; bufferY = maxY - vector.Y; bufferY -= size.Y - 1; } return(new Vector2Int32(bufferX, bufferY)); }
public FrameProperty(int id, string name, Vector2Short uv) : this() { Id = id; Name = name; UV = uv; }
void Update() { if (AnimalTransform == null) { return; } // 範囲外のオブジェクトの表示、非表示を切り替え var pos = AnimalTransform.position; var key = new Vector2Short((short)(pos.x / GridSize), (short)(pos.z / GridSize)); if (current == key) { return; } foreach (var g in grid) { var flag = (g.Key - key).sqrMagnitude < this.Distance; if (g.Value.gameObject.activeSelf == flag) { continue; } g.Value.gameObject.SetActive(flag); return; // 負荷分散したいので、SetActive()は 1フレーム1回のみ実行する。 } current = key; }
private static Vector2Short[] StringToVector2ShortArray(string v, short defaultX = 0, short defaultY = 0) { if (!string.IsNullOrWhiteSpace(v)) { if (!v.StartsWith("[")) { return(new Vector2Short [] { StringToVector2Short(v, defaultX, defaultY) }); } v = v.Trim(new [] { '[', ']' }); var items = v.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var result = new Vector2Short[items.Length]; for (int i = 0; i < items.Length; i++) { result[i] = StringToVector2Short(items[i], defaultX, defaultY); } if (result.Length > 0) { return(result); } } return(new Vector2Short[] { new Vector2Short(defaultX, defaultY) }); }
public void Enqueue(Vector2Short v, int priority) { if (!elements.ContainsKey(v)) { elements.Add(v, priority); count++; } }
public FrameProperty() { Id = 0; Name = "Default"; Color = Colors.Magenta; UV = new Vector2Short(0,0); Anchor = FrameAnchor.None; }
public TileProperty() { _frameSize = new Vector2Short(1, 1); _color = Colors.Magenta; _id = -1; _name = "UNKNOWN"; _isFramed = false; }
public FrameProperty() { Id = 0; Name = "Default"; Color = Colors.Magenta; UV = new Vector2Short(0, 0); Anchor = FrameAnchor.None; }
// Start is called before the first frame update void Start() { setupWritableObjects(); changeDrawTexture(m_drawTexture); setPixelCombinationType(PixelCombineType); for (int i = 0; i < m_bresenhamList.Length; i++) { m_bresenhamList[i] = new Vector2Short(); } m_playerCam = FirstPersonController.PlayerCam; }
public bool IsOrigin(Vector2Short uv) { if (uv == Vector2Short.Zero) { return(true); } var renderUV = WorldRenderXna.GetRenderUV((ushort)Id, uv.X, uv.Y); var frameSize = GetFrameSize((short)renderUV.Y); return(renderUV.X % ((TextureGrid.X + FrameGap.X) * frameSize.X) == 0 && renderUV.Y % ((TextureGrid.Y + FrameGap.Y) * frameSize.Y) == 0); }
public TileProperty() { _frameSize = new Vector2Short(1, 1); _color = Colors.Magenta; _id = -1; _name = "UNKNOWN"; _isFramed = false; _isGrass = false; /* Heathtech */ _isPlatform = false; /* Heathtech */ _isCactus = false; /* Heathtech */ _isStone = false; /* Heathtech */ _canBlend = false; /* Heathtech */ _mergeWith = null; /* Heathtech */ }
private int?_mergeWith; /* Heathtech */ public TileProperty() { _frameSize = new Vector2Short(1, 1); _color = Colors.Magenta; _id = -1; _name = "UNKNOWN"; _isFramed = false; _isGrass = false; /* Heathtech */ _isPlatform = false; /* Heathtech */ _isCactus = false; /* Heathtech */ _isStone = false; /* Heathtech */ _canBlend = false; /* Heathtech */ _mergeWith = null; /* Heathtech */ }
public Vector2Short[,] GetTiles() { var tiles = new Vector2Short[Size.X, Size.Y]; var tileprop = World.TileProperties[Tile]; for (int x = 0; x < Size.X; x++) { for (int y = 0; y < Size.Y; y++) { tiles[x, y] = new Vector2Short((short)((tileprop.TextureGrid.X + 2) * x + Origin.X), (short)((tileprop.TextureGrid.Y + 2) * y + Origin.Y)); } } return(tiles); }
// グリッド配置用親オブジェクトを生成 Transform GetGridParent(Vector2Short v, Transform parent) { Transform res; if (!grid.TryGetValue(v, out res)) { var go = Instantiate(Prefab); #if UNITY_EDITOR go.name = v.ToString(); #endif res = go.transform; res.SetParent(parent); grid.Add(v, res); } return(res); }
internal Vector2Short[,] GetTiles() { var tiles = new Vector2Short[SizeTiles.X, SizeTiles.Y]; for (int x = 0; x < SizeTiles.X; x++) { for (int y = 0; y < SizeTiles.Y; y++) { var curSize = SizePixelsInterval; var tileX = ((curSize.X) * x + UV.X); var tileY = ((curSize.Y) * y + UV.Y); if (Tile == 388 || Tile == 389) { switch (y) { case 0: tileY = UV.Y; break; case 1: tileY = 20 + UV.Y; break; case 2: tileY = 20 + 18 + UV.Y; break; case 3: tileY = 20 + 18 + 18 + UV.Y; break; case 4: tileY = 20 + 18 + 18 + 18 + UV.Y; break; } } tiles[x, y] = new Vector2Short((short)tileX, (short)tileY); } } return(tiles); }
/// <summary> /// Change default values for local drawing when selecing drawing mesh, to ensure values will be kept while drawing on the same mesh /// </summary> /// <param name="hitObj"></param> private void changeDefaultValues(GameObject hitObj) { m_prevLocalCoord = Vector2Short.zero; // if we already have object we were affecting then send message to start drawing on clients if (m_selectedObject) { CmdDrawLines(m_networkCoordinates.ToArray(), m_selectedObject, m_clientDrawSpeed, m_changeDelay, m_defaultBrushRadius); resetLocalValues(); } m_selectedObject = hitObj; m_selectObjRend = m_selectedObject.GetComponent <Renderer>(); m_writableMaterial = getWritableMat(m_selectObjRend); if (m_writableMaterial) { m_localTex = (Texture2D)m_writableMaterial.mainTexture; } }
/// <summary> /// Draws a point with the brush on the designated texture, along with the bresenham line algorithm to fill the connecting pixels /// </summary> /// <param name="coordinate"></param> /// <param name="prevCoord"></param> /// <param name="texture"></param> /// <param name="brushSize"></param> private void drawPoints(Vector2Short coordinate, Vector2Short prevCoord, Texture2D texture, int brushSize, bool firstPoint) { if (firstPoint) { return; } if (texture && prevCoord != Vector2Short.zero) { drawBrush(texture, brushSize, coordinate, prevCoord, true); // bresenhams algorithm if (m_useBresnhamAlgorithm) { // calculate connecting points bresenhamsAlgorithm(firstPoint ? coordinate : prevCoord, coordinate); drawBresenhamAlgorithm(texture, brushSize, true); } } }
/// <summary> /// Get a Sprite from one of it's UV's /// </summary> /// <param name="uv"></param> /// <returns></returns> public KeyValuePair <int, SpriteSub> GetStyleFromUV(Vector2Short uv) { var renderUV = WorldRenderXna.GetRenderUV(Tile, uv.X, uv.Y); foreach (var kvp in Styles) { if (kvp.Value.UV == uv) { return(kvp); } if (renderUV.X >= kvp.Value.UV.X && renderUV.Y >= kvp.Value.UV.Y && renderUV.X < kvp.Value.UV.X + (kvp.Value.SizePixelsInterval.X * kvp.Value.SizeTiles.X) && renderUV.Y < kvp.Value.UV.Y + (kvp.Value.SizePixelsInterval.Y * kvp.Value.SizeTiles.Y)) { return(kvp); } } return(default);
private Vector2Short[,] GetTiles(int styleId) { Vector2Short Origin = Vector2Short.Zero; if (Styles.TryGetValue(styleId, out var style)) { Origin = style.UV; } var tiles = new Vector2Short[SizeTiles.X, SizeTiles.Y]; for (int x = 0; x < SizeTiles.X; x++) { for (int y = 0; y < SizeTiles.Y; y++) { tiles[x, y] = new Vector2Short((short)((SizePixelsInterval.X) * x + Origin.X), (short)((SizePixelsInterval.Y) * y + Origin.Y)); } } return(tiles); }
public Vector2Short Dequeue() { int bestValue = 999; Vector2Short bestKey = Vector2Short.zero; Dictionary <Vector2Short, int> .Enumerator enumerator = elements.GetEnumerator(); KeyValuePair <Vector2Short, int> keyValue; while (enumerator.MoveNext()) { keyValue = enumerator.Current; if (keyValue.Value < bestValue) { bestValue = keyValue.Value; bestKey = keyValue.Key; } } elements.Remove(bestKey); count--; return(bestKey); }
/// <summary> /// Calculates list of pixel coordinates between two points to form a connected line /// </summary> /// <param name="start"></param> /// <param name="end"></param> private void bresenhamsAlgorithm(Vector2Short start, Vector2Short end) { int dx = Mathf.Abs(end.x - start.x), sx = start.x < end.x ? 1 : -1; int dy = -Mathf.Abs(end.y - start.y), sy = start.y < end.y ? 1 : -1; int err = dx + dy, e2; /* error value e_xy */ int counter = 0; for (; ;) { /* loop */ if (start.x == end.x && start.y == end.y) { break; } e2 = 2 * err; if (e2 >= dy) { err += dy; start.x += (short)sx; } if (e2 <= dx) { err += dx; start.y += (short)sy; } if (m_bresenhamInterval == 0 || counter > m_bresenhamInterval) { m_bresenhamList[m_bresenhamCounter].Set(start.x, start.y); m_bresenhamCounter++; counter = 0; } else { counter++; } } }
/// <summary> /// Draws point on texture either with texture or simple brush /// </summary> /// <param name="texture"></param> /// <param name="brushSize"></param> /// <param name="coordinate"></param> /// <param name="prevCoord"></param> /// <param name="circular"></param> private void drawBrush(Texture2D texture, int brushSize, Vector2Short coordinate, Vector2Short prevCoord, bool circular) { if (m_drawTexture && m_useDrawTexture) { if (pixelCombineFunc == null) { Debug.LogError("PixelCombineFunction hasn't been set in drawBrush call"); return; } Vector2Short shortDir = coordinate - prevCoord; Vector2 dir = new Vector2(shortDir.x, shortDir.y); Vector2 perp = Vector2.zero; Vector2 pos; perp.Set(dir.y, -dir.x); dir.Normalize(); perp.Normalize(); int drawTextureWidth = m_drawTexture.width; int drawTextureHeight = m_drawTexture.height; short index = 0; Color basePixel; Color drawPixel; Color finalPixel = Color.black; for (int y = 0; y < drawTextureHeight; y++) { for (int x = 0; x < drawTextureWidth; x++) { drawPixel = m_drawTexColMap[index]; if (drawPixel.a > m_alphaThreshold) { // apply position and rotation on pixel grid pos = coordinate + (((x - (drawTextureWidth / 2)) * m_drawTextureScale) * dir) + (((y - (drawTextureHeight / 2)) * m_drawTextureScale) * perp); // prevent wrap around if (pos.x <= texture.width && pos.y <= texture.height && pos.x > 0 && pos.y > 0) { basePixel = texture.GetPixel((int)pos.x, (int)pos.y); pixelCombineFunc(basePixel, drawPixel + m_drawTextureTint, out finalPixel); texture.SetPixel((int)pos.x, (int)pos.y, finalPixel); } } index++; } } } // Uses simple non-texture brush else { for (int y = -brushSize; y < brushSize; ++y) { for (int x = -brushSize; x < brushSize; ++x) { // circular brush if (circular) { if ((y * y + x * x) < (brushSize * brushSize)) { texture.SetPixel(coordinate.x + y, coordinate.y + x, m_defaultBrushColour); } } // square brush else { texture.SetPixel(coordinate.x + y, coordinate.y + x, m_defaultBrushColour); } } } } }
// call on clients to initiate drawing of other clients data private IEnumerator drawOtherClientLines(Vector2Short[] coordinates, GameObject go, short drawSpeed, float applyDelay, short brushSize) { if (!go) { Debug.LogWarning("GO on client network draw was null - check to see if it has a network transform", go); yield break; } var rend = go.GetComponent <Renderer>(); Texture2D texture = null; Material writeMat = null; if (rend) { writeMat = getWritableMat(rend); if (writeMat) { texture = (Texture2D)writeMat.mainTexture; } else { Debug.LogWarning("Failed to find writable mat on other client sent object"); } } if (!texture) { Debug.LogWarning("Failed to grab texture to affect on client draw", texture); yield break; } Vector2Short prevCoord = Vector2Short.zero; int coordCount = coordinates.Length; float applyTimer = 0f; int index = 0; while (index < coordCount) { applyTimer += Time.deltaTime; int updatedDrawSpeed = (int)(drawSpeed * (Time.deltaTime * 200.0f)); // Draw loop for (int i = 0; i < updatedDrawSpeed; i++, index++) { // breakout early at the end if (index >= coordCount) { break; } if (index < coordCount) { // grab previous point if (index > 0) { prevCoord = coordinates[index - 1]; } drawPoints(coordinates[index], prevCoord, texture, brushSize, index == 0); } } if (applyTimer >= applyDelay) { ApplyTextureChanges(texture); applyTimer = 0f; } // wait till next frame yield return(null); } // apply final changes before exiting ApplyTextureChanges(texture); }
// Update is called once per frame void Update() { if (!isLocalPlayer) { return; } if (Input.GetKeyDown(KeyCode.C)) { ClearTextureAlpha(m_localTex); } m_mousePos.Set((short)Input.mousePosition.x, (short)Input.mousePosition.y); if (Input.GetMouseButton(0)) { RaycastHit hit; if (Physics.Raycast(m_playerCam.transform.position, m_playerCam.transform.forward, out hit, m_maxDrawDistance, m_DrawableLayerMask)) { GameObject hitObj = hit.collider.gameObject; m_localChangeMade = m_networkChangeMade = true; // when changing object grab data for drawing on that object if (m_selectedObject != null && m_selectedObject != hitObj) { changeDefaultValues(hitObj); Debug.Log("Select new object"); } else if (m_selectedObject == null) { changeDefaultValues(hitObj); Debug.Log("Selected first object"); } if (m_writableMaterial && m_localTex) { // find pixel coordinate to affect Vector2 texCoord = hit.textureCoord; m_pixelCoord.x = (short)(m_localTex.width * texCoord.x); m_pixelCoord.y = (short)(m_localTex.height * texCoord.y); // grab previous coordinate if available if (m_networkCoordinates.Count > 1) { m_prevLocalCoord = m_networkCoordinates[m_networkCoordinates.Count - 1]; } // reached maximum array size, so send current values if (m_networkCoordinates.Count > m_maxNetworkArraySize) { CmdDrawLines(m_networkCoordinates.ToArray(), m_selectedObject, m_clientDrawSpeed, m_changeDelay, m_defaultBrushRadius); resetLocalValues(); } // add coordinate to list if position is different than last coordinate if (m_pixelCoord != m_prevLocalCoord) { m_networkCoordinates.Add(m_pixelCoord); // draw locally drawPoints(m_pixelCoord, m_prevLocalCoord, m_localTex, m_defaultBrushRadius, m_networkCoordinates.Count == 1); } } } } // Release input so send network data to clients immediately else if (Input.GetMouseButtonUp(0) && m_networkCoordinates.Count > 0) { CmdDrawLines(m_networkCoordinates.ToArray(), m_selectedObject, m_clientDrawSpeed, m_changeDelay, m_defaultBrushRadius); m_previousMousePos = Vector2Short.zero; m_prevLocalCoord = Vector2Short.zero; resetLocalValues(); } // chek locally for applying texture changes CheckApplyTexChanges(m_localTex); }
public Vector2Short[,] GetTiles() { var tiles = new Vector2Short[Size.X, Size.Y]; var tileprop = World.TileProperties[Tile]; for (int x = 0; x < Size.X; x++) { for (int y = 0; y < Size.Y; y++) { tiles[x, y] = new Vector2Short((short)((tileprop.TextureGrid.X+2) * x + Origin.X), (short)((tileprop.TextureGrid.Y+2) * y + Origin.Y)); } } return tiles; }
// Reverse the buffer along the x- or y- axis public void Flip(ClipboardBuffer buffer, bool flipX) { ClipboardBuffer flippedBuffer = new ClipboardBuffer(buffer.Size); //var sprites = new Dictionary<Vector2Int32, Sprite>(); var spriteSizes = new Dictionary <Vector2Int32, Vector2Short>(); int maxX = buffer.Size.X - 1; int maxY = buffer.Size.Y - 1; for (int x = 0; x <= maxX; x++) { for (int y = 0; y <= maxY; y++) { int bufferX; int bufferY; if (flipX) { bufferX = maxX - x; bufferY = y; } else { bufferX = x; bufferY = maxY - y; } Tile tile = (Tile)buffer.Tiles[x, y].Clone(); var tileProperties = World.TileProperties[tile.Type]; // locate all the sprites and make a list if (tileProperties.IsFramed) { var loc = new Vector2Int32(x, y); if (tileProperties.IsOrigin(tile.GetUV())) { Vector2Short tileSize = tileProperties.GetFrameSize(tile.V); spriteSizes[loc] = tileSize; } } else { if (flipX) { // Ignore multi-width objects when flipping on x-axis // Flip brick-style switch (tile.BrickStyle) { case BrickStyle.SlopeTopRight: tile.BrickStyle = BrickStyle.SlopeTopLeft; break; case BrickStyle.SlopeTopLeft: tile.BrickStyle = BrickStyle.SlopeTopRight; break; case BrickStyle.SlopeBottomRight: tile.BrickStyle = BrickStyle.SlopeBottomLeft; break; case BrickStyle.SlopeBottomLeft: tile.BrickStyle = BrickStyle.SlopeBottomRight; break; } } else { // Ignore multi-height tiles when flipping on y-axis // Flip brick-style switch (tile.BrickStyle) { case BrickStyle.SlopeTopRight: tile.BrickStyle = BrickStyle.SlopeBottomRight; break; case BrickStyle.SlopeTopLeft: tile.BrickStyle = BrickStyle.SlopeBottomLeft; break; case BrickStyle.SlopeBottomRight: tile.BrickStyle = BrickStyle.SlopeTopRight; break; case BrickStyle.SlopeBottomLeft: tile.BrickStyle = BrickStyle.SlopeTopLeft; break; } } flippedBuffer.Tiles[bufferX, bufferY] = (Tile)tile; } } } foreach (var item in spriteSizes) { var flipOrigin = FlipFramed(buffer.Size, item.Key, item.Value, flipX); for (int y = 0; y < item.Value.Y; y++) { int sourceY = y + item.Key.Y; int targetY = y + flipOrigin.Y; for (int x = 0; x < item.Value.X; x++) { try { int sourceX = x + item.Key.X; int targetX = x + flipOrigin.X; Tile tile = (Tile)buffer.Tiles[sourceX, sourceY].Clone(); flippedBuffer.Tiles[targetX, targetY] = (Tile)tile; } catch (Exception) { } } } } foreach (var chest in buffer.Chests) { var flipOrigin = FlipFramed(buffer.Size, new Vector2Int32(chest.X, chest.Y), new Vector2Short(2, 2), flipX); chest.X = flipOrigin.X; chest.Y = flipOrigin.Y; flippedBuffer.Chests.Add(chest); } foreach (var sign in buffer.Signs) { var flipOrigin = FlipFramed(buffer.Size, new Vector2Int32(sign.X, sign.Y), new Vector2Short(2, 2), flipX); sign.X = flipOrigin.X; sign.Y = flipOrigin.Y; flippedBuffer.Signs.Add(sign); } foreach (var te in buffer.TileEntities) { var tileProperties = World.TileProperties[(int)te.TileType]; Vector2Short tileSize = tileProperties.FrameSize[0]; var flipOrigin = FlipFramed(buffer.Size, new Vector2Int32(te.PosX, te.PosY), tileSize, flipX); te.PosX = (short)flipOrigin.X; te.PosY = (short)flipOrigin.Y; flippedBuffer.TileEntities.Add(te); } // Replace the existing buffer with the new one int bufferIndex = LoadedBuffers.IndexOf(buffer); if (bufferIndex > -1) { LoadedBuffers.Insert(bufferIndex, flippedBuffer); LoadedBuffers.RemoveAt(bufferIndex + 1); } flippedBuffer.RenderBuffer(); if (Buffer == buffer) { Buffer = flippedBuffer; _wvm.PreviewChange(); } }
// Reverse the buffer along the x- or y- axis public void Flip(ClipboardBuffer buffer, bool flipX) { ClipboardBuffer flippedBuffer = new ClipboardBuffer(buffer.Size); var sprites = new Dictionary <Vector2Int32, Sprite>(); for (int x = 0, maxX = buffer.Size.X - 1; x <= maxX; x++) { for (int y = 0, maxY = buffer.Size.Y - 1; y <= maxY; y++) { int bufferX; int bufferY; if (flipX) { bufferX = maxX - x; bufferY = y; } else { bufferX = x; bufferY = maxY - y; } Tile tile = (Tile)buffer.Tiles[x, y].Clone(); var tileProperties = World.TileProperties[tile.Type]; Vector2Short tileSize = tileProperties.FrameSize; // locate all the sprites and make a list if (tileProperties.IsFramed) { var loc = new Vector2Int32(x, y); var uv = tile.GetUV(); if (tileProperties.IsOrigin(uv, out var frame)) { var sprite = World.Sprites.FirstOrDefault(s => s.Tile == tile.Type && s.Origin == uv); sprites[loc] = sprite; } } if (flipX) { // Ignore multi-width objects when flipping on x-axis if (tileSize.X > 1) { ClearTile(tile); } // Flip brick-style switch (tile.BrickStyle) { case BrickStyle.SlopeTopRight: tile.BrickStyle = BrickStyle.SlopeTopLeft; break; case BrickStyle.SlopeTopLeft: tile.BrickStyle = BrickStyle.SlopeTopRight; break; case BrickStyle.SlopeBottomRight: tile.BrickStyle = BrickStyle.SlopeBottomLeft; break; case BrickStyle.SlopeBottomLeft: tile.BrickStyle = BrickStyle.SlopeBottomRight; break; } } else { // Ignore multi-height tiles when flipping on y-axis if (tileSize.Y > 1) { ClearTile(tile); } // Flip brick-style switch (tile.BrickStyle) { case BrickStyle.SlopeTopRight: tile.BrickStyle = BrickStyle.SlopeBottomRight; break; case BrickStyle.SlopeTopLeft: tile.BrickStyle = BrickStyle.SlopeBottomLeft; break; case BrickStyle.SlopeBottomRight: tile.BrickStyle = BrickStyle.SlopeTopRight; break; case BrickStyle.SlopeBottomLeft: tile.BrickStyle = BrickStyle.SlopeTopLeft; break; } } flippedBuffer.Tiles[bufferX, bufferY] = (Tile)tile; } } foreach (var sprite in sprites) { var flipOrigin = FlipSprite(buffer.Size, sprite.Key, sprite.Value.Size, flipX); Sprite.PlaceSprite(flipOrigin.X, flipOrigin.Y, sprite.Value, flippedBuffer); } foreach (var chest in buffer.Chests) { var flipOrigin = FlipSprite(buffer.Size, new Vector2Int32(chest.X, chest.Y), new Vector2Short(2, 2), flipX); chest.X = flipOrigin.X; chest.Y = flipOrigin.Y; flippedBuffer.Chests.Add(chest); } foreach (var sign in buffer.Signs) { var flipOrigin = FlipSprite(buffer.Size, new Vector2Int32(sign.X, sign.Y), new Vector2Short(2, 2), flipX); sign.X = flipOrigin.X; sign.Y = flipOrigin.Y; flippedBuffer.Signs.Add(sign); } foreach (var te in buffer.TileEntities) { var tileProperties = World.TileProperties[(int)te.TileType]; Vector2Short tileSize = tileProperties.FrameSize; var flipOrigin = FlipSprite(buffer.Size, new Vector2Int32(te.PosX, te.PosY), tileSize, flipX); te.PosX = (short)flipOrigin.X; te.PosY = (short)flipOrigin.Y; flippedBuffer.TileEntities.Add(te); } // Replace the existing buffer with the new one int bufferIndex = LoadedBuffers.IndexOf(buffer); if (bufferIndex > -1) { LoadedBuffers.Insert(bufferIndex, flippedBuffer); LoadedBuffers.RemoveAt(bufferIndex + 1); } flippedBuffer.RenderBuffer(); if (Buffer == buffer) { Buffer = flippedBuffer; _wvm.PreviewChange(); } }
public bool Contains(Vector2Short v) { return(elements.ContainsKey(v)); }
// Reverse the buffer along the x- or y- axis public void Flip(ClipboardBuffer buffer, bool flipX) { ClipboardBuffer flippedBuffer = new ClipboardBuffer(buffer.Size); for (int x = 0, maxX = buffer.Size.X - 1; x <= maxX; x++) { for (int y = 0, maxY = buffer.Size.Y - 1; y <= maxY; y++) { int bufferX; int bufferY; if (flipX) { bufferX = maxX - x; bufferY = y; } else { bufferX = x; bufferY = maxY - y; } Tile tile = (Tile)buffer.Tiles[x, y].Clone(); Vector2Short tileSize = World.TileProperties[tile.Type].FrameSize; if (flipX) { // Ignore multi-width objects when flipping on x-axis if (tileSize.X > 1) { ClearTile(tile); } // Flip brick-style switch (tile.BrickStyle) { case BrickStyle.SlopeTopRight: tile.BrickStyle = BrickStyle.SlopeTopLeft; break; case BrickStyle.SlopeTopLeft: tile.BrickStyle = BrickStyle.SlopeTopRight; break; case BrickStyle.SlopeBottomRight: tile.BrickStyle = BrickStyle.SlopeBottomLeft; break; case BrickStyle.SlopeBottomLeft: tile.BrickStyle = BrickStyle.SlopeBottomRight; break; } } else { // Ignore multi-height tiles when flipping on y-axis if (tileSize.Y > 1) { ClearTile(tile); } // Flip brick-style switch (tile.BrickStyle) { case BrickStyle.SlopeTopRight: tile.BrickStyle = BrickStyle.SlopeBottomRight; break; case BrickStyle.SlopeTopLeft: tile.BrickStyle = BrickStyle.SlopeBottomLeft; break; case BrickStyle.SlopeBottomRight: tile.BrickStyle = BrickStyle.SlopeTopRight; break; case BrickStyle.SlopeBottomLeft: tile.BrickStyle = BrickStyle.SlopeTopLeft; break; } } flippedBuffer.Tiles[bufferX, bufferY] = (Tile)tile; } } // Replace the existing buffer with the new one int bufferIndex = LoadedBuffers.IndexOf(buffer); if (bufferIndex > -1) { LoadedBuffers.Insert(bufferIndex, flippedBuffer); LoadedBuffers.RemoveAt(bufferIndex + 1); } flippedBuffer.RenderBuffer(); if (Buffer == buffer) { Buffer = flippedBuffer; _wvm.PreviewChange(); } }
public static Vector2Int32 FlipFramed(Vector2Int32 totalSize, Vector2Int32 origin, Vector2Short spriteSize, bool flipX) { var maxX = totalSize.X - 1; var maxY = totalSize.Y - 1; int bufferX; int bufferY; if (flipX) { // flip bufferX = maxX - origin.X - (spriteSize.X - 1); bufferY = origin.Y; } else { bufferX = origin.X; bufferY = maxY - origin.Y - (spriteSize.Y - 1); } return(new Vector2Int32(bufferX, bufferY)); }
public static string Vector2String(this Vector2Short v) => string.Format("{{x: {0}, y: {1}}}", v.X, v.Y);
public bool IsOrigin(Vector2Short uv, out FrameProperty frame) { frame = Frames.FirstOrDefault(f => f.UV == uv); return(frame != null); }