Skip to content

Commit

Permalink
added undo/redo for tilemapsize
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander Morgensterns committed Jul 2, 2024
1 parent bef9bd4 commit c4bb99e
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 15 deletions.
4 changes: 2 additions & 2 deletions source/GM-TE/GMTEEditTilesCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Class {

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

^ (GMTEEditTilesCommand new)
^ (self new)
tileMap: aTileMap;
previousSprites: aDictionary1;
currentSprites: aDictionary2;
Expand Down
48 changes: 37 additions & 11 deletions source/GM-TE/GMTEEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,26 @@ GMTEEditor >> renameLayer [

]

{
#category : #tilemap,
#'squeak_changestamp' : 'Alex M 7/1/2024 21:04'
}
GMTEEditor >> rescaleGridHeight: aValue [

self tileMap rescaleMapWidth: self getGridWidth height: aValue.
self changed: #getGridHeightAsString
]

{
#category : #tilemap,
#'squeak_changestamp' : 'Alex M 7/1/2024 21:04'
}
GMTEEditor >> rescaleGridWidth: aValue [

self tileMap rescaleMapWidth: aValue height: self getGridHeight.
self changed: #getGridWidthAsString
]

{
#category : #'menu button functions',
#'squeak_changestamp' : 'jj 6/22/2024 21:30'
Expand Down Expand Up @@ -1535,32 +1555,38 @@ GMTEEditor >> selectedTile: anObject [

{
#category : #tilemap,
#'squeak_changestamp' : 'jj 6/22/2024 21:41'
#'squeak_changestamp' : 'Alex M 7/1/2024 21:06'
}
GMTEEditor >> setGridHeight: aText [
"adjusts the grid height"

| newSize |
newSize := self parseGridSize: aText.
newSize
ifNotNil: [
self tileMap rescaleMapWidth: self getGridWidth height: newSize].
| oldHeight newHeight |
oldHeight := self getGridHeight.
newHeight := self parseGridSize: aText.
newHeight ifNotNil: [
self
rescaleGridHeight: newHeight;
addCommand: (GMTETilemapSizeCommand prevValue: oldHeight newValue: newHeight method: #rescaleGridHeight: editor: self)].
^ true


]

{
#category : #tilemap,
#'squeak_changestamp' : 'jj 6/22/2024 21:41'
#'squeak_changestamp' : 'Alex M 7/1/2024 21:06'
}
GMTEEditor >> setGridWidth: aText [
"adjusts the grid width"
"TODO: Fix visual layer bug"

| newSize |
newSize := self parseGridSize: aText.
newSize ifNotNil: [self tileMap rescaleMapWidth: newSize height: self getGridHeight].
| oldWidth newWidth |
oldWidth := self getGridWidth.
newWidth := self parseGridSize: aText.
oldWidth ifNotNil: [
self
rescaleGridWidth: newWidth;
addCommand: (GMTETilemapSizeCommand prevValue: oldWidth newValue: newWidth method: #rescaleGridWidth: editor: self)].
^ true

]
Expand Down Expand Up @@ -1755,7 +1781,7 @@ GMTEEditor >> trayViewer: anObject [

{
#category : #'command processing',
#'squeak_changestamp' : 'Alex M 7/1/2024 17:31'
#'squeak_changestamp' : 'Alex M 7/1/2024 20:24'
}
GMTEEditor >> undo [

Expand Down
4 changes: 2 additions & 2 deletions source/GM-TE/GMTEPlaceHolderCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Class {
}

{
#category : #'as yet unclassified',
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/1/2024 17:19'
}
GMTEPlaceHolderCommand >> do [
]

{
#category : #'as yet unclassified',
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/1/2024 17:20'
}
GMTEPlaceHolderCommand >> undo [
Expand Down
117 changes: 117 additions & 0 deletions source/GM-TE/GMTETilemapSizeCommand.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Class {
#name : #GMTETilemapSizeCommand,
#superclass : #GMTECommand,
#instVars : [
'editor',
'method',
'prevSize',
'newSize',
'savedTiles'
],
#category : #'GM-TE-CommandProcessor'
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 7/1/2024 18:39'
}
GMTETilemapSizeCommand class >> prevValue: aNumber1 newValue: aNumber2 method: aSymbol editor: anEditor [

^ (self new)

prevSize: aNumber1;
newSize: aNumber2;
method: aSymbol;
editor: anEditor
]

{
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:52'
}
GMTETilemapSizeCommand >> do [

self editor perform: self method with: self newSize.
self restoreTiles
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:00'
}
GMTETilemapSizeCommand >> editor [
^ editor
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:00'
}
GMTETilemapSizeCommand >> editor: anObject [
editor := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:48'
}
GMTETilemapSizeCommand >> method [
^ method
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:48'
}
GMTETilemapSizeCommand >> method: anObject [
method := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:16'
}
GMTETilemapSizeCommand >> newSize [
^ newSize
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:16'
}
GMTETilemapSizeCommand >> newSize: anObject [
newSize := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:16'
}
GMTETilemapSizeCommand >> prevSize [
^ prevSize
]

{
#category : #accessing,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:16'
}
GMTETilemapSizeCommand >> prevSize: anObject [
prevSize := anObject
]

{
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:23'
}
GMTETilemapSizeCommand >> restoreTiles [
]

{
#category : #execution,
#'squeak_changestamp' : 'Alex M 7/1/2024 18:52'
}
GMTETilemapSizeCommand >> undo [

self editor perform: self method with: self prevSize.
self restoreTiles
]

0 comments on commit c4bb99e

Please sign in to comment.