Skip to content

Commit

Permalink
Merge pull request #108 from not-blond-beard/feat/farm
Browse files Browse the repository at this point in the history
feat: implement farm #1
  • Loading branch information
boscohyun authored Dec 21, 2023
2 parents 8d16958 + bc0ea49 commit d969775
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 8 deletions.
88 changes: 88 additions & 0 deletions frontend/Saver-22b-godot/scenes/farm.tscn
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 1 addition & 5 deletions frontend/Saver-22b-godot/scenes/intro.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"]
49 changes: 49 additions & 0 deletions frontend/Saver-22b-godot/scripts/global/scene_context.gd
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 4 additions & 0 deletions frontend/Saver-22b-godot/scripts/scenes/farm.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends Control

func _ready():
print("farm scene ready")
80 changes: 77 additions & 3 deletions frontend/Saver-22b-godot/scripts/scenes/intro.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
})
1 change: 1 addition & 0 deletions frontend/Saver-22b-godot/scripts/scenes/select_village.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
3 changes: 3 additions & 0 deletions frontend/Saver-22b-godot/scripts/sign/Signer.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extends Node;

var signer
var signer_address

func _ready():
var script = load("res://scripts/sign/Signer.cs")
Expand All @@ -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)
28 changes: 28 additions & 0 deletions frontend/Saver-22b-godot/ui/farm_slot_button.gd
Original file line number Diff line number Diff line change
@@ -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())
20 changes: 20 additions & 0 deletions frontend/Saver-22b-godot/ui/farm_slot_button.tscn
Original file line number Diff line number Diff line change
@@ -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 블록 남음]"

0 comments on commit d969775

Please sign in to comment.