Skip to content

Commit

Permalink
Boids: clean up pass, split test to new package and add baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchodias committed Jul 12, 2024
1 parent cf52d70 commit 5cfd68f
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Class {
#name : #BaselineOfBlocTutorialBoids,
#superclass : #BaselineOf,
#category : #BaselineOfBlocTutorialBoids
}

{ #category : #baselines }
BaselineOfBlocTutorialBoids >> baseline: spec [
<baseline>

spec for: #common do: [
spec
baseline: #'Bloc'
with: [ spec repository: 'github://pharo-graphics/Bloc:master/src' ].
spec
package: #'BlocTutorials-Boids'
with: [ spec requires: #( #'Bloc' ) ].
spec
package: #'BlocTutorials-Boids-Tests'
with: [ spec requires: #( #'BlocTutorials-Boids' ) ]
]
]
1 change: 1 addition & 0 deletions src/BaselineOfBlocTutorialBoids/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #BaselineOfBlocTutorialBoids }
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A BoidTest is a test class for testing the behavior of Boid
Class {
#name : #BoidsSimulationTest,
#superclass : #TestCase,
#category : #'BlocTutorials-Boids-Model-Tests'
#category : #'BlocTutorials-Boids-Tests-Model'
}

{ #category : #'tests-moving' }
Expand Down
1 change: 1 addition & 0 deletions src/BlocTutorials-Boids-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'BlocTutorials-Boids-Tests' }
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Class {

{ #category : #examples }
BoidCustomGeometrySkyElement class >> exampleOpenInNewSpace [
<script>

^ self new openInNewSpace
]

Expand Down
2 changes: 1 addition & 1 deletion src/BlocTutorials-Boids/BoidsCustomDrawSkyElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {

{ #category : #examples }
BoidsCustomDrawSkyElement class >> exampleOpenInNewSpace [
<script>

^ self new openInNewSpace
]

Expand Down
44 changes: 18 additions & 26 deletions src/BlocTutorials-Boids/BoidsSkyElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ Class {
#name : #BoidsSkyElement,
#superclass : #BlElement,
#instVars : [
'steppingAnimation',
'simulation',
'randomGenerator'
'randomGenerator',
'steppingTask'
],
#category : #'BlocTutorials-Boids-UI-Bloc'
}

{ #category : #'as yet unclassified' }
{ #category : #examples }
BoidsSkyElement class >> exampleOpenInNewSpace [

^ self subclassResponsibility
]

Expand All @@ -41,18 +42,21 @@ BoidsSkyElement >> boidsMovedInSimulation [
{ #category : #accessing }
BoidsSkyElement >> ensureNotStepping [

steppingAnimation ifNotNil: [
steppingAnimation stop.
steppingAnimation := nil ]
steppingTask ifNotNil: [
steppingTask stop.
steppingTask := nil ]
]

{ #category : #accessing }
BoidsSkyElement >> ensureStepping [

steppingAnimation ifNil: [
steppingAnimation := self newSteppingAnimation.
self addAnimation: steppingAnimation ]

steppingTask ifNil: [
steppingTask :=
(BlRepeatedTaskAction new
delay: 0 seconds;
action: [ self step ];
yourself).
self enqueueTask: steppingTask ]
]

{ #category : #initialization }
Expand Down Expand Up @@ -84,25 +88,13 @@ BoidsSkyElement >> initializeSimulation [
simulation boids do: [ :each |
self boidWasAddedToSimulation: each ].

self ensureStepping.

self ensureStepping
]

{ #category : #testing }
BoidsSkyElement >> isSteppingAnimation [

^ steppingAnimation isNotNil
]

{ #category : #initialization }
BoidsSkyElement >> newSteppingAnimation [
BoidsSkyElement >> isStepping [

^ BlNumberTransition new
from: 0;
to: 1;
onStepDo: [ :t | self step ];
beInfinite;
yourself
^ steppingTask isNotNil
]

{ #category : #accessing }
Expand Down Expand Up @@ -134,7 +126,7 @@ BoidsSkyElement >> simulation: aBoidsSimulation [
BoidsSkyElement >> step [

simulation move.
self boidsMovedInSimulation.
self boidsMovedInSimulation
]

{ #category : #initialization }
Expand Down
21 changes: 11 additions & 10 deletions src/BlocTutorials-Boids/BoidsSkyPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ BoidsSkyPresenter >> doInspectSimulation [
BoidsSkyPresenter >> doStart [

boidsSkyElement ensureStepping.
self refreshToolbar.
self refreshToolbar
]

{ #category : #actions }
Expand All @@ -88,14 +88,14 @@ BoidsSkyPresenter >> doStep [
BoidsSkyPresenter >> doStop [

boidsSkyElement ensureNotStepping.
self refreshToolbar.
self refreshToolbar
]

{ #category : #actions }
BoidsSkyPresenter >> doToggleCircling [

boidsSkyElement simulation toggleCircling.
self refreshToolbar.
self refreshToolbar
]

{ #category : #initialization }
Expand Down Expand Up @@ -156,23 +156,24 @@ BoidsSkyPresenter >> initializeWindow: aWindowPresenter [
aWindowPresenter
centered;
title: 'Boids';
initialExtent: 510@560;
toolbar: toolbar.
initialExtent: 510 @ 560;
toolbar: toolbar
]

{ #category : #initialization }
BoidsSkyPresenter >> refreshToolbar [

startButton enabled: boidsSkyElement isSteppingAnimation not.
stepButton enabled: boidsSkyElement isSteppingAnimation not.
stopButton enabled: boidsSkyElement isSteppingAnimation.
startButton enabled: boidsSkyElement isStepping not.
stepButton enabled: boidsSkyElement isStepping not.
stopButton enabled: boidsSkyElement isStepping.

boidsSkyElement isStepping traceCr.

boidsSkyElement simulation ifNotNil: [
toggleCirclingButton label:
(boidsSkyElement simulation isCircling
ifTrue: [ 'Circle' ]
ifFalse: [ 'Free' ])]

ifFalse: [ 'Free' ]) ]
]

{ #category : #initialization }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {

{ #category : #examples }
BoidsSkyUsingGeometryElement class >> exampleOpenInNewSpace [
<script>

^ self new openInNewSpace
]

Expand Down

0 comments on commit 5cfd68f

Please sign in to comment.