Skip to content

Commit

Permalink
Merge pull request #2 from cake4everyone/Round-Duration
Browse files Browse the repository at this point in the history
Round duration
  • Loading branch information
Niraculix authored May 9, 2024
2 parents 3d6963c + b6e5f55 commit ab50c95
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
16 changes: 15 additions & 1 deletion scenes/menu.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://yyc1l3e78qgl"]
[gd_scene load_steps=3 format=3 uid="uid://yyc1l3e78qgl"]

[ext_resource type="Script" path="res://scripts/menu.gd" id="1_f4qtc"]

[sub_resource type="Theme" id="Theme_31w7n"]
default_font_size = 70

[node name="Menu" type="CanvasLayer"]
script = ExtResource("1_f4qtc")

Expand Down Expand Up @@ -59,4 +62,15 @@ layout_direction = 3
layout_mode = 2
alignment = 2

[node name="RoundDuration" type="SpinBox" parent="."]
offset_left = 54.0
offset_top = 190.0
offset_right = 326.225
offset_bottom = 278.0
theme = SubResource("Theme_31w7n")
min_value = 5.0
max_value = 90.0
value = 30.0
suffix = "s"

[connection signal="pressed" from="Start" to="." method="on_btn_start_pressed"]
5 changes: 4 additions & 1 deletion scripts/game_end.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func show_round_data(data: Dictionary):
answer.color = Color.hex(0x004200ff)

$StreamerAnswer.color = Color.hex(0x004200ff) if data.streamer_vote == data.correct else Color.hex(0x780000ff)
$StreamerAnswer/Label.text = "You voted %s" % [String.chr(65 + data.streamer_vote - 1)]
if data.streamer_vote == 0:
$StreamerAnswer/Label.text = "You voted nothing"
else:
$StreamerAnswer/Label.text = "You voted %s" % [String.chr(64 + data.streamer_vote)]

var total_votes: int = data.chat_vote_count[0] + data.chat_vote_count[1] + data.chat_vote_count[2] + data.chat_vote_count[3]

Expand Down
6 changes: 5 additions & 1 deletion scripts/menu.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
class_name Menu extends CanvasLayer

## Time for each round in seconds
var round_duration: int = 30
var round_duration: int

## ready is called when the node enters the scene tree for the first time.
func _ready():
$ModeSelect.add_item("Streamer VS Chat", 0)
if(scene_manager.round_duration > 0):
round_duration = scene_manager.round_duration
$RoundDuration.value = round_duration
api.category(on_category_response)

## on_category_response is called as when the categories api call completed.
Expand All @@ -27,6 +30,7 @@ func update_category_list(categories: Dictionary):
## on_btn_start_pressed is called when pressed the start game button.
## It collects all the selected categories and creates a new game on the server.
func on_btn_start_pressed():
round_duration = $RoundDuration.value
var categories: Dictionary = {}
for category: HBoxContainer in $CategoryBox/Categories.get_children():
var amount: int = category.get_child(0).value
Expand Down
5 changes: 4 additions & 1 deletion scripts/question_end.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func show_round_data(data: Dictionary):
answer.color = Color.hex(0x004200ff)

$StreamerAnswer.color = Color.hex(0x004200ff) if data.streamer_vote == data.correct else Color.hex(0x780000ff)
$StreamerAnswer/Label.text = "You voted %s" % [String.chr(65 + data.streamer_vote - 1)]
if data.streamer_vote == 0:
$StreamerAnswer/Label.text = "You voted nothing"
else:
$StreamerAnswer/Label.text = "You voted %s" % [String.chr(64 + data.streamer_vote)]

var total_votes: int = data.chat_vote_count[0] + data.chat_vote_count[1] + data.chat_vote_count[2] + data.chat_vote_count[3]

Expand Down
1 change: 1 addition & 0 deletions scripts/scene_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ func change_scene(from: Node, to_scene_name: String):

var scene_path = scene_path_format % [to_scene_name]
from.get_tree().call_deferred("change_scene_to_file", scene_path)
api.got_ws_message = Callable()

0 comments on commit ab50c95

Please sign in to comment.