From 055c98b84da0a40945a0899c935e8467ff56df0c Mon Sep 17 00:00:00 2001 From: Atralupus Date: Mon, 20 May 2024 03:21:18 +0900 Subject: [PATCH] fix: GqlClient usage --- frontend/Savor-22b/gql/query.gd | 181 +++++++----------- frontend/Savor-22b/gql/query_executor.gd | 138 +++++++++++++ frontend/Savor-22b/scenes/farm/farm.gd | 114 +++++------ .../Savor-22b/scenes/house/cook/cook_book.gd | 36 ++-- frontend/Savor-22b/scenes/house/house.gd | 87 ++++----- frontend/Savor-22b/scenes/shop/system_shop.gd | 34 ++-- .../Savor-22b/scenes/village/select_house.gd | 44 ++--- 7 files changed, 356 insertions(+), 278 deletions(-) create mode 100644 frontend/Savor-22b/gql/query_executor.gd diff --git a/frontend/Savor-22b/gql/query.gd b/frontend/Savor-22b/gql/query.gd index fdc388be..217aeda0 100644 --- a/frontend/Savor-22b/gql/query.gd +++ b/frontend/Savor-22b/gql/query.gd @@ -1,112 +1,77 @@ -var get_villages_query = "query { - villages { - id - name - width - height - worldX - worldY - } -}" - -var place_house_query_format = "query { - createAction_PlaceUserHouse( - publicKey: {}, - villageId: {}, - x: {}, - y: {} - ) -}" - -var stage_tx_query_format = "mutation { - stageTransaction( - unsignedTransaction:\"%s\", - signature:\"%s\") -}" - -var plant_seed_query_format = "query { - createAction_PlantingSeed( - publicKey: {}, - fieldIndex: {}, - itemStateIdToUse: {} - ) -}" - - -var harvest_seed_query_format = "query { - createAction_HarvestingSeed( - publicKey: {}, - fieldIndex: {} - ) -}" - - -var remove_seed_query_format = "query { - createAction_RemovePlantedSeed( - publicKey: {}, - fieldIndex: {} - ) -}" - -var remove_weed_query_format = "query { - createAction_RemoveWeed( - publicKey: {}, - fieldIndex: {} - ) -}" - - - -var buy_shop_item_query_format = "query { - createAction_BuyShopItem( - publicKey: {}, - desiredShopItemID: {} - ) -}" - -var buy_kitchen_equipment_query_format = "query { - createAction_BuyKitchenEquipment( - publicKey: {}, - desiredEquipmentID: {} - ) -}" - -var install_kitchen_equipment_query_format = "query { - createAction_InstallKitchenEquipmentAction( - publicKey: {}, - kitchenEquipmentStateID: {}, - spaceNumber: {} - ) -}" - -var create_food_query_format = "query { - createAction_CreateFood( - publicKey: {}, - recipeID: {}, - refrigeratorStateIdsToUse: {}, - kitchenEquipmentStateIdsToUse: {} - ) -}" - -var uninstall_kitchen_equipment_query_format = "query { - createAction_UninstallKitchenEquipmentActionQuery( - publicKey: {}, - spaceNumber: {}, - ) -}" - -var calculate_relocation_cost_query_template = GQLQuery.new("calculateRelocationCost").set_args({ +var stage_tx_mutation = GQLQuery.new("stageTransaction").set_args({ + "unsignedTransaction": "unsignedTransaction", + "signature": "signature", +}); + +var get_villages_query = GQLQuery.new("villages").set_props([ + "id", + "name", + "width", + "height", + "worldX", + "worldY" +]); + +var calculate_relocation_cost_query = GQLQuery.new("calculateRelocationCost").set_args({ "villageId": "villageId", - "relocationVillageId": "relocationVillageId", + "relocationVillageId": "relocationVillageId" }).set_props([ "durationBlocks", - "price", -]) + "price" +]); -var calculate_relocation_cost_query = SvrGqlClient.query( - 'CalculateRelocationCost', - { - "villageId": "Int!", - "relocationVillageId": "Int!", - }, - calculate_relocation_cost_query_template) +var place_house_query = GQLQuery.new("createAction_PlaceUserHouse").set_args({ + "publicKey": "publicKey", + "villageId": "villageId", + "x": "x", + "y": "y" +}); + +var plant_seed_query = GQLQuery.new("createAction_PlantingSeed").set_args({ + "publicKey": "publicKey", + "fieldIndex": "fieldIndex", + "itemStateIdToUse": "itemStateIdToUse" +}); + +var harvest_seed_query = GQLQuery.new("createAction_HarvestingSeed").set_args({ + "publicKey": "publicKey", + "fieldIndex": "fieldIndex" +}); + +var remove_seed_query = GQLQuery.new("createAction_RemovePlantedSeed").set_args({ + "publicKey": "publicKey", + "fieldIndex": "fieldIndex" +}); + +var remove_weed_query = GQLQuery.new("createAction_RemoveWeed").set_args({ + "publicKey": "publicKey", + "fieldIndex": "fieldIndex" +}); + +var buy_shop_item_query = GQLQuery.new("createAction_BuyShopItem").set_args({ + "publicKey": "publicKey", + "desiredShopItemID": "desiredShopItemID" +}); + +var buy_kitchen_equipment_query = GQLQuery.new("createAction_BuyKitchenEquipment").set_args({ + "publicKey": "publicKey", + "desiredEquipmentID": "desiredEquipmentID" +}); + +var install_kitchen_equipment_query = GQLQuery.new("createAction_InstallKitchenEquipmentAction").set_args({ + "publicKey": "publicKey", + "kitchenEquipmentStateID": "kitchenEquipmentStateID", + "spaceNumber": "spaceNumber" +}); + +var create_food_query = GQLQuery.new("createAction_CreateFood").set_args({ + "publicKey": "publicKey", + "recipeID": "recipeID", + "refrigeratorStateIdsToUse": "refrigeratorStateIdsToUse", + "kitchenEquipmentStateIdsToUse": "kitchenEquipmentStateIdsToUse" +}); + +var uninstall_kitchen_equipment_query = GQLQuery.new("createAction_UninstallKitchenEquipmentActionQuery").set_args({ + "publicKey": "publicKey", + "spaceNumber": "spaceNumber" +}); diff --git a/frontend/Savor-22b/gql/query_executor.gd b/frontend/Savor-22b/gql/query_executor.gd new file mode 100644 index 00000000..12c30ea7 --- /dev/null +++ b/frontend/Savor-22b/gql/query_executor.gd @@ -0,0 +1,138 @@ +extends Node + +class_name QueryExecutor + +const GqlQuery = preload("res://gql/query.gd"); +var gql_query = GqlQuery.new(); + +var stage_tx_mutation_executor = SvrGqlClient.mutation( + 'StageTransaction', + { + "unsignedTransaction": "String!", + "signature": "String!" + }, + gql_query.stage_tx_mutation +); + +var calculate_relocation_cost_query_executor = SvrGqlClient.query( + 'CalculateRelocationCost', + { + "villageId": "Int!", + "relocationVillageId": "Int!" + }, + gql_query.calculate_relocation_cost_query +); + +var get_villages_query_executor = SvrGqlClient.query( + 'GetVillages', + {}, + gql_query.get_villages_query +); + +var place_house_query_executor = SvrGqlClient.query( + 'PlaceHouse', + { + "publicKey": "String!", + "villageId": "Int!", + "x": "Int!", + "y": "Int!" + }, + gql_query.place_house_query +); + +var plant_seed_query_executor = SvrGqlClient.query( + 'PlantSeed', + { + "publicKey": "String!", + "fieldIndex": "Int!", + "itemStateIdToUse": "Int!" + }, + gql_query.plant_seed_query +); + +var harvest_seed_query_executor = SvrGqlClient.query( + 'HarvestSeed', + { + "publicKey": "String!", + "fieldIndex": "Int!" + }, + gql_query.harvest_seed_query +); + +var remove_seed_query_executor = SvrGqlClient.query( + 'RemoveSeed', + { + "publicKey": "String!", + "fieldIndex": "Int!" + }, + gql_query.remove_seed_query +); + +var remove_weed_query_executor = SvrGqlClient.query( + 'RemoveWeed', + { + "publicKey": "String!", + "fieldIndex": "Int!" + }, + gql_query.remove_weed_query +); + +var buy_shop_item_query_executor = SvrGqlClient.query( + 'BuyShopItem', + { + "publicKey": "String!", + "desiredShopItemID": "Int!" + }, + gql_query.buy_shop_item_query +); + +var buy_kitchen_equipment_query_executor = SvrGqlClient.query( + 'BuyKitchenEquipment', + { + "publicKey": "String!", + "desiredEquipmentID": "Int!" + }, + gql_query.buy_kitchen_equipment_query +); + +var install_kitchen_equipment_query_executor = SvrGqlClient.query( + 'InstallKitchenEquipment', + { + "publicKey": "String!", + "kitchenEquipmentStateID": "Int!", + "spaceNumber": "Int!" + }, + gql_query.install_kitchen_equipment_query +); + +var create_food_query_executor = SvrGqlClient.query( + 'CreateFood', + { + "publicKey": "String!", + "recipeID": "Int!", + "refrigeratorStateIdsToUse": "Int!", + "kitchenEquipmentStateIdsToUse": "Int!" + }, + gql_query.create_food_query +); + +var uninstall_kitchen_equipment_query_executor = SvrGqlClient.query( + 'UninstallKitchenEquipment', + { + "publicKey": "String!", + "spaceNumber": "Int!" + }, + gql_query.uninstall_kitchen_equipment_query +); + +func stage_action(params, query_executor, mutation_executor): + query_executor.graphql_response.connect( + func(data): + var unsigned_tx = data["data"][data["data"].keys()[0]] + var signature = GlobalSigner.sign(unsigned_tx) + mutation_executor.run({ + "unsignedTransaction": unsigned_tx, + "signature": signature + }) + ) + query_executor.run(params) diff --git a/frontend/Savor-22b/scenes/farm/farm.gd b/frontend/Savor-22b/scenes/farm/farm.gd index 624f1e8a..acb1e621 100644 --- a/frontend/Savor-22b/scenes/farm/farm.gd +++ b/frontend/Savor-22b/scenes/farm/farm.gd @@ -10,7 +10,6 @@ const FarmActionPopupScn = preload("res://scenes/farm/farm_action_popup.tscn") const FarmAskRemovePopupScn = preload("res://scenes/farm/farm_ask_remove_popup.tscn") const FarmRemoveDonePopupScn = preload("res://scenes/farm/farm_remove_done_popup.tscn") -const GqlQuery = preload("res://gql/query.gd") @onready var left_farm = $MC/HC/CR/MC/HC/Left @onready var right_farm = $MC/HC/CR/MC/HC/Right @@ -22,7 +21,25 @@ var item_state_Id_to_use var harvested_name var action_success = false +var query_executor = QueryExecutor.new() +var remove_seed_query_executor +var remove_weed_query_executor +var plant_seed_query_executor +var harvest_seed_query_executor +var stage_tx_mutation_executor + func _ready(): + remove_seed_query_executor = query_executor.remove_seed_query_executor + remove_weed_query_executor = query_executor.remove_weed_query_executor + plant_seed_query_executor = query_executor.plant_seed_query_executor + harvest_seed_query_executor = query_executor.harvest_seed_query_executor + stage_tx_mutation_executor = query_executor.stage_tx_mutation_executor + add_child(remove_seed_query_executor) + add_child(remove_weed_query_executor) + add_child(plant_seed_query_executor) + add_child(harvest_seed_query_executor) + add_child(stage_tx_mutation_executor) + farms = SceneContext.user_state["villageState"]["houseFieldStates"] item_state_ids = SceneContext.user_state["inventoryState"]["itemStateList"] @@ -103,23 +120,15 @@ func plant_popup(): func plant_seed(): - var gql_query = GqlQuery.new() - var query_string = gql_query.plant_seed_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - SceneContext.selected_field_index, - "\"%s\"" % item_state_ids[0]["stateID"]], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect( - func(data): - var unsigned_tx = data["data"]["createAction_PlantingSeed"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "fieldIndex": SceneContext.selected_field_index, + "itemStateIdToUse": item_state_ids[0]["stateID"], + }, + plant_seed_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) func set_harvested_name(seed_name): harvested_name = seed_name @@ -137,24 +146,15 @@ func done_popup(): func harvest_seed(): action_success = false - var gql_query = GqlQuery.new() - var query_string = gql_query.harvest_seed_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - SceneContext.selected_field_index], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect( - func(data): - var unsigned_tx = data["data"]["createAction_HarvestingSeed"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "fieldIndex": SceneContext.selected_field_index, + }, + harvest_seed_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) - action_success = true - fetch_new() func action_popup(weed : bool): if is_instance_valid(popup_area): @@ -195,22 +195,15 @@ func control_seed(weed : bool): action_popup(weed) func remove_seed(): - var gql_query = GqlQuery.new() - var query_string = gql_query.remove_seed_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - SceneContext.selected_field_index], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect( - func(data): - var unsigned_tx = data["data"]["createAction_RemovePlantedSeed"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "fieldIndex": SceneContext.selected_field_index, + }, + remove_seed_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) + fetch_new() func fetch_new(): @@ -234,23 +227,14 @@ func fetch_new(): _ready() func remove_weed(): - var gql_query = GqlQuery.new() - var query_string = gql_query.remove_weed_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - SceneContext.selected_field_index], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect( - func(data): - var unsigned_tx = data["data"]["createAction_RemoveWeed"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "fieldIndex": SceneContext.selected_field_index, + }, + remove_weed_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) - fetch_new() func _on_refresh_button_down(): fetch_new() diff --git a/frontend/Savor-22b/scenes/house/cook/cook_book.gd b/frontend/Savor-22b/scenes/house/cook/cook_book.gd index 866a3e32..3c52b8a6 100644 --- a/frontend/Savor-22b/scenes/house/cook/cook_book.gd +++ b/frontend/Savor-22b/scenes/house/cook/cook_book.gd @@ -5,7 +5,6 @@ signal reload_signal signal cook_started const RecipeAvailableScn = preload("res://scenes/house/cook/recipe_available.tscn") -const GqlQuery = preload("res://gql/query.gd") @onready var grid = $background/M/V/S/G @onready var installed_tool = $background/M/V/Description/ToolList @@ -15,7 +14,16 @@ var installed_list = SceneContext.installed_tool_name var available_tool_list : Array var available_recipe_list : Array +var query_executor = QueryExecutor.new() +var create_food_query_executor +var stage_tx_mutation_executor + func _ready(): + create_food_query_executor = query_executor.create_food_query_executor + stage_tx_mutation_executor = query_executor.stage_tx_mutation_executor + add_child(create_food_query_executor) + add_child(stage_tx_mutation_executor) + var format_string = "[%s]" var unique_list = remove_duplicates(installed_list) installed_tool.text = format_string % [", ".join(unique_list)] @@ -78,24 +86,16 @@ func _on_cook_button_down(): else: tool_str = tool_arr[0] - var gql_query = GqlQuery.new() - var query_string = gql_query.create_food_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - SceneContext.selected_recipe_index, - #need to be fixed - "[\"%s\"]" % ingredient_str, - "[\"%s\"]" % tool_str], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect(func(data): - var unsigned_tx = data["data"]["createAction_CreateFood"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "recipeID": SceneContext.selected_recipe_index, + "refrigeratorStateIdsToUse": ingredient_str, + "kitchenEquipmentStateIdsToUse": tool_str + }, + create_food_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) # Init past selected infos SceneContext.selected_ingredients = [] diff --git a/frontend/Savor-22b/scenes/house/house.gd b/frontend/Savor-22b/scenes/house/house.gd index bff681f9..d998ba36 100644 --- a/frontend/Savor-22b/scenes/house/house.gd +++ b/frontend/Savor-22b/scenes/house/house.gd @@ -10,7 +10,6 @@ const BigToolInstallPopupScn = preload("res://scenes/house/big_tool_install_popu const CookBookScn = preload("res://scenes/house/Cook/cook_book.tscn") const CookStartedPopup = preload("res://scenes/house/Cook/cook_started_popup.tscn") const ConfirmPopupScn = preload("res://scenes/common/prefabs/confirm_popup.tscn") -const GqlQuery = preload("res://gql/query.gd") @onready var sub_scene = $M/V/sub_scene @onready var popup = $Popups @@ -19,7 +18,22 @@ const GqlQuery = preload("res://gql/query.gd") var selected_space var cook_book +var query_executor = QueryExecutor.new() +var buy_kitchen_equipment_query_executor +var install_kitchen_equipment_query_executor +var uninstall_kitchen_equipment_query_executor +var stage_tx_mutation_executor + func _ready(): + buy_kitchen_equipment_query_executor = query_executor.buy_kitchen_equipment_query_executor + install_kitchen_equipment_query_executor = query_executor.install_kitchen_equipment_query_executor + uninstall_kitchen_equipment_query_executor = query_executor.uninstall_kitchen_equipment_query_executor + stage_tx_mutation_executor = query_executor.stage_tx_mutation_executor + add_child(buy_kitchen_equipment_query_executor) + add_child(install_kitchen_equipment_query_executor) + add_child(uninstall_kitchen_equipment_query_executor) + add_child(stage_tx_mutation_executor) + load_kitchen() func _on_inventory_button_down(): @@ -47,23 +61,16 @@ func buy_action(): popup.add_child(done_popup) func buy_tool(): - var item_num = SceneContext.selected_item_index - var gql_query = GqlQuery.new() - var query_string = gql_query.buy_kitchen_equipment_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - item_num], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect( - func(data): - var unsigned_tx = data["data"]["createAction_BuyKitchenEquipment"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + var item_num = SceneContext.selected_item_index + + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "desiredEquipmentID": item_num, + }, + buy_kitchen_equipment_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) func clear_popup(): if is_instance_valid(popup): @@ -137,22 +144,15 @@ func on_empty_slot_pressed(spaceNumber : int): selected_space = spaceNumber func install_tool(stateId : String): - var gql_query = GqlQuery.new() - var query_string = gql_query.install_kitchen_equipment_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - "\"%s\"" % stateId, selected_space], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect( - func(data): - var unsigned_tx = data["data"]["createAction_InstallKitchenEquipmentAction"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "kitchenEquipmentStateID": stateId, + "spaceNumber": selected_space, + }, + install_kitchen_equipment_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) func _on_cook_button_down(): var cook_book_area = MarginContainer.new() @@ -188,20 +188,11 @@ func on_uninstall_slot_pressed(spaceNumber: int): confirmPopup.add_child(confirmPopupResource) func uninsatll_big_tool(spaceNumber: int): - var gql_query = GqlQuery.new() - var query_string = gql_query.uninstall_kitchen_equipment_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - "%s" % spaceNumber], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect( - func(data): - var unsigned_tx = data["data"]["createAction_UninstallKitchenEquipmentActionQuery"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "spaceNumber": spaceNumber, + }, + uninstall_kitchen_equipment_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) - diff --git a/frontend/Savor-22b/scenes/shop/system_shop.gd b/frontend/Savor-22b/scenes/shop/system_shop.gd index d27452c6..0336da4e 100644 --- a/frontend/Savor-22b/scenes/shop/system_shop.gd +++ b/frontend/Savor-22b/scenes/shop/system_shop.gd @@ -4,14 +4,23 @@ const ShopItemScn = preload("res://scenes/shop/shop_item.tscn") const AskPopupScn = preload("res://scenes/shop/ask_popup.tscn") const DonePopupScn = preload("res://scenes/shop/done_popup.tscn") -const GqlQuery = preload("res://gql/query.gd") +const GqlQueryExecutor = preload("res://gql/query_executor.gd") @onready var shop_list = $M/H/C/M/S/Lists @onready var popup = $Popups var shop_items = [] +var query_executor = QueryExecutor.new() +var buy_shop_item_query_executor +var stage_tx_mutation_executor + func _ready(): + buy_shop_item_query_executor = query_executor.buy_shop_item_query_executor + stage_tx_mutation_executor = query_executor.stage_tx_mutation_executor + add_child(buy_shop_item_query_executor) + add_child(stage_tx_mutation_executor) + shop_items = SceneContext.shop var size = shop_items.size() @@ -29,22 +38,15 @@ func buy_item(): func buy_query(): var item_num = SceneContext.selected_item_index - var gql_query = GqlQuery.new() - var query_string = gql_query.buy_shop_item_query_format.format([ - "\"%s\"" % GlobalSigner.signer.GetPublicKey(), - item_num], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect( - func(data): - var unsigned_tx = data["data"]["createAction_BuyShopItem"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) - add_child(mutation_executor) - mutation_executor.run({}) + + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "desiredShopItemID": item_num, + }, + buy_shop_item_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) func print_done_popup(): clear_popup() diff --git a/frontend/Savor-22b/scenes/village/select_house.gd b/frontend/Savor-22b/scenes/village/select_house.gd index 53a84ca2..cf343573 100644 --- a/frontend/Savor-22b/scenes/village/select_house.gd +++ b/frontend/Savor-22b/scenes/village/select_house.gd @@ -3,7 +3,6 @@ extends Control const HouseSlotButtonScn = preload("res://scenes/village/house_slot_button.tscn") const NoticePopupScn = preload("res://scenes/common/prefabs/notice_popup.tscn") const ConfirmPopupScn = preload("res://scenes/common/prefabs/confirm_popup.tscn") -const GqlQuery = preload("res://gql/query.gd") @onready var notice_popup = $MarginContainer/Background/Noticepopup @onready var confirm_popup = $MarginContainer/Background/ConfirmPopup @@ -11,8 +10,16 @@ const GqlQuery = preload("res://gql/query.gd") var houses = [] var exist_houses = SceneContext.get_selected_village()["houses"] +var query_executor = QueryExecutor.new() +var place_house_query_executor +var stage_tx_mutation_executor func _ready(): + place_house_query_executor = query_executor.place_house_query_executor + stage_tx_mutation_executor = query_executor.stage_tx_mutation_executor + add_child(place_house_query_executor) + add_child(stage_tx_mutation_executor) + var size = SceneContext.selected_village_capacity grid_container.columns = SceneContext.selected_village_width @@ -72,8 +79,8 @@ func _on_build_button_down(): build_house() func _query_relocation_cost_and_open(): - var gql_query = GqlQuery.new() - gql_query.calculate_relocation_cost_query.graphql_response.connect( + var cost_query_executor = query_executor.calculate_relocation_cost_query_executor + cost_query_executor.graphql_response.connect( func(data): var confirm_popup_scn = ConfirmPopupScn.instantiate() @@ -84,8 +91,8 @@ func _query_relocation_cost_and_open(): confirm_popup_scn.ok_button_clicked_signal.connect(build_house) confirm_popup.add_child(confirm_popup_scn) ) - add_child(gql_query.calculate_relocation_cost_query) - gql_query.calculate_relocation_cost_query.run({ + add_child(cost_query_executor) + cost_query_executor.run({ "villageId": SceneContext.user_state["villageState"]["houseState"]["villageId"], "relocationVillageId": SceneContext.get_selected_village()["id"] }) @@ -95,25 +102,16 @@ func print_notice(): notice_popup.add_child(box) func build_house(): - var gql_query = GqlQuery.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], "{}") - - var query_executor = SvrGqlClient.raw(query_string) - query_executor.graphql_response.connect(func(data): - var unsigned_tx = data["data"]["createAction_PlaceUserHouse"] - var signature = GlobalSigner.sign(unsigned_tx) - var mutation_executor = SvrGqlClient.raw_mutation( - gql_query.stage_tx_query_format % [unsigned_tx, signature] - ) - add_child(mutation_executor) - mutation_executor.run({}) + query_executor.stage_action( + { + "publicKey": GlobalSigner.signer.GetPublicKey(), + "villageId": SceneContext.get_selected_village()["id"], + "x": SceneContext.selected_house_location.x, + "y": SceneContext.selected_house_location.y, + }, + place_house_query_executor, + stage_tx_mutation_executor ) - add_child(query_executor) - query_executor.run({}) func _on_refresh_button_down(): Intro._query_villages()