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

집 선택 화면에 던전 리스트 추가 #192

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 14 additions & 0 deletions frontend/Savor-22b/gql/models/dungeon.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Resource

class_name DungeonData

@export var x: int
@export var y: int
@export var name: String

func from_dict(data: Dictionary) -> DungeonData:
var instance = DungeonData.new()
instance.x = data["x"]
instance.y = data["y"]
instance.name = data["name"]
return instance
14 changes: 14 additions & 0 deletions frontend/Savor-22b/gql/models/house.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Resource

class_name HouseData

@export var x: int
@export var y: int
@export var owner: String

func from_dict(data: Dictionary) -> HouseData:
var instance = HouseData.new()
instance.x = data["x"]
instance.y = data["y"]
instance.owner = data["owner"]
return instance
30 changes: 30 additions & 0 deletions frontend/Savor-22b/gql/models/village.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extends Resource

class_name VillageData

@export var id: int
@export var name: String
@export var width: int
@export var height: int
@export var worldX: int
@export var worldY: int
@export var houses: Array
@export var dungeons: Array

func from_dict(data: Dictionary) -> VillageData:
var instance = VillageData.new()
instance.id = data["id"]
instance.name = data["name"]
instance.width = data["width"]
instance.height = data["height"]
instance.worldX = data["worldX"]
instance.worldY = data["worldY"]

instance.houses = []
for house in data["houses"]:
instance.houses.append(HouseData.new().from_dict(house))

instance.dungeons = []
for dungeon in data["dungeons"]:
instance.dungeons.append(DungeonData.new().from_dict(dungeon))
return instance
28 changes: 19 additions & 9 deletions frontend/Savor-22b/gql/query.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ var stage_tx_mutation = GQLQuery.new("stageTransaction").set_args({
"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"
Expand Down Expand Up @@ -75,3 +66,22 @@ var uninstall_kitchen_equipment_query = GQLQuery.new("createAction_UninstallKitc
"publicKey": "publicKey",
"spaceNumber": "spaceNumber"
});

var get_houses_and_dungeons_query = GQLQuery.new("villages").set_props([
"id",
"name",
"width",
"height",
"worldX",
"worldY",
GQLQuery.new("houses").set_props([
"x",
"y",
"owner",
]),
GQLQuery.new("dungeons").set_props([
"x",
"y",
"name",
]),
]);
8 changes: 4 additions & 4 deletions frontend/Savor-22b/gql/query_executor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ var calculate_relocation_cost_query_executor = SvrGqlClient.query(
gql_query.calculate_relocation_cost_query
);

var get_villages_query_executor = SvrGqlClient.query(
'GetVillages',
var get_houses_and_dungeons_query_executor = SvrGqlClient.query(
'GetHousesAndDungeons',
{},
gql_query.get_villages_query
gql_query.get_houses_and_dungeons_query
);

var place_house_query_executor = SvrGqlClient.query(
Expand All @@ -45,7 +45,7 @@ var plant_seed_query_executor = SvrGqlClient.query(
{
"publicKey": "String!",
"fieldIndex": "Int!",
"itemStateIdToUse": "Int!"
"itemStateIdToUse": "Guid!"
},
gql_query.plant_seed_query
);
Expand Down
41 changes: 19 additions & 22 deletions frontend/Savor-22b/scenes/village/house_slot_button.gd
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
extends ColorRect

signal button_down(child_index: int)
signal button_down(x: int, y: int)

@onready var button = $Button

var house: Dictionary
var exist_houses = SceneContext.get_selected_village()["houses"]
var entity = {}

var format_string = "%s
(x = %d, y = %d)"
var house_format_string = "%s의 집\n(x = %d, y = %d)"
var dungeon_format_string = "%s\n(x = %d, y = %d)"
var default_format_string = "(x = %d, y = %d)"

func _ready():
_update_button()
pass

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 exist_houses:
if h1["x"] == house["x"] and h1["y"] == house["y"]:
house["owner"] = h1["owner"]
func _update_text():
if entity.get("house", null) != null:
button.text = house_format_string % [entity.house.owner.substr(0, 6), entity.x, entity.y]
elif entity.get("dungeon", null) != null:
button.text = dungeon_format_string % [entity.dungeon.name, entity.x, entity.y]
else:
button.text = default_format_string % [entity.x, entity.y]

func set_entity(entity):
self.entity = entity
_update_text()

func disable_button_selected():
if(button.button_pressed):
button.button_pressed = false

func disable_button():
button.disabled = true

func _on_button_down():
button_down.emit(get_index())
button_down.emit(entity.x, entity.y)
137 changes: 76 additions & 61 deletions frontend/Savor-22b/scenes/village/select_house.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,82 @@ 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 HouseData = preload("res://gql/models/house.gd")
const DungeonData = preload("res://gql/models/dungeon.gd")
const VillageData = preload("res://gql/models/village.gd")

@onready var notice_popup = $MarginContainer/Background/Noticepopup
@onready var confirm_popup = $MarginContainer/Background/ConfirmPopup
@onready var grid_container = $MarginContainer/Background/MarginContainer/ScrollContainer/HomeGridContainer

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
var get_houses_and_dungeons_query_executor
var calculate_relocation_cost_query_executor

func _ready():
var village_entities = []
var selected_entity = null

func register_query_executor():
place_house_query_executor = query_executor.place_house_query_executor
stage_tx_mutation_executor = query_executor.stage_tx_mutation_executor
get_houses_and_dungeons_query_executor = query_executor.get_houses_and_dungeons_query_executor
calculate_relocation_cost_query_executor = query_executor.calculate_relocation_cost_query_executor
add_child(place_house_query_executor)
add_child(stage_tx_mutation_executor)
add_child(get_houses_and_dungeons_query_executor)
add_child(calculate_relocation_cost_query_executor)

var size = SceneContext.selected_village_capacity

grid_container.columns = SceneContext.selected_village_width

var start_x_loc = -(( SceneContext.selected_village_width - 1 ) / 2)
var start_y_loc = (SceneContext.selected_village_height -1 ) / 2
var end_x_loc = ( SceneContext.selected_village_width - 1 ) / 2

#create blank slots
for i in range(size):
var house = {"x" : start_x_loc, "y" : start_y_loc, "owner" : "none"}
houses.append(house)
func _ready():
register_query_executor()

get_houses_and_dungeons_query_executor.graphql_response.connect(
func(data):
handle_houses_and_dungeons_response(data)
)
get_houses_and_dungeons_query_executor.run({})

func handle_houses_and_dungeons_response(data):
var villages = []
for village_data in data.get("data").get("villages"):
var village = VillageData.new().from_dict(village_data)
villages.append(village)

draw_houses_and_dungeons(villages[SceneContext.selected_village_index])

func draw_houses_and_dungeons(village: VillageData):
grid_container.columns = village.width

for i in range(village.height):
village_entities.append([])

for y in range(1, village["height"] + 1):
for x in range(1, village["width"] + 1):
var entity = {"x": x, "y": y, "house": null, "dungeon": null}
village_entities[y - 1].append(entity)

for house in village.houses:
village_entities[house.y - 1][house.x - 1].house = house

if(start_x_loc == end_x_loc):
start_y_loc -= 1
start_x_loc = -(( SceneContext.selected_village_width - 1 ) / 2)
else:
start_x_loc += 1
for dungeon in village.dungeons:
village_entities[dungeon.y - 1][dungeon.x - 1].dungeon = dungeon

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

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

func button_selected(house_index):
var format_string1 = "house button down: %s"
var format_string2 = "selected slot location: %s"
SceneContext.selected_house_index = house_index
SceneContext.selected_house_location = houses[house_index]
for row in village_entities:
for entity in row:
var button = HouseSlotButtonScn.instantiate()
grid_container.add_child(button)
button.set_entity(entity)
button.button_down.connect(button_selected)

#Toggle mode
func button_selected(x: int, y: int):
selected_entity = { "x": x, "y": y }

# Calc lagacy house index
var house_index = (y-1) * len(village_entities[0]) + x
SceneContext.selected_house_index = house_index
SceneContext.selected_house_location = village_entities[y - 1][x - 1]
#
for slot in grid_container.get_children():
if(slot.get_index() != house_index):
slot.disable_button_selected()
Expand All @@ -65,7 +88,11 @@ func _on_button_pressed():
get_tree().change_scene_to_file("res://scenes/village/select_village.tscn")

func _on_build_button_down():
if (SceneContext.selected_house_location["owner"] != "none"):
var dungeon = village_entities[selected_entity.y - 1][selected_entity.x - 1].get("dungeon", null)
var house = village_entities[selected_entity.y - 1][selected_entity.x - 1].get("house", null)
if (dungeon != null):
print_notice()
if (house != null):
print_notice()
else:
var isHouseOwner = false
Expand All @@ -76,23 +103,22 @@ func _on_build_button_down():
if (isHouseOwner):
_query_relocation_cost_and_open()
else:
build_house()
build_house(selected_entity.x, selected_entity.y)

func _query_relocation_cost_and_open():
var cost_query_executor = query_executor.calculate_relocation_cost_query_executor
cost_query_executor.graphql_response.connect(
calculate_relocation_cost_query_executor.graphql_response.connect(
func(data):
var confirm_popup_scn = ConfirmPopupScn.instantiate()

confirm_popup_scn.set_label("%s 블록이 소요되며 %sBBG 가 필요합니다." % [
str(data.data.calculateRelocationCost.durationBlocks),
str(data.data.calculateRelocationCost.price)
])
confirm_popup_scn.ok_button_clicked_signal.connect(build_house)
confirm_popup_scn.ok_button_clicked_signal.connect(build_house(selected_entity.x, selected_entity.y))
confirm_popup.add_child(confirm_popup_scn)
)
add_child(cost_query_executor)
cost_query_executor.run({

calculate_relocation_cost_query_executor.run({
"villageId": SceneContext.user_state["villageState"]["houseState"]["villageId"],
"relocationVillageId": SceneContext.get_selected_village()["id"]
})
Expand All @@ -101,13 +127,13 @@ func print_notice():
var box = NoticePopupScn.instantiate()
notice_popup.add_child(box)

func build_house():
func build_house(x: int, y: int):
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,
"x": x,
"y": y,
},
place_house_query_executor,
stage_tx_mutation_executor
Expand All @@ -119,20 +145,9 @@ func _on_refresh_button_down():
for child in grid_container.get_children():
child.queue_free()

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

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

for info in houses:
var button = HouseSlotButtonScn.instantiate()
button.set_house(info)
button.button_down.connect(button_selected)
grid_container.add_child(button)
village_entities = []

get_houses_and_dungeons_query_executor.run({})

func _on_back_button_down():
get_tree().change_scene_to_file("res://scenes/village/village_view.tscn")
Loading