Skip to content

Commit c4bb99e

Browse files
author
Aleksander Morgensterns
committed
added undo/redo for tilemapsize
1 parent bef9bd4 commit c4bb99e

4 files changed

+158
-15
lines changed

source/GM-TE/GMTEEditTilesCommand.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Class {
1111

1212
{
1313
#category : #'as yet unclassified',
14-
#'squeak_changestamp' : 'Alex M 6/28/2024 21:20'
14+
#'squeak_changestamp' : 'Alex M 7/1/2024 17:59'
1515
}
1616
GMTEEditTilesCommand class >> previousTiles: aDictionary1 currentTiles: aDictionary2 tilemap: aTileMap [
1717

18-
^ (GMTEEditTilesCommand new)
18+
^ (self new)
1919
tileMap: aTileMap;
2020
previousSprites: aDictionary1;
2121
currentSprites: aDictionary2;

source/GM-TE/GMTEEditor.class.st

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,26 @@ GMTEEditor >> renameLayer [
13751375

13761376
]
13771377

1378+
{
1379+
#category : #tilemap,
1380+
#'squeak_changestamp' : 'Alex M 7/1/2024 21:04'
1381+
}
1382+
GMTEEditor >> rescaleGridHeight: aValue [
1383+
1384+
self tileMap rescaleMapWidth: self getGridWidth height: aValue.
1385+
self changed: #getGridHeightAsString
1386+
]
1387+
1388+
{
1389+
#category : #tilemap,
1390+
#'squeak_changestamp' : 'Alex M 7/1/2024 21:04'
1391+
}
1392+
GMTEEditor >> rescaleGridWidth: aValue [
1393+
1394+
self tileMap rescaleMapWidth: aValue height: self getGridHeight.
1395+
self changed: #getGridWidthAsString
1396+
]
1397+
13781398
{
13791399
#category : #'menu button functions',
13801400
#'squeak_changestamp' : 'jj 6/22/2024 21:30'
@@ -1535,32 +1555,38 @@ GMTEEditor >> selectedTile: anObject [
15351555

15361556
{
15371557
#category : #tilemap,
1538-
#'squeak_changestamp' : 'jj 6/22/2024 21:41'
1558+
#'squeak_changestamp' : 'Alex M 7/1/2024 21:06'
15391559
}
15401560
GMTEEditor >> setGridHeight: aText [
15411561
"adjusts the grid height"
15421562

1543-
| newSize |
1544-
newSize := self parseGridSize: aText.
1545-
newSize
1546-
ifNotNil: [
1547-
self tileMap rescaleMapWidth: self getGridWidth height: newSize].
1563+
| oldHeight newHeight |
1564+
oldHeight := self getGridHeight.
1565+
newHeight := self parseGridSize: aText.
1566+
newHeight ifNotNil: [
1567+
self
1568+
rescaleGridHeight: newHeight;
1569+
addCommand: (GMTETilemapSizeCommand prevValue: oldHeight newValue: newHeight method: #rescaleGridHeight: editor: self)].
15481570
^ true
15491571

15501572

15511573
]
15521574

15531575
{
15541576
#category : #tilemap,
1555-
#'squeak_changestamp' : 'jj 6/22/2024 21:41'
1577+
#'squeak_changestamp' : 'Alex M 7/1/2024 21:06'
15561578
}
15571579
GMTEEditor >> setGridWidth: aText [
15581580
"adjusts the grid width"
15591581
"TODO: Fix visual layer bug"
15601582

1561-
| newSize |
1562-
newSize := self parseGridSize: aText.
1563-
newSize ifNotNil: [self tileMap rescaleMapWidth: newSize height: self getGridHeight].
1583+
| oldWidth newWidth |
1584+
oldWidth := self getGridWidth.
1585+
newWidth := self parseGridSize: aText.
1586+
oldWidth ifNotNil: [
1587+
self
1588+
rescaleGridWidth: newWidth;
1589+
addCommand: (GMTETilemapSizeCommand prevValue: oldWidth newValue: newWidth method: #rescaleGridWidth: editor: self)].
15641590
^ true
15651591

15661592
]
@@ -1755,7 +1781,7 @@ GMTEEditor >> trayViewer: anObject [
17551781

17561782
{
17571783
#category : #'command processing',
1758-
#'squeak_changestamp' : 'Alex M 7/1/2024 17:31'
1784+
#'squeak_changestamp' : 'Alex M 7/1/2024 20:24'
17591785
}
17601786
GMTEEditor >> undo [
17611787

source/GM-TE/GMTEPlaceHolderCommand.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Class {
55
}
66

77
{
8-
#category : #'as yet unclassified',
8+
#category : #execution,
99
#'squeak_changestamp' : 'Alex M 7/1/2024 17:19'
1010
}
1111
GMTEPlaceHolderCommand >> do [
1212
]
1313

1414
{
15-
#category : #'as yet unclassified',
15+
#category : #execution,
1616
#'squeak_changestamp' : 'Alex M 7/1/2024 17:20'
1717
}
1818
GMTEPlaceHolderCommand >> undo [
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Class {
2+
#name : #GMTETilemapSizeCommand,
3+
#superclass : #GMTECommand,
4+
#instVars : [
5+
'editor',
6+
'method',
7+
'prevSize',
8+
'newSize',
9+
'savedTiles'
10+
],
11+
#category : #'GM-TE-CommandProcessor'
12+
}
13+
14+
{
15+
#category : #'as yet unclassified',
16+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:39'
17+
}
18+
GMTETilemapSizeCommand class >> prevValue: aNumber1 newValue: aNumber2 method: aSymbol editor: anEditor [
19+
20+
^ (self new)
21+
22+
prevSize: aNumber1;
23+
newSize: aNumber2;
24+
method: aSymbol;
25+
editor: anEditor
26+
]
27+
28+
{
29+
#category : #execution,
30+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:52'
31+
}
32+
GMTETilemapSizeCommand >> do [
33+
34+
self editor perform: self method with: self newSize.
35+
self restoreTiles
36+
]
37+
38+
{
39+
#category : #accessing,
40+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:00'
41+
}
42+
GMTETilemapSizeCommand >> editor [
43+
^ editor
44+
]
45+
46+
{
47+
#category : #accessing,
48+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:00'
49+
}
50+
GMTETilemapSizeCommand >> editor: anObject [
51+
editor := anObject
52+
]
53+
54+
{
55+
#category : #accessing,
56+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:48'
57+
}
58+
GMTETilemapSizeCommand >> method [
59+
^ method
60+
]
61+
62+
{
63+
#category : #accessing,
64+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:48'
65+
}
66+
GMTETilemapSizeCommand >> method: anObject [
67+
method := anObject
68+
]
69+
70+
{
71+
#category : #accessing,
72+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:16'
73+
}
74+
GMTETilemapSizeCommand >> newSize [
75+
^ newSize
76+
]
77+
78+
{
79+
#category : #accessing,
80+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:16'
81+
}
82+
GMTETilemapSizeCommand >> newSize: anObject [
83+
newSize := anObject
84+
]
85+
86+
{
87+
#category : #accessing,
88+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:16'
89+
}
90+
GMTETilemapSizeCommand >> prevSize [
91+
^ prevSize
92+
]
93+
94+
{
95+
#category : #accessing,
96+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:16'
97+
}
98+
GMTETilemapSizeCommand >> prevSize: anObject [
99+
prevSize := anObject
100+
]
101+
102+
{
103+
#category : #execution,
104+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:23'
105+
}
106+
GMTETilemapSizeCommand >> restoreTiles [
107+
]
108+
109+
{
110+
#category : #execution,
111+
#'squeak_changestamp' : 'Alex M 7/1/2024 18:52'
112+
}
113+
GMTETilemapSizeCommand >> undo [
114+
115+
self editor perform: self method with: self prevSize.
116+
self restoreTiles
117+
]

0 commit comments

Comments
 (0)