2024-11-16 03:41:32 +02:00
|
|
|
class_name TileSetCustom
|
|
|
|
extends RefCounted
|
|
|
|
|
2024-11-18 03:09:46 +02:00
|
|
|
signal updated
|
|
|
|
|
2024-11-16 03:41:32 +02:00
|
|
|
var name := ""
|
|
|
|
var tile_size: Vector2i
|
|
|
|
var tiles: Array[Image] = []
|
|
|
|
|
|
|
|
|
|
|
|
func _init(_tile_size: Vector2i, _name := "") -> void:
|
|
|
|
tile_size = _tile_size
|
|
|
|
name = _name
|
|
|
|
#var indices_x := ceili(float(_project_size.x) / tile_size.x)
|
|
|
|
#var indices_y := ceili(float(_project_size.y) / tile_size.y)
|
|
|
|
#tiles.resize(indices_x * indices_y + 1)
|
|
|
|
var empty_image := Image.create_empty(tile_size.x, tile_size.y, false, Image.FORMAT_RGBA8)
|
|
|
|
tiles.append(empty_image)
|
2024-11-18 03:09:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
func add_tile(tile: Image) -> void:
|
|
|
|
tiles.append(tile)
|
|
|
|
updated.emit()
|
|
|
|
|
|
|
|
|
|
|
|
func remove_tile_at_index(index: int) -> void:
|
|
|
|
tiles.remove_at(index)
|
|
|
|
updated.emit()
|
|
|
|
|
|
|
|
|
|
|
|
func replace_tile_at(new_tile: Image, index: int) -> void:
|
|
|
|
tiles[index].copy_from(new_tile)
|
|
|
|
updated.emit()
|