Skip to content

Commit

Permalink
refactoring SKExecuteControls. refactor SKKara move to use SKDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
Das-Killer committed Jul 11, 2024
1 parent 9c36aec commit 0eb3dff
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 122 deletions.
34 changes: 34 additions & 0 deletions src/SqueakKara-Core/SKDirection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 }.
}
]
6 changes: 3 additions & 3 deletions src/SqueakKara-Core/SKExecuteContext.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

{
Expand Down
11 changes: 5 additions & 6 deletions src/SqueakKara-Core/SKExecuteControls.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

{
Expand Down Expand Up @@ -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
]

{
Expand Down
52 changes: 3 additions & 49 deletions src/SqueakKara-Core/SKKara.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions src/SqueakKara-Core/SKWorkspace.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ SENSOREN: kara

{
#category : #initialization,
#'squeak_changestamp' : 'JJG 7/1/2024 15:13'
#'squeak_changestamp' : 'EB 7/11/2024 15:19'
}
SKWorkspace >> initializeWithKara: aKara [

super initialize.
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

Expand Down
34 changes: 34 additions & 0 deletions src/SqueakKara/SKDirection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 }.
}
]
6 changes: 3 additions & 3 deletions src/SqueakKara/SKExecuteContext.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

{
Expand Down
11 changes: 5 additions & 6 deletions src/SqueakKara/SKExecuteControls.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

{
Expand Down Expand Up @@ -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
]

{
Expand Down
52 changes: 3 additions & 49 deletions src/SqueakKara/SKKara.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions src/SqueakKara/SKWorkspace.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ SENSOREN: kara

{
#category : #initialization,
#'squeak_changestamp' : 'JJG 7/1/2024 15:13'
#'squeak_changestamp' : 'EB 7/11/2024 15:19'
}
SKWorkspace >> initializeWithKara: aKara [

super initialize.
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

Expand Down

0 comments on commit 0eb3dff

Please sign in to comment.