This commit is contained in:
2026-01-21 23:40:20 +01:00
commit d1f8068081
478 changed files with 24902 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
extends Object
class_name RoomImageLoader
signal finishedLoading
signal finishedGettingDoors
func loadRoomData(image: Image) -> Array[Array]:
var imageSize: Vector2i = image.get_size()
var returnArray: Array[Array]
for x in imageSize.x:
var yArray: Array[GridCell]
returnArray.push_back(yArray)
for y in imageSize.y:
var gridCell: GridCell = GridCell.new()
var pixel: Color = image.get_pixel(x,y)
gridCell.spaceTaken = isColorTakingSpace(pixel)
if pixel == Color(1,0,0,1):
gridCell.door = true
gridCell.doorOrientation = getDoorOrientation(image,Vector2i(x,y))
yArray.push_back(gridCell)
finishedLoading.emit()
return returnArray
func isColorTakingSpace(pixel: Color) -> bool:
var returnBool: bool = true
if pixel == Color(1,1,1,1) or pixel == Color(1,0,0,1):
returnBool = false
return returnBool
func getDoors(grid: Array[Array]) -> Array[DoorPosition]:
var returnArray: Array[DoorPosition]
for x in grid.size():
for y in grid[x].size():
if grid[x][y].door:
var newDoorPos := DoorPosition.new()
newDoorPos.pos = Vector2i(x,y)
newDoorPos.orientation = grid[x][y].doorOrientation
returnArray.push_back(newDoorPos)
finishedGettingDoors.emit()
return returnArray
func getDoorOrientation(image: Image,pos: Vector2i) -> int:
var imageHeight: int = image.get_height()
var imageWidth: int = image.get_width()
if !(pos.y == imageHeight-1):
if image.get_pixelv(pos + Vector2i(0,1)) == Color(0,0,1,1): return GridCell.doorOrientations.north
if !(pos.x == 0):
if image.get_pixelv(pos + Vector2i(-1,0)) == Color(0,0,1,1): return GridCell.doorOrientations.east
if !(pos.y == 0):
if image.get_pixelv(pos + Vector2i(0,-1)) == Color(0,0,1,1): return GridCell.doorOrientations.south
if !(pos.x == imageWidth-1):
if image.get_pixelv(pos + Vector2i(1,0)) == Color(0,0,1,1): return GridCell.doorOrientations.west
return 0