This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Scenes/Rendering/MapTiles.gd

56 lines
1.7 KiB
GDScript3
Raw Permalink Normal View History

2020-07-06 12:38:05 +00:00
extends TileMap
class_name MapTiles
2020-07-12 15:26:40 +00:00
var transparentImage = preload("res://Graphics/transparent.png")
2020-07-06 12:38:05 +00:00
export(NodePath) var extended_tilemap_node
2020-07-08 12:30:46 +00:00
2020-07-06 12:38:05 +00:00
export var occluders = ["Wall"]
export var shadow_intensity = 0.2
onready var extended_tilemap = get_node(extended_tilemap_node) as TileMap
func _ready():
# Convert 2x2 tiles to 1x1 if possible
convert_extended()
func convert_extended():
var extended = extended_tilemap.tile_set
for id in tile_set.get_tiles_ids():
var name = tile_set.tile_get_name(id)
var extended_id = extended.find_tile_by_name(name)
if extended_id < 0:
# Not found, skip it
continue
# Find all uses of this tile
for cell in get_used_cells_by_id(id):
var x = cell.x * 2
var y = cell.y * 2
extended_tilemap.set_cell(x, y, extended_id)
extended_tilemap.set_cell(x+1, y, extended_id)
extended_tilemap.set_cell(x, y+1, extended_id)
extended_tilemap.set_cell(x+1, y+1, extended_id)
2020-07-12 15:26:40 +00:00
tile_set.tile_set_texture(id, transparentImage)
2020-07-06 12:38:05 +00:00
extended_tilemap.update_bitmask_region()
extended_tilemap.update_dirty_quadrants()
2020-07-12 15:27:55 +00:00
func create_occlusion_mask():
var tile_size = get_used_rect()
var mask_image = Image.new()
mask_image.create(tile_size.size.x, tile_size.size.y, false, Image.FORMAT_L8)
mask_image.fill(Color.black)
mask_image.lock()
2020-07-06 12:38:05 +00:00
var occluder_ids = []
2020-07-12 15:27:55 +00:00
for occluder in occluders:
occluder_ids.append(tile_set.find_tile_by_name(occluder))
for occluder_id in occluder_ids:
for cell in get_used_cells_by_id(occluder_id):
mask_image.set_pixelv(cell - tile_size.position, Color.white)
mask_image.unlock()
mask_image.save_png("res://test.png")
var mask_texture = ImageTexture.new()
mask_texture.create_from_image(mask_image, 0)
return mask_texture