1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 15:39:49 +00:00

Initial work for tilemap layers

This commit is contained in:
Emmanouil Papadeas 2024-11-16 03:41:32 +02:00
parent ff5713ae91
commit d562e50af7
4 changed files with 80 additions and 1 deletions

View file

@ -14,7 +14,7 @@ signal cel_switched ## Emitted whenever you select a different cel.
signal project_data_changed(project: Project) ## Emitted when project data is modified.
signal font_loaded ## Emitted when a new font has been loaded, or an old one gets unloaded.
enum LayerTypes { PIXEL, GROUP, THREE_D }
enum LayerTypes { PIXEL, GROUP, THREE_D, TILEMAP }
enum GridTypes { CARTESIAN, ISOMETRIC, ALL }
## ## Used to tell whether a color is being taken from the current theme,
## or if it is a custom color.

View file

@ -0,0 +1,44 @@
class_name CelTileMap
extends PixelCel
enum TileEditingMode { MANUAL, AUTO, STACK }
var tileset: TileSetCustom
var tile_editing_mode := TileEditingMode.MANUAL
var indices := PackedInt32Array()
var indices_x: int
var indices_y: int
func _init(_tileset: TileSetCustom, _image := Image.new(), _opacity := 1.0) -> void:
super._init(_image, _opacity)
tileset = _tileset
indices_x = ceili(float(get_image().get_width()) / tileset.tile_size.x)
indices_y = ceili(float(get_image().get_height()) / tileset.tile_size.y)
indices.resize(indices_x * indices_y)
func update_texture() -> void:
super.update_texture()
for i in indices.size():
var x_coord := float(tileset.tile_size.x) * (i % indices_x)
var y_coord := float(tileset.tile_size.y) * (i / indices_x)
var rect := Rect2i(Vector2i(x_coord, y_coord), tileset.tile_size)
var image_portion := image.get_region(rect)
var index := indices[i]
if tile_editing_mode == TileEditingMode.MANUAL:
if index == 0:
continue
if image_portion.get_data() != tileset.tiles[index].get_data():
tileset.tiles[index].copy_from(image_portion)
elif tile_editing_mode == TileEditingMode.AUTO:
if index == 0:
continue
else:
if not image_portion.is_invisible():
tileset.tiles.append(image_portion)
indices[i] = tileset.tiles.size()
func get_class_name() -> String:
return "CelTileMap"

View file

@ -0,0 +1,19 @@
class_name LayerTileMap
extends PixelLayer
var tileset: TileSetCustom
func _init(_project: Project, _tileset: TileSetCustom, _name := "") -> void:
super._init(_project, _name)
tileset = _tileset
# Overridden Methods:
func get_layer_type() -> int:
return Global.LayerTypes.TILEMAP
func new_empty_cel() -> BaseCel:
var image := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
return CelTileMap.new(tileset, image)

View file

@ -0,0 +1,16 @@
class_name TileSetCustom
extends RefCounted
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)