This commit is contained in:
chardub
2025-04-19 15:42:41 -04:00
parent 86471fbedf
commit 0807a7ea79

View File

@@ -4,6 +4,7 @@
class TilemapRenderer
attr_reader :tilesets
attr_reader :autotiles
attr_reader :custom_autotile_ids
attr_accessor :tone
attr_accessor :color
attr_reader :viewport
@@ -44,9 +45,27 @@ class TilemapRenderer
# 6 => [["Water rock", "Sea deep"], []]
EXTRA_AUTOTILES = {
# 23 => {
# 384 => "flowers_pink",
# }
23 => {
1232 => "flowers_orange[10]",
1240 => "flowers_pink[10]",
1248 => "flowers_yellow[10]",
1256 => "flowers_blue[10]",
1264 => "flowers_purple[10]",
1272 => "flowers_red[10]",
1280 => "flowers_grey[10]",
1288 => "flowers_white[10]",
},
30 => {
2620 => "flowers_orange[10]",
2628 => "flowers_pink[10]",
2636 => "flowers_yellow[10]",
2644 => "flowers_blue[10]",
2652 => "flowers_purple[10]",
2660 => "flowers_red[10]",
2668 => "flowers_grey[10]",
2676 => "flowers_white[10]",
}
}
#=============================================================================
@@ -203,15 +222,24 @@ class TilemapRenderer
end
def set_src_rect(tile, tile_id)
return if nil_or_empty?(tile.filename)
return if !@bitmaps[tile.filename]
frame = current_frame(tile.filename)
if @bitmaps[tile.filename].height == SOURCE_TILE_HEIGHT
filename = tile.filename
# Check if this tile_id was overridden to use a specific autotile
override_filename = @custom_autotile_ids && @custom_autotile_ids[tile_id]
filename = override_filename if override_filename
return if nil_or_empty?(filename)
return unless @bitmaps[filename]
frame = current_frame(filename)
if @bitmaps[filename].height == SOURCE_TILE_HEIGHT
tile.src_rect.x = frame * SOURCE_TILE_WIDTH
tile.src_rect.y = 0
return
end
wraps = @bitmap_wraps[tile.filename]
wraps = @bitmap_wraps[filename]
high_id = ((tile_id % TILES_PER_AUTOTILE) >= TILES_PER_AUTOTILE / 2)
tile.src_rect.x = 0
tile.src_rect.y = (tile_id % TILES_PER_AUTOTILE) * SOURCE_TILE_HEIGHT
@@ -220,6 +248,9 @@ class TilemapRenderer
tile.src_rect.y -= SOURCE_TILE_HEIGHT * TILES_PER_AUTOTILE / 2
end
tile.src_rect.x += frame * SOURCE_TILE_WIDTH * (wraps ? 2 : 1)
# Override the filename in the tile object for consistency
tile.filename = filename if override_filename
end
def update
@@ -270,6 +301,7 @@ class TilemapRenderer
def initialize(viewport)
@tilesets = TilesetBitmaps.new
@autotiles = AutotileBitmaps.new
@custom_autotile_ids = {} # key: tile_id, value: filename
@tiles_horizontal_count = (Graphics.width.to_f / DISPLAY_TILE_WIDTH).ceil + 1
@tiles_vertical_count = (Graphics.height.to_f / DISPLAY_TILE_HEIGHT).ceil + 1
@tone = Tone.new(0, 0, 0, 0)
@@ -343,9 +375,11 @@ class TilemapRenderer
end
def add_extra_autotiles(tileset_id)
return if !EXTRA_AUTOTILES[tileset_id]
EXTRA_AUTOTILES[tileset_id].each do |arr|
arr.each { |filename| add_autotile(filename) }
overrides = EXTRA_AUTOTILES[tileset_id]
return unless overrides
overrides.each do |tile_id, filename|
@autotiles.add(filename)
@custom_autotile_ids[tile_id] = filename
end
end
@@ -374,21 +408,31 @@ class TilemapRenderer
priority = map.priorities[tile_id] || 0
single_autotile_start_id = TILESET_START_ID
true_tileset_start_id = TILESET_START_ID
extra_autotile_arrays = EXTRA_AUTOTILES[map.tileset_id]
if extra_autotile_arrays
large_autotile_count = extra_autotile_arrays[0].length
single_autotile_count = extra_autotile_arrays[1].length
single_autotile_start_id += large_autotile_count * TILES_PER_AUTOTILE
true_tileset_start_id += large_autotile_count * TILES_PER_AUTOTILE
true_tileset_start_id += single_autotile_count
end
if tile_id < true_tileset_start_id
filename = ""
# extra_autotile_arrays = EXTRA_AUTOTILES[map.tileset_id]
# if extra_autotile_arrays
# large_autotile_count = extra_autotile_arrays[0].length
# single_autotile_count = extra_autotile_arrays[1].length
# single_autotile_start_id += large_autotile_count * TILES_PER_AUTOTILE
# true_tileset_start_id += large_autotile_count * TILES_PER_AUTOTILE
# true_tileset_start_id += single_autotile_count
# end
filename = nil
extra_autotile_hash = EXTRA_AUTOTILES[map.tileset_id]
if extra_autotile_hash && extra_autotile_hash[tile_id]
# Custom tile_id override
filename = extra_autotile_hash[tile_id]
tile.set_bitmap(filename, tile_id, true, @autotiles.animated?(filename),
priority, @autotiles[filename])
elsif tile_id < true_tileset_start_id
# Default behavior
if tile_id < TILESET_START_ID # Real autotiles
filename = map.autotile_names[(tile_id / TILES_PER_AUTOTILE) - 1]
elsif tile_id < single_autotile_start_id # Large extra autotiles
filename = extra_autotile_arrays[0][(tile_id - TILESET_START_ID) / TILES_PER_AUTOTILE]
else # Single extra autotiles
else
# Single extra autotiles
filename = extra_autotile_arrays[1][tile_id - single_autotile_start_id]
end
tile.set_bitmap(filename, tile_id, true, @autotiles.animated?(filename),
@@ -397,6 +441,7 @@ class TilemapRenderer
filename = map.tileset_name
tile.set_bitmap(filename, tile_id, false, false, priority, @tilesets[filename])
end
tile.shows_reflection = terrain_tag_data&.shows_reflections
tile.bridge = terrain_tag_data&.bridge
end