public void GetRectEdgeLoc( int x, int y, int width, int length, Dir4 dir, int sizeX, int sizeY, int scalar, int expectedX, int expectedY, bool exception) { Mock <ITiledGenContext> testContext = new Mock <ITiledGenContext>(MockBehavior.Strict); Mock <RoomGen <ITiledGenContext> > roomGen = new Mock <RoomGen <ITiledGenContext> > { CallBase = true }; roomGen.SetupGet(p => p.Draw).Returns(new Rect(x, y, width, length)); if (exception) { Assert.Throws <ArgumentException>(() => { roomGen.Object.GetEdgeRectLoc(dir, new Loc(sizeX, sizeY), scalar); }); } else { Assert.That(roomGen.Object.GetEdgeRectLoc(dir, new Loc(sizeX, sizeY), scalar), Is.EqualTo(new Loc(expectedX, expectedY))); } }
public void GetSupportRect(int x, int y, Dir4 dir, int expectX, int expectY, int expectW, int expectH) { // the adjacent tile lines up perfectly // 2x2 rooms here TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { new Rect(3, 3, 6, 6), new Rect(5, 9, 2, 2), new Rect(1, 5, 2, 2), new Rect(5, 1, 2, 2), new Rect(9, 5, 2, 2) }, Array.Empty <Rect>(), new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C'), Tuple.Create('A', 'D'), Tuple.Create('A', 'E') }); IRoomGen oldGen = floorPlan.GetRoom(0); Mock <IRoomGen> mockTo = new Mock <IRoomGen>(MockBehavior.Strict); mockTo.SetupGet(p => p.Draw).Returns(new Rect(x, y, 2, 2)); var indexLookup = new Dictionary <Dir4, int> { { Dir4.Down, 1 }, { Dir4.Left, 2 }, { Dir4.Up, 3 }, { Dir4.Right, 4 } }; var adjacentsInDir = new List <RoomHallIndex> { new RoomHallIndex(indexLookup[dir], false) }; Rect rect = AddSpecialRoomTestStep.GetSupportRect(floorPlan, oldGen, mockTo.Object, dir, adjacentsInDir); Assert.That(rect, Is.EqualTo(new Rect(expectX, expectY, expectW, expectH))); }
public void ReceiveBorderRangeFulfilledTile(int rangeStart, int rangeEnd, Dir4 dir, int expectedStart, int expectedEnd, bool exception) { Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict); var roomGen = new TestRoomGenException <ITiledGenContext> { OpenDown = true, OpenLeft = true, OpenUp = true, OpenRight = true, }; roomGen.PrepareSize(testRand.Object, new Loc(5, 7)); roomGen.SetLoc(new Loc(1, 2)); if (exception) { Assert.Throws <ArgumentException>(() => { roomGen.ReceiveBorderRange(new IntRange(rangeStart, rangeEnd), dir); }); } else { roomGen.ReceiveBorderRange(new IntRange(rangeStart, rangeEnd), dir); IntRange newRange = roomGen.RoomSideReqs[dir][0]; Assert.That(newRange, Is.EqualTo(new IntRange(expectedStart, expectedEnd))); } }
/// <summary>Used to create cache for the overlapping model</summary> public static bool testCompatibility(int from, Dir4 dir, int to, PatternStorage patterns, Map source) { int N = patterns.N; // patterns have size of NxN var fromPattern = patterns[from]; var toPattern = patterns[to]; // TODO: use row/col vector for performance for (int row = 0; row < N - 1; row++) { for (int col = 0; col < N; col++) { // Now, consider a concrete situation: `from` is down and `to` is up (direction = North) // get local positions in each pattern var downLocal = new Vec2i(col, row); var upLocal = new Vec2i(col, row + 1); // apply the direction downLocal = dir.applyAsRotation(downLocal, N); upLocal = dir.applyAsRotation(upLocal, N); // convert them (local positions) into global positions (position in the source) var downGlobal = fromPattern.localPosToSourcePos(downLocal, N); var upGlobal = toPattern.localPosToSourcePos(upLocal, N); // test the equaility if (source[downGlobal.x, downGlobal.y] != source[upGlobal.x, upGlobal.y]) { return(false); } } } // if all of the tiles are same, that's a compatible combination return(true); }
private void Initialize() { Dir4[] values = Dir4.GetList(); optionLabels = values.Select(dir => dir.identifier).ToArray(); optionValues = values.Select((_, i) => i).ToArray(); initialized = true; }
public void GetHallTouchRangeLargeRoom(Dir4 dir, int tier, int rangeMin, int rangeMax) { // a room that takes up multiple cells string[] inGrid = { "A.A.0.0", ". . . .", "A.A.0.0", ". . . .", "A.A.0.0", ". . . .", "0.0.0.0", }; TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid, 6, 4); Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict); IRoomGen testGen = floorPlan.PublicArrayRooms[0].RoomGen; testGen.PrepareSize(testRand.Object, new Loc(5, 10)); testGen.SetLoc(new Loc(1, 2)); IntRange bounds = floorPlan.GetHallTouchRange(testGen, dir, tier); IntRange compareBounds = new IntRange(rangeMin, rangeMax); Assert.That(bounds, Is.EqualTo(compareBounds)); }
/// <summary> /// Draws a bundle of halls from one direction, going up to the specified point, and connects them. /// </summary> /// <param name="map"></param> /// <param name="dir"></param> /// <param name="forwardEnd"></param> /// <param name="starts"></param> public void DrawCombinedHall(ITiledGenContext map, Dir4 dir, int forwardEnd, int[] starts) { bool vertical = dir.ToAxis() == Axis4.Vert; // Choose whether to start at the min X/Y, or the max X/Y Loc forwardStartLoc = (dir == Dir4.Up || dir == Dir4.Left) ? this.Draw.Start : this.Draw.End - new Loc(1); IntRange start = this.Draw.GetSide(dir.ToAxis()); start.Max -= 1; start = new IntRange(start.Max, start.Min); // draw the halls for (int jj = 0; jj < starts.Length; jj++) { start.Min = Math.Min(start.Min, starts[jj]); start.Max = Math.Max(start.Max, starts[jj]); Loc startLoc = new Loc(vertical ? starts[jj] : forwardStartLoc.X, vertical ? forwardStartLoc.Y : starts[jj]); Loc endLoc = new Loc(vertical ? starts[jj] : forwardEnd, vertical ? forwardEnd : starts[jj]); this.DrawHall(map, startLoc, endLoc, vertical); } // combine the halls Loc combineStart = new Loc(vertical ? start.Min : forwardEnd, vertical ? forwardEnd : start.Min); Loc combineEnd = new Loc(vertical ? start.Max : forwardEnd, vertical ? forwardEnd : start.Max); this.DrawHall(map, combineStart, combineEnd, !vertical); }
public Vector2 Move(Vector2 moveAmount) { float x = Move(Mathf.Abs(moveAmount.x), Dir4.FromXFloat(moveAmount.x)); float y = Move(Mathf.Abs(moveAmount.y), Dir4.FromYFloat(moveAmount.y)); return(new Vector2(x, y)); }
private void OnMouseUp() { clickEnd = cam.ScreenToWorldPoint(Input.mousePosition); Dir4 dir4 = Direction.CalculateDir4(clickStart, clickEnd, 0.4F); switch (dir4) { case Dir4.None: board.UserClicks(this); break; case Dir4.N: board.UserMoves(this, x, y + 1); break; case Dir4.S: board.UserMoves(this, x, y - 1); break; case Dir4.E: board.UserMoves(this, x + 1, y); break; case Dir4.W: board.UserMoves(this, x - 1, y); break; } }
private Vector2 GetNewHitPoint(Vector2 hitPoint, Vector3Int tilePosition, Dir4 dir) { Vector2 tileWorldPosition = ToWorldPosition(tilePosition, dir); int axis = dir.Axis; hitPoint[axis] = tileWorldPosition[axis]; return(hitPoint); }
public static bool IsValid(this Dir4 dir, bool allowNeutral = true) { if (dir == Dir4.Neutral) { return(allowNeutral); } return(dir == Dir4.N || dir == Dir4.E || dir == Dir4.S || dir == Dir4.W); }
private void MoveEffectables(Dir4 dir, float moveAmount) { foreach (StandEffectable effectable in carryEffector.GetEffectables()) { PhysicsMovement movement = effectable.GetComponent <PhysicsMovement>(); movement.TryToMove(moveAmount, dir); } }
public static LocRay4 GetWallDir(Loc loc, Grid.LocTest checkBlock, Grid.LocTest checkGround) { if (checkBlock == null) { throw new ArgumentNullException(nameof(checkBlock)); } if (checkGround == null) { throw new ArgumentNullException(nameof(checkGround)); } // check the four directions Dir4 chosenDir = Dir4.None; // ensure that there is only one direction where it is unblocked foreach (Dir4 dir in DirExt.VALID_DIR4) { Loc newLoc = loc + dir.GetLoc(); if (checkGround(newLoc)) { if (chosenDir != Dir4.None) { return(new LocRay4(loc)); } else { chosenDir = dir.Reverse(); } } else if (!checkBlock(newLoc)) { // all four directions must be valid ground, or valid block return(new LocRay4(loc)); } } if (chosenDir == Dir4.None) { return(new LocRay4(loc)); } // then check to make sure that the left and right diagonal of this direction are also valid blocked Loc lLoc = loc + DirExt.AddAngles(chosenDir.ToDir8(), Dir8.DownLeft).GetLoc(); if (!checkBlock(lLoc)) { return(new LocRay4(loc)); } Loc rLoc = loc + DirExt.AddAngles(chosenDir.ToDir8(), Dir8.DownRight).GetLoc(); if (!checkBlock(rLoc)) { return(new LocRay4(loc)); } return(new LocRay4(loc, chosenDir)); }
public void GetBorderLength(int w, int h, Dir4 dir, int result) { Mock <ITiledGenContext> testContext = new Mock <ITiledGenContext>(MockBehavior.Strict); Mock <RoomGen <ITiledGenContext> > roomGen = new Mock <RoomGen <ITiledGenContext> > { CallBase = true }; roomGen.SetupGet(p => p.Draw).Returns(new Rect(0, 0, w, h)); Assert.That(roomGen.Object.GetBorderLength(dir), Is.EqualTo(result)); }
public float Move(float distance, Dir4 dir) { float moveAmount = movement.TryToMove(distance, dir); if (dir != Dir4.up) { MoveEffectables(dir, moveAmount); } return(moveAmount); }
private static IEnumerable <Point> PointsAtChebyshevDistanceInternal( this Point source, int distance, bool clockwise, bool orderByEuclideanDistance, Dir8 startDir) { if (distance == 0) { yield return(source); yield break; } if (orderByEuclideanDistance) { Dir4 orthoDir = (Dir4)startDir; // If this bool is true, startDir must be orthogonal foreach (Point p in source.StartingPointsAtChebyshevDistance(distance, clockwise, orthoDir)) { yield return(p); } if (distance > 1) { var enumerators = new IEnumerator <Point> [4]; Dir4 currentDir = orthoDir; for (int i = 0; i < 4; ++i) { enumerators[i] = source.MiddlePointsAtChebyshevDistance(distance, clockwise, currentDir).GetEnumerator(); currentDir = currentDir.Rotate(clockwise); } // MiddlePointsAtChebyshevDistance *must* provide pairs, so 2 points are yielded for each, per iteration: while (enumerators[0].MoveNext() && enumerators[1].MoveNext() && enumerators[2].MoveNext() && enumerators[3].MoveNext()) { for (int i = 0; i < 4; ++i) { yield return(enumerators[i].Current); enumerators[i].MoveNext(); yield return(enumerators[i].Current); } } } foreach (Point p in source.FinalPointsAtChebyshevDistance(distance, clockwise, orthoDir)) { yield return(p); } } else { Dir8 currentDir = startDir; for (int i = 0; i < 8; ++i) { foreach (Point p in source.PointsInOctantAtChebyshevDistance(distance, clockwise, currentDir)) { yield return(p); } currentDir = currentDir.Rotate(clockwise); } } }
public void PrepareFulfillableBorder(Dir4 dir, bool[] fulfillable) { if (fulfillable.Length != this.FulfillableBorder[dir].Length) { throw new ArgumentException("Incorrect border length."); } for (int jj = 0; jj < fulfillable.Length; jj++) { this.FulfillableBorder[dir][jj] = fulfillable[jj]; } }
public void Rotate(Dir4 dir, int n, Dir4 expected, bool exception = false) { if (exception) { Assert.Throws <ArgumentOutOfRangeException>(() => { dir.Rotate(n); }); } else { Assert.That(dir.Rotate(n), Is.EqualTo(expected)); } }
public void ToDir4(DirV dir, Dir4 expected, bool exception = false) { if (exception) { Assert.Throws <ArgumentOutOfRangeException>(() => { dir.ToDir8(); }); } else { Assert.That(dir.ToDir4(), Is.EqualTo(expected)); } }
public void AddAngles(Dir4 dir1, Dir4 dir2, Dir4 expected, bool exception = false) { if (exception) { Assert.Throws <ArgumentOutOfRangeException>(() => { DirExt.AddAngles(dir1, dir2); }); } else { Assert.That(DirExt.AddAngles(dir1, dir2), Is.EqualTo(expected)); } }
public void DirFromAxis(Axis4 axis, int scalar, Dir4 expected, bool exception = false) { if (exception) { Assert.Throws <ArgumentOutOfRangeException>(() => { axis.GetDir(scalar); }); } else { Assert.That(axis.GetDir(scalar), Is.EqualTo(expected)); } }
public static Dir4 Rotate(this Dir4 dir, int n) { if (!dir.Validate()) { throw new ArgumentOutOfRangeException(nameof(dir), dir, "Invalid enum value."); } if (dir == Dir4.None) { return(Dir4.None); } return((Dir4)(((int)dir + n) & (DIR4_COUNT - 1))); }
public void Reverse(Dir4 dir, Dir4 expected, bool exception = false) { if (exception) { Assert.Throws <ArgumentOutOfRangeException>(() => { dir.Reverse(); }); } else { Assert.That(dir.Reverse(), Is.EqualTo(expected)); Assert.That(expected.Reverse(), Is.EqualTo(dir)); } }
public static Dir4 AddAngles(Dir4 dir1, Dir4 dir2) { // dir1 is validated by Dir4.Rotate if (!dir2.Validate()) { throw new ArgumentOutOfRangeException(nameof(dir2), dir2, "Invalid enum value."); } if (dir1 == Dir4.None || dir2 == Dir4.None) { return(Dir4.None); } return(dir1.Rotate((int)dir2)); }
public static IEnumerable <Point> EnumeratePointsAtManhattanDistance( this Point source, int distance, bool clockwise, Dir4 startDir = Dir4.N) { if (distance < 0) { throw new ArgumentException("distance must be nonnegative"); } if (!startDir.IsValid(false)) { throw new ArgumentException("startDir must be an orthogonal direction"); } return(source.PointsAtManhattanDistanceInternal(distance, clockwise, startDir)); }
private static Dir4 InitUpDir4() { string assetPath = $"{KiteSettingsEditor.path}/Dir4Up.asset"; Dir4 upDir4 = AssetDatabase.LoadAssetAtPath <Dir4>(assetPath); if (!upDir4) { upDir4 = ScriptableObject.CreateInstance <Dir4>(); upDir4.identifier = "Up"; upDir4.y = 1; AssetDatabase.CreateAsset(upDir4, assetPath); } return(upDir4); }
private static Dir4 InitRightDir4() { string assetPath = $"{KiteSettingsEditor.path}/Dir4Right.asset"; Dir4 rightDir4 = AssetDatabase.LoadAssetAtPath <Dir4>(assetPath); if (!rightDir4) { rightDir4 = ScriptableObject.CreateInstance <Dir4>(); rightDir4.identifier = "Right"; rightDir4.x = 1; AssetDatabase.CreateAsset(rightDir4, assetPath); } return(rightDir4); }
private static Dir4 InitDownDir4() { string assetPath = $"{KiteSettingsEditor.path}/Dir4Down.asset"; Dir4 downDir4 = AssetDatabase.LoadAssetAtPath <Dir4>(assetPath); if (!downDir4) { downDir4 = ScriptableObject.CreateInstance <Dir4>(); downDir4.identifier = "Down"; downDir4.y = -1; AssetDatabase.CreateAsset(downDir4, assetPath); } return(downDir4); }
private static Dir4 InitLeftDir4() { string assetPath = $"{KiteSettingsEditor.path}/Dir4Left.asset"; Dir4 leftDir4 = AssetDatabase.LoadAssetAtPath <Dir4>(assetPath); if (!leftDir4) { leftDir4 = ScriptableObject.CreateInstance <Dir4>(); leftDir4.identifier = "Left"; leftDir4.x = -1; AssetDatabase.CreateAsset(leftDir4, assetPath); } return(leftDir4); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { bool isSettings = property.serializedObject.targetObject is KiteSettings; if (isSettings) { EditorGUI.PropertyField(position, property, label); return; } if (!Dir4Settings.IsInitialized()) { Dir4Settings.Initialize(); } if (!initialized) { Initialize(); } Rect valueRect = EditorGUI.PrefixLabel(position, new GUIContent(property.displayName)); Dir4[] values = Dir4.GetList(); Dir4 value = property.objectReferenceValue as Dir4; if (value != null) { int currentIndex = Array.IndexOf(values, value); if (currentIndex != -1) { int buttonWidth = 24; Vector2 buttonSize = new Vector2(buttonWidth, valueRect.height); Rect buttonRect = new Rect(valueRect.position, buttonSize); if (GUI.Button(buttonRect, EditorGUIUtility.IconContent("d_Refresh", "|Rotate"))) { property.objectReferenceValue = Dir4Rotation.Clockwise(value); } valueRect.x += buttonWidth; valueRect.width -= buttonWidth; EditorGUI.BeginChangeCheck(); int selectedIndex = EditorGUI.IntPopup(valueRect, currentIndex, optionLabels, optionValues); if (EditorGUI.EndChangeCheck()) { property.objectReferenceValue = values[selectedIndex]; } return; } } property.objectReferenceValue = values[0]; }