From 450e2ae6eb1169a3f9391fbc8641302bf5572098 Mon Sep 17 00:00:00 2001 From: Aleksander Morgensterns Date: Thu, 4 Jul 2024 01:44:20 +0200 Subject: [PATCH] addLayer & moveLayer Commands proof of concept added (needs refactoring) --- source/GM-TE/GMTEAddLayerCommand.class.st | 59 +++++++++++++ source/GM-TE/GMTECommand.class.st | 3 + source/GM-TE/GMTEDeleteLayerCommand.class.st | 5 ++ source/GM-TE/GMTEEditor.class.st | 10 ++- source/GM-TE/GMTEMoveLayerCommand.class.st | 93 ++++++++++++++++++++ source/GM-TE/GMTETilemapSizeCommand.class.st | 4 +- 6 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 source/GM-TE/GMTEAddLayerCommand.class.st create mode 100644 source/GM-TE/GMTEDeleteLayerCommand.class.st create mode 100644 source/GM-TE/GMTEMoveLayerCommand.class.st diff --git a/source/GM-TE/GMTEAddLayerCommand.class.st b/source/GM-TE/GMTEAddLayerCommand.class.st new file mode 100644 index 00000000..df822419 --- /dev/null +++ b/source/GM-TE/GMTEAddLayerCommand.class.st @@ -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 +] diff --git a/source/GM-TE/GMTECommand.class.st b/source/GM-TE/GMTECommand.class.st index 4b41ddd3..0330f175 100644 --- a/source/GM-TE/GMTECommand.class.st +++ b/source/GM-TE/GMTECommand.class.st @@ -1,6 +1,9 @@ Class { #name : #GMTECommand, #superclass : #Object, + #classVars : [ + 'GMTEAddLayerCommand' + ], #category : #'GM-TE-UI' } diff --git a/source/GM-TE/GMTEDeleteLayerCommand.class.st b/source/GM-TE/GMTEDeleteLayerCommand.class.st new file mode 100644 index 00000000..8f193057 --- /dev/null +++ b/source/GM-TE/GMTEDeleteLayerCommand.class.st @@ -0,0 +1,5 @@ +Class { + #name : #GMTEDeleteLayerCommand, + #superclass : #GMTETilemapSizeCommand, + #category : #'GM-TE-UI' +} diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 3eb293d3..c707dd0d 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -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" @@ -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; @@ -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" @@ -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" @@ -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] ] diff --git a/source/GM-TE/GMTEMoveLayerCommand.class.st b/source/GM-TE/GMTEMoveLayerCommand.class.st new file mode 100644 index 00000000..cf8af250 --- /dev/null +++ b/source/GM-TE/GMTEMoveLayerCommand.class.st @@ -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 +] diff --git a/source/GM-TE/GMTETilemapSizeCommand.class.st b/source/GM-TE/GMTETilemapSizeCommand.class.st index 77964fcd..7613d036 100644 --- a/source/GM-TE/GMTETilemapSizeCommand.class.st +++ b/source/GM-TE/GMTETilemapSizeCommand.class.st @@ -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" ] {