fixed finally webrtc
This commit is contained in:
@@ -764,6 +764,19 @@ func _place_torches_in_room(room: Dictionary, grid: Array, all_doors: Array, _ma
|
||||
# We need to check all valid Y positions on the left/right walls and place at torch_y_from_floor
|
||||
# Left/right walls are valid from room.y + 2 to room.y + room.h - 2 (skipping 2-tile corners)
|
||||
for y in range(room.y + 2, room.y + room.h - 2):
|
||||
# First check if there's a door at this Y position on the left wall
|
||||
# Left door (dir="W") is 3 tiles tall, so check if y is in any door's Y range
|
||||
var has_door_at_y = false
|
||||
for door in all_doors:
|
||||
var door_dir = door.dir if "dir" in door else ""
|
||||
if door_dir == "W" and door.x == room.x:
|
||||
# Left door at room.x, check if y is within door's Y range (door.y to door.y + 3)
|
||||
if y >= door.y and y <= door.y + 3:
|
||||
has_door_at_y = true
|
||||
break
|
||||
if has_door_at_y:
|
||||
continue # Skip this Y position if there's a door here
|
||||
|
||||
# Check if this is a valid left wall position
|
||||
# Left wall has 2 tiles: room.x and room.x + 1
|
||||
# Check both tiles to ensure we're not placing on a door
|
||||
@@ -804,14 +817,18 @@ func _place_torches_in_room(room: Dictionary, grid: Array, all_doors: Array, _ma
|
||||
# Door position is at door.x, door.y (upper-left tile)
|
||||
# Door occupies tiles: x from door.x to door.x + 2, y from door.y to door.y + 3
|
||||
# Door world bounding box: from (door.x * 16, door.y * 16) to ((door.x + 2) * 16, (door.y + 3) * 16)
|
||||
var door_min_x = door.x * tile_size_check
|
||||
var door_max_x = (door.x + 2) * tile_size_check
|
||||
var door_min_y = door.y * tile_size_check
|
||||
var door_max_y = (door.y + 3) * tile_size_check
|
||||
# CRITICAL: A torch is 16x16 pixels (8px in each direction), so expand door bounds by 8px in ALL directions
|
||||
# Door occupies columns room.x (0) and room.x + 1 (1), so torch at room.x + 1 can overlap if it extends left
|
||||
var door_min_x = door.x * tile_size_check - 8
|
||||
var door_max_x = (door.x + 2) * tile_size_check + 8
|
||||
var door_min_y = door.y * tile_size_check - 8
|
||||
var door_max_y = (door.y + 3) * tile_size_check + 8
|
||||
|
||||
# Check if torch bounding box overlaps with door bounding box
|
||||
if not (torch_bbox_max_x < door_min_x or torch_bbox_min_x > door_max_x or \
|
||||
torch_bbox_max_y < door_min_y or torch_bbox_min_y > door_max_y):
|
||||
# Check if torch bounding box overlaps with door bounding box (non-overlapping means torch is safe)
|
||||
# Overlap exists if NOT (torch_max < door_min OR torch_min > door_max)
|
||||
var x_overlap = not (torch_bbox_max_x < door_min_x or torch_bbox_min_x > door_max_x)
|
||||
var y_overlap = not (torch_bbox_max_y < door_min_y or torch_bbox_min_y > door_max_y)
|
||||
if x_overlap and y_overlap:
|
||||
overlaps_door = true
|
||||
break
|
||||
|
||||
@@ -1823,17 +1840,26 @@ func _place_interactable_objects_in_room(room: Dictionary, grid: Array, map_size
|
||||
|
||||
# Check if room has a "switch_pillar" puzzle - if so, we MUST spawn at least 1 pillar
|
||||
var has_pillar_switch_puzzle = false
|
||||
var matching_puzzle_room = null
|
||||
if room_puzzle_data.size() > 0:
|
||||
for puzzle_room in room_puzzle_data.keys():
|
||||
# Compare rooms by values (x, y, w, h)
|
||||
if puzzle_room.x == room.x and puzzle_room.y == room.y and \
|
||||
puzzle_room.w == room.w and puzzle_room.h == room.h:
|
||||
var puzzle_info = room_puzzle_data[puzzle_room]
|
||||
LogManager.log("DungeonGenerator: Checking room (" + str(room.x) + "," + str(room.y) + ") - puzzle_room (" + str(puzzle_room.x) + "," + str(puzzle_room.y) + ") puzzle_type: " + str(puzzle_info.type), LogManager.CATEGORY_DUNGEON)
|
||||
if puzzle_info.type == "switch_pillar":
|
||||
has_pillar_switch_puzzle = true
|
||||
LogManager.log("DungeonGenerator: Room (" + str(room.x) + "," + str(room.y) + ") has pillar switch puzzle - will spawn at least 1 pillar", LogManager.CATEGORY_DUNGEON)
|
||||
# Try direct lookup first (room dictionary as key)
|
||||
if room_puzzle_data.has(room):
|
||||
matching_puzzle_room = room
|
||||
else:
|
||||
# Fallback: find matching room by comparing values (x, y, w, h)
|
||||
for puzzle_room in room_puzzle_data.keys():
|
||||
# Compare rooms by values (x, y, w, h)
|
||||
if puzzle_room.x == room.x and puzzle_room.y == room.y and \
|
||||
puzzle_room.w == room.w and puzzle_room.h == room.h:
|
||||
matching_puzzle_room = puzzle_room
|
||||
break
|
||||
|
||||
if matching_puzzle_room != null:
|
||||
var puzzle_info = room_puzzle_data[matching_puzzle_room]
|
||||
LogManager.log("DungeonGenerator: Checking room (" + str(room.x) + "," + str(room.y) + ") - puzzle_room (" + str(matching_puzzle_room.x) + "," + str(matching_puzzle_room.y) + ") puzzle_type: " + str(puzzle_info.type), LogManager.CATEGORY_DUNGEON)
|
||||
if puzzle_info.type == "switch_pillar":
|
||||
has_pillar_switch_puzzle = true
|
||||
LogManager.log("DungeonGenerator: Room (" + str(room.x) + "," + str(room.y) + ") has pillar switch puzzle - will spawn at least 1 pillar", LogManager.CATEGORY_DUNGEON)
|
||||
else:
|
||||
LogManager.log("DungeonGenerator: room_puzzle_data is empty for room (" + str(room.x) + "," + str(room.y) + ")", LogManager.CATEGORY_DUNGEON)
|
||||
|
||||
@@ -1905,8 +1931,33 @@ func _place_interactable_objects_in_room(room: Dictionary, grid: Array, map_size
|
||||
# Early return if no valid positions (unless pillar is required, but that's handled below)
|
||||
if valid_positions.size() == 0:
|
||||
if has_pillar_switch_puzzle:
|
||||
push_warning("DungeonGenerator: Room (", room.x, ",", room.y, ") has pillar switch puzzle but NO valid positions! Cannot place pillar.")
|
||||
return objects
|
||||
# CRITICAL: Pillar is REQUIRED, so we must find at least one position
|
||||
# Try a more permissive search - use ALL floor tiles in the room (even if near doors/walls)
|
||||
LogManager.log("DungeonGenerator: Room (" + str(room.x) + "," + str(room.y) + ") has pillar switch puzzle but no valid positions. Trying fallback search...", LogManager.CATEGORY_DUNGEON)
|
||||
# Use same bounds but skip the position validation check
|
||||
var found_fallback = false
|
||||
for x in range(min_x, max_x + 1):
|
||||
for y in range(min_y, max_y + 1):
|
||||
if x >= 0 and x < map_size.x and y >= 0 and y < map_size.y:
|
||||
if grid[x][y] == 1: # Floor
|
||||
var world_x = x * tile_size + 8
|
||||
var world_y = y * tile_size + 8
|
||||
var world_pos = Vector2(world_x, world_y)
|
||||
valid_positions.append(world_pos)
|
||||
# Only need one position for the required pillar
|
||||
found_fallback = true
|
||||
break
|
||||
if found_fallback:
|
||||
break
|
||||
|
||||
if valid_positions.size() == 0:
|
||||
push_warning("DungeonGenerator: Room (", room.x, ",", room.y, ") has pillar switch puzzle but NO floor tiles! Cannot place pillar.")
|
||||
return objects
|
||||
else:
|
||||
LogManager.log("DungeonGenerator: Found fallback position for required pillar in room (" + str(room.x) + "," + str(room.y) + ")", LogManager.CATEGORY_DUNGEON)
|
||||
else:
|
||||
# No pillar required, safe to return
|
||||
return objects
|
||||
|
||||
# Shuffle positions to randomize placement
|
||||
valid_positions.shuffle()
|
||||
|
||||
Reference in New Issue
Block a user