online multiplayer chess game (note server currently down)
| -rw-r--r-- | assets/silhouette/B.png | 3 | ||||
| -rw-r--r-- | assets/silhouette/B.png.import | 35 | ||||
| -rw-r--r-- | assets/silhouette/K.png | 3 | ||||
| -rw-r--r-- | assets/silhouette/K.png.import | 35 | ||||
| -rw-r--r-- | assets/silhouette/N.png | 3 | ||||
| -rw-r--r-- | assets/silhouette/N.png.import | 35 | ||||
| -rw-r--r-- | assets/silhouette/P.png | 3 | ||||
| -rw-r--r-- | assets/silhouette/P.png.import | 35 | ||||
| -rw-r--r-- | assets/silhouette/Q.png | 3 | ||||
| -rw-r--r-- | assets/silhouette/Q.png.import | 35 | ||||
| -rw-r--r-- | assets/silhouette/R.png | 3 | ||||
| -rw-r--r-- | assets/silhouette/R.png.import | 35 | ||||
| -rw-r--r-- | project.godot | 14 | ||||
| -rw-r--r-- | ui/menus/sidebarright/SidebarRight.tscn | 23 | ||||
| -rw-r--r-- | ui/menus/sidebarright/material/MaterialLabel.gd | 29 | ||||
| -rw-r--r-- | ui/menus/sidebarright/material/MaterialLabelManager.gd | 53 |
16 files changed, 344 insertions, 3 deletions
diff --git a/assets/silhouette/B.png b/assets/silhouette/B.png new file mode 100644 index 0000000..d5246c4 --- /dev/null +++ b/assets/silhouette/B.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:080e083ba0bc286d9dacd53edd563a441ef796d5ea51a429dfa4ba5d19b7bf61 +size 655 diff --git a/assets/silhouette/B.png.import b/assets/silhouette/B.png.import new file mode 100644 index 0000000..ed3422c --- /dev/null +++ b/assets/silhouette/B.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/B.png-c8246caac42a56fc72787420e677d7c2.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/silhouette/B.png" +dest_files=[ "res://.import/B.png-c8246caac42a56fc72787420e677d7c2.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/assets/silhouette/K.png b/assets/silhouette/K.png new file mode 100644 index 0000000..7a4b9a2 --- /dev/null +++ b/assets/silhouette/K.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:163fcb49906114cb9d857bdf1331f5d24dbfa017d2b6e6905463c580c67fa8fe +size 651 diff --git a/assets/silhouette/K.png.import b/assets/silhouette/K.png.import new file mode 100644 index 0000000..1f60c29 --- /dev/null +++ b/assets/silhouette/K.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/K.png-6b79cad31246dbb425090a8601bd0984.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/silhouette/K.png" +dest_files=[ "res://.import/K.png-6b79cad31246dbb425090a8601bd0984.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/assets/silhouette/N.png b/assets/silhouette/N.png new file mode 100644 index 0000000..90c9c0a --- /dev/null +++ b/assets/silhouette/N.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef4dd28132a5ca217326bcd8d120fe2577fc6962412f6b562b56d82c704a2748 +size 764 diff --git a/assets/silhouette/N.png.import b/assets/silhouette/N.png.import new file mode 100644 index 0000000..d5c54f4 --- /dev/null +++ b/assets/silhouette/N.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/N.png-c08e57c834cbba25a726d86cb041aa48.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/silhouette/N.png" +dest_files=[ "res://.import/N.png-c08e57c834cbba25a726d86cb041aa48.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/assets/silhouette/P.png b/assets/silhouette/P.png new file mode 100644 index 0000000..d423960 --- /dev/null +++ b/assets/silhouette/P.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f12ebe613776362b4863ebf15585dccc6fc780ab0815410efbda6eb83ff2f969 +size 556 diff --git a/assets/silhouette/P.png.import b/assets/silhouette/P.png.import new file mode 100644 index 0000000..1b26963 --- /dev/null +++ b/assets/silhouette/P.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/P.png-14ea057a05fae9c26210957f744e6cc3.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/silhouette/P.png" +dest_files=[ "res://.import/P.png-14ea057a05fae9c26210957f744e6cc3.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/assets/silhouette/Q.png b/assets/silhouette/Q.png new file mode 100644 index 0000000..f3b6c42 --- /dev/null +++ b/assets/silhouette/Q.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2a6b4d38111162879c36c12929b8b8310536d71eab6dd1a97cb821dff1e9ac4 +size 1188 diff --git a/assets/silhouette/Q.png.import b/assets/silhouette/Q.png.import new file mode 100644 index 0000000..3bc8054 --- /dev/null +++ b/assets/silhouette/Q.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Q.png-4843c43282658cb237a48b5cb6c7dffa.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/silhouette/Q.png" +dest_files=[ "res://.import/Q.png-4843c43282658cb237a48b5cb6c7dffa.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/assets/silhouette/R.png b/assets/silhouette/R.png new file mode 100644 index 0000000..31eef2e --- /dev/null +++ b/assets/silhouette/R.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36431668bd912c5a801638438ac0cff0cc5fccc9ee71ac7efe0c9c011ca966e4 +size 564 diff --git a/assets/silhouette/R.png.import b/assets/silhouette/R.png.import new file mode 100644 index 0000000..23caef1 --- /dev/null +++ b/assets/silhouette/R.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/R.png-148e0efc61edcbae9e3eca2ca6e4576e.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/silhouette/R.png" +dest_files=[ "res://.import/R.png-148e0efc61edcbae9e3eca2ca6e4576e.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/project.godot b/project.godot index 896ec4c..dfe2fb0 100644 --- a/project.godot +++ b/project.godot @@ -34,7 +34,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://ui/checkboxbutton/CheckBoxButton.gd" }, { -"base": "Reference", +"base": "Resource", "class": "Chess", "language": "GDScript", "path": "res://board/chess.gd" @@ -124,6 +124,16 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://ui/menus/lobby/Lobby.gd" }, { +"base": "HBoxContainer", +"class": "MaterialLabel", +"language": "GDScript", +"path": "res://ui/menus/sidebarright/material/MaterialLabel.gd" +}, { +"base": "Node", +"class": "MaterialLabelManager", +"language": "GDScript", +"path": "res://ui/menus/sidebarright/material/MaterialLabelManager.gd" +}, { "base": "PanelContainer", "class": "MessageList", "language": "GDScript", @@ -238,6 +248,8 @@ _global_script_class_icons={ "Key": "", "KeyUtils": "", "Lobby": "", +"MaterialLabel": "", +"MaterialLabelManager": "", "MessageList": "", "Network": "", "OldColorView": "", diff --git a/ui/menus/sidebarright/SidebarRight.tscn b/ui/menus/sidebarright/SidebarRight.tscn index d36b303..a17e064 100644 --- a/ui/menus/sidebarright/SidebarRight.tscn +++ b/ui/menus/sidebarright/SidebarRight.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=21 format=2] +[gd_scene load_steps=23 format=2] [ext_resource path="res://ui/menus/sidebarright/drawbutton.gd" type="Script" id=1] [ext_resource path="res://ui/menus/sidebarright/resignbutton.gd" type="Script" id=2] @@ -10,6 +10,8 @@ [ext_resource path="res://ui/ubuntu-bold-small.tres" type="DynamicFont" id=8] [ext_resource path="res://ui/ubuntu-bold.tres" type="DynamicFont" id=9] [ext_resource path="res://ui/menus/sidebarright/OpeningLabel.gd" type="Script" id=10] +[ext_resource path="res://ui/menus/sidebarright/material/MaterialLabelManager.gd" type="Script" id=11] +[ext_resource path="res://ui/menus/sidebarright/material/MaterialLabel.gd" type="Script" id=12] [ext_resource path="res://ui/menus/sidebarright/SidebarRight.gd" type="Script" id=13] [ext_resource path="res://ui/theme/main.theme" type="Theme" id=14] [ext_resource path="res://ui/menus/sidebarright/undobutton.gd" type="Script" id=18] @@ -18,7 +20,7 @@ [ext_resource path="res://ui/menus/sidebarright/UserPanel.tscn" type="PackedScene" id=22] [sub_resource type="StyleBoxFlat" id=9] -bg_color = Color( 0.14902, 0.141176, 0.129412, 0.588235 ) +bg_color = Color( 0.14902, 0.141176, 0.129412, 0.784314 ) [sub_resource type="StyleBoxEmpty" id=11] @@ -63,6 +65,11 @@ __meta__ = { } panel_holder = NodePath("V") +[node name="MaterialLabelManager" type="Node" parent="."] +script = ExtResource( 11 ) +white_path = NodePath("../V/WhitePanel/WhiteMaterialLabel") +black_path = NodePath("../V/BlackPanel/BlackMaterialLabel") + [node name="V" type="VBoxContainer" parent="."] margin_right = 1422.0 margin_bottom = 800.0 @@ -83,6 +90,12 @@ margin_top = 223.0 margin_right = 1422.0 margin_bottom = 263.0 +[node name="BlackMaterialLabel" type="HBoxContainer" parent="V/BlackPanel"] +margin_right = 1422.0 +margin_bottom = 40.0 +alignment = 2 +script = ExtResource( 12 ) + [node name="buttonbarholder" type="PanelContainer" parent="V"] margin_top = 263.0 margin_right = 1422.0 @@ -167,6 +180,12 @@ margin_top = 513.0 margin_right = 1422.0 margin_bottom = 553.0 +[node name="WhiteMaterialLabel" type="HBoxContainer" parent="V/WhitePanel"] +margin_right = 1422.0 +margin_bottom = 40.0 +alignment = 2 +script = ExtResource( 12 ) + [node name="Status" type="Label" parent="V"] margin_top = 553.0 margin_right = 1422.0 diff --git a/ui/menus/sidebarright/material/MaterialLabel.gd b/ui/menus/sidebarright/material/MaterialLabel.gd new file mode 100644 index 0000000..79d0af4 --- /dev/null +++ b/ui/menus/sidebarright/material/MaterialLabel.gd @@ -0,0 +1,29 @@ +extends HBoxContainer +class_name MaterialLabel + +var l := Label.new() + + +func _ready(): + add_constant_override("separation", 0) + add_child(l) + l.add_font_override("font", load("res://ui/ubuntu-bold-small.tres")) + l.name = "Label" + + +# {p=0, ...} +func display(pieces: Dictionary, score: int) -> void: + get_tree().call_group("material@" + name, "free") + for p in pieces: + for i in pieces[p]: + var t := TextureRect.new() + t.expand = true + t.stretch_mode = t.STRETCH_KEEP_ASPECT + t.rect_min_size = Vector2(30, 30) + t.texture = load("res://assets/silhouette/%s.png" % p.to_upper()) + + add_child(t) + t.add_to_group("material@" + name) + t.name = p + move_child(l, get_child_count()) + l.text = ("+%d " % score) if score > 0 else "" diff --git a/ui/menus/sidebarright/material/MaterialLabelManager.gd b/ui/menus/sidebarright/material/MaterialLabelManager.gd new file mode 100644 index 0000000..6b616f0 --- /dev/null +++ b/ui/menus/sidebarright/material/MaterialLabelManager.gd @@ -0,0 +1,53 @@ +extends Node +class_name MaterialLabelManager + +const PIECE_SCORES = { + p = 1, + n = 3, + b = 3, + r = 5, + q = 9, + k = 0, +} + +export(NodePath) var white_path +onready var w: MaterialLabel = get_node(white_path) +export(NodePath) var black_path +onready var b: MaterialLabel = get_node(black_path) + + +func _ready(): + Events.connect("turn_over", self, "show_material_imbalance") + + +func get_material_diff() -> Dictionary: + var diff := { + w = {k = 0, q = 0, r = 0, b = 0, n = 0, p = 0}, + b = {k = 0, q = 0, r = 0, b = 0, n = 0, p = 0}, + } + for i in Globals.grid.chess.SQUARE_MAP.values(): + var p = Globals.grid.chess.board[i] + if !p: + continue + var them = diff[Chess.__swap_color(p.color)] + if them[p.type] > 0: + them[p.type] -= 1 + else: + diff[p.color][p.type] += 1 + return diff + + +func get_material_score(pieces: Dictionary) -> int: + var score = 0 + for c in pieces: # color + for p in pieces[c]: # dictionary of pieces : {p=0} + for i in pieces[c][p]: # number of pieces + score += PIECE_SCORES[p] * (1 if c == "w" else -1) + return score + + +func show_material_imbalance(): + var d = get_material_diff() + var score = get_material_score(d) + w.display(d.w, score if score > 0 else 0) + b.display(d.b, abs(score) if score < 0 else 0) |