aboutsummaryrefslogtreecommitdiff
path: root/src/addons/rmsmartshape/LEGACY_vertex_properties_array.gd
blob: e1e15dddc9b275eea223bad13048cfb7db753bbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
extends Reference
class_name RMS2D_VertexPropertiesArray

var properties:Array = []

#############
# INTERFACE #
#############
"""
Returns true if changed
"""
func remove_point(idx:int)->bool:
	assert(_is_array_index_in_range(properties, idx))
	properties.remove(idx)
	return true

"""
Returns true if changed
"""
func add_point(idx:int)->bool:
	var new_point_idx = -1
	if idx < 0:
		properties.push_back(RMS2D_VertexProperties.new())
		new_point_idx = properties.size() - 1
	else:
		assert(_is_array_index_in_range(properties, idx))
		properties.insert(idx, RMS2D_VertexProperties.new())
		new_point_idx = idx

	var old_idx = new_point_idx - 1
	properties[new_point_idx] = properties[old_idx].duplicate()
	return true

"""
Returns true if changed
"""
func resize(new_size:int):
	var old_size = properties.size()
	var delta = new_size - old_size
	if delta == 0:
		return false
	properties.resize(new_size)
	if delta > 0:
		for i in range(old_size-1, new_size, 1):
			properties[i] = RMS2D_VertexProperties.new()
	return true

"""
Returns true if changed
"""
func set_texture_idx(v:int, idx:int)->bool:
	if not _is_array_index_in_range(properties, idx):
		return false
	properties[idx].texture_idx = v
	return true

"""
Returns true if changed
"""
func set_flip(v:bool, idx:int)->bool:
	if not _is_array_index_in_range(properties, idx):
		return false
	properties[idx].flip = v
	return true

"""
Returns true if changed
"""
func set_width(v:float, idx:int)->bool:
	if not _is_array_index_in_range(properties, idx):
		return false
	properties[idx].width = v
	return true


#########
# GODOT #
#########
"""
Accepts either int or another instance of this class as a constructor argument
"""
func _init(arg):
	if typeof(arg) == TYPE_INT:
		__init_size(arg)
	#elif arg is RMS2D_VertexPropertiesArray:
	#	__init_class(arg)
	else:
		assert(false)

func __init_size(_size):
	for i in range(0, _size, 1):
		properties.push_back(RMS2D_VertexProperties.new())

func __init_class(other):
	for p in other.properties:
		properties.push_back(p.duplicate())

###########
# GETTERS #
###########
func get_texture_idx(idx:int)->int:
	if not _is_array_index_in_range(properties, idx):
		return -1
	return properties[idx].texture_idx

func get_flip(idx:int)->bool:
	if not _is_array_index_in_range(properties, idx):
		return false
	return properties[idx].flip

func get_width(idx:int)->float:
	if not _is_array_index_in_range(properties, idx):
		return 1.0
	return properties[idx].width


###########
# PRIVATE #
###########
func _is_array_index_in_range(a:Array, i:int)->bool:
	if a.size() > i and i >= 0:
		return true
	return false