Commit 16ca120a authored by Gavin An's avatar Gavin An

merged to lv2 할 때 중앙 정렬이 안 됨

parent 18b3c970
...@@ -162,7 +162,7 @@ func can_merge_to_lv2() -> bool: ...@@ -162,7 +162,7 @@ func can_merge_to_lv2() -> bool:
return _get_merge_materials().size() == 3 return _get_merge_materials().size() == 3
## Warrior Lv1 세 기를 Warrior Lv2 한 기로 교체합니다. ## Warrior Lv1 세 기를 Warrior Lv2 한 기로 교체합니다.
## 합성 결과는 클릭된 이 유닛의 위치, 회전, 타일 점유 상태를 이어받고, ## 합성 결과는 클릭된 이 유닛의 전역 좌표 변환값과 타일 점유 상태를 그대로 이어받고,
## 능력치는 DataManager에 등록된 Lv2 템플릿을 그대로 사용합니다. ## 능력치는 DataManager에 등록된 Lv2 템플릿을 그대로 사용합니다.
func merge_to_lv2() -> bool: func merge_to_lv2() -> bool:
var merge_materials: Array[WarriorLv1Unit] = _get_merge_materials() var merge_materials: Array[WarriorLv1Unit] = _get_merge_materials()
...@@ -184,46 +184,20 @@ func merge_to_lv2() -> bool: ...@@ -184,46 +184,20 @@ func merge_to_lv2() -> bool:
push_error("WarriorLv1Unit: Failed to instantiate Warrior Lv2 scene.") push_error("WarriorLv1Unit: Failed to instantiate Warrior Lv2 scene.")
return false return false
var spawn_position: Vector3 = global_position # 합성 대상(클릭한 self)의 월드 좌표를 변형 없이 그대로 보관합니다.
var spawn_rotation: Vector3 = global_rotation var selected_global_transform: Transform3D = global_transform
var was_tile_bound: bool = is_tile_bound var was_tile_bound: bool = is_tile_bound
var tile_cell: Vector3i = occupied_tile_cell var tile_cell: Vector3i = occupied_tile_cell
if was_tile_bound:
# 물리 이동 중 생길 수 있는 현재 좌표의 미세한 오차 대신, GridMap 셀의 실제 중심을 사용합니다.
spawn_position = _get_tile_center(tile_cell, spawn_position)
for material: WarriorLv1Unit in merge_materials: for material: WarriorLv1Unit in merge_materials:
material.queue_free() material.queue_free()
warrior_lv2.unit_data = warrior_lv2_data warrior_lv2.unit_data = warrior_lv2_data
spawn_parent.add_child(warrior_lv2) spawn_parent.add_child(warrior_lv2)
warrior_lv2.global_rotation = spawn_rotation warrior_lv2.global_transform = selected_global_transform
if was_tile_bound: if was_tile_bound:
warrior_lv2.place_on_tile(spawn_position, tile_cell) # place_on_tile()은 이동/타겟 상태만 초기화하고, 위치는 선택한 Lv1의 origin으로 유지합니다.
else: warrior_lv2.place_on_tile(selected_global_transform.origin, tile_cell)
warrior_lv2.global_position = spawn_position
return true return true
## 타일 셀의 월드 중심을 반환합니다. 배치 HUD와 같은 GridMap 변환식을 사용합니다.
func _get_tile_center(tile_cell: Vector3i, fallback_position: Vector3) -> Vector3:
var current_scene: Node = get_tree().current_scene
var grid_map: GridMap = _find_grid_map(current_scene)
if not grid_map:
push_warning("WarriorLv1Unit: GridMap not found; using the current unit position for merge.")
return fallback_position
return grid_map.to_global(grid_map.map_to_local(tile_cell))
func _find_grid_map(node: Node) -> GridMap:
if not node:
return null
if node is GridMap:
return node as GridMap
for child: Node in node.get_children():
var grid_map: GridMap = _find_grid_map(child)
if grid_map:
return grid_map
return null
## 클릭한 Lv1을 첫 재료로 고정하고, 나머지 재료는 필드의 다른 Lv1에서 찾습니다. ## 클릭한 Lv1을 첫 재료로 고정하고, 나머지 재료는 필드의 다른 Lv1에서 찾습니다.
func _get_merge_materials() -> Array[WarriorLv1Unit]: func _get_merge_materials() -> Array[WarriorLv1Unit]:
if not unit_data or unit_data.unit_id != WARRIOR_LV1_ID: if not unit_data or unit_data.unit_id != WARRIOR_LV1_ID:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment