Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

SVR-170: 시스템 상점 내의 아이템 구매 기능 추가 #134

Merged
merged 2 commits into from
Mar 2, 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/Asset.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var asset
var format_string = "%s : %s"

func _ready():
Intro._query_assets()
asset = SceneContext.user_asset
update_asset()

Expand Down
8 changes: 8 additions & 0 deletions frontend/Savor-22b/gql/query.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ var remove_seed_query_format = "query {
fieldIndex: {}
)
}"


var buy_shop_item_query_format = "query {
createAction_BuyShopItem(
publicKey: {},
desiredShopItemID: {}
)
}"
18 changes: 15 additions & 3 deletions frontend/Savor-22b/scenes/shop/ask_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ extends ColorRect

signal buy_button_down

func _ready():
pass # Replace with function body.
@onready var Itemname = $M/V/Itemname

var itemname
var format_string = "%s %s"

func _ready():
update_info()



func update_info():
if itemname == null:
return

Itemname.text = format_string % [itemname, "을(를)
구매하시겠습니까?"]

func _on_buy_button_down():
buy_button_down.emit()


func set_itemname(itemname: String):
self.itemname = itemname

func _on_cancel_button_down():
queue_free()
5 changes: 5 additions & 0 deletions frontend/Savor-22b/scenes/shop/done_popup.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends ColorRect


func _on_ok_button_down():
queue_free()
9 changes: 7 additions & 2 deletions frontend/Savor-22b/scenes/shop/done_popup.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://e4jeslfxnied"]
[gd_scene load_steps=3 format=3 uid="uid://e4jeslfxnied"]

[ext_resource type="Script" path="res://scenes/shop/done_popup.gd" id="1_brj1d"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xo5gb"]
bg_color = Color(0, 0, 0, 1)
Expand All @@ -8,6 +10,7 @@ offset_right = 600.0
offset_bottom = 200.0
pivot_offset = Vector2(-716, 741)
color = Color(1, 0.541176, 0, 1)
script = ExtResource("1_brj1d")

[node name="M" type="MarginContainer" parent="."]
layout_mode = 1
Expand All @@ -34,9 +37,11 @@ theme_override_font_sizes/font_size = 50
text = "구매가 완료되었습니다."
horizontal_alignment = 1

[node name="Cancel" type="Button" parent="M/V"]
[node name="Ok" type="Button" parent="M/V"]
layout_mode = 2
size_flags_horizontal = 4
theme_override_font_sizes/font_size = 40
theme_override_styles/normal = SubResource("StyleBoxFlat_xo5gb")
text = " 확인 "

[connection signal="button_down" from="M/V/Ok" to="." method="_on_ok_button_down"]
6 changes: 4 additions & 2 deletions frontend/Savor-22b/scenes/shop/shop_item.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends ColorRect

signal button_down(item_id: int)
signal button_down

@onready var itemname = $M/V/Itemname
@onready var desc = $M/V/Description/Text
Expand All @@ -26,4 +26,6 @@ func set_item(info: Dictionary):


func _on_buy_button_down():
button_down.emit(item.id)
SceneContext.selected_item_index = item.id
SceneContext.selected_item_name = item.name
button_down.emit()
47 changes: 46 additions & 1 deletion frontend/Savor-22b/scenes/shop/systemshop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ const ITEM = preload("res://scenes/shop/shop_item.tscn")
const SHOP_ASK_POPUP = preload("res://scenes/shop/ask_popup.tscn")
const SHOP_DONE_POPUP = preload("res://scenes/shop/done_popup.tscn")

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

@onready var shoplist = $M/H/C/M/Lists
@onready var popup = $Popups

var shopitems = []



func _ready():
print("shop opened")
shopitems = SceneContext.shop
Expand All @@ -21,14 +25,55 @@ func _ready():
singleitem.set_item(item)
singleitem.button_down.connect(buy_item)
shoplist.add_child(singleitem)



func buy_item():
print("buy item")
var askpopup = SHOP_ASK_POPUP.instantiate()

askpopup.buy_button_down.connect(buyquery)
askpopup.set_itemname(SceneContext.selected_item_name)
popup.add_child(askpopup)


func buyquery():
var itemnum = SceneContext.selected_item_index
var gql_query = Gql_query.new()
var query_string = gql_query.buy_shop_item_query_format.format([
"\"%s\"" % GlobalSigner.signer.GetPublicKey(),
itemnum], "{}")
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_BuyShopItem"]
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({})

print_done_popup()

func print_done_popup():
clear_popup()
var pop = SHOP_DONE_POPUP.instantiate()
popup.add_child(pop)



func clear_popup():
if is_instance_valid(popup):
for pop in popup.get_children():
pop.queue_free()

func _on_close_button_down():
queue_free()
3 changes: 3 additions & 0 deletions frontend/Savor-22b/scripts/global/scene_context.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ var selected_village_height := 0

var selected_field_index := 0

var selected_item_index := 0
var selected_item_name : String

#func _ready():
#var json = JSON.new()
#var error = json.parse(villages_json_string)
Expand Down
5 changes: 0 additions & 5 deletions frontend/Savor-22b/scripts/scenes/intro.gd
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,3 @@ func _query_shop():
add_child(query_executor)
query_executor.run({})


func reload_datas():
_query_villages()
_query_user_state()
_query_assets()
Loading