diff --git a/frontend/Saver-22b-godot/scenes/farm.tscn b/frontend/Saver-22b-godot/scenes/farm.tscn new file mode 100644 index 00000000..67001138 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/farm.tscn @@ -0,0 +1,88 @@ +[gd_scene load_steps=2 format=3 uid="uid://vy5r0acj44oh"] + +[ext_resource type="Script" path="res://scripts/scenes/farm.gd" id="1_q2tum"] + +[node name="Farm" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_q2tum") + +[node name="ColorRect" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"] +layout_mode = 2 +theme_override_constants/separation = 0 + +[node name="ColorRect" type="ColorRect" parent="MarginContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 0.7 +color = Color(0, 0, 0, 1) + +[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/ColorRect"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="GridContainer" type="GridContainer" parent="MarginContainer/HBoxContainer/ColorRect/MarginContainer"] +layout_mode = 2 +theme_override_constants/h_separation = 10 +theme_override_constants/v_separation = 10 +columns = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 0.3 + +[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer/VBoxContainer/MarginContainer"] +layout_mode = 2 + +[node name="HomeButton" type="Button" parent="MarginContainer/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_font_sizes/font_size = 50 +text = "Home" + +[node name="InventoryButton" type="Button" parent="MarginContainer/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_font_sizes/font_size = 50 +text = "Inventory" diff --git a/frontend/Saver-22b-godot/scenes/intro.tscn b/frontend/Saver-22b-godot/scenes/intro.tscn index 74c47cf3..30230aa6 100644 --- a/frontend/Saver-22b-godot/scenes/intro.tscn +++ b/frontend/Saver-22b-godot/scenes/intro.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=3 format=3 uid="uid://cg773cnsx4rb0"] +[gd_scene load_steps=2 format=3 uid="uid://cg773cnsx4rb0"] [ext_resource type="Script" path="res://scripts/scenes/intro.gd" id="1_0m54y"] -[ext_resource type="Script" path="res://scripts/gql_test.gd" id="2_yxm3e"] [node name="Intro" type="Control"] layout_mode = 3 @@ -97,8 +96,5 @@ grow_vertical = 2 theme_override_font_sizes/font_size = 70 text = "Play" -[node name="gql_test" type="Node" parent="."] -script = ExtResource("2_yxm3e") - [connection signal="button_down" from="QuitButtonContainer/Button" to="." method="_on_quit_button_button_down"] [connection signal="button_down" from="PlayButtonContainer/Button" to="." method="_on_play_button_button_down"] diff --git a/frontend/Saver-22b-godot/scripts/global/scene_context.gd b/frontend/Saver-22b-godot/scripts/global/scene_context.gd index 431d531c..700c3eb9 100644 --- a/frontend/Saver-22b-godot/scripts/global/scene_context.gd +++ b/frontend/Saver-22b-godot/scripts/global/scene_context.gd @@ -1,10 +1,59 @@ extends Node +#var villages_json_string := """{ + #"villages": [ + #{ + #"id": 1, + #"name": "평범한 도시 1", + #"width": 3, + #"height": 11, + #"worldX": 5, + #"worldY": 1, + #"houses": [ + #{ + #"x": 1, + #"y": 1, + #"owner": "0x53103C2D7875D2f5f02AeC3075155e268a6e3A94" + #} + #] + #}, + #{ + #"id": 2, + #"name": "외로운 섬", + #"width": 7, + #"height": 13, + #"worldX": -2, + #"worldY": 7, + #"houses": [] + #}, + #{ + #"id": 3, + #"name": "정글", + #"width": 3, + #"height": 5, + #"worldX": 1, + #"worldY": -3, + #"houses": [] + #} + #] + #}""" var villages: Array var selected_village_index := 0 +var user_state: Dictionary + +#func _ready(): + #var json = JSON.new() + #var error = json.parse(villages_json_string) + #if error != OK: + #print(error) + #else: + #villages = json.data.villages func set_villages(query_data: Dictionary): villages = query_data.data.villages +func set_user_state(query_data: Dictionary): + user_state = query_data.data.userState + func get_selected_village(): return villages[selected_village_index] diff --git a/frontend/Saver-22b-godot/scripts/scenes/farm.gd b/frontend/Saver-22b-godot/scripts/scenes/farm.gd new file mode 100644 index 00000000..d5252b81 --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/scenes/farm.gd @@ -0,0 +1,4 @@ +extends Control + +func _ready(): + print("farm scene ready") diff --git a/frontend/Saver-22b-godot/scripts/scenes/intro.gd b/frontend/Saver-22b-godot/scripts/scenes/intro.gd index ada2e83d..ec87c59a 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/intro.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/intro.gd @@ -3,6 +3,7 @@ extends Control func _ready(): print("intro scene ready") _query_villages() + _query_user_state() func _on_quit_button_button_down(): print("quit button down") @@ -26,9 +27,82 @@ func _query_villages(): "owner", ]), ]) - + print(query.serialize()) var query_executor = SvrGqlClient.query('query', {}, query) - query_executor.graphql_response.connect(func(data): - SceneContext.set_villages(data)) + query_executor.graphql_response.connect( + func(data): + SceneContext.set_villages(data) + ) add_child(query_executor) query_executor.run({}) + +func _query_user_state(): + print("signer address: %s" % GlobalSigner.signer_address) + var query = GQLQuery.new("userState").set_args({ + "signer_address": "address", + }).set_props([ + GQLQuery.new("inventoryState").set_props([ + GQLQuery.new("seedStateList").set_props([ + "stateId", + "seedId", + "name", + ]), + GQLQuery.new("refrigeratorStateList").set_props([ + "stateId", + "ingredientId", + "foodID", + "name", + "grade", + "hp", + "attack", + "defense", + "speed", + "isSuperFood", + "isAvailable", + ]), + GQLQuery.new("kitchenEquipmentStateList").set_props([ + "stateId", + "equipmentId", + "equipmentName", + "blockTimeReductionPercent", + "equipmentCategoryId", + "equipmentCategoryName", + "equipmentCategoryType", + "isCooking", + "cookingEndBlockIndex", + GQLQuery.new("cookingFood").set_props([ + "stateId", + "ingredientId", + "foodID", + "name", + "grade", + "hp", + "attack", + "defense", + "speed", + "isSuperFood", + "isAvailable", + ]), + ]), + GQLQuery.new("itemStateList").set_props([ + "stateID", + "itemID", + "itemName", + ]), + ]), + ]) + print(query.serialize()) + var query_executor = SvrGqlClient.query( + 'query', + { + "signer_address": "String!", + }, + query) + query_executor.graphql_response.connect( + func(data): + SceneContext.set_user_state(data) + ) + add_child(query_executor) + query_executor.run({ + "signer_address": GlobalSigner.signer_address + }) diff --git a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd index e0b84a90..9db991cf 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd @@ -28,3 +28,4 @@ func _on_village_button_button_down(village_index): func _on_start_button_button_down(): print("start button down: %s" % SceneContext.selected_village_index) get_tree().change_scene_to_file("res://village_view/VillageView.tscn") + #get_tree().change_scene_to_file("res://scenes/farm.tscn") diff --git a/frontend/Saver-22b-godot/scripts/sign/Signer.gd b/frontend/Saver-22b-godot/scripts/sign/Signer.gd index 20e76d3d..9bae0a38 100644 --- a/frontend/Saver-22b-godot/scripts/sign/Signer.gd +++ b/frontend/Saver-22b-godot/scripts/sign/Signer.gd @@ -1,6 +1,7 @@ extends Node; var signer +var signer_address func _ready(): var script = load("res://scripts/sign/Signer.cs") @@ -14,6 +15,8 @@ func _ready(): var f = FileAccess.open("user://privkey", FileAccess.WRITE) f.store_string(signer.GetRaw()) f.close() + + signer_address = signer.GetAddress() func sign(unsignedTransaction: String) -> String: return self.signer.Sign(unsignedTransaction) diff --git a/frontend/Saver-22b-godot/ui/farm_slot_button.gd b/frontend/Saver-22b-godot/ui/farm_slot_button.gd new file mode 100644 index 00000000..effed01b --- /dev/null +++ b/frontend/Saver-22b-godot/ui/farm_slot_button.gd @@ -0,0 +1,28 @@ +extends ColorRect + +signal button_down(child_index: int) + +@onready var button = $Button + +var farm_slot: Dictionary + +func _ready(): + _update_button() + +func _update_button(): + if button == null: + return + + button.text = """%s %s + (%d %s)""" % [ + "벼", + "자라는 중", + 1, + "블록 남음"] + +func set_farm_slot(farm_slot: Dictionary): + self.farm_slot = farm_slot + _update_button() + +func _on_button_button_down(): + button_down.emit(get_index()) diff --git a/frontend/Saver-22b-godot/ui/farm_slot_button.tscn b/frontend/Saver-22b-godot/ui/farm_slot_button.tscn new file mode 100644 index 00000000..5f930c51 --- /dev/null +++ b/frontend/Saver-22b-godot/ui/farm_slot_button.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=2 format=3 uid="uid://c0qm0ud7mwmwb"] + +[ext_resource type="Script" path="res://ui/farm_slot_button.gd" id="1_vqq1f"] + +[node name="FarmSlotButton" type="ColorRect"] +custom_minimum_size = Vector2(2.08165e-12, 200) +size_flags_horizontal = 3 +size_flags_vertical = 0 +script = ExtResource("1_vqq1f") + +[node name="Button" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_font_sizes/font_size = 50 +text = "[벼] 자라는 중 +[N 블록 남음]"