41 lines
1.6 KiB
GDScript
41 lines
1.6 KiB
GDScript
extends Control
|
|
## A replaceable room layer. Hull and corridor belong to the parent deck.
|
|
var room_id := ""
|
|
var room_kind := ""
|
|
var built := false
|
|
var design_rect := Rect2()
|
|
var _renovation: AtlasTexture
|
|
var _furnished: AtlasTexture
|
|
var _time := 0.0
|
|
|
|
func configure(id: String, kind: String, bounds: Rect2, complete: bool) -> void:
|
|
room_id = id
|
|
room_kind = kind
|
|
design_rect = bounds
|
|
built = complete
|
|
_renovation = AtlasTexture.new()
|
|
_renovation.atlas = preload("res://assets/freighter/interior_deck.png")
|
|
var original_size := _renovation.atlas.get_size()
|
|
_renovation.region = Rect2(bounds.position / Vector2(1792,768) * original_size, bounds.size / Vector2(1792,768) * original_size)
|
|
_furnished = AtlasTexture.new()
|
|
_furnished.atlas = preload("res://assets/freighter/room_interiors.png")
|
|
var tile := _furnished.atlas.get_size() / 2.0
|
|
var index: int = {"laboratory":0,"alien_research":1,"module_storage":2,"crew_cabin":3}.get(kind,3)
|
|
_furnished.region = Rect2(Vector2(index % 2,floori(index / 2.0)) * tile,tile)
|
|
queue_redraw()
|
|
|
|
func _process(delta: float) -> void:
|
|
_time += delta
|
|
if built: queue_redraw()
|
|
|
|
func _draw() -> void:
|
|
if _renovation == null: return
|
|
draw_texture_rect(_renovation,Rect2(Vector2.ZERO,size),false)
|
|
if not built: return
|
|
# Leave structural walls and door threshold from the shared deck intact.
|
|
var inset := size * Vector2(0.045,0.045)
|
|
draw_texture_rect(_furnished,Rect2(inset,size-inset*2),false)
|
|
var light := Color("71dbe1") if room_kind != "alien_research" else Color("8ddd82")
|
|
light.a = 0.35 + 0.25 * sin(_time * 2.0 + design_rect.position.x)
|
|
draw_circle(size * Vector2(0.78,0.12),2.0,light)
|