Skip to content

Commit

Permalink
[SVR-330] [부엌] 음식 조리하기 (#171)
Browse files Browse the repository at this point in the history
* feat: create food implment

* feat: refrigerator in inventory ui

* fix: main tool food appears in sub tool food area
  • Loading branch information
kth1888 authored Apr 24, 2024
1 parent 66f901f commit e873459
Show file tree
Hide file tree
Showing 43 changed files with 1,237 additions and 768 deletions.
11 changes: 10 additions & 1 deletion frontend/Savor-22b/gql/query.gd
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ var install_kitchen_equipment_query_format = "query {
)
}"

var create_food_query_format = "query {
createAction_CreateFood(
publicKey: {},
recipeID: {},
refrigeratorStateIdsToUse: {},
kitchenEquipmentStateIdsToUse: {}
)
}"

var uninstall_kitchen_equipment_query_format = "query {
createAction_UninstallKitchenEquipmentActionQuery(
publicKey: {},
Expand All @@ -100,4 +109,4 @@ var calculate_relocation_cost_query = SvrGqlClient.query(
"villageId": "Int!",
"relocationVillageId": "Int!",
},
calculate_relocation_cost_query_template)
calculate_relocation_cost_query_template)
123 changes: 123 additions & 0 deletions frontend/Savor-22b/scenes/house/Cook/cook_book.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
extends Control

signal closeall
signal reload_signal
signal cook_started

const RECIPE = preload("res://scenes/house/Cook/recipe_available.tscn")

@onready var grid = $background/M/V/S/G
@onready var installed_tool = $background/M/V/Description/ToolList

const Gql_query = preload("res://gql/query.gd")

var recipe_list = SceneContext.recipe["recipe"]
var installed_list = SceneContext.installed_tool_name
var available_tool_list : Array
var available_recipe_list : Array

func _ready():
var format_string = "[%s]"
var unique_list = remove_duplicates(installed_list)
installed_tool.text = format_string % [", ".join(unique_list)]

filter_recipe()

for recipe_data in recipe_list:
print("recipe")
print(recipe_data)
for name in available_tool_list:
for tool in recipe_data["requiredKitchenEquipmentCategoryList"]:
if name == tool.name:
available_recipe_list.append(recipe_data)
var recipe = RECIPE.instantiate()
recipe.set_info(recipe_data)
recipe.select_signal.connect(recipe_selected)
grid.add_child(recipe)

func filter_recipe():
# 작은 조리도구 이름 추출
var small_tool_name : Array
var all_equipment_list = SceneContext.shop["kitchenEquipments"]
for equipment in all_equipment_list:
if equipment["categoryType"] == "sub":
small_tool_name.append(equipment["name"])

available_tool_list.append_array(small_tool_name)
available_tool_list.append_array(installed_list)


func remove_duplicates(array):
var unique_elements = []
for item in array:
if not unique_elements.has(item):
unique_elements.append(item)

return unique_elements


func recipe_selected(recipe_index):
SceneContext.selected_recipe_index = recipe_index

# Visual toggle
for recipe in grid.get_children():
if(recipe.get_index() != recipe_index):
recipe.disable_button_selected()





func _on_close_button_down():
queue_free()
closeall.emit()


func _on_cook_button_down():
var ingarr = SceneContext.selected_ingredients
var toolarr = SceneContext.selected_tools
var ingstr
var toolstr

if ingarr.size() > 1 :
ingstr = "\", \"".join(ingarr)
else:
ingstr = ingarr[0]
if toolarr.size() > 1 :
toolstr = "\", \"".join(toolarr)
else:
toolstr = toolarr[0]
print(ingstr)
print(toolstr)

var gql_query = Gql_query.new()
var query_string = gql_query.create_food_query_format.format([
"\"%s\"" % GlobalSigner.signer.GetPublicKey(),
SceneContext.selected_recipe_index,
#need to be fixed
"[\"%s\"]" % ingstr,
"[\"%s\"]" % toolstr], "{}")
print(query_string)

var query_executor = SvrGqlClient.raw(query_string)
query_executor.graphql_response.connect(func(data):
print("gql response: ", data)
var unsigned_tx = data["data"]["createAction_CreateFood"]
print("unsigned tx: ", unsigned_tx)
var signature = GlobalSigner.sign(unsigned_tx)
print("signed tx: ", signature)
var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature])
mutation_executor.graphql_response.connect(func(data):
print("mutation res: ", data)
)
add_child(mutation_executor)
mutation_executor.run({})
)
add_child(query_executor)
query_executor.run({})

# Init past selected infos
SceneContext.selected_ingredients = []
SceneContext.selected_tools = []

cook_started.emit()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=7 format=3 uid="uid://paaor8um57hy"]
[gd_scene load_steps=7 format=3 uid="uid://bb0hth2o7k30q"]

[ext_resource type="Script" path="res://scenes/house/recipebook/recipebook.gd" id="1_2wc5e"]
[ext_resource type="Script" path="res://scenes/house/Cook/cook_book.gd" id="1_q1ejr"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tvose"]
bg_color = Color(0.94902, 0.694118, 0.0784314, 1)
Expand Down Expand Up @@ -34,13 +34,13 @@ corner_radius_top_right = 15
corner_radius_bottom_right = 15
corner_radius_bottom_left = 15

[node name="Recipebook" type="Control"]
[node name="Cookbook" type="Control"]
custom_minimum_size = Vector2(1600, 900)
layout_mode = 3
anchors_preset = 0
offset_right = 1600.0
offset_bottom = 900.0
script = ExtResource("1_2wc5e")
script = ExtResource("1_q1ejr")

[node name="background" type="Panel" parent="."]
custom_minimum_size = Vector2(1600, 900)
Expand Down Expand Up @@ -79,15 +79,15 @@ layout_mode = 2
size_flags_vertical = 4
alignment = 1

[node name="Desc" type="Label" parent="background/M/V/Description"]
[node name="Text" type="Label" parent="background/M/V/Description"]
layout_mode = 2
size_flags_horizontal = 4
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_fonts/font = SubResource("FontVariation_eybux")
theme_override_font_sizes/font_size = 45
text = "현재 설치된 조리도구"

[node name="ription" type="Label" parent="background/M/V/Description"]
[node name="ToolList" type="Label" parent="background/M/V/Description"]
layout_mode = 2
size_flags_horizontal = 4
theme_override_colors/font_color = Color(0, 0, 0, 1)
Expand Down Expand Up @@ -126,3 +126,4 @@ theme_override_styles/normal = SubResource("StyleBoxFlat_rle7u")
text = "선택한 레시피로 조리하기"

[connection signal="button_down" from="background/M/V/BottomMenu/Close" to="." method="_on_close_button_down"]
[connection signal="button_down" from="background/M/V/BottomMenu/Cook" to="." method="_on_cook_button_down"]
13 changes: 13 additions & 0 deletions frontend/Savor-22b/scenes/house/Cook/cook_started_popup.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends Control

signal close_book

# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.




func _on_button_pressed():
close_book.emit()
58 changes: 58 additions & 0 deletions frontend/Savor-22b/scenes/house/Cook/cook_started_popup.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[gd_scene load_steps=3 format=3 uid="uid://dyxrqvghkcb0x"]

[ext_resource type="Script" path="res://scenes/house/Cook/cook_started_popup.gd" id="1_4u6i2"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_e6j35"]
bg_color = Color(0.313726, 0.313726, 0.313726, 1)
corner_radius_top_left = 40
corner_radius_top_right = 40
corner_radius_bottom_right = 40
corner_radius_bottom_left = 40

[node name="cook_started_popup" type="Control"]
custom_minimum_size = Vector2(500, 250)
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_4u6i2")

[node name="Panel" type="Panel" parent="."]
custom_minimum_size = Vector2(500, 250)
layout_mode = 0
offset_left = 600.0
offset_top = 400.0
offset_right = 1100.0
offset_bottom = 650.0
theme_override_styles/panel = SubResource("StyleBoxFlat_e6j35")

[node name="M" type="MarginContainer" parent="Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_top = 50

[node name="V" type="VBoxContainer" parent="Panel/M"]
layout_mode = 2
theme_override_constants/separation = 30

[node name="Label" type="Label" parent="Panel/M/V"]
layout_mode = 2
theme_override_font_sizes/font_size = 40
text = "조리를 시작합니다."
horizontal_alignment = 1
vertical_alignment = 1

[node name="Button" type="Button" parent="Panel/M/V"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_font_sizes/font_size = 40
text = " 확인 "

[connection signal="pressed" from="Panel/M/V/Button" to="." method="_on_button_pressed"]
49 changes: 49 additions & 0 deletions frontend/Savor-22b/scenes/house/Cook/ingredient.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extends Control

signal select_ingredient(name : String)
signal select_tool(name : String)

@onready var button = $Ing
@onready var empty = $Empty

var ingname
var format_string = "[%s]
사용 가능"
var isTool = false

func _ready():
update_info()




func set_ingname(name: String):
ingname = name

func get_ingname():
return ingname

func disable_button():
button.disabled = true
empty.set_visible(true)
button.text = "[%s]
" % [ingname]

func update_info():
button.text = format_string % [ingname]

func set_toggled(state: bool):
button.set_toggle_mode(state)

func change_state_text():
button.text = "[%s]
선택됨" % [ingname]

func button_is_tool():
isTool = true

func _on_ing_button_down():
if (isTool):
select_tool.emit(ingname)
else:
select_ingredient.emit(ingname)
74 changes: 74 additions & 0 deletions frontend/Savor-22b/scenes/house/Cook/ingredient.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[gd_scene load_steps=6 format=3 uid="uid://c0ui8bu7d5c3c"]

[ext_resource type="Script" path="res://scenes/house/Cook/ingredient.gd" id="1_0odus"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jup0i"]
bg_color = Color(0.94902, 0.596078, 0.0784314, 1)
corner_radius_top_left = 20
corner_radius_top_right = 20
corner_radius_bottom_right = 20
corner_radius_bottom_left = 20

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8gche"]
corner_radius_top_left = 20
corner_radius_top_right = 20
corner_radius_bottom_right = 20
corner_radius_bottom_left = 20

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_snsw5"]
bg_color = Color(0.94902, 0.596078, 0.0784314, 1)
border_width_left = 10
border_width_top = 10
border_width_right = 10
border_width_bottom = 10
border_color = Color(1, 1, 1, 1)
corner_radius_top_left = 20
corner_radius_top_right = 20
corner_radius_bottom_right = 20
corner_radius_bottom_left = 20

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_76ikv"]
corner_radius_top_left = 20
corner_radius_top_right = 20
corner_radius_bottom_right = 20
corner_radius_bottom_left = 20

[node name="ingredient" type="Control"]
custom_minimum_size = Vector2(180, 110)
layout_mode = 3
anchors_preset = 0
offset_right = 180.0
offset_bottom = 110.0
script = ExtResource("1_0odus")

[node name="Ing" type="Button" parent="."]
custom_minimum_size = Vector2(180, 110)
layout_mode = 0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 25
theme_override_styles/normal = SubResource("StyleBoxFlat_jup0i")
theme_override_styles/hover = SubResource("StyleBoxFlat_8gche")
theme_override_styles/pressed = SubResource("StyleBoxFlat_snsw5")
theme_override_styles/disabled = SubResource("StyleBoxFlat_76ikv")
toggle_mode = true
text = "[춘장]
"

[node name="Empty" type="Label" parent="."]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_colors/font_color = Color(1, 0, 0, 1)
theme_override_font_sizes/font_size = 25
text = "
없음
"
horizontal_alignment = 1
vertical_alignment = 1

[connection signal="button_down" from="Ing" to="." method="_on_ing_button_down"]
Loading

0 comments on commit e873459

Please sign in to comment.