finished belts. Some random errors in corners...
This commit is contained in:
+16
-11
@@ -14,6 +14,7 @@ const DELETE_SCENE = preload("res://delete.tscn")
|
||||
|
||||
enum Mode { NONE, PLACE_EXTRACTOR, PLACE_BELT, PLACE_ADDER, DELETE }
|
||||
var current_mode = Mode.NONE
|
||||
var current_direction = 0
|
||||
var preview_item: Node2D = null # Holds the visual for the mouse
|
||||
|
||||
# These should likely be changed to be the same format as above
|
||||
@@ -67,6 +68,14 @@ func _input(event):
|
||||
elif event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
|
||||
clear_preview()
|
||||
current_mode = Mode.NONE
|
||||
if event is InputEventKey and event.pressed:
|
||||
print('key pressed')
|
||||
if event.keycode == KEY_BRACKETLEFT:
|
||||
current_direction = (current_direction + 1) % 4
|
||||
preview_item.rotate(-PI / 2)
|
||||
elif event.keycode == KEY_BRACKETRIGHT:
|
||||
current_direction = (current_direction - 1) % 4
|
||||
preview_item.rotate(+PI / 2)
|
||||
|
||||
|
||||
# Returns the grid position of the mouse
|
||||
@@ -135,16 +144,8 @@ func process_grid_data_at(coords: Vector2i) -> void:
|
||||
|
||||
# Formula: Start at 1, add 1 extra value for every 10 tiles away
|
||||
var producer_value = 1 + floor(distance / 10.0)
|
||||
|
||||
# Register the producer in our global data registry
|
||||
# disabled: for x in range(-1, 2):
|
||||
# disabled: for y in range(-1, 2):
|
||||
# disabled: grid_data[coords + Vector2i(x, y)] = {
|
||||
# disabled: "type": "producer",
|
||||
# disabled: "value": producer_value
|
||||
# disabled: }
|
||||
|
||||
|
||||
|
||||
grid_data[coords] = [{
|
||||
"type": "producer",
|
||||
"value": producer_value
|
||||
@@ -169,6 +170,7 @@ func set_preview_mode(mode_type: Mode, scene_to_preview: PackedScene):
|
||||
|
||||
if scene_to_preview:
|
||||
preview_item = scene_to_preview.instantiate()
|
||||
preview_item.rotate(-PI / 2 * current_direction)
|
||||
# Optional: Make the preview slightly transparent
|
||||
preview_item.modulate.a = 0.5
|
||||
add_child(preview_item)
|
||||
@@ -213,7 +215,7 @@ func place_item(item: PackedScene):
|
||||
if item == EXTRACTOR_SCENE:
|
||||
new_item.setup(object_at_coords['value'])
|
||||
elif item == BELT_SCENE:
|
||||
new_item.setup(spawn_pos, 0)
|
||||
new_item.setup(spawn_pos, current_direction)
|
||||
else:
|
||||
print("No custom setup for %s" % item)
|
||||
|
||||
@@ -242,7 +244,10 @@ func register_object_at_coordinate(coords: Vector2i, object_data: Dictionary) ->
|
||||
grid_data[coords] = [object_data]
|
||||
|
||||
func delete_object_at_coordinate(coords: Vector2i):
|
||||
grid_data[coords].pop_back()
|
||||
if grid_data.has(coords):
|
||||
grid_data[coords].pop_back()
|
||||
if grid_data[coords] == []:
|
||||
grid_data.erase(coords)
|
||||
|
||||
|
||||
# --- UI Button Signals ---
|
||||
|
||||
Reference in New Issue
Block a user