Restructure tile size usage
This commit is contained in:
@@ -4,8 +4,6 @@ extends Node2D
|
||||
## Renders wall textures by sampling segments from the aux_terrain texture atlas
|
||||
## and compositing them onto tile edges. Each edge is made of two half-segments.
|
||||
|
||||
const TILE_SIZE := 100.0
|
||||
|
||||
## Source atlas rects (x, y, w, h) from aux_terrain.BMP
|
||||
## Each edge has two half-segments that together span the full tile edge.
|
||||
|
||||
@@ -42,7 +40,9 @@ const WALL_THICKNESS := 20.0
|
||||
## Inner corner piece size in game pixels (quarter of a tile)
|
||||
const CORNER_SIZE := 50.0
|
||||
## Half the tile edge length
|
||||
const HALF_EDGE := TILE_SIZE / 2.0
|
||||
var HALF_EDGE: float:
|
||||
get:
|
||||
return BattleMapHelper.TILE_SIZE / 2.0
|
||||
|
||||
@export var atlas_texture: Texture2D
|
||||
|
||||
@@ -114,7 +114,7 @@ func _direction_to_edge(dir: Vector2i) -> StringName:
|
||||
|
||||
|
||||
func _build_tile_walls(tile: Vector2i, edges: Array) -> void:
|
||||
var tile_origin := Vector2(tile) * TILE_SIZE
|
||||
var tile_origin := Vector2(tile) * BattleMapHelper.TILE_SIZE
|
||||
|
||||
for edge in edges:
|
||||
_build_edge_segments(tile_origin, edge)
|
||||
@@ -147,8 +147,8 @@ func _build_edge_segments(tile_origin: Vector2, edge: StringName) -> void:
|
||||
seg_b_rect = RIGHT_LOWER_RECT
|
||||
seg_a_size = Vector2(WALL_THICKNESS, HALF_EDGE)
|
||||
seg_b_size = Vector2(WALL_THICKNESS, HALF_EDGE)
|
||||
seg_a_offset = Vector2(TILE_SIZE - WALL_THICKNESS, 0)
|
||||
seg_b_offset = Vector2(TILE_SIZE - WALL_THICKNESS, HALF_EDGE)
|
||||
seg_a_offset = Vector2(BattleMapHelper.TILE_SIZE - WALL_THICKNESS, 0)
|
||||
seg_b_offset = Vector2(BattleMapHelper.TILE_SIZE - WALL_THICKNESS, HALF_EDGE)
|
||||
&"top":
|
||||
seg_a_rect = TOP_LEFT_RECT
|
||||
seg_b_rect = TOP_RIGHT_RECT
|
||||
@@ -161,8 +161,8 @@ func _build_edge_segments(tile_origin: Vector2, edge: StringName) -> void:
|
||||
seg_b_rect = BOTTOM_RIGHT_RECT
|
||||
seg_a_size = Vector2(HALF_EDGE, WALL_THICKNESS)
|
||||
seg_b_size = Vector2(HALF_EDGE, WALL_THICKNESS)
|
||||
seg_a_offset = Vector2(0, TILE_SIZE - WALL_THICKNESS)
|
||||
seg_b_offset = Vector2(HALF_EDGE, TILE_SIZE - WALL_THICKNESS)
|
||||
seg_a_offset = Vector2(0, BattleMapHelper.TILE_SIZE - WALL_THICKNESS)
|
||||
seg_b_offset = Vector2(HALF_EDGE, BattleMapHelper.TILE_SIZE - WALL_THICKNESS)
|
||||
|
||||
_queue_segment(tile_origin + seg_a_offset, seg_a_size, seg_a_rect)
|
||||
_queue_segment(tile_origin + seg_b_offset, seg_b_size, seg_b_rect)
|
||||
@@ -187,8 +187,8 @@ func _build_opening_sprites(map_layout: MapLayout) -> void:
|
||||
tile_b = swap
|
||||
diff = -diff
|
||||
|
||||
var origin_a := Vector2(tile_a) * TILE_SIZE
|
||||
var origin_b := Vector2(tile_b) * TILE_SIZE
|
||||
var origin_a := Vector2(tile_a) * BattleMapHelper.TILE_SIZE
|
||||
var origin_b := Vector2(tile_b) * BattleMapHelper.TILE_SIZE
|
||||
|
||||
if diff == Vector2i.DOWN:
|
||||
_queue_vertical_opening(origin_a, origin_b)
|
||||
@@ -203,10 +203,10 @@ func _queue_vertical_opening(origin_upper: Vector2, origin_lower: Vector2) -> vo
|
||||
var h_total: float = src.size.y
|
||||
var h_upper: float = floorf(h_total / 2.0) # 14
|
||||
var h_lower: float = h_total - h_upper # 15
|
||||
var x_offset := (TILE_SIZE - w) / 2.0
|
||||
var x_offset := (BattleMapHelper.TILE_SIZE - w) / 2.0
|
||||
var src_upper := Rect2(src.position, Vector2(w, h_upper))
|
||||
var src_lower := Rect2(src.position + Vector2(0, h_upper), Vector2(w, h_lower))
|
||||
_queue_segment(origin_upper + Vector2(x_offset, TILE_SIZE - h_upper), Vector2(w, h_upper), src_upper)
|
||||
_queue_segment(origin_upper + Vector2(x_offset, BattleMapHelper.TILE_SIZE - h_upper), Vector2(w, h_upper), src_upper)
|
||||
_queue_segment(origin_lower + Vector2(x_offset, 0), Vector2(w, h_lower), src_lower)
|
||||
|
||||
|
||||
@@ -217,10 +217,10 @@ func _queue_horizontal_opening(origin_left: Vector2, origin_right: Vector2) -> v
|
||||
var h: float = src.size.y
|
||||
var w_left: float = floorf(w_total / 2.0) # 14
|
||||
var w_right: float = w_total - w_left # 14
|
||||
var y_offset := (TILE_SIZE - h) / 2.0
|
||||
var y_offset := (BattleMapHelper.TILE_SIZE - h) / 2.0
|
||||
var src_left := Rect2(src.position, Vector2(w_left, h))
|
||||
var src_right := Rect2(src.position + Vector2(w_left, 0), Vector2(w_right, h))
|
||||
_queue_segment(origin_left + Vector2(TILE_SIZE - w_left, y_offset), Vector2(w_left, h), src_left)
|
||||
_queue_segment(origin_left + Vector2(BattleMapHelper.TILE_SIZE - w_left, y_offset), Vector2(w_left, h), src_left)
|
||||
_queue_segment(origin_right + Vector2(0, y_offset), Vector2(w_right, h), src_right)
|
||||
|
||||
|
||||
@@ -248,19 +248,19 @@ func _build_inner_corners(_tile: Vector2i, tile_origin: Vector2, edges: Array) -
|
||||
)
|
||||
if has_top and has_right:
|
||||
_queue_segment(
|
||||
tile_origin + Vector2(TILE_SIZE - CORNER_SIZE, 0),
|
||||
tile_origin + Vector2(BattleMapHelper.TILE_SIZE - CORNER_SIZE, 0),
|
||||
corner_size,
|
||||
INNER_CORNER_UPPER_RIGHT_RECT
|
||||
)
|
||||
if has_bottom and has_left:
|
||||
_queue_segment(
|
||||
tile_origin + Vector2(0, TILE_SIZE - CORNER_SIZE),
|
||||
tile_origin + Vector2(0, BattleMapHelper.TILE_SIZE - CORNER_SIZE),
|
||||
corner_size,
|
||||
INNER_CORNER_LOWER_LEFT_RECT
|
||||
)
|
||||
if has_bottom and has_right:
|
||||
_queue_segment(
|
||||
tile_origin + Vector2(TILE_SIZE - CORNER_SIZE, TILE_SIZE - CORNER_SIZE),
|
||||
tile_origin + Vector2(BattleMapHelper.TILE_SIZE - CORNER_SIZE, BattleMapHelper.TILE_SIZE - CORNER_SIZE),
|
||||
corner_size,
|
||||
INNER_CORNER_LOWER_RIGHT_RECT
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user