From 0eb3dff0d1f7e9d2a2545f45200a422a22d5c3b0 Mon Sep 17 00:00:00 2001 From: Emil Botezatu Date: Thu, 11 Jul 2024 15:22:55 +0200 Subject: [PATCH] refactoring SKExecuteControls. refactor SKKara move to use SKDirection --- src/SqueakKara-Core/SKDirection.class.st | 34 ++++++++++++ src/SqueakKara-Core/SKExecuteContext.class.st | 6 +-- .../SKExecuteControls.class.st | 11 ++-- src/SqueakKara-Core/SKKara.class.st | 52 ++----------------- src/SqueakKara-Core/SKWorkspace.class.st | 6 +-- src/SqueakKara/SKDirection.class.st | 34 ++++++++++++ src/SqueakKara/SKExecuteContext.class.st | 6 +-- src/SqueakKara/SKExecuteControls.class.st | 11 ++-- src/SqueakKara/SKKara.class.st | 52 ++----------------- src/SqueakKara/SKWorkspace.class.st | 6 +-- 10 files changed, 96 insertions(+), 122 deletions(-) diff --git a/src/SqueakKara-Core/SKDirection.class.st b/src/SqueakKara-Core/SKDirection.class.st index 1ed6664..90ce64e 100644 --- a/src/SqueakKara-Core/SKDirection.class.st +++ b/src/SqueakKara-Core/SKDirection.class.st @@ -52,3 +52,37 @@ SKDirection class >> right [ ^ 1 @ 0 ] + +{ + #category : #directions, + #'squeak_changestamp' : 'EB 7/11/2024 15:17' +} +SKDirection class >> rotateLeft [ + + ^ { + { 0. 1 }. + { -1. 0 }. + } +] + +{ + #category : #directions, + #'squeak_changestamp' : 'EB 7/11/2024 15:13' +} +SKDirection class >> rotatePosition: aPosition by: aMatrix [ + |vector| + vector := aMatrix collect: [:row |((row at: 1) * aPosition x) + ((row at: 2) * aPosition y)]. + ^ (vector first) @ (vector second) +] + +{ + #category : #directions, + #'squeak_changestamp' : 'EB 7/11/2024 15:17' +} +SKDirection class >> rotateRight [ + + ^ { + { 0. -1 }. + { 1. 0 }. + } +] diff --git a/src/SqueakKara-Core/SKExecuteContext.class.st b/src/SqueakKara-Core/SKExecuteContext.class.st index d42c733..7698a4c 100644 --- a/src/SqueakKara-Core/SKExecuteContext.class.st +++ b/src/SqueakKara-Core/SKExecuteContext.class.st @@ -15,12 +15,12 @@ Class { { #category : #initialization, - #'squeak_changestamp' : 'KD 7/9/2024 15:26' + #'squeak_changestamp' : 'EB 7/11/2024 15:20' } SKExecuteContext >> initialize [ - left := 'left'. - right := 'right' + left := SKDirection rotateLeft. + right := SKDirection rotateRight ] { diff --git a/src/SqueakKara-Core/SKExecuteControls.class.st b/src/SqueakKara-Core/SKExecuteControls.class.st index bcfce04..f39d4a3 100644 --- a/src/SqueakKara-Core/SKExecuteControls.class.st +++ b/src/SqueakKara-Core/SKExecuteControls.class.st @@ -72,26 +72,26 @@ SKExecuteControls >> addWidgetCentered: aWidget atXPosition: aXValue [ { #category : #widgets, - #'squeak_changestamp' : 'JJG 7/1/2024 14:58' + #'squeak_changestamp' : 'EB 7/11/2024 14:40' } SKExecuteControls >> buildButtonRun [ ^ IconicButton new target: self; actionSelector: #actionRun; - color: Color lightGray + color: SKStylesheet secondaryColor ] { #category : #widgets, - #'squeak_changestamp' : 'EB 6/23/2024 19:42' + #'squeak_changestamp' : 'EB 7/11/2024 14:40' } SKExecuteControls >> buildButtonStop [ ^ IconicButton new target: self; actionSelector: #actionStop; - color: Color lightGray + color: SKStylesheet secondaryColor ] { @@ -275,12 +275,11 @@ SKExecuteControls >> sliderSpeed: anObject [ { #category : #widgets, - #'squeak_changestamp' : 'JJG 7/1/2024 15:00' + #'squeak_changestamp' : 'EB 7/11/2024 14:40' } SKExecuteControls >> sliderSpeedValueChanged: aValue [ self environment executionSpeed: aValue. - Transcript showln: aValue ] { diff --git a/src/SqueakKara-Core/SKKara.class.st b/src/SqueakKara-Core/SKKara.class.st index 59f3d4d..dc855b4 100644 --- a/src/SqueakKara-Core/SKKara.class.st +++ b/src/SqueakKara-Core/SKKara.class.st @@ -11,40 +11,6 @@ Class { #'squeak_changestamp' : 'JJG 7/1/2024 15:56' } -{ - #category : #turning, - #'squeak_changestamp' : 'JJG 7/6/2024 17:57' -} -SKKara >> convertAngleToDirection: angle [ - - | angleToDirection | - - angleToDirection := Dictionary newFrom: { - 0 -> SKDirection above. - 90 -> SKDirection right. - 180 -> SKDirection below. - 270 -> SKDirection left.}. - - ^ angleToDirection at: angle -] - -{ - #category : #turning, - #'squeak_changestamp' : 'JJG 7/6/2024 17:58' -} -SKKara >> convertDirectionToAngle: direction [ - - | directionToAngle | - - directionToAngle := Dictionary newFrom: { - SKDirection above -> 0. - SKDirection right -> 90. - SKDirection below -> 180. - SKDirection left -> 270.}. - - ^ directionToAngle at: direction -] - { #category : #appearance, #'squeak_changestamp' : 'jt 6/11/2024 19:59' @@ -105,23 +71,11 @@ SKKara >> trunkAhead [ { #category : #turning, - #'squeak_changestamp' : 'JJG 6/17/2024 16:30' + #'squeak_changestamp' : 'EB 7/11/2024 15:18' } -SKKara >> turn: aDirection [ - - "also update SKWorkspace initialize, when kara turn method is updated to use SKDirection" - - | angle | - - angle := self convertDirectionToAngle: self viewDirection. - - aDirection = 'left' - ifTrue: [angle := (angle - 90) \\\ 360] - ifFalse: - [aDirection = 'right' - ifTrue: [angle := (angle + 90) \\\ 360]]. +SKKara >> turn: aRotation [ - self viewDirection: (self convertAngleToDirection: angle). + self viewDirection: (SKDirection rotatePosition: self viewDirection by: aRotation). self setTexture diff --git a/src/SqueakKara-Core/SKWorkspace.class.st b/src/SqueakKara-Core/SKWorkspace.class.st index ccacf32..cda3173 100644 --- a/src/SqueakKara-Core/SKWorkspace.class.st +++ b/src/SqueakKara-Core/SKWorkspace.class.st @@ -51,7 +51,7 @@ SENSOREN: kara { #category : #initialization, - #'squeak_changestamp' : 'JJG 7/1/2024 15:13' + #'squeak_changestamp' : 'EB 7/11/2024 15:19' } SKWorkspace >> initializeWithKara: aKara [ @@ -59,8 +59,8 @@ SKWorkspace >> initializeWithKara: aKara [ self buildAndOpen. self windowTitle: 'SKWorkspace'. - self bindings at: #left put: 'left'. - self bindings at: #right put: 'right'. + self bindings at: #left put: SKDirection rotateLeft. + self bindings at: #right put: SKDirection rotateRight. self bindings at: #kara put: aKara. self contents: self getExampleCode diff --git a/src/SqueakKara/SKDirection.class.st b/src/SqueakKara/SKDirection.class.st index 1ed6664..90ce64e 100644 --- a/src/SqueakKara/SKDirection.class.st +++ b/src/SqueakKara/SKDirection.class.st @@ -52,3 +52,37 @@ SKDirection class >> right [ ^ 1 @ 0 ] + +{ + #category : #directions, + #'squeak_changestamp' : 'EB 7/11/2024 15:17' +} +SKDirection class >> rotateLeft [ + + ^ { + { 0. 1 }. + { -1. 0 }. + } +] + +{ + #category : #directions, + #'squeak_changestamp' : 'EB 7/11/2024 15:13' +} +SKDirection class >> rotatePosition: aPosition by: aMatrix [ + |vector| + vector := aMatrix collect: [:row |((row at: 1) * aPosition x) + ((row at: 2) * aPosition y)]. + ^ (vector first) @ (vector second) +] + +{ + #category : #directions, + #'squeak_changestamp' : 'EB 7/11/2024 15:17' +} +SKDirection class >> rotateRight [ + + ^ { + { 0. -1 }. + { 1. 0 }. + } +] diff --git a/src/SqueakKara/SKExecuteContext.class.st b/src/SqueakKara/SKExecuteContext.class.st index d42c733..7698a4c 100644 --- a/src/SqueakKara/SKExecuteContext.class.st +++ b/src/SqueakKara/SKExecuteContext.class.st @@ -15,12 +15,12 @@ Class { { #category : #initialization, - #'squeak_changestamp' : 'KD 7/9/2024 15:26' + #'squeak_changestamp' : 'EB 7/11/2024 15:20' } SKExecuteContext >> initialize [ - left := 'left'. - right := 'right' + left := SKDirection rotateLeft. + right := SKDirection rotateRight ] { diff --git a/src/SqueakKara/SKExecuteControls.class.st b/src/SqueakKara/SKExecuteControls.class.st index bcfce04..f39d4a3 100644 --- a/src/SqueakKara/SKExecuteControls.class.st +++ b/src/SqueakKara/SKExecuteControls.class.st @@ -72,26 +72,26 @@ SKExecuteControls >> addWidgetCentered: aWidget atXPosition: aXValue [ { #category : #widgets, - #'squeak_changestamp' : 'JJG 7/1/2024 14:58' + #'squeak_changestamp' : 'EB 7/11/2024 14:40' } SKExecuteControls >> buildButtonRun [ ^ IconicButton new target: self; actionSelector: #actionRun; - color: Color lightGray + color: SKStylesheet secondaryColor ] { #category : #widgets, - #'squeak_changestamp' : 'EB 6/23/2024 19:42' + #'squeak_changestamp' : 'EB 7/11/2024 14:40' } SKExecuteControls >> buildButtonStop [ ^ IconicButton new target: self; actionSelector: #actionStop; - color: Color lightGray + color: SKStylesheet secondaryColor ] { @@ -275,12 +275,11 @@ SKExecuteControls >> sliderSpeed: anObject [ { #category : #widgets, - #'squeak_changestamp' : 'JJG 7/1/2024 15:00' + #'squeak_changestamp' : 'EB 7/11/2024 14:40' } SKExecuteControls >> sliderSpeedValueChanged: aValue [ self environment executionSpeed: aValue. - Transcript showln: aValue ] { diff --git a/src/SqueakKara/SKKara.class.st b/src/SqueakKara/SKKara.class.st index 59f3d4d..dc855b4 100644 --- a/src/SqueakKara/SKKara.class.st +++ b/src/SqueakKara/SKKara.class.st @@ -11,40 +11,6 @@ Class { #'squeak_changestamp' : 'JJG 7/1/2024 15:56' } -{ - #category : #turning, - #'squeak_changestamp' : 'JJG 7/6/2024 17:57' -} -SKKara >> convertAngleToDirection: angle [ - - | angleToDirection | - - angleToDirection := Dictionary newFrom: { - 0 -> SKDirection above. - 90 -> SKDirection right. - 180 -> SKDirection below. - 270 -> SKDirection left.}. - - ^ angleToDirection at: angle -] - -{ - #category : #turning, - #'squeak_changestamp' : 'JJG 7/6/2024 17:58' -} -SKKara >> convertDirectionToAngle: direction [ - - | directionToAngle | - - directionToAngle := Dictionary newFrom: { - SKDirection above -> 0. - SKDirection right -> 90. - SKDirection below -> 180. - SKDirection left -> 270.}. - - ^ directionToAngle at: direction -] - { #category : #appearance, #'squeak_changestamp' : 'jt 6/11/2024 19:59' @@ -105,23 +71,11 @@ SKKara >> trunkAhead [ { #category : #turning, - #'squeak_changestamp' : 'JJG 6/17/2024 16:30' + #'squeak_changestamp' : 'EB 7/11/2024 15:18' } -SKKara >> turn: aDirection [ - - "also update SKWorkspace initialize, when kara turn method is updated to use SKDirection" - - | angle | - - angle := self convertDirectionToAngle: self viewDirection. - - aDirection = 'left' - ifTrue: [angle := (angle - 90) \\\ 360] - ifFalse: - [aDirection = 'right' - ifTrue: [angle := (angle + 90) \\\ 360]]. +SKKara >> turn: aRotation [ - self viewDirection: (self convertAngleToDirection: angle). + self viewDirection: (SKDirection rotatePosition: self viewDirection by: aRotation). self setTexture diff --git a/src/SqueakKara/SKWorkspace.class.st b/src/SqueakKara/SKWorkspace.class.st index ccacf32..cda3173 100644 --- a/src/SqueakKara/SKWorkspace.class.st +++ b/src/SqueakKara/SKWorkspace.class.st @@ -51,7 +51,7 @@ SENSOREN: kara { #category : #initialization, - #'squeak_changestamp' : 'JJG 7/1/2024 15:13' + #'squeak_changestamp' : 'EB 7/11/2024 15:19' } SKWorkspace >> initializeWithKara: aKara [ @@ -59,8 +59,8 @@ SKWorkspace >> initializeWithKara: aKara [ self buildAndOpen. self windowTitle: 'SKWorkspace'. - self bindings at: #left put: 'left'. - self bindings at: #right put: 'right'. + self bindings at: #left put: SKDirection rotateLeft. + self bindings at: #right put: SKDirection rotateRight. self bindings at: #kara put: aKara. self contents: self getExampleCode