diff --git a/source/GM-TE/GMTEEditableTileMap.class.st b/source/GM-TE/GMTEEditableTileMap.class.st index 7d471ea1..c055600b 100644 --- a/source/GM-TE/GMTEEditableTileMap.class.st +++ b/source/GM-TE/GMTEEditableTileMap.class.st @@ -68,45 +68,77 @@ GMTEEditableTileMap >> model: anObject [ { #category : #'event handling', - #'squeak_changestamp' : 'TW 5/22/2024 23:40' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:53' } GMTEEditableTileMap >> mouseDown: anEvent [ "TODO: make this useful." - | clickedTile | + | clickedTile tileIdx tmpActiveLayer| - clickedTile := self tileFromPosition: anEvent position. + tmpActiveLayer := self model LAYER_TEST. + + clickedTile := self tileFromPosition: anEvent position layer: 1. (anEvent redButtonPressed) ifTrue: [clickedTile ifNotNil: [self updateTileSprite: clickedTile]]. (anEvent yellowButtonPressed) ifTrue: [clickedTile ifNotNil: [clickedTile reset]]. + + (anEvent redButtonPressed) + ifTrue: [clickedTile + ifNil: [ + tileIdx := self tileIdxFromPosition: anEvent position. + tileIdx ifNil: [^nil]. + clickedTile := self generateTileAtlayer: tmpActiveLayer x: tileIdx x y: tileIdx y stack: self tileMatrixStack.]. + self updateTileSprite: clickedTile]. + (anEvent yellowButtonPressed) + ifTrue: [clickedTile + ifNotNil: [ + tileIdx := self tileIdxFromPosition: anEvent position. + self tileMatrixStack layer: 1 at: tileIdx y at: tileIdx x put: nil. + clickedTile abandon]]. + ^ true. ] { #category : #'event handling', - #'squeak_changestamp' : 'Alex M 5/23/2024 10:37' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:57' } GMTEEditableTileMap >> mouseMove: anEvent [ - | hoveredTile | + | hoveredTile hoveredTileVisual tileIdx tmpActiveLayer | + + "TODO currently hard coded" + tmpActiveLayer := self model LAYER_TEST. - hoveredTile := self tileFromPosition: anEvent position. - hoveredTile ifNil: [ - self tileSelectionSet clearAllHighlightings. - ^nil]. + hoveredTile := self tileFromPosition: anEvent position layer: tmpActiveLayer. + hoveredTileVisual := self tileVisualFromPosition: anEvent position. self tileSelectionSet clearAllHighlightings. - self tileSelectionSet highlightTile: hoveredTile. - - (anEvent redButtonPressed) ifTrue: [hoveredTile ifNotNil: [self updateTileSprite: hoveredTile]]. - (anEvent yellowButtonPressed) ifTrue: [hoveredTile ifNotNil: [hoveredTile reset]]. + + hoveredTileVisual + ifNotNil: [self tileSelectionSet highlightTile: hoveredTileVisual]. + + "TODO why another ifNil check here?" + (anEvent redButtonPressed) + ifTrue: [hoveredTile + ifNil: [ + tileIdx := self tileIdxFromPosition: anEvent position. + tileIdx ifNil: [^nil]. + hoveredTile := self generateTileAtlayer: tmpActiveLayer x: tileIdx x y: tileIdx y stack: self tileMatrixStack.]. + self updateTileSprite: hoveredTile]. + (anEvent yellowButtonPressed) + ifTrue: [hoveredTile + ifNotNil: [ + tileIdx := self tileIdxFromPosition: anEvent position. + self tileMatrixStack layer: 1 at: tileIdx y at: tileIdx x put: nil. + hoveredTile abandon]]. "This solves the bug but not the root of the issue. TODO further investigation." "self updateTiles." - hoveredTile + "hoveredTileVisual extent: self tileSizeWidth@self tileSizeHeight; borderColor: Color white; color: Color veryLightGray; - borderWidth: 2 + borderWidth: 2" ] { diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index ca545832..ca360d5d 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -11,7 +11,8 @@ Class { 'layerList', 'tileMapMatrix', 'selectedTile', - 'ratio' + 'ratio', + 'LAYER_TEST' ], #category : #'GM-TE' } @@ -128,6 +129,24 @@ GMTEEditor class >> layerList [ ^ {'Layer 1'. 'Layer 2'} ] +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:52' +} +GMTEEditor >> LAYER_TEST [ + + ^ LAYER_TEST +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:52' +} +GMTEEditor >> LAYER_TEST: anObject [ + + LAYER_TEST := anObject. +] + { #category : #building, #'squeak_changestamp' : 'Alex M 5/23/2024 21:09' @@ -434,7 +453,7 @@ GMTEEditor >> importFromMorph [ { #category : #initialisation, - #'squeak_changestamp' : 'Alex M 5/23/2024 02:25' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:58' } GMTEEditor >> initialize [ @@ -442,7 +461,8 @@ GMTEEditor >> initialize [ self open; selectedLayer: self layerList first; - ratio:1 + ratio: 1; + LAYER_TEST: 1 ] { diff --git a/source/GM-TE/GMTETile.class.st b/source/GM-TE/GMTETile.class.st index 50382dfb..34547435 100644 --- a/source/GM-TE/GMTETile.class.st +++ b/source/GM-TE/GMTETile.class.st @@ -6,11 +6,11 @@ Class { { #category : #'as yet unclassified', - #'squeak_changestamp' : 'TW 5/22/2024 23:31' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:21' } GMTETile class >> placeHolderColor [ - ^Color veryLightGray + ^Color transparent ] { diff --git a/source/GM-TE/GMTETileMap.class.st b/source/GM-TE/GMTETileMap.class.st index 32db4caf..6a8993a7 100644 --- a/source/GM-TE/GMTETileMap.class.st +++ b/source/GM-TE/GMTETileMap.class.st @@ -21,7 +21,8 @@ Class { 'fullGridSizeHeight', 'tileCornerOffset', 'mapPaddedHeight', - 'gridTileMatrix' + 'tileMatrixStack', + 'tileMatrixStackVisual' ], #category : #'GM-TE-Core' } @@ -140,12 +141,12 @@ GMTETileMap >> exportAsImage [ { #category : #accessing, - #'squeak_changestamp' : 'Alex M 5/23/2024 21:55' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:53' } GMTETileMap >> extent: aPoint [ super extent: aPoint. - self gridTileMatrix ifNotNil: [self rescaleMap]. + self tileMatrixStack ifNotNil: [self rescaleMap]. ] { @@ -186,46 +187,42 @@ GMTETileMap >> fullGridSizeWidth: anObject [ { #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 5/21/2024 20:18' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:40' } -GMTETileMap >> generateTiles [ - "Create grid tile matrix datastructure" - +GMTETileMap >> generateTileAtlayer: aLayer x: x y: y stack: aStack [ + | tilePos correctedTilePos newTile | - - 1 to: self tileHeight do: [:y | - 1 to: self tileWidth do: [:x | - - tilePos := self tilePosFromVirtual: x@y. - correctedTilePos := self correctedTilePosition: tilePos. + + tilePos := self tilePosFromVirtual: x@y. + correctedTilePos := self correctedTilePosition: tilePos. - newTile := GMTETile - position: correctedTilePos - extent: self tileSizeWidth@self tileSizeHeight. - newTile lock. - newTile beTransparent. - - self addMorphFrontInLayer: newTile. - self gridTileMatrix at: y at: x put: newTile]]. - -] - -{ - #category : #accessing, - #'squeak_changestamp' : 'Ivo Zilkenat 5/19/2024 15:57' -} -GMTETileMap >> gridTileMatrix [ + newTile := (GMTETile + position: correctedTilePos + extent: self tileSizeWidth@self tileSizeHeight) + lock; + beTransparent; + yourself. + + self addMorphFrontInLayer: newTile. + aStack layer: aLayer at: y at: x put: newTile. + ^newTile - ^ gridTileMatrix + + + ] { - #category : #accessing, - #'squeak_changestamp' : 'Ivo Zilkenat 5/19/2024 15:57' + #category : #updating, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:32' } -GMTETileMap >> gridTileMatrix: anObject [ +GMTETileMap >> generateVisualTiles [ + "Create grid tile matrix datastructure" + + 1 to: self tileHeight do: [:y | + 1 to: self tileWidth do: [:x | + self generateTileAtlayer: 1 x: x y: y stack: self tileMatrixStackVisual]]. - gridTileMatrix := anObject. ] { @@ -367,14 +364,13 @@ GMTETileMap >> mapTileWidth: anObject [ { #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 5/21/2024 21:20' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:21' } GMTETileMap >> processTiles [ "comment stating purpose of message" - self gridTileMatrix do: [ :tile | - tile borderColor: Color white. - tile color: Color veryLightGray. + (self tileMatrixStackVisual layer: 1) do: [ :tile | + tile borderColor: Color white. tile borderWidth: 2] ] @@ -452,18 +448,16 @@ GMTETileMap >> tileCornerOffset: anObject [ { #category : #accessing, - #'squeak_changestamp' : 'TW 5/22/2024 18:42' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:01' } -GMTETileMap >> tileFromPosition: aPoint [ +GMTETileMap >> tileFromPosition: aPoint layer: aLayer [ | idx | idx := self tileIdxFromPosition: aPoint. idx ifNil: [^nil]. - "Transcript show: idx; cr." - - ^ self gridTileMatrix at: idx y at: idx x. + ^ self tileMatrixStack layer: aLayer at: idx y at: idx x. ] { @@ -486,7 +480,7 @@ GMTETileMap >> tileHeight: anObject [ { #category : #conversion, - #'squeak_changestamp' : 'Ivo Zilkenat 5/21/2024 20:55' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:58' } GMTETileMap >> tileIdxFromPosition: aPoint [ @@ -496,10 +490,46 @@ GMTETileMap >> tileIdxFromPosition: aPoint [ idx := (uncorrectedPos x / self tileSizeWidth + 1)@(uncorrectedPos y / self tileSizeHeight + 1). idx := idx floor. - (self gridTileMatrix validIdx: idx) ifFalse: [^nil]. + ((self tileMatrixStackVisual layer: 1) validIdx: idx) ifFalse: [^nil]. ^idx. ] +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:03' +} +GMTETileMap >> tileMatrixStack [ + + ^ tileMatrixStack +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:03' +} +GMTETileMap >> tileMatrixStack: anObject [ + + tileMatrixStack := anObject. +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:20' +} +GMTETileMap >> tileMatrixStackVisual [ + + ^ tileMatrixStackVisual +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:20' +} +GMTETileMap >> tileMatrixStackVisual: anObject [ + + tileMatrixStackVisual := anObject. +] + { #category : #conversion, #'squeak_changestamp' : 'Ivo Zilkenat 5/21/2024 20:21' @@ -563,6 +593,20 @@ GMTETileMap >> tileSizeWidth: anObject [ tileSizeWidth := anObject. ] +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:00' +} +GMTETileMap >> tileVisualFromPosition: aPoint [ + + | idx | + + idx := self tileIdxFromPosition: aPoint. + idx ifNil: [^nil]. + + ^ self tileMatrixStackVisual layer: 1 at: idx y at: idx x. +] + { #category : #accessing, #'squeak_changestamp' : 'Ivo Zilkenat 5/19/2024 15:57' @@ -634,36 +678,50 @@ GMTETileMap >> updateDimensions [ { #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 5/21/2024 19:46' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:21' } GMTETileMap >> updateMap [ "Update map by: fitting grid to current screen, generating tile matrix, adding sprites" self updateDimensions. - self gridTileMatrix + self tileMatrixStack ifNil: [ - self gridTileMatrix: (GMTEStaticCoordinateMatrix rows: self tileHeight columns: self tileWidth). - self generateTiles] + self tileMatrixStack: (GMTETileMatrixStack fromWidth: self tileWidth height: self tileHeight). + self tileMatrixStackVisual: (GMTETileMatrixStack fromWidth: self tileWidth height: self tileHeight). + self generateVisualTiles] ifNotNil: [self updateTiles]. self processTiles ] { #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 5/21/2024 20:18' + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:49' } -GMTETileMap >> updateTiles [ +GMTETileMap >> updateTileMatrixStack: aStack [ | tilePos correctedTilePos tile | 1 to: self tileHeight do: [:y | 1 to: self tileWidth do: [:x | - - tilePos := self tilePosFromVirtual: x@y. - correctedTilePos := self correctedTilePosition: tilePos. - tile := self gridTileMatrix at: y at: x. - - tile - position: correctedTilePos; - extent: self tileSizeWidth@self tileSizeHeight.]] + 1 to: (self tileMatrixStack layerCount) do: [: l | + + tilePos := self tilePosFromVirtual: x@y. + correctedTilePos := self correctedTilePosition: tilePos. + tile := aStack layer: l at: y at: x. + + tile ifNotNil: [ + tile + position: correctedTilePos; + extent: self tileSizeWidth@self tileSizeHeight.]] + ]] +] + +{ + #category : #updating, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:49' +} +GMTETileMap >> updateTiles [ + + self updateTileMatrixStack: self tileMatrixStack. + self updateTileMatrixStack: self tileMatrixStackVisual ] diff --git a/source/GM-TE/GMTETileMatrixLayer.class.st b/source/GM-TE/GMTETileMatrixLayer.class.st new file mode 100644 index 00000000..3ebf8567 --- /dev/null +++ b/source/GM-TE/GMTETileMatrixLayer.class.st @@ -0,0 +1,14 @@ +Class { + #name : #GMTETileMatrixLayer, + #superclass : #GMTEStaticCoordinateMatrix, + #category : #'GM-TE-Core' +} + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:40' +} +GMTETileMatrixLayer >> free [ + + self contents do: [ :imageMorph | imageMorph abandon] +] diff --git a/source/GM-TE/GMTETileMatrixStack.class.st b/source/GM-TE/GMTETileMatrixStack.class.st new file mode 100644 index 00000000..f3bc494a --- /dev/null +++ b/source/GM-TE/GMTETileMatrixStack.class.st @@ -0,0 +1,150 @@ +Class { + #name : #GMTETileMatrixStack, + #superclass : #Object, + #instVars : [ + 'width', + 'height', + 'matrixLayers' + ], + #category : #'GM-TE-Core' +} + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:07' +} +GMTETileMatrixStack class >> fromWidth: aWidth height: aHeight [ + + ^GMTETileMatrixStack new + width: aWidth; + height: aHeight; + pushLayer; + yourself + +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:16' +} +GMTETileMatrixStack >> height [ + + ^ height +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:16' +} +GMTETileMatrixStack >> height: anObject [ + + height := anObject. +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 22:08' +} +GMTETileMatrixStack >> initialize [ + + super initialize. + self matrixLayers: LinkedList new. + "TODO: no base layer created" +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:34' +} +GMTETileMatrixStack >> layer: aLayerIdx [ + + ^ self matrixLayers at: aLayerIdx +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:32' +} +GMTETileMatrixStack >> layer: aLayerIdx at: x at: y [ + + ^ (self matrixLayers at: aLayerIdx) at: x at: y +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:48' +} +GMTETileMatrixStack >> layer: aLayerIdx at: x at: y put: aTile [ + + "TODO this is temporary solution; set max layers; use constants" + + aTile ifNotNil: [aTile morphicLayerNumber: 100 - aLayerIdx]. + ^ (self matrixLayers at: aLayerIdx) at: x at: y put: aTile +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:23' +} +GMTETileMatrixStack >> layerCount [ + + ^ self matrixLayers size +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:15' +} +GMTETileMatrixStack >> matrixLayers [ + + ^ matrixLayers +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:15' +} +GMTETileMatrixStack >> matrixLayers: anObject [ + + matrixLayers := anObject. +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:38' +} +GMTETileMatrixStack >> pushLayer [ + + self matrixLayers addLast: (GMTETileMatrixLayer rows: self width columns: self height) +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:46' +} +GMTETileMatrixStack >> removeLayerAt: idx [ + + | removedLayer |. + self assert: idx ~= 1 description: 'Base layer cannot be removed!'. + + removedLayer := self matrixLayers removeLink: (self matrixLayers linkAt: idx) value. + removedLayer free. +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:19' +} +GMTETileMatrixStack >> width [ + + ^ widht +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 21:19' +} +GMTETileMatrixStack >> width: anObject [ + + widht := anObject. +] diff --git a/testingResources/squeak2.gif b/testingResources/squeak2.gif index 69c0b089..d86e2ed1 100644 Binary files a/testingResources/squeak2.gif and b/testingResources/squeak2.gif differ