Skip to content

Commit 1f49794

Browse files
author
Joshua Storost
committed
minor refactor
1 parent 113bd39 commit 1f49794

File tree

1 file changed

+58
-31
lines changed

1 file changed

+58
-31
lines changed

source/GM-TE/GMTEEditorTileMap.class.st

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ GMTEEditorTileMap class >> tileWidth: aWidth tileHeight: aHeight padding: aPaddi
2222
model: aModel
2323
]
2424

25+
{
26+
#category : #accessing,
27+
#'squeak_changestamp' : 'JS 7/12/2024 14:48'
28+
}
29+
GMTEEditorTileMap >> brush [
30+
31+
^ model brush
32+
]
33+
2534
{
2635
#category : #accessing,
2736
#'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:15'
@@ -85,6 +94,22 @@ GMTEEditorTileMap >> handlesMouseOver: anEvent [
8594
^ true
8695
]
8796

97+
{
98+
#category : #'event handling',
99+
#'squeak_changestamp' : 'JS 7/12/2024 15:15'
100+
}
101+
GMTEEditorTileMap >> highlightTilesFromIndices: anIndexSet [
102+
103+
| hoveredHighlightingTile |
104+
self tileSelectionSet clearAllHighlightings.
105+
anIndexSet ifNil: [^ nil].
106+
107+
(anIndexSet select: [:c |
108+
(self tileMatrixStack layer: self model selectedLayers anyOne) inBounds: c]) do: [:t |
109+
hoveredHighlightingTile := self highlightingTileFromIndex: t.
110+
hoveredHighlightingTile ifNotNil: [self tileSelectionSet highlightTile: hoveredHighlightingTile]]
111+
]
112+
88113
{
89114
#category : #initialization,
90115
#'squeak_changestamp' : 'Alex M 6/28/2024 20:24'
@@ -118,71 +143,64 @@ GMTEEditorTileMap >> model: anObject [
118143

119144
{
120145
#category : #'event handling',
121-
#'squeak_changestamp' : 'JS 7/11/2024 14:13'
146+
#'squeak_changestamp' : 'JS 7/12/2024 15:19'
122147
}
123148
GMTEEditorTileMap >> mouseDown: anEvent [
124-
"Implements placement of tiles"
125149

126150
| selectedIndex |
127-
self flag: 'refactor; method extraction for "Add tiles to layer" to minimize redundancy with mouseMove?'.
128-
self model singleLayerSelected ifFalse: [^nil].
151+
self model singleLayerSelected ifFalse: [^ nil].
152+
129153
selectedIndex := self tileIndexFromPosition: anEvent position.
130-
self model brush firstMatrixIndex: selectedIndex.
131-
self model brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: self model selectedLayers anyOne).
132-
anEvent yellowButtonPressed ifTrue: [self tileSelectionSet highlightImage: nil].
154+
self brush firstMatrixIndex: selectedIndex.
133155

134-
^ true
156+
self brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: self selectedLayers anyOne).
157+
anEvent yellowButtonPressed ifTrue: [self tileSelectionSet highlightImage: nil]
135158
]
136159

137160
{
138161
#category : #'event handling',
139-
#'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 17:18'
162+
#'squeak_changestamp' : 'JS 7/12/2024 15:18'
140163
}
141164
GMTEEditorTileMap >> mouseLeave: anEvent [
142165

143-
self tileSelectionSet clearAllHighlightings.
144-
145-
^ true
166+
self tileSelectionSet clearAllHighlightings
146167
]
147168

148169
{
149170
#category : #'event handling',
150-
#'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 17:01'
171+
#'squeak_changestamp' : 'JS 7/12/2024 15:17'
151172
}
152173
GMTEEditorTileMap >> mouseMove: anEvent [
153174
"Implements highlighting of tiles when hovering"
154175

155-
| hoveredTileHighlighting activeLayer selectedCoordinates |
176+
| activeLayer selectedIndices |
156177
self model singleLayerSelected ifFalse: [^ nil].
157178

158-
activeLayer := self model selectedLayers anyOne.
159-
selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position) andLayer: (self tileMatrixStack layer: activeLayer).
160-
(anEvent redButtonPressed or: [anEvent yellowButtonPressed]) ifFalse: [self model brush resetOutputSet].
161-
self tileSelectionSet clearAllHighlightings.
179+
activeLayer := self tileMatrixStack layer: self model selectedLayers anyOne.
180+
selectedIndices := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position) andLayer: activeLayer.
162181

163-
selectedCoordinates ifNil: [^ nil].
182+
(anEvent redButtonPressed or: [anEvent yellowButtonPressed]) ifFalse: [self model brush resetOutputSet].
164183

165-
(selectedCoordinates select: [:c |
166-
(self tileMatrixStack layer: activeLayer) inBounds: c]) do: [:t |
167-
hoveredTileHighlighting := self highlightingTileFromIndex: t.
168-
hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]]
184+
self highlightTilesFromIndices: selectedIndices
169185
]
170186

171187
{
172188
#category : #'event handling',
173-
#'squeak_changestamp' : 'mcjj 7/11/2024 16:20'
189+
#'squeak_changestamp' : 'JS 7/12/2024 15:23'
174190
}
175191
GMTEEditorTileMap >> mouseUp: anEvent [
176192

177-
| indicesToAdd activeLayer |
178-
self model brush firstMatrixIndex: nil.
179-
indicesToAdd := self model brush outputSet.
180-
activeLayer := self model selectedLayers anyOne.
181-
self updateTiles: (indicesToAdd asCollection) inLayer: activeLayer FromEvent: anEvent.
193+
| selectedIndices |
194+
self brush firstMatrixIndex: nil.
195+
196+
selectedIndices := self brush outputSet asCollection.
197+
198+
self updateTiles: selectedIndices inLayer: self selectedLayers anyOne FromEvent: anEvent.
182199
self model brush resetOutputSet.
200+
183201
(self previousTileStates isEmpty) ifFalse: [self saveTileEditChanges].
184-
self tileSelectionSet clearAllHighlightings.
185-
self tileSelectionSet highlightImage: (self model selectedTile)
202+
self tileSelectionSet clearAllHighlightings;
203+
highlightImage: (self model selectedTile)
186204

187205
]
188206

@@ -317,6 +335,15 @@ GMTEEditorTileMap >> saveTileEditChanges [
317335
self resetTileEditChanges.
318336
]
319337

338+
{
339+
#category : #accessing,
340+
#'squeak_changestamp' : 'JS 7/12/2024 14:49'
341+
}
342+
GMTEEditorTileMap >> selectedLayers [
343+
344+
^ model selectedLayers
345+
]
346+
320347
{
321348
#category : #accessing,
322349
#'squeak_changestamp' : 'jj 6/23/2024 13:35'

0 commit comments

Comments
 (0)