Working on adding items and windows build
This commit is contained in:
+18
-4
@@ -9,8 +9,10 @@ extends Node2D
|
||||
# preload scenes that we can place:
|
||||
const EXTRACTOR_SCENE = preload("res://extractor.tscn")
|
||||
const BELT_SCENE = preload("res://belt.tscn")
|
||||
const ADDER_SCENE = preload("res://adder.tscn")
|
||||
const DELETE_SCENE = preload("res://delete.tscn")
|
||||
|
||||
enum Mode { NONE, PLACE_EXTRACTOR, PLACE_BELT, DELETE }
|
||||
enum Mode { NONE, PLACE_EXTRACTOR, PLACE_BELT, PLACE_ADDER, DELETE }
|
||||
var current_mode = Mode.NONE
|
||||
var preview_item: Node2D = null # Holds the visual for the mouse
|
||||
|
||||
@@ -42,7 +44,7 @@ func _process(_delta: float) -> void:
|
||||
generate_and_render_around_camera()
|
||||
|
||||
# Update the preview item's position and snap to the grid
|
||||
if preview_item and (current_mode != Mode.NONE and current_mode != Mode.DELETE):
|
||||
if preview_item and current_mode != Mode.NONE:
|
||||
var grid_pos = get_grid_snapped_mouse_position()
|
||||
preview_item.global_position = tile_layer.map_to_local(grid_pos)
|
||||
# var scaled_pos = (get_grid_snapped_mouse_position() * 32)
|
||||
@@ -68,7 +70,7 @@ func _input(event):
|
||||
|
||||
|
||||
# Returns the grid position of the mouse
|
||||
func get_grid_snapped_mouse_position() -> Vector2i:
|
||||
func get_grid_snapped_mouse_position() -> Vector2:
|
||||
return tile_layer.local_to_map(get_global_mouse_position())
|
||||
|
||||
|
||||
@@ -207,7 +209,8 @@ func place_item(item: PackedScene):
|
||||
"type": new_item.name,
|
||||
})
|
||||
|
||||
func delete_item(target_pos: Vector2i):
|
||||
func delete_item(target_pos: Vector2):
|
||||
print("deleting item")
|
||||
var targets = get_tree().get_nodes_in_group("Placed_objects")
|
||||
for item in targets:
|
||||
if item.global_position == target_pos:
|
||||
@@ -236,3 +239,14 @@ func _on_extractor_button_pressed():
|
||||
## clear_preview()
|
||||
## current_mode = Mode.DELETE
|
||||
##
|
||||
|
||||
|
||||
func _on_belt_button_pressed() -> void:
|
||||
set_preview_mode(Mode.PLACE_BELT, BELT_SCENE)
|
||||
|
||||
func _on_adder_button_pressed() -> void:
|
||||
set_preview_mode(Mode.PLACE_ADDER, ADDER_SCENE)
|
||||
|
||||
|
||||
func _on_delete_button_pressed() -> void:
|
||||
set_preview_mode(Mode.DELETE, DELETE_SCENE)
|
||||
|
||||
Reference in New Issue
Block a user