Skip to content

Commit

Permalink
Added main logic for supporting layers. Only gui implementation left
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Zilkenat committed May 27, 2024
1 parent fec3cd9 commit e345b61
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 79 deletions.
62 changes: 47 additions & 15 deletions source/GM-TE/GMTEEditableTileMap.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

{
Expand Down
26 changes: 23 additions & 3 deletions source/GM-TE/GMTEEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Class {
'layerList',
'tileMapMatrix',
'selectedTile',
'ratio'
'ratio',
'LAYER_TEST'
],
#category : #'GM-TE'
}
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -434,15 +453,16 @@ GMTEEditor >> importFromMorph [

{
#category : #initialisation,
#'squeak_changestamp' : 'Alex M 5/23/2024 02:25'
#'squeak_changestamp' : 'Ivo Zilkenat 5/27/2024 23:58'
}
GMTEEditor >> initialize [

super initialize.
self
open;
selectedLayer: self layerList first;
ratio:1
ratio: 1;
LAYER_TEST: 1
]

{
Expand Down
4 changes: 2 additions & 2 deletions source/GM-TE/GMTETile.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

{
Expand Down
Loading

0 comments on commit e345b61

Please sign in to comment.