Skip to content

Commit 7d5b848

Browse files
author
Aleksander Morgensterns
committed
added deletion command (only for deleting the top layer so far)
1 parent fbe0277 commit 7d5b848

File tree

3 files changed

+86
-22
lines changed

3 files changed

+86
-22
lines changed

source/GM-TE/GMTEAddLayerCommand.class.st

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ GMTEAddLayerCommand class >> withEditor: anEditor [
2020

2121
{
2222
#category : #execution,
23-
#'squeak_changestamp' : 'Alex M 7/4/2024 01:43'
23+
#'squeak_changestamp' : 'Alex M 7/6/2024 23:13'
2424
}
2525
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
26+
27+
self editor addTilemapLayer
3228
]
3329

3430
{
@@ -49,11 +45,9 @@ GMTEAddLayerCommand >> editor: anObject [
4945

5046
{
5147
#category : #execution,
52-
#'squeak_changestamp' : 'Alex M 7/4/2024 01:40'
48+
#'squeak_changestamp' : 'Alex M 7/7/2024 00:53'
5349
}
5450
GMTEAddLayerCommand >> undo [
5551

56-
self editor
57-
selectLayer: self editor layerCount;
58-
deleteSelectedLayers
52+
self editor deleteTilemapLayers: {self editor getLayerList size}
5953
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
Class {
22
#name : #GMTEDeleteLayerCommand,
33
#superclass : #GMTETilemapSizeCommand,
4+
#instVars : [
5+
'layers'
6+
],
47
#category : #'GM-TE-UI'
58
}
9+
10+
{
11+
#category : #'as yet unclassified',
12+
#'squeak_changestamp' : 'Alex M 7/6/2024 23:20'
13+
}
14+
GMTEDeleteLayerCommand class >> fromLayers: aLayerList editor: anEditor [
15+
16+
^ (self new)
17+
layers: aLayerList;
18+
editor: anEditor;
19+
yourself
20+
]
21+
22+
{
23+
#category : #execution,
24+
#'squeak_changestamp' : 'Alex M 7/6/2024 23:18'
25+
}
26+
GMTEDeleteLayerCommand >> do [
27+
28+
self editor deleteTilemapLayers: self layers
29+
30+
]
31+
32+
{
33+
#category : #accessing,
34+
#'squeak_changestamp' : 'Alex M 7/6/2024 23:19'
35+
}
36+
GMTEDeleteLayerCommand >> layers [
37+
^ layers
38+
]
39+
40+
{
41+
#category : #accessing,
42+
#'squeak_changestamp' : 'Alex M 7/6/2024 23:19'
43+
}
44+
GMTEDeleteLayerCommand >> layers: anObject [
45+
layers := anObject
46+
]
47+
48+
{
49+
#category : #execution,
50+
#'squeak_changestamp' : 'Alex M 7/6/2024 23:31'
51+
}
52+
GMTEDeleteLayerCommand >> undo [
53+
self flag: 'NEEDS TO BE EXPENDED TO MULTIPLE LAYERS'.
54+
55+
self editor addTilemapLayer
56+
]

source/GM-TE/GMTEEditor.class.st

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,26 @@ GMTEEditor >> addCommand: aCommand [
185185

186186
{
187187
#category : #'layer button functions',
188-
#'squeak_changestamp' : 'Alex M 7/4/2024 01:37'
188+
#'squeak_changestamp' : 'Alex M 7/7/2024 00:51'
189189
}
190190
GMTEEditor >> addLayer [
191191
"adds a new tileMap layer"
192-
193-
| newLayerNumber |
194192
(self layerCount >= GMTETileMap maxLayers) ifTrue: [^ nil].
195-
newLayerNumber := self layerCount + 1.
193+
self
194+
addCommand: (GMTEAddLayerCommand withEditor: self);
195+
addTilemapLayer
196+
]
196197

197-
self addCommand: (GMTEAddLayerCommand withEditor: self).
198+
{
199+
#category : #'layer manipulation',
200+
#'squeak_changestamp' : 'Alex M 7/6/2024 23:12'
201+
}
202+
GMTEEditor >> addTilemapLayer [
198203

204+
| newLayerNumber |
205+
(self layerCount >= GMTETileMap maxLayers) ifTrue: [^ nil].
206+
newLayerNumber := self layerCount + 1.
207+
199208
self tileMap tileMatrixStack pushLayer.
200209
self
201210
selectOnlyLayer: newLayerNumber;
@@ -731,14 +740,24 @@ GMTEEditor >> currentCommand: anObject [
731740

732741
{
733742
#category : #'layer button functions',
734-
#'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 10:45'
743+
#'squeak_changestamp' : 'Alex M 7/7/2024 00:53'
735744
}
736745
GMTEEditor >> deleteSelectedLayers [
737746
"deletes all selected layers unless this would delete all layers"
738-
739747
(self anyLayerSelected not or: (self selectedLayers size >= self getLayerList size)) ifTrue: [^ nil].
740748

741-
self tileMap tileMatrixStack removeLayersAt: self selectedLayers.
749+
self
750+
addCommand: (GMTEDeleteLayerCommand fromLayers: self selectedLayers editor: self);
751+
deleteTilemapLayers: self selectedLayers
752+
]
753+
754+
{
755+
#category : #'layer manipulation',
756+
#'squeak_changestamp' : 'Alex M 7/7/2024 00:51'
757+
}
758+
GMTEEditor >> deleteTilemapLayers: aLayerList [
759+
760+
self tileMap tileMatrixStack removeLayersAt: aLayerList.
742761
self
743762
deselectAllLayers;
744763
changed: #getLayerList;
@@ -1848,15 +1867,15 @@ GMTEEditor >> trayViewer: anObject [
18481867

18491868
{
18501869
#category : #'command processing',
1851-
#'squeak_changestamp' : 'TW 7/2/2024 18:32'
1870+
#'squeak_changestamp' : 'Alex M 7/6/2024 23:35'
18521871
}
18531872
GMTEEditor >> undo [
18541873

1855-
"A bit hacky, maybe fix later"
1874+
self flag: 'DO THIS USING TILEMAP FUNCTIONS'.
18561875
(self currentCommand > 1)
18571876
ifTrue: [(self commands at: self currentCommand) undo.
18581877
self currentCommand: self currentCommand - 1.
1859-
((self commands at: self currentCommand + 1) class = GMTETilemapSizeCommand)
1878+
({GMTETilemapSizeCommand. GMTEDeleteLayerCommand} includes: (self commands at: self currentCommand + 1) class)
18601879
ifTrue: [self redoAllCommandsUntil: self currentCommand].
18611880
self savedSinceModified: false]
18621881
]

0 commit comments

Comments
 (0)