From 1f4979481666af270d1a136aae29539c64a9cc94 Mon Sep 17 00:00:00 2001 From: Joshua Storost Date: Fri, 12 Jul 2024 15:25:34 +0200 Subject: [PATCH] minor refactor --- source/GM-TE/GMTEEditorTileMap.class.st | 89 ++++++++++++++++--------- 1 file changed, 58 insertions(+), 31 deletions(-) diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index dcc54e73..7a619573 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -22,6 +22,15 @@ GMTEEditorTileMap class >> tileWidth: aWidth tileHeight: aHeight padding: aPaddi model: aModel ] +{ + #category : #accessing, + #'squeak_changestamp' : 'JS 7/12/2024 14:48' +} +GMTEEditorTileMap >> brush [ + + ^ model brush +] + { #category : #accessing, #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:15' @@ -85,6 +94,22 @@ GMTEEditorTileMap >> handlesMouseOver: anEvent [ ^ true ] +{ + #category : #'event handling', + #'squeak_changestamp' : 'JS 7/12/2024 15:15' +} +GMTEEditorTileMap >> highlightTilesFromIndices: anIndexSet [ + + | hoveredHighlightingTile | + self tileSelectionSet clearAllHighlightings. + anIndexSet ifNil: [^ nil]. + + (anIndexSet select: [:c | + (self tileMatrixStack layer: self model selectedLayers anyOne) inBounds: c]) do: [:t | + hoveredHighlightingTile := self highlightingTileFromIndex: t. + hoveredHighlightingTile ifNotNil: [self tileSelectionSet highlightTile: hoveredHighlightingTile]] +] + { #category : #initialization, #'squeak_changestamp' : 'Alex M 6/28/2024 20:24' @@ -118,71 +143,64 @@ GMTEEditorTileMap >> model: anObject [ { #category : #'event handling', - #'squeak_changestamp' : 'JS 7/11/2024 14:13' + #'squeak_changestamp' : 'JS 7/12/2024 15:19' } GMTEEditorTileMap >> mouseDown: anEvent [ - "Implements placement of tiles" | selectedIndex | - self flag: 'refactor; method extraction for "Add tiles to layer" to minimize redundancy with mouseMove?'. - self model singleLayerSelected ifFalse: [^nil]. + self model singleLayerSelected ifFalse: [^ nil]. + selectedIndex := self tileIndexFromPosition: anEvent position. - self model brush firstMatrixIndex: selectedIndex. - self model brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: self model selectedLayers anyOne). - anEvent yellowButtonPressed ifTrue: [self tileSelectionSet highlightImage: nil]. + self brush firstMatrixIndex: selectedIndex. - ^ true + self brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: self selectedLayers anyOne). + anEvent yellowButtonPressed ifTrue: [self tileSelectionSet highlightImage: nil] ] { #category : #'event handling', - #'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 17:18' + #'squeak_changestamp' : 'JS 7/12/2024 15:18' } GMTEEditorTileMap >> mouseLeave: anEvent [ - self tileSelectionSet clearAllHighlightings. - - ^ true + self tileSelectionSet clearAllHighlightings ] { #category : #'event handling', - #'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 17:01' + #'squeak_changestamp' : 'JS 7/12/2024 15:17' } GMTEEditorTileMap >> mouseMove: anEvent [ "Implements highlighting of tiles when hovering" - | hoveredTileHighlighting activeLayer selectedCoordinates | + | activeLayer selectedIndices | self model singleLayerSelected ifFalse: [^ nil]. - activeLayer := self model selectedLayers anyOne. - selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position) andLayer: (self tileMatrixStack layer: activeLayer). - (anEvent redButtonPressed or: [anEvent yellowButtonPressed]) ifFalse: [self model brush resetOutputSet]. - self tileSelectionSet clearAllHighlightings. + activeLayer := self tileMatrixStack layer: self model selectedLayers anyOne. + selectedIndices := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position) andLayer: activeLayer. - selectedCoordinates ifNil: [^ nil]. + (anEvent redButtonPressed or: [anEvent yellowButtonPressed]) ifFalse: [self model brush resetOutputSet]. - (selectedCoordinates select: [:c | - (self tileMatrixStack layer: activeLayer) inBounds: c]) do: [:t | - hoveredTileHighlighting := self highlightingTileFromIndex: t. - hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]] + self highlightTilesFromIndices: selectedIndices ] { #category : #'event handling', - #'squeak_changestamp' : 'mcjj 7/11/2024 16:20' + #'squeak_changestamp' : 'JS 7/12/2024 15:23' } GMTEEditorTileMap >> mouseUp: anEvent [ - | indicesToAdd activeLayer | - self model brush firstMatrixIndex: nil. - indicesToAdd := self model brush outputSet. - activeLayer := self model selectedLayers anyOne. - self updateTiles: (indicesToAdd asCollection) inLayer: activeLayer FromEvent: anEvent. + | selectedIndices | + self brush firstMatrixIndex: nil. + + selectedIndices := self brush outputSet asCollection. + + self updateTiles: selectedIndices inLayer: self selectedLayers anyOne FromEvent: anEvent. self model brush resetOutputSet. + (self previousTileStates isEmpty) ifFalse: [self saveTileEditChanges]. - self tileSelectionSet clearAllHighlightings. - self tileSelectionSet highlightImage: (self model selectedTile) + self tileSelectionSet clearAllHighlightings; + highlightImage: (self model selectedTile) ] @@ -317,6 +335,15 @@ GMTEEditorTileMap >> saveTileEditChanges [ self resetTileEditChanges. ] +{ + #category : #accessing, + #'squeak_changestamp' : 'JS 7/12/2024 14:49' +} +GMTEEditorTileMap >> selectedLayers [ + + ^ model selectedLayers +] + { #category : #accessing, #'squeak_changestamp' : 'jj 6/23/2024 13:35'