online multiplayer chess game (note server currently down)
multicolor arrows + circles
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Square.gd | 2 | ||||
| -rw-r--r-- | Square.tscn | 20 | ||||
| -rw-r--r-- | project.godot | 2 | ||||
| -rw-r--r-- | ui/board/Arrows.gd | 50 | ||||
| -rw-r--r-- | ui/board/Board.gd | 1 | ||||
| -rw-r--r-- | ui/board/Board.tscn | 1 | ||||
| -rw-r--r-- | ui/menus/tests/engine_test.gd | 2 |
8 files changed, 52 insertions, 27 deletions
@@ -5,3 +5,4 @@ logs/ *.pgn .vscode/ exports/ +*.x86_64 @@ -6,7 +6,7 @@ signal right_clicked var color: Color -onready var circle: TextureRect = $BackgroundSquare/CircleHolder/Circle +onready var circle: TextureRect = $CircleHolder/Circle onready var move_indicator: ColorRect = $MoveIndicator onready var b_square: ColorRect = $BackgroundSquare diff --git a/Square.tscn b/Square.tscn index 68bff26..76e168a 100644 --- a/Square.tscn +++ b/Square.tscn @@ -36,12 +36,18 @@ margin_right = 40.0 margin_bottom = 40.0 mouse_filter = 2 -[node name="CircleHolder" type="CenterContainer" parent="BackgroundSquare"] -anchor_right = 1.0 -anchor_bottom = 1.0 +[node name="MoveIndicator" type="ColorRect" parent="."] +visible = false +margin_right = 40.0 +margin_bottom = 40.0 +mouse_filter = 2 + +[node name="CircleHolder" type="CenterContainer" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 mouse_filter = 2 -[node name="Circle" type="TextureRect" parent="BackgroundSquare/CircleHolder"] +[node name="Circle" type="TextureRect" parent="CircleHolder"] material = SubResource( 3 ) margin_left = 20.0 margin_top = 20.0 @@ -50,9 +56,3 @@ margin_bottom = 20.0 mouse_filter = 2 texture = ExtResource( 2 ) expand = true - -[node name="MoveIndicator" type="ColorRect" parent="."] -visible = false -margin_right = 40.0 -margin_bottom = 40.0 -mouse_filter = 2 diff --git a/project.godot b/project.godot index 7c76f9d..896ec4c 100644 --- a/project.godot +++ b/project.godot @@ -34,7 +34,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://ui/checkboxbutton/CheckBoxButton.gd" }, { -"base": "Resource", +"base": "Reference", "class": "Chess", "language": "GDScript", "path": "res://board/chess.gd" diff --git a/ui/board/Arrows.gd b/ui/board/Arrows.gd index 2f84bd2..c871c71 100644 --- a/ui/board/Arrows.gd +++ b/ui/board/Arrows.gd @@ -1,11 +1,14 @@ extends Control -var arrows := [] +var arrows := [] # [from, to, color] +var circles := [] # [position, color] var first: Vector2 var ev: Vector2 var b: Grid -const w = 20 +const w = 15 + +export(Color) var red_overlay func _setup(_b: Grid): @@ -29,24 +32,44 @@ func _draw(): var s = b.piece_size var c = b.overlay_color if first: + var shift = Input.is_action_pressed("shift") var loc_m = ((get_local_mouse_position() / s) - Vector2(.5, .5)).round() loc_m = Vector2(clamp(loc_m.x, 0, 7), clamp(loc_m.y, 0, 7)) var m_pos = (loc_m * s) + s / 2 - if Input.is_action_pressed("rclick"): # dragging - draw_line(first, m_pos, c, w, true) - draw_triangle(first.angle_to_point(m_pos), m_pos, c) + var clr = red_overlay if shift else c + if Input.is_action_pressed("rclick"): # previews + if first != m_pos: + draw_line(first, m_pos, clr, w, true) + draw_triangle(first.angle_to_point(m_pos), m_pos, clr) + else: + draw_arc(first, (s.x / 2) - 5, 0, PI * 2, 40, clr, 10, true) else: + var flag := true # no for-else :c if first != m_pos: - var arr: PoolVector2Array = [first, m_pos] - if arrows.find(arr) == -1: + var arr := [first, m_pos, clr] + for i in range(len(arrows)): + if arrows[i][0] == first and arrows[i][1] == m_pos: + arrows.remove(i) + flag = false + break + if flag: arrows.append(arr) - else: - arrows.erase(arr) # redoing == kill + else: + var arr := [first, clr] + for i in range(len(circles)): + if circles[i][0] == arr[0]: + circles.remove(i) + flag = false + break + if flag: + circles.append(arr) first = Vector2.ZERO - for arrow in arrows: - draw_line(arrow[0], arrow[1], c, w, true) - draw_triangle(arrow[0].angle_to_point(arrow[1]), arrow[1], c) + for a in arrows: + draw_line(a[0], a[1], a[2], w, true) + draw_triangle(a[0].angle_to_point(a[1]), a[1], a[2]) + for ci in circles: + draw_arc(ci[0], (s.x / 2) - 5, 0, PI * 2, 40, ci[1], 10, true) # r: the radians of rotation. @@ -54,11 +77,12 @@ func draw_triangle(r: float, p: Vector2, c: Color) -> void: var tri: PoolVector2Array = [Vector2(-24, 0), Vector2(0, -40), Vector2(24, 0)] for i in range(len(tri)): tri[i] = tri[i].rotated(r - PI / 2) + p - draw_colored_polygon(tri, c) + draw_primitive(tri, [c, c, c], []) func clear_arrows(): arrows.resize(0) + circles.resize(0) first = Vector2.ZERO diff --git a/ui/board/Board.gd b/ui/board/Board.gd index 3659c0f..4a7495a 100644 --- a/ui/board/Board.gd +++ b/ui/board/Board.gd @@ -187,7 +187,6 @@ func square_clicked(clicked_square: String) -> void: func move(san: String, is_recieved_move := true) -> void: var sound_handled = false var move_0x88 = chess.__move_from_san(san, true) - Log.info(chess.moves({square = chess.algebraic(move_0x88.from), stripped = true})) if ( chess.moves({square = chess.algebraic(move_0x88.from), stripped = true}).find(chess.stripped_san(san)) == -1 diff --git a/ui/board/Board.tscn b/ui/board/Board.tscn index 2451c8c..ca74f43 100644 --- a/ui/board/Board.tscn +++ b/ui/board/Board.tscn @@ -34,6 +34,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 mouse_filter = 2 script = ExtResource( 2 ) +red_overlay = Color( 0.9, 0.216, 0.216, 0.498039 ) [node name="Darken" type="ColorRect" parent="."] visible = false diff --git a/ui/menus/tests/engine_test.gd b/ui/menus/tests/engine_test.gd index 0b6af50..25704c3 100644 --- a/ui/menus/tests/engine_test.gd +++ b/ui/menus/tests/engine_test.gd @@ -19,7 +19,7 @@ class TestChess: ] for perft in perfts: var c = Chess.new(perft.fen) - var nodes = c.perft(perft.depth) + var _nodes = c.perft(perft.depth) func test_single_square_move_generation(): var positions = [ |