diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index c707dd0d..652142c4 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -17,7 +17,8 @@ Class { 'tileMap', 'associatedMorph', 'commands', - 'currentCommand' + 'currentCommand', + 'brushMode' ], #category : #'GM-TE-UI' } @@ -270,6 +271,22 @@ GMTEEditor >> blendSelectedLayers [ self changed: #getLayerList ] +{ + #category : #accessing, + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 15:39' +} +GMTEEditor >> brushMode [ + ^ brushMode +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 15:39' +} +GMTEEditor >> brushMode: anObject [ + brushMode := anObject +] + { #category : #building, #'squeak_changestamp' : 'TW 6/25/2024 15:56' diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 8d657e6a..029d84cd 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -22,6 +22,30 @@ GMTEEditorTileMap class >> tileWidth: aWidth tileHeight: aHeight padding: aPaddi model: aModel ] +{ + #category : #TODO, + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 17:07' +} +GMTEEditorTileMap >> calculateTileCollectionFromPosition: aPos andLayer: aLayer [ + + | index rawCollection resultCollection | + self flag: 'remove method'. + index := self tileIndexFromPosition: aPos. + index ifNil: [^ nil]. + rawCollection := OrderedCollection new. + resultCollection := OrderedCollection new. + self flag: 'Add different algos'. + rawCollection add: (self tileMatrixStack layer: aLayer at: index y at: index x). + self halt. + + rawCollection add: (self tileMatrixStack layer: aLayer at: index y at: ((index x)+1)). + rawCollection do: [:t | + t ifNil: [resultCollection add: (self generateTileAtlayer: aLayer x: index x y: index y stack: self tileMatrixStack tileType: GMTETile)]. + t ifNotNil: [resultCollection add: t] + ]. + ^ resultCollection +] + { #category : #accessing, #'squeak_changestamp' : 'Alex M 6/28/2024 19:28' @@ -89,29 +113,29 @@ GMTEEditorTileMap >> model: anObject [ { #category : #'event handling', - #'squeak_changestamp' : 'Alex M 7/1/2024 15:40' + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 17:39' } GMTEEditorTileMap >> mouseDown: anEvent [ "Implements placement of tiles" - | clickedTile activeLayer | + | selectedCoordinates activeLayer | self model singleLayerSelected ifTrue: [ activeLayer := self model selectedLayers anyOne. - clickedTile := self tileFromPosition: anEvent position layer: activeLayer. - self updateTile: clickedTile inLayer: activeLayer FromEvent: anEvent]. + selectedCoordinates := self radiusBrushFromCenter: (self tileIndexFromPosition: anEvent position) withRadius: 1. + self updateTiles: selectedCoordinates inLayer: activeLayer FromEvent: anEvent]. ^ true ] { #category : #'event handling', - #'squeak_changestamp' : 'Alex M 7/1/2024 15:40' + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 16:21' } GMTEEditorTileMap >> mouseMove: anEvent [ "Implements highlighting of tiles when hovering" - +" | hoveredTile hoveredTileHighlighting activeLayer | self model singleLayerSelected ifTrue: [activeLayer := self model selectedLayers anyOne. @@ -123,9 +147,9 @@ GMTEEditorTileMap >> mouseMove: anEvent [ hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]. - "TODO why another ifNil check here?" + TODO why another ifNil check here? - self updateTile: hoveredTile inLayer: activeLayer FromEvent: anEvent] + self updateTile: hoveredTile inLayer: activeLayer FromEvent: anEvent]" ] { @@ -153,6 +177,20 @@ GMTEEditorTileMap >> previousTileStates: anObject [ previousTileStates := anObject ] +{ + #category : #initialization, + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 17:19' +} +GMTEEditorTileMap >> radiusBrushFromCenter: aPos withRadius: aRadius [ + + |collection| + self flag: 'temporary only'. + collection := OrderedCollection new. + collection add: aPos. + collection add: (aPos + (0@1)). + ^ collection +] + { #category : #updating, #'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:35' @@ -252,54 +290,34 @@ GMTEEditorTileMap >> tileSelectionSet: anObject [ { #category : #updating, - #'squeak_changestamp' : 'Alex M 7/1/2024 16:08' + #'squeak_changestamp' : 'Alex M 6/25/2024 18:08' +} +GMTEEditorTileMap >> updateTileSprite: aTile [ + "Helper function to apply sprite from tile selection to aTile" + + self model selectedTile ifNotNil: [aTile updateSprite: self model selectedTile] +] + +{ + #category : #updating, + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 17:59' } -GMTEEditorTileMap >> updateTile: aTile inLayer: aLayer FromEvent: anEvent [ +GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEvent: anEvent [ "Add currently selected tile (model) to editable matrix stack at mouse position" - - | tileIndex hoveredTile | - hoveredTile := aTile. + | tile | (self tileIndexFromPosition: anEvent position) ifNil: [^ nil]. (anEvent redButtonPressed and: [self model selectedTile notNil]) ifTrue: [ - - self savePreviousImageFromPosition: anEvent position inLayer: aLayer. - - "Add tile if nil at mouse position" - hoveredTile ifNil: [ - tileIndex := self tileIndexFromPosition: anEvent position. - tileIndex ifNil: [^ nil]. - hoveredTile := self generateTileAtlayer: aLayer x: tileIndex x y: tileIndex y stack: self tileMatrixStack tileType: GMTETile]. - - "Set tile to currently selected tile" - self updateTileSprite: hoveredTile. - - self saveNewImageFromPosition: anEvent position inLayer: aLayer. + aCoordinateCollection do: [:c | + self savePreviousImageFromPosition: (self correctedTilePositionMap: c) inLayer: aLayer. + ((self tileMatrixStack layer: aLayer) inBounds: c) ifTrue: [ + tile := self tileMatrixStack layer: aLayer at: c y at: c x. + tile + ifNil: [ tile := self generateTileAtlayer: aLayer x: c x y: c y stack: tileMatrixStack tileType: GMTETile]. + self updateTileSprite: tile. + self saveNewImageFromPosition: tile position inLayer: aLayer] + ]. self model savedSinceModified: false]. - - ((anEvent yellowButtonPressed) and: [hoveredTile notNil]) - ifTrue: [ - self savePreviousImageFromPosition: anEvent position inLayer: aLayer. - - "Remove tile if any present at mouse position" - aLayer ifNotNil: [ - tileIndex := self tileIndexFromPosition: anEvent position. - self tileMatrixStack layer: aLayer at: tileIndex y at: tileIndex x put: nil. - hoveredTile abandon]. - - self saveNewImageFromPosition: anEvent position inLayer: aLayer. - self model savedSinceModified: false]. - -] - -{ - #category : #updating, - #'squeak_changestamp' : 'Alex M 6/25/2024 18:08' -} -GMTEEditorTileMap >> updateTileSprite: aTile [ - "Helper function to apply sprite from tile selection to aTile" - - self model selectedTile ifNotNil: [aTile updateSprite: self model selectedTile] ] diff --git a/source/GM-TE/GMTETileMatrixLayer.class.st b/source/GM-TE/GMTETileMatrixLayer.class.st index 3c6a52af..96ddfb73 100644 --- a/source/GM-TE/GMTETileMatrixLayer.class.st +++ b/source/GM-TE/GMTETileMatrixLayer.class.st @@ -32,14 +32,17 @@ GMTETileMatrixLayer >> aboveLayer: aLayer [ { #category : #adding, - #'squeak_changestamp' : 'Ivo Zilkenat 6/23/2024 21:27' + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 17:50' } GMTETileMatrixLayer >> addTile: aTile at: y at: x [ - aTile ifNotNil: [ + (aTile isNil not and: [self inBounds: x@y]) ifTrue: [ aTile morphicLayerNumber: self layerIndex. aTile visible: self visible]. ^ self at: y at: x put: aTile + + + ] { @@ -119,6 +122,17 @@ GMTETileMatrixLayer >> free [ self setNil ] +{ + #category : #comparing, + #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 17:52' +} +GMTETileMatrixLayer >> inBounds: aPos [ + + (aPos x > self columnCount or: [aPos x < 1]) ifTrue: [^ false]. + (aPos y > self rowCount or: [aPos y < 1]) ifTrue: [^ false]. + ^ true +] + { #category : #initialization, #'squeak_changestamp' : 'Ivo Zilkenat 6/23/2024 21:09'