Skip to content

Commit

Permalink
Merge pull request #32 from hpi-swa-teaching/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
Johanna-G authored Jul 6, 2024
2 parents 250bfe3 + 7969f20 commit d242ef9
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 126 deletions.
5 changes: 2 additions & 3 deletions src/SqueakKara-Core/SKEnvironment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,15 @@ SKEnvironment >> grid: anObject [

{
#category : #initialization,
#'squeak_changestamp' : 'JJG 7/1/2024 16:28'
#'squeak_changestamp' : 'JJG 7/6/2024 17:48'
}
SKEnvironment >> initializeObjects [


self workspace: (SKWorkspace newWithKara: self kara).
self executer: (SKExecuter new).
(self executer kara) kara: self kara.
self executeControls: SKExecuteControls new.
executeControls environment: self.
self executeControls environment: self.

self setSystemWindow.
self systemWindow openInHand
Expand Down
51 changes: 30 additions & 21 deletions src/SqueakKara-Core/SKExecuteControls.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,30 @@ SKExecuteControls >> actionStop [

{
#category : #widgets,
#'squeak_changestamp' : 'JJG 7/1/2024 14:57'
#'squeak_changestamp' : 'JJG 7/6/2024 17:26'
}
SKExecuteControls >> addAllWidgets [

| verticalSpace|

self buttonRun: self buildButtonRun.
self sliderSpeed: self buildSliderSpeed.
self buttonStop: self buildButtonStop.
self buttonRunSetTexture: self runTextureFilename.
self buttonStopSetTexture.
verticalSpace := self addWidgetCentered: self buttonRun atXPosition: self widgetMargin.
verticalSpace := self addWidgetCentered: self sliderSpeed atXPosition: verticalSpace + self widgetMargin.
verticalSpace := self addWidgetCentered: self buttonStop atXPosition: verticalSpace + self widgetMargin
self positionWidgets
]

{
#category : #widgets,
#'squeak_changestamp' : 'JJG 7/1/2024 14:57'
#'squeak_changestamp' : 'JJG 7/6/2024 17:24'
}
SKExecuteControls >> addWidgetCentered: aWidget atXPosition: aXValue [

|verticalCenter widgetCenter|

self addMorph: aWidget.
verticalCenter := (self extent y)/2.
widgetCenter := (aWidget extent y)/2.
aWidget position: (aXValue @ (verticalCenter-widgetCenter)).
verticalCenter := (self extent y) / 2.
widgetCenter := (aWidget extent y) / 2.
aWidget position: (aXValue @ (verticalCenter - widgetCenter)).

^ aXValue + aWidget extent x
]
Expand Down Expand Up @@ -100,12 +96,12 @@ SKExecuteControls >> buildButtonStop [

{
#category : #widgets,
#'squeak_changestamp' : 'JJG 7/1/2024 14:58'
#'squeak_changestamp' : 'JJG 7/6/2024 17:24'
}
SKExecuteControls >> buildSliderSpeed [

^ SimpleSliderMorph new
bounds: (0@0 extent: 100@20);
bounds: (0 @ 0 extent: 100 @ 20);
minVal: 0;
maxVal: 50;
setNumericValue: 25;
Expand Down Expand Up @@ -169,7 +165,7 @@ SKExecuteControls >> buttonStopSetTexture [
]

{
#category : #widgets,
#category : #accessing,
#'squeak_changestamp' : 'JJG 7/1/2024 14:59'
}
SKExecuteControls >> defaultBounds [
Expand Down Expand Up @@ -214,18 +210,18 @@ SKExecuteControls >> getTexture: aFilename [
]

{
#category : #widgets,
#'squeak_changestamp' : 'JJG 7/1/2024 14:59'
#category : #initialization,
#'squeak_changestamp' : 'JJG 7/6/2024 17:32'
}
SKExecuteControls >> initialize [

super initialize.
self bounds: self defaultBounds.
self color: Color lightGreen lighter.
self borderWidth: 1 px.
self borderColor: Color lightGray.
self addAllWidgets.
self openInWorld
self bounds: self defaultBounds;
color: SKStylesheet primaryColor;
borderWidth: 1 px;
borderColor: SKStylesheet secondaryColor;
addAllWidgets;
openInWorld
]

{
Expand All @@ -237,6 +233,19 @@ SKExecuteControls >> pauseTextureFilename [
^ 'pause.png'
]

{
#category : #widgets,
#'squeak_changestamp' : 'JJG 7/6/2024 17:26'
}
SKExecuteControls >> positionWidgets [

| verticalSpace|

verticalSpace := self addWidgetCentered: self buttonRun atXPosition: self widgetMargin.
verticalSpace := self addWidgetCentered: self sliderSpeed atXPosition: verticalSpace + self widgetMargin.
verticalSpace := self addWidgetCentered: self buttonStop atXPosition: verticalSpace + self widgetMargin
]

{
#category : #texture,
#'squeak_changestamp' : 'JJG 7/1/2024 14:59'
Expand Down
29 changes: 15 additions & 14 deletions src/SqueakKara-Core/SKExecuter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,13 @@ SKExecuter >> process: anObject [

{
#category : #execution,
#'squeak_changestamp' : 'EB 6/22/2024 14:10'
#'squeak_changestamp' : 'JJG 7/6/2024 17:52'
}
SKExecuter >> resumeExecution [

(self process isTerminated not) ifTrue: [
(self process isTerminated) ifFalse: [
self state: #running.
self process resume.
]
self process resume.]
]

{
Expand All @@ -164,18 +163,18 @@ SKExecuter >> speed: aSpeed [

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 14:08'
#'squeak_changestamp' : 'JJG 7/6/2024 17:49'
}
SKExecuter >> state [

(self process isNil) ifTrue: [
(self process isNil)
ifTrue: [
self state: #terminated
]
]
ifFalse: [
(self process isTerminated) ifTrue: [
self state: #terminated
]
].
self state: #terminated]
].
^ state
]

Expand Down Expand Up @@ -210,21 +209,23 @@ SKExecuter >> stepTime [

{
#category : #execution,
#'squeak_changestamp' : 'EB 6/22/2024 14:09'
#'squeak_changestamp' : 'JJG 7/6/2024 17:47'
}
SKExecuter >> suspendExecution [

((self process isTerminated not) and: (self process isSuspended not)) ifTrue: [
self state: #suspended.
process suspend.
self process suspend.
].
]

{
#category : #execution,
#'squeak_changestamp' : 'EB 6/22/2024 14:34'
#'squeak_changestamp' : 'JJG 7/6/2024 17:54'
}
SKExecuter >> terminate [

(self state = #terminated) ifFalse: [self process terminate. self state: #terminated]
(self state = #terminated) ifFalse: [
self process terminate.
self state: #terminated]
]
15 changes: 0 additions & 15 deletions src/SqueakKara-Core/SKGrid.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ Class {
#'squeak_changestamp' : 'JJG 7/1/2024 15:48'
}

{
#category : #'instance creation',
#'squeak_changestamp' : 'NR 7/5/2024 12:01'
}
SKGrid class >> newWithChallenge: aNumber [

"comment stating purpose of message"






]

{
#category : #'instance creation',
#'squeak_changestamp' : 'JJG 6/5/2024 17:29'
Expand Down
16 changes: 8 additions & 8 deletions src/SqueakKara-Core/SKKara.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ Class {

{
#category : #turning,
#'squeak_changestamp' : 'jt 6/11/2024 12:44'
#'squeak_changestamp' : 'JJG 7/6/2024 17:57'
}
SKKara >> convertAngleToDirection: angle [

| AngleToDirection |
| angleToDirection |

AngleToDirection := Dictionary newFrom: {
angleToDirection := Dictionary newFrom: {
0 -> SKDirection above.
90 -> SKDirection right.
180 -> SKDirection below.
270 -> SKDirection left.}.

^ AngleToDirection at: angle
^ angleToDirection at: angle
]

{
#category : #turning,
#'squeak_changestamp' : 'jt 6/11/2024 13:22'
#'squeak_changestamp' : 'JJG 7/6/2024 17:58'
}
SKKara >> convertDirectionToAngle: direction [

| DirectionToAngle |
| directionToAngle |

DirectionToAngle := Dictionary newFrom: {
directionToAngle := Dictionary newFrom: {
SKDirection above -> 0.
SKDirection right -> 90.
SKDirection below -> 180.
SKDirection left -> 270.}.

^ DirectionToAngle at: direction
^ directionToAngle at: direction
]

{
Expand Down
4 changes: 2 additions & 2 deletions src/SqueakKara-Core/SKWorkspace.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'KD 6/12/2024 18:43'
#'squeak_changestamp' : 'JJG 7/6/2024 17:17'
}
SKWorkspace class >> newWithKara: aKara [

^self basicNew initializeWithKara: aKara.
^ self basicNew initializeWithKara: aKara.
]

{
Expand Down
5 changes: 2 additions & 3 deletions src/SqueakKara/SKEnvironment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,15 @@ SKEnvironment >> grid: anObject [

{
#category : #initialization,
#'squeak_changestamp' : 'JJG 7/1/2024 16:28'
#'squeak_changestamp' : 'JJG 7/6/2024 17:48'
}
SKEnvironment >> initializeObjects [


self workspace: (SKWorkspace newWithKara: self kara).
self executer: (SKExecuter new).
(self executer kara) kara: self kara.
self executeControls: SKExecuteControls new.
executeControls environment: self.
self executeControls environment: self.

self setSystemWindow.
self systemWindow openInHand
Expand Down
Loading

0 comments on commit d242ef9

Please sign in to comment.