Skip to content

Commit 450e2ae

Browse files
author
Aleksander Morgensterns
committed
addLayer & moveLayer Commands proof of concept added (needs refactoring)
1 parent 044b421 commit 450e2ae

6 files changed

+169
-5
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Class {
2+
#name : #GMTEAddLayerCommand,
3+
#superclass : #GMTECommand,
4+
#instVars : [
5+
'editor'
6+
],
7+
#category : #'GM-TE-UI'
8+
}
9+
10+
{
11+
#category : #'as yet unclassified',
12+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:30'
13+
}
14+
GMTEAddLayerCommand class >> withEditor: anEditor [
15+
16+
^ (self new)
17+
editor: anEditor;
18+
yourself
19+
]
20+
21+
{
22+
#category : #execution,
23+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:43'
24+
}
25+
GMTEAddLayerCommand >> do [
26+
"TODO: refactor this nicely by using inbuilt editor function while avoiding recursion"
27+
28+
self editor tileMap tileMatrixStack pushLayer.
29+
self editor
30+
selectOnlyLayer: self editor layerCount;
31+
changed: #getLayerList
32+
]
33+
34+
{
35+
#category : #accessing,
36+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:37'
37+
}
38+
GMTEAddLayerCommand >> editor [
39+
^ editor
40+
]
41+
42+
{
43+
#category : #accessing,
44+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:37'
45+
}
46+
GMTEAddLayerCommand >> editor: anObject [
47+
editor := anObject
48+
]
49+
50+
{
51+
#category : #execution,
52+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:40'
53+
}
54+
GMTEAddLayerCommand >> undo [
55+
56+
self editor
57+
selectLayer: self editor layerCount;
58+
deleteSelectedLayers
59+
]

source/GM-TE/GMTECommand.class.st

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Class {
22
#name : #GMTECommand,
33
#superclass : #Object,
4+
#classVars : [
5+
'GMTEAddLayerCommand'
6+
],
47
#category : #'GM-TE-UI'
58
}
69

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Class {
2+
#name : #GMTEDeleteLayerCommand,
3+
#superclass : #GMTETilemapSizeCommand,
4+
#category : #'GM-TE-UI'
5+
}

source/GM-TE/GMTEEditor.class.st

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ GMTEEditor >> addCommand: aCommand [
184184

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

196+
self addCommand: (GMTEAddLayerCommand withEditor: self).
197+
196198
self tileMap tileMatrixStack pushLayer.
197199
self
198200
selectOnlyLayer: newLayerNumber;
@@ -1223,7 +1225,7 @@ GMTEEditor >> morphBuilders: anObject [
12231225

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

12341236
selectedLayer := self getSelectedLayer.
1237+
self addCommand: (GMTEMoveLayerCommand fromLayerID: selectedLayer withDirection: -1 withEditor: self).
12351238
(selectedLayer == 1) ifFalse: [self swapLayer: selectedLayer with: selectedLayer - 1]
12361239
]
12371240

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

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

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Class {
2+
#name : #GMTEMoveLayerCommand,
3+
#superclass : #GMTECommand,
4+
#instVars : [
5+
'layerID',
6+
'moveDirection',
7+
'editor'
8+
],
9+
#category : #'GM-TE-UI'
10+
}
11+
12+
{
13+
#category : #'as yet unclassified',
14+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:17'
15+
}
16+
GMTEMoveLayerCommand class >> fromLayerID: aNumber1 withDirection: aNumber2 withEditor: anEditor [
17+
18+
^ (self new)
19+
layerID: aNumber1;
20+
moveDirection: aNumber2;
21+
editor: anEditor;
22+
yourself
23+
]
24+
25+
{
26+
#category : #execution,
27+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:26'
28+
}
29+
GMTEMoveLayerCommand >> do [
30+
31+
"moveDirection = 1 for up, -1 for down"
32+
self editor
33+
swapLayer: self layerID with: self layerID + self moveDirection
34+
]
35+
36+
{
37+
#category : #accessing,
38+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:17'
39+
}
40+
GMTEMoveLayerCommand >> editor [
41+
^ editor
42+
]
43+
44+
{
45+
#category : #accessing,
46+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:17'
47+
}
48+
GMTEMoveLayerCommand >> editor: anObject [
49+
editor := anObject
50+
]
51+
52+
{
53+
#category : #accessing,
54+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:12'
55+
}
56+
GMTEMoveLayerCommand >> layerID [
57+
^ layerID
58+
]
59+
60+
{
61+
#category : #accessing,
62+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:12'
63+
}
64+
GMTEMoveLayerCommand >> layerID: anObject [
65+
layerID := anObject
66+
]
67+
68+
{
69+
#category : #accessing,
70+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:12'
71+
}
72+
GMTEMoveLayerCommand >> moveDirection [
73+
^ moveDirection
74+
]
75+
76+
{
77+
#category : #accessing,
78+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:12'
79+
}
80+
GMTEMoveLayerCommand >> moveDirection: anObject [
81+
moveDirection := anObject
82+
]
83+
84+
{
85+
#category : #execution,
86+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:26'
87+
}
88+
GMTEMoveLayerCommand >> undo [
89+
90+
"moveDirection = 1 for up, -1 for down"
91+
self editor
92+
swapLayer: self layerID + self moveDirection with: self layerID
93+
]

source/GM-TE/GMTETilemapSizeCommand.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ GMTETilemapSizeCommand >> prevSize: anObject [
100100

101101
{
102102
#category : #execution,
103-
#'squeak_changestamp' : 'Alex M 7/2/2024 17:23'
103+
#'squeak_changestamp' : 'Alex M 7/4/2024 01:06'
104104
}
105105
GMTETilemapSizeCommand >> restoreTiles [
106106
"TODO: Use function of tilemap"
107107

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

111111
{

0 commit comments

Comments
 (0)