Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVR-176: 집 설치 API 작업 #120

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/Savor-22b/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ GlobalSigner="*res://scripts/sign/Signer.gd"
SvrGqlClient="*res://gql/svr_gql_client.gd"
SceneContext="*res://scripts/global/scene_context.gd"
GlobalInventory="*res://scripts/global/inventory.gd"
Intro="*res://scripts/scenes/intro.gd"

[display]

Expand Down
27 changes: 27 additions & 0 deletions frontend/Savor-22b/scenes/select_house.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ grow_vertical = 2
theme_override_font_sizes/font_size = 70
text = "Build"

[node name="RefreshButtonContainer" type="ColorRect" parent="BottomMenuMarginContainer/Control"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = 70.0
offset_top = -50.0
offset_right = 430.0
offset_bottom = 50.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 1)

[node name="RefreshButton" type="Button" parent="BottomMenuMarginContainer/Control/RefreshButtonContainer"]
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 = 70
text = "Refresh"

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 0
offset_top = 140.0
Expand Down Expand Up @@ -132,3 +157,5 @@ offset_bottom = 340.0

[connection signal="pressed" from="TopMenuMarginContainer/Control/HomeButtonContainer/Button" to="." method="_on_button_pressed"]
[connection signal="button_down" from="BottomMenuMarginContainer/Control/BuildButtonContainer/BuildButton" to="." method="_on_build_button_button_down"]
[connection signal="button_down" from="BottomMenuMarginContainer/Control/RefreshButtonContainer/RefreshButton" to="." method="_on_build_button_button_down"]
[connection signal="button_down" from="BottomMenuMarginContainer/Control/RefreshButtonContainer/RefreshButton" to="." method="_on_refresh_button_button_down"]
1 change: 1 addition & 0 deletions frontend/Savor-22b/scripts/global/scene_context.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var selected_village_index := 0
var user_state: Dictionary

var selected_house_index := 0
var selected_house_location: Dictionary
var selected_village_capacity := 0
var selected_village_width := 0
var selected_village_height := 0
Expand Down
99 changes: 72 additions & 27 deletions frontend/Savor-22b/scripts/scenes/select_house.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ extends Control

const SELECT_HOUSE_BUTTON = preload("res://ui/house_slot_button.tscn")
const SLOT_IS_FULL = preload("res://ui/notice_popup.tscn")
const Gql_query = preload("res://gql/query.gd")

@onready var noticepopup = $MarginContainer/Background/Noticepopup
@onready var gridcontainer = $MarginContainer/Background/MarginContainer/ScrollContainer/HomeGridContainer

var houses = []
var existhouses = SceneContext.get_selected_village()["houses"]


func _ready():
print("select_house scene ready")
var size = SceneContext.selected_village_capacity
testinput()


gridcontainer.columns = SceneContext.selected_village_width

Expand All @@ -26,54 +26,99 @@ func _ready():
print("endxloc: %s" % endxloc)



#create blank slots
for i in range(size):
var house = {"x" : startxloc, "y" : startyloc, "owner" : "none"}
houses.append(house)
var button = SELECT_HOUSE_BUTTON.instantiate()
button.set_house(house)
button.button_down.connect(button_selected)
gridcontainer.add_child(button)

if(startxloc == endxloc):
startyloc -= 1
startxloc = -(( SceneContext.selected_village_width - 1 ) / 2)
else:
startxloc += 1



#for house in houses:
#var button = SELECT_HOUSE_BUTTON.instantiate()
#print(house)
#button.set_house(house)
#button.button_down.connect(button_selected)
#
#gridcontainer.add_child(button)

pass

func testinput():
houses.append({"x" : 12, "y" : 23, "owner" : "doge"})
houses.append({"x" : 13, "y" : 55, "owner" : "hampter"})
houses.append({"x" : 14, "y" : 78, "owner" : "kirby"})

for h1 in existhouses:
for h2 in houses:
if h1["x"] == h2["x"] and h1["y"] == h2["y"]:
h2["owner"] = h1["owner"]

for info in houses:
var button = SELECT_HOUSE_BUTTON.instantiate()
button.set_house(info)
button.button_down.connect(button_selected)
gridcontainer.add_child(button)


func button_selected(house_index):
var format_string = "house button down: %s"
print(format_string % house_index)
var format_string1 = "house button down: %s"
var format_string2 = "selected slot location: %s"
print(format_string1 % house_index)
print(format_string2 % houses[house_index])
SceneContext.selected_house_index = house_index
SceneContext.selected_house_location = houses[house_index]


func _on_button_pressed():
get_tree().change_scene_to_file("res://scenes/select_village.tscn")


func _on_build_button_button_down():
print_notice()
if (SceneContext.selected_house_location["owner"] != "none"):
print_notice()
else:
build_house()



func print_notice():
var box = SLOT_IS_FULL.instantiate()
noticepopup.add_child(box)

func build_house():
var gql_query = Gql_query.new()
var query_string = gql_query.place_house_query_format.format([
"\"%s\"" % GlobalSigner.signer.GetPublicKey(),
SceneContext.get_selected_village()["id"],
SceneContext.selected_house_location.x,
SceneContext.selected_house_location.y], "{}")
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_PlaceUserHouse"]
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({})



func _on_refresh_button_button_down():
Intro._query_villages()

for child in gridcontainer.get_children():
child.queue_free()

for h0 in houses:
h0["owner"] = "none"

existhouses = SceneContext.get_selected_village()["houses"]
for h1 in existhouses:
for h2 in houses:
if h1["x"] == h2["x"] and h1["y"] == h2["y"]:
h2["owner"] = h1["owner"]

for info in houses:
var button = SELECT_HOUSE_BUTTON.instantiate()
button.set_house(info)
button.button_down.connect(button_selected)
gridcontainer.add_child(button)
2 changes: 2 additions & 0 deletions frontend/Savor-22b/scripts/scenes/select_village.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const SELECT_VILLAGE_VILLAGE_BUTTON = preload("res://ui/select_village_village_b

func _ready():
print("select_village scene ready")
Intro._query_villages()
_update_village_info_label()
for village in SceneContext.villages:
var button = SELECT_VILLAGE_VILLAGE_BUTTON.instantiate()
button.set_village(village)
Expand Down
8 changes: 7 additions & 1 deletion frontend/Savor-22b/ui/house_slot_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ signal button_down(child_index: int)
@onready var button = $Button

var house: Dictionary
var existhouses = SceneContext.get_selected_village()["houses"]

var format_string = "%s
(x = %d, y = %d)"
Expand All @@ -15,13 +16,18 @@ func _ready():
func _update_button():
if button == null:
return

button.text = format_string % [ house.owner, house.x, house.y ]


func set_house(house: Dictionary):
self.house = house
_update_button()

func update_owner():
for h1 in existhouses:
if h1["x"] == house["x"] and h1["y"] == house["y"]:
house["owner"] = h1["owner"]



Expand Down
3 changes: 2 additions & 1 deletion frontend/Savor-22b/ui/house_slot_button.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[node name="HouseSlotButton" type="ColorRect"]
z_as_relative = false
custom_minimum_size = Vector2(200, 150)
custom_minimum_size = Vector2(400, 150)
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
Expand All @@ -33,5 +33,6 @@ theme_override_styles/pressed = SubResource("StyleBoxEmpty_phxol")
theme_override_styles/disabled = SubResource("StyleBoxEmpty_phxol")
theme_override_styles/focus = SubResource("StyleBoxEmpty_phxol")
text = "집 설치 가능"
text_overrun_behavior = 3

[connection signal="button_down" from="Button" to="." method="_on_button_button_down"]
Loading