Add Progress bar to Hob
This commit is contained in:
+4
-4
@@ -45,7 +45,7 @@ static func get_combination_result(first_id: StringName, second_id: StringName)
|
||||
return get_item_scene(result_id)
|
||||
|
||||
|
||||
static func get_cooking_result(ingredient_id: StringName) -> PackedScene:
|
||||
static func get_cooking_result(ingredient_id: StringName) -> String:
|
||||
load_recipes()
|
||||
for cooked_id in _cooking_map.keys():
|
||||
var cook_defs = _cooking_map[cooked_id]
|
||||
@@ -53,12 +53,12 @@ static func get_cooking_result(ingredient_id: StringName) -> PackedScene:
|
||||
if typeof(cook_defs) == TYPE_ARRAY:
|
||||
for cook_def in cook_defs:
|
||||
if cook_def["ingredient"] == ingredient_id:
|
||||
return get_item_scene(cooked_id)
|
||||
return cooked_id
|
||||
else:
|
||||
var cook_def = cook_defs
|
||||
if cook_def["ingredient"] == ingredient_id:
|
||||
return get_item_scene(cooked_id)
|
||||
return null
|
||||
return cooked_id
|
||||
return ""
|
||||
|
||||
|
||||
static func get_cooking_time(ingredient_id: StringName) -> float:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[ext_resource type="Script" uid="uid://cquqe4f1m1sw6" path="res://addons/godot-xr-tools/objects/snap_zone.gd" id="1_dlkho"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_24d3s"]
|
||||
size = Vector3(1, 1, 1.0517578)
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_dlkho"]
|
||||
radius = 0.3
|
||||
@@ -15,7 +16,8 @@ albedo_color = Color(1.1759251, 0.741115, 0.5692133, 1)
|
||||
|
||||
[node name="Counter" type="StaticBody3D" unique_id=1487893288 groups=["station"]]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=692568688]
|
||||
[node name="CollisionShape3DCuttingBoard" type="CollisionShape3D" parent="." unique_id=706340473]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.025878906)
|
||||
shape = SubResource("BoxShape3D_24d3s")
|
||||
|
||||
[node name="XRToolsSnapZone" type="Area3D" parent="." unique_id=1647380272 groups=["station"]]
|
||||
@@ -31,6 +33,7 @@ transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, -0.000975132, 0)
|
||||
shape = SubResource("SphereShape3D_dlkho")
|
||||
|
||||
[node name="CSGCombiner3D" type="CSGCombiner3D" parent="." unique_id=451757283]
|
||||
use_collision = true
|
||||
|
||||
[node name="CSGBox3D" type="CSGBox3D" parent="CSGCombiner3D" unique_id=305755330]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.045776367, 0)
|
||||
@@ -64,8 +67,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.060837455, 0.12459713, 0.55
|
||||
radius = 0.025492515
|
||||
|
||||
[node name="CSGBox3D6" type="CSGBox3D" parent="CSGCombiner3D" unique_id=187377667]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.060742255, 0.4885016, 0.0011152327)
|
||||
size = Vector3(0.56365967, 0.092285156, 0.42160034)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.060742255, 0.51602846, 0.0011152327)
|
||||
size = Vector3(0.56365967, 0.037231445, 0.42160034)
|
||||
material = SubResource("StandardMaterial3D_vlqg6")
|
||||
|
||||
[node name="CSGBox3D6" type="CSGBox3D" parent="CSGCombiner3D/CSGBox3D6" unique_id=1146824846]
|
||||
|
||||
+9
-4
@@ -2,8 +2,10 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://bsn8vhv5adxdo" path="res://Stations/hob.gd" id="1_7jc4g"]
|
||||
[ext_resource type="Script" uid="uid://cquqe4f1m1sw6" path="res://addons/godot-xr-tools/objects/snap_zone.gd" id="2_er1dp"]
|
||||
[ext_resource type="PackedScene" uid="uid://bxbocxdaayvwx" path="res://UI/progress_bar.tscn" id="3_7uuqv"]
|
||||
[ext_resource type="Script" uid="uid://bv7oracwmgre8" path="res://UI/progress_bar_3d.gd" id="3_zz9kp"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_24d3s"]
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_kdxnr"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_vlqg6"]
|
||||
radius = 0.3
|
||||
@@ -20,7 +22,7 @@ properties/1/replication_mode = 1
|
||||
script = ExtResource("1_7jc4g")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1283846023]
|
||||
shape = SubResource("BoxShape3D_24d3s")
|
||||
shape = SubResource("BoxShape3D_kdxnr")
|
||||
|
||||
[node name="XRToolsSnapZone" type="Area3D" parent="." unique_id=538157739]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5270121, 0)
|
||||
@@ -112,6 +114,9 @@ transform = Transform3D(0.94465846, 0, 0, 0, 0.94465846, 0, 0, 0, 0.94465846, -0
|
||||
operation = 2
|
||||
size = Vector3(0.9842529, 0.8349304, 0.072387695)
|
||||
|
||||
[node name="Sync" type="MultiplayerSynchronizer" parent="."]
|
||||
root_path = NodePath("..")
|
||||
[node name="Sync" type="MultiplayerSynchronizer" parent="." unique_id=768992259]
|
||||
replication_config = SubResource("SceneReplicationConfig_np_hob")
|
||||
|
||||
[node name="ProgressBar3D" parent="." unique_id=654673176 instance=ExtResource("3_7uuqv")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.74736404, -0.09216304)
|
||||
script = ExtResource("3_zz9kp")
|
||||
|
||||
+30
-9
@@ -4,14 +4,29 @@ const RECIPE_MANAGER = preload("res://RecipeManager.gd")
|
||||
|
||||
@export var cook_speed = 1
|
||||
@onready var snap_zone: XRToolsSnapZone = $XRToolsSnapZone
|
||||
@onready var progress_bar: ProgressBar3D = $ProgressBar3D
|
||||
|
||||
var time_cooked = 0
|
||||
var cooking_result = null
|
||||
var cooking_result: String
|
||||
var cooking_result_time = 0
|
||||
|
||||
func _ready() -> void:
|
||||
if not progress_bar or progress_bar is not ProgressBar3D:
|
||||
push_error("Hob missing reference to progressbar, or wrong type:", progress_bar)
|
||||
snap_zone.has_picked_up.connect(_on_object_picked_up)
|
||||
snap_zone.has_dropped.connect(_on_object_dropped)
|
||||
_refresh_progress_bar()
|
||||
|
||||
|
||||
func _refresh_progress_bar() -> void:
|
||||
var progress := 0.0
|
||||
if cooking_result and cooking_result_time > 0:
|
||||
progress = clampf(float(time_cooked) / cooking_result_time, 0.0, 1.0)
|
||||
|
||||
#print("time_cooked: %s / cooking_result_time: %s = progress: %s" % [time_cooked, cooking_result_time, progress])
|
||||
progress_bar.set_progress(progress)
|
||||
progress_bar.set_bar_visible(not cooking_result.is_empty())
|
||||
progress_bar.override_fill_color(Color.RED if cooking_result == "charcoal" else Color.GREEN)
|
||||
|
||||
func _on_object_picked_up(_item) -> void:
|
||||
print("Hob: object picked up: ", _item)
|
||||
@@ -23,21 +38,24 @@ func _on_object_picked_up(_item) -> void:
|
||||
return
|
||||
var result = RECIPE_MANAGER.get_cooking_result(_food_item.id)
|
||||
if not result:
|
||||
print("Hob: held a FoodItem that is not cookable, id: ", _food_item.id)
|
||||
print("Hob: held a FoodItem that is not cookable, id: %s result: %s" % [_food_item.id, result])
|
||||
return
|
||||
|
||||
cooking_result = result
|
||||
cooking_result_time = RECIPE_MANAGER.get_cooking_time(_food_item.id)
|
||||
cooking_result_time = RECIPE_MANAGER.get_cooking_time(_food_item.id)
|
||||
print("Hob: set cooking_result ", cooking_result)
|
||||
_refresh_progress_bar()
|
||||
|
||||
|
||||
func _on_object_dropped() -> void:
|
||||
print("Hob: object drop ")
|
||||
time_cooked = 0
|
||||
cooking_result = null
|
||||
cooking_result_time = 0
|
||||
cooking_result = ""
|
||||
cooking_result_time = 0
|
||||
_refresh_progress_bar()
|
||||
|
||||
|
||||
func convert_held_to_item(_item: PackedScene) -> void:
|
||||
func convert_held_to_item(_item: String) -> void:
|
||||
if not NetworkManager.owns_world():
|
||||
return
|
||||
print("Hob converting ", _item)
|
||||
@@ -50,20 +68,23 @@ func convert_held_to_item(_item: PackedScene) -> void:
|
||||
# Spawn the new item through the server so it replicates to every peer
|
||||
# (including late joiners), in the old item's position.
|
||||
var original_transform = old_pickable.global_transform
|
||||
var new_scene_instance = NetworkManager.spawn_item(_item.resource_path, original_transform)
|
||||
var new_scene_instance = NetworkManager.spawn_item(RECIPE_MANAGER.get_item_scene(_item).resource_path, original_transform)
|
||||
|
||||
# Drop and free the old item and pick up the new one
|
||||
print("Hob freeing old_pickable ", old_pickable)
|
||||
snap_zone.drop_object()
|
||||
NetworkManager.despawn_item(old_pickable)
|
||||
snap_zone.pick_up_object(new_scene_instance)
|
||||
|
||||
|
||||
|
||||
# If cooking something, progress cooking, when done, convert item
|
||||
func _process(delta: float) -> void:
|
||||
func _process(delta: float) -> void:
|
||||
if cooking_result:
|
||||
#print("Hob cooking_result: ", cooking_result)
|
||||
time_cooked += cook_speed * delta
|
||||
_refresh_progress_bar()
|
||||
if time_cooked >= cooking_result_time:
|
||||
time_cooked = 0
|
||||
convert_held_to_item(cooking_result)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
[gd_scene format=3 uid="uid://bxbocxdaayvwx"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_copv3"]
|
||||
viewport_path = NodePath("Sprite3D/SubViewport")
|
||||
|
||||
[node name="ProgressBar3D" type="Node3D" unique_id=654673176]
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="." unique_id=1484008334]
|
||||
pixel_size = 0.002
|
||||
texture = SubResource("ViewportTexture_copv3")
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="Sprite3D" unique_id=35936518]
|
||||
transparent_bg = true
|
||||
size = Vector2i(320, 80)
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="Sprite3D/SubViewport" unique_id=727723524]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -150.0
|
||||
offset_top = -13.5
|
||||
offset_right = 150.0
|
||||
offset_bottom = 36.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
@@ -0,0 +1,29 @@
|
||||
extends Node3D
|
||||
class_name ProgressBar3D
|
||||
|
||||
|
||||
@onready var progress_bar: ProgressBar = $Sprite3D/SubViewport/ProgressBar
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not progress_bar:
|
||||
push_error("Progressbar3D missing reference to ProgressBar")
|
||||
|
||||
func set_progress(value: float) -> void:
|
||||
print("ProgressBar set_progress: ", value)
|
||||
progress_bar.value = clamp(value, 0.0, 1.0) * 100
|
||||
|
||||
|
||||
func get_progress() -> float:
|
||||
return progress_bar.value
|
||||
|
||||
|
||||
func set_bar_visible(value: bool) -> void:
|
||||
progress_bar.visible = value
|
||||
|
||||
|
||||
func override_fill_color(color: Color) -> void:
|
||||
var style_box := StyleBoxFlat.new()
|
||||
style_box.bg_color = color
|
||||
# Override the 'fill' StyleBox on the ProgressBar
|
||||
progress_bar.add_theme_stylebox_override("fill", style_box)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bv7oracwmgre8
|
||||
@@ -16,7 +16,8 @@
|
||||
"dd822d14-88e5-4790-808e-7d2cf7f79133",
|
||||
"784d5cd3-333a-40a9-b35f-3d0c73f00761",
|
||||
"21bc19f1-ee3c-4bbb-ab9a-07ec6123a823",
|
||||
"d93a31cd-d475-4c5a-87fc-983174b2594f"
|
||||
"d93a31cd-d475-4c5a-87fc-983174b2594f",
|
||||
"9d7ecbc4-db2a-4d09-9f40-ceed3cf98c00"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -242,6 +243,13 @@
|
||||
"description": "",
|
||||
"category": "bf4ec62e-526e-4027-876f-0b22bd17f79a",
|
||||
"steps": []
|
||||
},
|
||||
{
|
||||
"uuid": "9d7ecbc4-db2a-4d09-9f40-ceed3cf98c00",
|
||||
"title": "Add test that a hob can chain cook",
|
||||
"description": "",
|
||||
"category": "bf4ec62e-526e-4027-876f-0b22bd17f79a",
|
||||
"steps": []
|
||||
}
|
||||
],
|
||||
"layout": {
|
||||
|
||||
Reference in New Issue
Block a user