diff options
Diffstat (limited to 'stage/dice_throw')
-rw-r--r-- | stage/dice_throw/dice_throw.gd | 32 | ||||
-rw-r--r-- | stage/dice_throw/dice_throw_3d.gd | 14 |
2 files changed, 28 insertions, 18 deletions
diff --git a/stage/dice_throw/dice_throw.gd b/stage/dice_throw/dice_throw.gd index c6573be..d6bdc34 100644 --- a/stage/dice_throw/dice_throw.gd +++ b/stage/dice_throw/dice_throw.gd @@ -1,8 +1,12 @@ extends Control +const DICE_SCENE := preload("res://stage/dice_throw/dice.tscn") + signal throw_finished +@export var dice_configurations: Array[DiceConfiguration]: set = set_dice_configurations + func _ready() -> void: %Side.position.x = -%Side.size.x @@ -13,18 +17,28 @@ func _ready() -> void: %ability.text = "Ability: %s" % str(Network.current_player.current_ability_points) -func _on_dice_throw_3d_throw_finished() -> void: - await get_tree().create_timer(0.25).timeout +func set_dice_configurations(value: Array[DiceConfiguration]) -> void: + dice_configurations = value var dices: Array[Dice] - dices.assign(%DiceThrow3D/Dice.get_children()) + for configuration in value: + var dice := DICE_SCENE.instantiate() + dice.configuration = configuration + dices.append(dice) + + get_node("%DiceThrow3D").dices = dices + + +func _on_dice_throw_3d_throw_finished(thrown_dices: Array[Dice]) -> void: + await get_tree().create_timer(0.25).timeout + var top_faces: Array[DiceFace] = [] var tween := create_tween().set_parallel() # move to center and rotate to camera - for idx in dices.size(): - var dice := dices[idx] + for idx in thrown_dices.size(): + var dice := thrown_dices[idx] dice.freeze = true tween.tween_property( @@ -51,7 +65,7 @@ func _on_dice_throw_3d_throw_finished() -> void: # show sidebar tween = create_tween().set_parallel() tween.tween_property(%Side, "position", Vector2(0, %Side.position.y), 0.25) - for dice in dices: + for dice in thrown_dices: var p2d: Vector2 = %Camera3D.unproject_position(dice.position) var p3d = %Camera3D.project_position(p2d + %Side.size * 0.5, 1) tween.tween_property(dice, "position", Vector3(p3d.x, dice.position.y, dice.position.z), 0.25) @@ -61,8 +75,8 @@ func _on_dice_throw_3d_throw_finished() -> void: # move to labels tween = create_tween().set_parallel() - for idx in dices.size(): - var dice := dices[idx] + for idx in thrown_dices.size(): + var dice := thrown_dices[idx] var top_face := top_faces[idx] var node := get_node("%" + top_face.configuration.type) var p3d = %Camera3D.project_position(node.position + node.size * 0.5, 1) @@ -87,7 +101,7 @@ func _on_dice_throw_3d_throw_finished() -> void: %ability.text = "Ability: %s" % str(Network.current_player.current_ability_points) await tween.finished - for dice in dices: + for dice in thrown_dices: dice.visible = false await get_tree().create_timer(1.0).timeout diff --git a/stage/dice_throw/dice_throw_3d.gd b/stage/dice_throw/dice_throw_3d.gd index 5c2ef94..507ae6a 100644 --- a/stage/dice_throw/dice_throw_3d.gd +++ b/stage/dice_throw/dice_throw_3d.gd @@ -1,19 +1,15 @@ extends Node3D -signal throw_finished +signal throw_finished(dices: Array[Dice]) -var dice_scene := preload("res://stage/dice_throw/dice.tscn") -var dices := [] var do_check_dice_state := false -@export var dice_count := 3 +@export var dices: Array[Dice] -# Called when the node enters the scene tree for the first time. func _ready() -> void: - for _i in dice_count: - var dice: Node3D = dice_scene.instantiate() + for dice in dices: $Dice.add_child(dice) dice.position = Vector3( randf_range(-3, 3), @@ -25,9 +21,9 @@ func _ready() -> void: randf_range(0, 360), randf_range(0, 360) ) - dices.append(dice) dice.roll() + # wait until dice are rolling for real await get_tree().create_timer(0.5).timeout do_check_dice_state = true @@ -45,4 +41,4 @@ func _physics_process(_delta: float) -> void: if do_check_dice_state and not moving: do_check_dice_state = false - throw_finished.emit() + throw_finished.emit(dices) |