Paint brush

This commit is contained in:
Rendo 2025-10-15 00:10:51 +05:00
commit 1c20d54651
4 changed files with 21 additions and 21 deletions

View file

@ -2,6 +2,7 @@ extends Node2D
## Currently held structure
var held_construction : Structure
var selected_prototype : Prototype
func _ready() -> void:
GuiEventBus.construction_selected.connect(on_construction_selected)
@ -11,23 +12,25 @@ func _input(event: InputEvent) -> void:
return
if event.is_action_pressed("plc_place"):
var zone = try_get_zone(held_construction.global_position)
if zone == null:
held_construction.queue_free()
else:
if held_construction.try_place(zone):
held_construction = null
if zone != null and held_construction.try_place(zone):
var facing = held_construction.facing
held_construction = selected_prototype.scene.instantiate()
add_child(held_construction)
held_construction.set_facing(facing)
if event.is_action_pressed("plc_rotate_up"):
if held_construction != null:
held_construction.cycle_up_facing()
if event.is_action_pressed("plc_cancel"):
held_construction.queue_free()
selected_prototype = null
func on_construction_selected(constructible : Prototype):
if held_construction:
held_construction.queue_free()
held_construction = constructible.scene.instantiate()
add_child(held_construction)
selected_prototype = constructible
func _process(_delta: float) -> void:

View file

@ -83,8 +83,16 @@ func get_dimension_points() -> Array[Vector2]:
result[x + y * dimensions.size.x] = (Vector2(x,y)*Globals.GRID_SIZE + Vector2(dimensions.position))
return result
func set_facing(to : Facing) -> void:
facing = to
switched_facing.emit(facing)
func cycle_up_facing() -> void:
if facing == Facing.UNDIRECTIONAL:
return
facing = wrapi(facing+1,1,5) as Facing
switched_facing.emit(facing)
set_facing(wrapi(facing+1,1,5))
func cycle_down_facing() -> void:
if facing == Facing.UNDIRECTIONAL:
return
set_facing(wrapi(facing-1,1,5))

View file

@ -5,5 +5,5 @@ const test_item :=preload("res://generic/items/dbg_item.tres")
func _process(_delta: float) -> void:
for point in [Vector2(-1,0),Vector2(1,0),Vector2(0,1),Vector2(0,-1)]:
var found_structure = get_parent().get_relative(point)
if found_structure:
if found_structure and found_structure.inventory:
found_structure.inventory.add(Stack.new(test_item,1))