210 lines
5.0 KiB
GDScript
210 lines
5.0 KiB
GDScript
extends Node3D
|
|
|
|
var load_tile = preload("res://tiles/base_tile/tile.tscn")
|
|
|
|
var tile_drag_dict = {}
|
|
var tile_drag_array_global = []
|
|
|
|
var tile_count_x_hist = null
|
|
var tile_count_z_hist = null
|
|
|
|
var tile_drag_x_hist = null
|
|
var tile_drag_z_hist = null
|
|
|
|
func _ready():
|
|
pass
|
|
|
|
func clear_build_drag():
|
|
tile_count_x_hist = 0
|
|
tile_count_z_hist = 0
|
|
|
|
tile_drag_x_hist = 0
|
|
tile_drag_z_hist = 0
|
|
|
|
for i in tile_drag_dict:
|
|
var tile = tile_drag_dict[i]
|
|
tile.queue_free()
|
|
|
|
tile_drag_dict.clear()
|
|
|
|
func draw_tile_click(start_pos):
|
|
|
|
var build_start_pos: Vector3i = start_pos.snapped(Vector3i(1, 1, 1))
|
|
tile_drag_x_hist = 0
|
|
tile_drag_z_hist = 0
|
|
|
|
var tile = load_tile.instantiate()
|
|
|
|
tile.position = build_start_pos
|
|
|
|
tile_drag_dict[build_start_pos] = tile
|
|
|
|
add_child(tile)
|
|
|
|
func init_tile_drag(float_build_start_pos, float_build_mouse_pos):
|
|
|
|
var build_start_pos: Vector3i = float_build_start_pos.snapped(Vector3i(1.0, 1.0, 1.0))
|
|
var build_mouse_pos: Vector3i = float_build_mouse_pos.snapped(Vector3i(1.0, 1.0, 1.0))
|
|
|
|
var tile_count_x = build_mouse_pos.x - build_start_pos.x
|
|
var tile_count_z = build_mouse_pos.z - build_start_pos.z
|
|
|
|
if not tile_count_x_hist == tile_count_x or not tile_count_z_hist == tile_count_z:
|
|
var tile_count_x_diff = tile_count_x_hist - tile_count_x
|
|
var tile_count_z_diff = tile_count_z_hist - tile_count_z
|
|
|
|
tile_count_x_hist = tile_count_x
|
|
tile_count_z_hist = tile_count_z
|
|
|
|
draw_tile_drag(tile_count_x_diff, tile_count_z_diff, build_start_pos)
|
|
|
|
|
|
|
|
func draw_tile_drag(x_diff, z_diff, start_pos):
|
|
|
|
tile_drag_x_hist = x_diff + tile_drag_x_hist
|
|
tile_drag_z_hist = z_diff + tile_drag_z_hist
|
|
|
|
if x_diff:
|
|
for z in range(min(0, tile_drag_z_hist), max(0, tile_drag_z_hist) + 1):
|
|
for x in abs(x_diff):
|
|
var id = Vector3i(start_pos.x - tile_drag_x_hist, 0, start_pos.z - tile_drag_z_hist - z)
|
|
|
|
if tile_drag_dict.has(id):
|
|
var tile = tile_drag_dict[id]
|
|
tile.queue_free()
|
|
tile_drag_dict.erase(id)
|
|
else:
|
|
|
|
var tile = load_tile.instantiate()
|
|
tile.position = id
|
|
tile_drag_dict[id] = tile
|
|
add_child(tile)
|
|
|
|
if z_diff:
|
|
for x in range(min(0, tile_drag_x_hist), max(0, tile_drag_x_hist) + 1):
|
|
for z in abs(z_diff):
|
|
var id = Vector3i(start_pos.x - tile_drag_x_hist - x, 0, start_pos.z - tile_drag_z_hist)
|
|
|
|
if tile_drag_dict.has(id):
|
|
var tile = tile_drag_dict[id]
|
|
tile.queue_free()
|
|
tile_drag_dict.erase(id)
|
|
else:
|
|
var tile = load_tile.instantiate()
|
|
tile.position = id
|
|
tile_drag_dict[id] = tile
|
|
add_child(tile)
|
|
|
|
print(tile_drag_dict)
|
|
#if x_diff > 0:
|
|
#var tile = load_tile.instantiate()
|
|
#tile.position = Vector3i(start_pos.x - tile_drag_x_hist, 0, tile_drag_z_hist - z)
|
|
#
|
|
#print(Vector3i(start_pos.x - tile_drag_x_hist, 0, tile_drag_z_hist - z))
|
|
#tile_drag_dict[tile.position] = tile
|
|
#
|
|
#add_child(tile)
|
|
#
|
|
#if x_diff < 0:
|
|
#print(Vector3i(start_pos.x - tile_drag_x_hist, 0, tile_drag_z_hist - z))
|
|
|
|
|
|
|
|
|
|
#print(tile_drag_z_hist)
|
|
|
|
|
|
|
|
# order of events:
|
|
# get start and current mouse pos
|
|
# check for changes in drag grid dimension
|
|
# if changes, send to gird draw func
|
|
# add/remove tiles along each changed dimension
|
|
|
|
#var tile_x_diff = null
|
|
#var tile_z_diff = null
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
#if tile_count_x_hist == null:
|
|
#tile_x_diff = 0
|
|
#else:
|
|
#tile_x_diff = tile_count_x_hist - tile_count_x
|
|
#
|
|
#tile_count_x_hist = tile_x_diff
|
|
##print(tile_count_x_hist)
|
|
#
|
|
#if not tile_count_z_hist:
|
|
#tile_z_diff = 0
|
|
#else:
|
|
#tile_z_diff = tile_count_z_hist - tile_count_z
|
|
#
|
|
#if tile_x_diff or tile_z_diff:
|
|
#draw_tile_drag(tile_x_diff, tile_z_diff, build_start_pos)
|
|
#tile_count_x_hist = tile_count_x
|
|
#tile_count_z_hist = tile_count_z
|
|
|
|
#var tile_drag_array = []
|
|
#var tile_count_x_array = [0]
|
|
#var tile_count_z_array = [0]
|
|
#
|
|
#var tile_count_x = build_mouse_pos.x - build_start_pos.x
|
|
#var tile_count_z = build_mouse_pos.z - build_start_pos.z
|
|
|
|
#if tile_count_x < 0:
|
|
#tile_count_x_array.append_array(range(-1, tile_count_x - 1, -1))
|
|
#tile_count_x_array.reverse()
|
|
#
|
|
#if tile_count_x > 0:
|
|
#tile_count_x_array.append_array(range(1, tile_count_x + 1))
|
|
#
|
|
#if tile_count_z < 0:
|
|
#tile_count_z_array.append_array(range(-1, tile_count_z - 1, -1))
|
|
#tile_count_z_array.reverse()
|
|
#
|
|
#if tile_count_z > 0:
|
|
#tile_count_z_array.append_array(range(1, tile_count_z + 1))
|
|
|
|
#for x in range(min(0, tile_count_x), max(0, tile_count_x) + 1):
|
|
#for z in range(min(0, tile_count_z), max(0, tile_count_z) + 1):
|
|
#var tile_drag_pos = build_start_pos + Vector3i(x, 0, z)
|
|
#
|
|
#tile_drag_array.append(tile_drag_pos)
|
|
|
|
#for x in tile_count_x_array:
|
|
#for z in tile_count_z_array:
|
|
#
|
|
#print(tile_drag_array)
|
|
|
|
#func draw_tile_drag(x_diff, z_diff, start_pos):
|
|
|
|
#print(x_diff, " ", z_diff)
|
|
|
|
#i
|
|
#
|
|
#tile.position = i
|
|
#
|
|
#tile_drag_dict[i] = tile
|
|
|
|
pass
|
|
#print(x_diff, " ", z_diff)
|
|
|
|
#for i in self.get_children():
|
|
#i.queue_free()
|
|
|
|
#for i in array:
|
|
#
|
|
#var id = i
|
|
#
|
|
#if not tile_drag_dict.has(id):
|
|
#var tile = load_tile.instantiate()
|
|
#
|
|
#tile.position = i
|
|
#
|
|
#tile_drag_dict[id] = tile
|
|
#
|
|
#add_child(tile)
|