51 lines
1.7 KiB
Plaintext
51 lines
1.7 KiB
Plaintext
|
|
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:
|
||
|
|
if image.get_pixelv(pos + Vector2i(0,-1)) == Color(0,0,1,1): return GridCell.doorOrientations.north
|
||
|
|
if image.get_pixelv(pos + Vector2i(1,0)) == Color(0,0,1,1): return GridCell.doorOrientations.east
|
||
|
|
if image.get_pixelv(pos + Vector2i(0,1)) == Color(0,0,1,1): return GridCell.doorOrientations.south
|
||
|
|
if image.get_pixelv(pos + Vector2i(-1,0)) == Color(0,0,1,1): return GridCell.doorOrientations.west
|
||
|
|
return 0
|