extends Node # This autoload generates placeholder textures for entities # Add to autoload as "SpriteGenerator" const TILE_SIZE := 16 const DUNGEON_TILESET_PATH := "res://assets/sprites/Dungeon_Tileset.png" # Tile coordinates in the tileset (x, y in tile units) const FLOOR_TILE_COORD := Vector2i(3, 2) const WALL_TILE_COORD := Vector2i(1, 0) var circle_texture: ImageTexture var square_texture: ImageTexture var _tileset_texture: Texture2D var _floor_tile_texture: Texture2D var _wall_tile_texture: Texture2D func _ready(): _generate_circle_texture() _generate_square_texture() _load_tileset_tiles() func _load_tileset_tiles(): if not ResourceLoader.exists(DUNGEON_TILESET_PATH): push_warning("Tileset not found at: %s - using fallback textures" % DUNGEON_TILESET_PATH) _generate_fallback_tiles() return _tileset_texture = load(DUNGEON_TILESET_PATH) if _tileset_texture == null: push_error("Failed to load dungeon tileset: %s" % DUNGEON_TILESET_PATH) _generate_fallback_tiles() return _floor_tile_texture = _make_atlas_tile(_tileset_texture, FLOOR_TILE_COORD) _wall_tile_texture = _make_atlas_tile(_tileset_texture, WALL_TILE_COORD) print("[SpriteGenerator] Tileset loaded successfully") func _make_atlas_tile(atlas: Texture2D, tile_coord: Vector2i) -> AtlasTexture: var tex := AtlasTexture.new() tex.atlas = atlas tex.region = Rect2( tile_coord.x * TILE_SIZE, tile_coord.y * TILE_SIZE, TILE_SIZE, TILE_SIZE ) return tex func _generate_fallback_tiles(): print("[SpriteGenerator] Using fallback generated tiles") _floor_tile_texture = _generate_colored_tile(Color(0.18, 0.14, 0.1)) _wall_tile_texture = _generate_colored_tile(Color(0.35, 0.28, 0.45)) func _generate_colored_tile(color: Color) -> ImageTexture: var img = Image.create(TILE_SIZE, TILE_SIZE, false, Image.FORMAT_RGBA8) for x in range(TILE_SIZE): for y in range(TILE_SIZE): var noise_val = randf() * 0.05 var c = Color( clamp(color.r + noise_val, 0, 1), clamp(color.g + noise_val, 0, 1), clamp(color.b + noise_val, 0, 1), 1.0 ) img.set_pixel(x, y, c) return ImageTexture.create_from_image(img) func _generate_circle_texture(): var size := 32 var img := Image.create(size, size, false, Image.FORMAT_RGBA8) var center := Vector2(size / 2.0, size / 2.0) var radius := size / 2.0 - 1.0 for x in range(size): for y in range(size): var dist := Vector2(x, y).distance_to(center) if dist <= radius: var brightness := 1.0 - (dist / radius) * 0.3 img.set_pixel(x, y, Color(brightness, brightness, brightness, 1.0)) elif dist <= radius + 1.0: var alpha := 1.0 - (dist - radius) img.set_pixel(x, y, Color(0.8, 0.8, 0.8, alpha)) else: img.set_pixel(x, y, Color(0, 0, 0, 0)) circle_texture = ImageTexture.create_from_image(img) func _generate_square_texture(): var size := 32 var img := Image.create(size, size, false, Image.FORMAT_RGBA8) for x in range(size): for y in range(size): var border := 2 if x < border or x >= size - border or y < border or y >= size - border: img.set_pixel(x, y, Color(0.6, 0.6, 0.6, 1.0)) else: img.set_pixel(x, y, Color(0.9, 0.9, 0.9, 1.0)) square_texture = ImageTexture.create_from_image(img) func get_circle() -> Texture2D: return circle_texture func get_square() -> Texture2D: return square_texture func get_floor_tile() -> Texture2D: if _floor_tile_texture: return _floor_tile_texture return square_texture func get_wall_tile() -> Texture2D: if _wall_tile_texture: return _wall_tile_texture return square_texture