@@ -10,6 +10,9 @@ onready var oSlabPlacement = Nodelist.list["oSlabPlacement"]
10
10
onready var oResizeFillWithID = Nodelist .list ["oResizeFillWithID" ]
11
11
onready var oResizeFillWithIDLabel = Nodelist .list ["oResizeFillWithIDLabel" ]
12
12
onready var oResizeMapApplyBorderCheckbox = Nodelist .list ["oResizeMapApplyBorderCheckbox" ]
13
+ onready var oMessage = Nodelist .list ["oMessage" ]
14
+ onready var oLoadingBar = Nodelist .list ["oLoadingBar" ]
15
+ onready var oDataClmPos = Nodelist .list ["oDataClmPos" ]
13
16
14
17
func _on_ResizeCurrentMapSizeButton_pressed ():
15
18
Utils .popup_centered (self )
@@ -18,54 +21,106 @@ func _on_ResizeCurrentMapSize_about_to_show():
18
21
oSettingsXSizeLine .text = str (M .xSize )
19
22
oSettingsYSizeLine .text = str (M .ySize )
20
23
21
- func _on_ResizeApplyButton_pressed ():
22
- var newWidth = int (oSettingsXSizeLine .text )
23
- var newHeight = int (oSettingsYSizeLine .text )
24
-
25
- var previousWidth = M .xSize
26
- var previousHeight = M .ySize
24
+ # Function to handle updating the map size
25
+ func set_new_map_size (newWidth , newHeight ):
27
26
M .xSize = newWidth
28
27
M .ySize = newHeight
29
28
oMapSizeTextLabel .text = str (M .xSize ) + " x " + str (M .ySize )
30
29
30
+ # Function to get positions that need to be updated
31
+ func get_positions_to_update (newWidth , newHeight , previousWidth , previousHeight ):
31
32
var positionsToUpdate = {}
32
-
33
- # Handle width
34
33
if newWidth > previousWidth :
35
34
for x in range (previousWidth , newWidth ):
36
- for y in range ( newHeight ) :
35
+ for y in newHeight :
37
36
positionsToUpdate [Vector2 (x , y )] = true
38
- # Handle height
39
37
if newHeight > previousHeight :
40
38
for y in range (previousHeight , newHeight ):
41
- for x in range ( newWidth ) :
39
+ for x in newWidth :
42
40
positionsToUpdate [Vector2 (x , y )] = true
41
+ oSlabPlacement .place_shape_of_slab_id (positionsToUpdate .keys (), Slabs .EARTH , 5 )
42
+ return positionsToUpdate
43
43
44
+ # Function to remove old borders
45
+ func remove_old_borders (newWidth , newHeight , previousWidth , previousHeight ):
46
+ var removeBorder = []
47
+ if newWidth > previousWidth :
48
+ for y in previousHeight :
49
+ removeBorder .append (Vector2 (previousWidth - 1 , y ))
50
+ if newHeight > previousHeight :
51
+ for x in previousWidth :
52
+ removeBorder .append (Vector2 (x , previousHeight - 1 ))
53
+ oSlabPlacement .place_shape_of_slab_id (removeBorder , Slabs .EARTH , 5 )
54
+ return removeBorder
55
+
56
+ # Function to add new borders
57
+ func add_new_borders (newWidth , newHeight ):
58
+ var addBorder = []
59
+ for x in newWidth :
60
+ addBorder .append (Vector2 (x , 0 ))
61
+ addBorder .append (Vector2 (x , newHeight - 1 ))
62
+ for y in newHeight :
63
+ addBorder .append (Vector2 (0 , y ))
64
+ addBorder .append (Vector2 (newWidth - 1 , y ))
65
+ oSlabPlacement .place_shape_of_slab_id (addBorder , Slabs .ROCK , 5 )
66
+ return addBorder
67
+
68
+ # Function to remove instances outside of the new map size
69
+ func remove_outside_instances (newWidth , newHeight ):
70
+ var deletedInstancesCount = 0
71
+ var newHeightInSubtiles = newHeight * 3
72
+ var newWidthInSubtiles = newWidth * 3
73
+
74
+ for instance in get_tree ().get_nodes_in_group ("Instance" ):
75
+ if instance .locationX >= newWidthInSubtiles or instance .locationY >= newHeightInSubtiles :
76
+ deletedInstancesCount += 1
77
+ instance .queue_free ()
78
+
79
+ if deletedInstancesCount > 0 :
80
+ oMessage .quick ("Deleted " + str (deletedInstancesCount ) + " instances that were outside of the new map size." )
81
+
82
+ func update_editor_appearance ():
44
83
oEditor .update_boundaries ()
45
84
oOverheadOwnership .start ()
46
85
oOverheadGraphics .update_map_overhead_2d_textures ()
47
86
48
- # Apply changes for added positions
49
- var newlyAddedPositions = positionsToUpdate .keys ()
50
- oSlabPlacement .place_shape_of_slab_id (newlyAddedPositions , int (oResizeFillWithID .value ), 5 )
87
+ # The main function that calls all the helper functions
88
+ func _on_ResizeApplyButton_pressed ():
89
+ var newWidth = int (oSettingsXSizeLine .text )
90
+ var newHeight = int (oSettingsYSizeLine .text )
91
+ var previousWidth = M .xSize
92
+ var previousHeight = M .ySize
93
+ set_new_map_size (newWidth , newHeight )
94
+ remove_outside_instances (newWidth , newHeight )
51
95
52
- if oResizeMapApplyBorderCheckbox .pressed == true :
53
- var borderPositions = []
54
- for x in range (newWidth ):
55
- positionsToUpdate [Vector2 (x , 0 )] = true
56
- positionsToUpdate [Vector2 (x , newHeight - 1 )] = true
57
- borderPositions .append (Vector2 (x , 0 )) # Top border
58
- borderPositions .append (Vector2 (x , newHeight - 1 )) # Bottom border
59
- for y in range (newHeight ):
60
- positionsToUpdate [Vector2 (0 , y )] = true
61
- positionsToUpdate [Vector2 (newWidth - 1 , y )] = true
62
- borderPositions .append (Vector2 (0 , y )) # Left border
63
- borderPositions .append (Vector2 (newWidth - 1 , y )) # Right border
64
- oSlabPlacement .place_shape_of_slab_id (borderPositions , Slabs .ROCK , 5 )
96
+ var positionsToUpdate = get_positions_to_update (newWidth , newHeight , previousWidth , previousHeight )
97
+ var removeBorder = remove_old_borders (newWidth , newHeight , previousWidth , previousHeight )
98
+ var addBorder = add_new_borders (newWidth , newHeight )
99
+ for pos in removeBorder :
100
+ positionsToUpdate [pos ] = true
101
+ for pos in addBorder :
102
+ positionsToUpdate [pos ] = true
103
+
104
+ set_various_grid_data (newWidth , newHeight , previousWidth , previousHeight )
105
+
106
+ update_editor_appearance ()
65
107
66
- # Finalize
67
108
oSlabPlacement .generate_slabs_based_on_id (positionsToUpdate .keys (), false )
68
109
110
+ func set_various_grid_data (newWidth , newHeight , previousWidth , previousHeight ):
111
+ var newWidthInSubtiles = newWidth * 3
112
+ var newHeightInSubtiles = newHeight * 3
113
+ var prevWidthInSubtiles = previousWidth * 3
114
+ var prevHeightInSubtiles = previousHeight * 3
115
+
116
+ for x in prevWidthInSubtiles :
117
+ for y in prevHeightInSubtiles :
118
+ if x >= newWidthInSubtiles or y >= newHeightInSubtiles :
119
+ oDataClmPos .set_cell (x , y , 0 )
120
+
121
+
122
+
123
+
69
124
func _on_SettingsXSizeLine_focus_exited ():
70
125
if int (oSettingsXSizeLine .text ) > 170 :
71
126
oSettingsXSizeLine .text = "170"
@@ -74,6 +129,82 @@ func _on_SettingsYSizeLine_focus_exited():
74
129
if int (oSettingsYSizeLine .text ) > 170 :
75
130
oSettingsYSizeLine .text = "170"
76
131
132
+ func _on_ResizeFillWithID_value_changed (value ):
133
+ value = int (value )
134
+ if Slabs .data .has (value ):
135
+ oResizeFillWithIDLabel .text = Slabs .data [value ][Slabs .NAME ]
136
+
137
+
138
+
139
+ # func _on_ResizeApplyButton_pressed():
140
+ # var newWidth = int(oSettingsXSizeLine.text)
141
+ # var newHeight = int(oSettingsYSizeLine.text)
142
+ #
143
+ # var previousWidth = M.xSize
144
+ # var previousHeight = M.ySize
145
+ # M.xSize = newWidth
146
+ # M.ySize = newHeight
147
+ # oMapSizeTextLabel.text = str(M.xSize) + " x " + str(M.ySize)
148
+ #
149
+ # var positionsToUpdate = {}
150
+ #
151
+ # # Handle width
152
+ # if newWidth > previousWidth:
153
+ # for x in range(previousWidth, newWidth):
154
+ # for y in newHeight:
155
+ # positionsToUpdate[Vector2(x, y)] = true
156
+ # # Handle height
157
+ # if newHeight > previousHeight:
158
+ # for y in range(previousHeight, newHeight):
159
+ # for x in newWidth:
160
+ # positionsToUpdate[Vector2(x, y)] = true
161
+ #
162
+ # oEditor.update_boundaries()
163
+ # oOverheadOwnership.start()
164
+ # oOverheadGraphics.update_map_overhead_2d_textures()
165
+ #
166
+ # # Apply changes for added positions
167
+ # oSlabPlacement.place_shape_of_slab_id(positionsToUpdate.keys(), Slabs.EARTH, 5)
168
+ #
169
+ # var removeBorder = [] # Remove old south and east borders when enlarging the map
170
+ # if newWidth > previousWidth:
171
+ # for y in previousHeight:
172
+ # removeBorder.append(Vector2(previousWidth - 1, y))
173
+ # if newHeight > previousHeight:
174
+ # for x in previousWidth:
175
+ # removeBorder.append(Vector2(x, previousHeight - 1))
176
+ # oSlabPlacement.place_shape_of_slab_id(removeBorder, Slabs.EARTH, 5)
177
+ #
178
+ # var addBorder = []
179
+ # for x in newWidth:
180
+ # addBorder.append(Vector2(x, 0))
181
+ # addBorder.append(Vector2(x, newHeight - 1))
182
+ # for y in newHeight:
183
+ # addBorder.append(Vector2(0, y))
184
+ # addBorder.append(Vector2(newWidth - 1, y))
185
+ # oSlabPlacement.place_shape_of_slab_id(addBorder, Slabs.ROCK, 5)
186
+ #
187
+ # for pos in addBorder: # Update the appearance of any border alterations
188
+ # positionsToUpdate[pos] = true
189
+ # for pos in removeBorder: # Update the appearance of any border alterations
190
+ # positionsToUpdate[pos] = true
191
+ #
192
+ # # Remove instances outside of the new map size
193
+ # var instances = get_tree().get_nodes_in_group("Instance")
194
+ # var deletedInstancesCount = 0
195
+ # var newHeightInSubtiles = newHeight * 3
196
+ # var newWidthInSubtiles = newWidth * 3
197
+ # for instance in instances:
198
+ # if instance.locationX >= newWidthInSubtiles or instance.locationY >= newHeightInSubtiles:
199
+ # deletedInstancesCount+=1
200
+ # instance.queue_free()
201
+ # if deletedInstancesCount > 0:
202
+ # oMessage.quick("Deleted " + str(deletedInstancesCount) + " instances that were outside of the new map size.")
203
+ #
204
+ # # Finalize
205
+ # oSlabPlacement.generate_slabs_based_on_id(positionsToUpdate.keys(), false)
206
+
207
+
77
208
78
209
# onready var resizeSegments = [ # These are ColorRects by the way.
79
210
# $MarginContainer/VBoxContainer/GridContainer/ResizeSegment1,
@@ -152,7 +283,3 @@ func _on_SettingsYSizeLine_focus_exited():
152
283
# if x >= previousWidth or y >= previousHeight:
153
284
# newPositionArray.append(Vector2(x, y))
154
285
155
- func _on_ResizeFillWithID_value_changed (value ):
156
- value = int (value )
157
- if Slabs .data .has (value ):
158
- oResizeFillWithIDLabel .text = Slabs .data [value ][Slabs .NAME ]
0 commit comments