Restructure tile size usage
This commit is contained in:
@@ -9,7 +9,6 @@ extends Node2D
|
||||
@onready var fog_renderer: FogRenderer = %FogRenderer
|
||||
|
||||
const DEPLOYED_UNIT_SCENE = preload("res://prefabs/deployed_unit.tscn")
|
||||
const TILE_SIZE := 100.0
|
||||
const SOURCE_ID: int = 0
|
||||
|
||||
var _pending_layout: String
|
||||
@@ -26,15 +25,6 @@ func _ready() -> void:
|
||||
apply_layout(map_layout)
|
||||
|
||||
|
||||
func snap_to_grid(pos: Vector2) -> Vector2:
|
||||
return Vector2(floorf(pos.x / TILE_SIZE), floorf(pos.y / TILE_SIZE)) * TILE_SIZE
|
||||
|
||||
func world_to_coords(pos: Vector2) -> Vector2i:
|
||||
return Vector2i(snap_to_grid(pos) / TILE_SIZE)
|
||||
|
||||
func coords_to_world(coords: Vector2i) -> Vector2:
|
||||
return Vector2(coords) * TILE_SIZE
|
||||
|
||||
func draw_wall(coords: Vector2i) -> void:
|
||||
draw_custom(coords, tile_set.wall_tile_coords)
|
||||
|
||||
@@ -73,7 +63,7 @@ func _apply_layout(layout: String) -> void:
|
||||
|
||||
|
||||
func _apply_deploy(deployed: DeployedUnit, coords: Vector2i) -> void:
|
||||
deployed.position = coords_to_world(coords)
|
||||
deployed.position = BattleMapHelper.coords_to_world(coords)
|
||||
add_child(deployed)
|
||||
|
||||
|
||||
@@ -119,7 +109,7 @@ func draw_fog() -> void:
|
||||
func get_map_rect() -> Rect2:
|
||||
if not map_layout:
|
||||
return Rect2()
|
||||
return Rect2(Vector2.ZERO, Vector2(map_layout.size) * TILE_SIZE)
|
||||
return Rect2(Vector2.ZERO, Vector2(map_layout.size) * BattleMapHelper.TILE_SIZE)
|
||||
|
||||
|
||||
func load_from_layout() -> void:
|
||||
|
||||
@@ -4,7 +4,6 @@ extends Node2D
|
||||
## Renders a fog/cave texture over every tile inside the map's bounding rect
|
||||
## that is not part of any room. Future: drive visibility from map state.
|
||||
|
||||
const TILE_SIZE := 100.0
|
||||
## Fog tile region in aux_terrain.BMP
|
||||
const FOG_RECT := Rect2(53, 53, 100, 100)
|
||||
|
||||
@@ -23,14 +22,14 @@ func draw_fog_for_layout(map_layout: MapLayout) -> void:
|
||||
var tile := Vector2i(x, y)
|
||||
if map_layout.is_tile_valid(tile):
|
||||
continue
|
||||
_fog_tiles.append(Vector2(tile) * TILE_SIZE)
|
||||
_fog_tiles.append(Vector2(tile) * BattleMapHelper.TILE_SIZE)
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
if not atlas_texture:
|
||||
return
|
||||
var dest_size := Vector2(TILE_SIZE, TILE_SIZE)
|
||||
var dest_size := Vector2(BattleMapHelper.TILE_SIZE, BattleMapHelper.TILE_SIZE)
|
||||
for pos in _fog_tiles:
|
||||
draw_texture_rect_region(
|
||||
atlas_texture,
|
||||
|
||||
@@ -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