42 lines
1.7 KiB
Plaintext
42 lines
1.7 KiB
Plaintext
extends Object
|
|
class_name RoomImageLoader
|
|
|
|
signal finishedLoading
|
|
|
|
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 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,-1)) == Color(0,0,1,1): return GridCell.doorOrientations.north_west
|
|
if image.get_pixelv(pos + Vector2i(1,0)) == Color(0,0,1,1): return GridCell.doorOrientations.west
|
|
if image.get_pixelv(pos + Vector2i(1,1)) == Color(0,0,1,1): return GridCell.doorOrientations.south_west
|
|
if image.get_pixelv(pos + Vector2i(0,1)) == Color(0,0,1,1): return GridCell.doorOrientations.south
|
|
if image.get_pixelv(pos + Vector2i(-1,1)) == Color(0,0,1,1): return GridCell.doorOrientations.south_east
|
|
if image.get_pixelv(pos + Vector2i(-1,0)) == Color(0,0,1,1): return GridCell.doorOrientations.east
|
|
if image.get_pixelv(pos + Vector2i(-1,-1)) == Color(0,0,1,1): return GridCell.doorOrientations.north_east
|
|
return 0
|