Skip to content

Commit

Permalink
addLayer & moveLayer Commands proof of concept added (needs refactoring)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander Morgensterns committed Jul 3, 2024
1 parent 044b421 commit 450e2ae
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 5 deletions.
59 changes: 59 additions & 0 deletions source/GM-TE/GMTEAddLayerCommand.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Class {
#name : #GMTEAddLayerCommand,
#superclass : #GMTECommand,
#instVars : [
'editor'
],
#category : #'GM-TE-UI'
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 7/4/2024 01:30'
}
GMTEAddLayerCommand class >> withEditor: anEditor [

^ (self new)
editor: anEditor;
yourself
]

{
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:43'
}
GMTEAddLayerCommand >> do [
"TODO: refactor this nicely by using inbuilt editor function while avoiding recursion"

self editor tileMap tileMatrixStack pushLayer.
self editor
selectOnlyLayer: self editor layerCount;
changed: #getLayerList
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:37'
}
GMTEAddLayerCommand >> editor [
^ editor
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:37'
}
GMTEAddLayerCommand >> editor: anObject [
editor := anObject
]

{
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:40'
}
GMTEAddLayerCommand >> undo [

self editor
selectLayer: self editor layerCount;
deleteSelectedLayers
]
3 changes: 3 additions & 0 deletions source/GM-TE/GMTECommand.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Class {
#name : #GMTECommand,
#superclass : #Object,
#classVars : [
'GMTEAddLayerCommand'
],
#category : #'GM-TE-UI'
}

Expand Down
5 changes: 5 additions & 0 deletions source/GM-TE/GMTEDeleteLayerCommand.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class {
#name : #GMTEDeleteLayerCommand,
#superclass : #GMTETilemapSizeCommand,
#category : #'GM-TE-UI'
}
10 changes: 7 additions & 3 deletions source/GM-TE/GMTEEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ GMTEEditor >> addCommand: aCommand [

{
#category : #'layer button functions',
#'squeak_changestamp' : 'TW 6/23/2024 21:37'
#'squeak_changestamp' : 'Alex M 7/4/2024 01:37'
}
GMTEEditor >> addLayer [
"adds a new tileMap layer"
Expand All @@ -193,6 +193,8 @@ GMTEEditor >> addLayer [
(self layerCount >= GMTETileMap maxLayers) ifTrue: [^ nil].
newLayerNumber := self layerCount + 1.

self addCommand: (GMTEAddLayerCommand withEditor: self).

self tileMap tileMatrixStack pushLayer.
self
selectOnlyLayer: newLayerNumber;
Expand Down Expand Up @@ -1223,7 +1225,7 @@ GMTEEditor >> morphBuilders: anObject [

{
#category : #'layer button functions',
#'squeak_changestamp' : 'jj 6/22/2024 21:12'
#'squeak_changestamp' : 'Alex M 7/4/2024 01:21'
}
GMTEEditor >> moveLayerDown [
"moves the selected layer down by one"
Expand All @@ -1232,12 +1234,13 @@ GMTEEditor >> moveLayerDown [
self singleLayerSelected ifFalse: [^ nil].

selectedLayer := self getSelectedLayer.
self addCommand: (GMTEMoveLayerCommand fromLayerID: selectedLayer withDirection: -1 withEditor: self).
(selectedLayer == 1) ifFalse: [self swapLayer: selectedLayer with: selectedLayer - 1]
]

{
#category : #'layer button functions',
#'squeak_changestamp' : 'jj 6/22/2024 21:13'
#'squeak_changestamp' : 'Alex M 7/4/2024 01:26'
}
GMTEEditor >> moveLayerUp [
"moves the selected layer up by one"
Expand All @@ -1246,6 +1249,7 @@ GMTEEditor >> moveLayerUp [
self singleLayerSelected ifFalse: [^ nil].

selectedLayer := self getSelectedLayer.
self addCommand: (GMTEMoveLayerCommand fromLayerID: selectedLayer withDirection: 1 withEditor: self).
(selectedLayer == self layerCount) ifFalse: [self swapLayer: selectedLayer with: selectedLayer + 1]
]

Expand Down
93 changes: 93 additions & 0 deletions source/GM-TE/GMTEMoveLayerCommand.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Class {
#name : #GMTEMoveLayerCommand,
#superclass : #GMTECommand,
#instVars : [
'layerID',
'moveDirection',
'editor'
],
#category : #'GM-TE-UI'
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 7/4/2024 01:17'
}
GMTEMoveLayerCommand class >> fromLayerID: aNumber1 withDirection: aNumber2 withEditor: anEditor [

^ (self new)
layerID: aNumber1;
moveDirection: aNumber2;
editor: anEditor;
yourself
]

{
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:26'
}
GMTEMoveLayerCommand >> do [

"moveDirection = 1 for up, -1 for down"
self editor
swapLayer: self layerID with: self layerID + self moveDirection
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:17'
}
GMTEMoveLayerCommand >> editor [
^ editor
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:17'
}
GMTEMoveLayerCommand >> editor: anObject [
editor := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:12'
}
GMTEMoveLayerCommand >> layerID [
^ layerID
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:12'
}
GMTEMoveLayerCommand >> layerID: anObject [
layerID := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:12'
}
GMTEMoveLayerCommand >> moveDirection [
^ moveDirection
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:12'
}
GMTEMoveLayerCommand >> moveDirection: anObject [
moveDirection := anObject
]

{
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/4/2024 01:26'
}
GMTEMoveLayerCommand >> undo [

"moveDirection = 1 for up, -1 for down"
self editor
swapLayer: self layerID + self moveDirection with: self layerID
]
4 changes: 2 additions & 2 deletions source/GM-TE/GMTETilemapSizeCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ GMTETilemapSizeCommand >> prevSize: anObject [

{
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/2/2024 17:23'
#'squeak_changestamp' : 'Alex M 7/4/2024 01:06'
}
GMTETilemapSizeCommand >> restoreTiles [
"TODO: Use function of tilemap"

"self editor redoAllCommandsUntil: self editor currentCommand - 1."
"currently done by Editor, needs to be implemented correctly"
]

{
Expand Down

0 comments on commit 450e2ae

Please sign in to comment.