'From MIT Squeak 0.9.4 (June 1, 2003) [No updates present.] on 15 October 2009 at 2:24:26 pm'! SimpleClientSocket subclass: #ScratchClientSocket instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Network-Kernel'! !ScratchClientSocket methodsFor: 'connection open/close' stamp: 'ka 1/31/2009 18:54'! connectTo: hostAddress ^ self connectTo: hostAddress port: self class defaultPort! ! !ScratchClientSocket methodsFor: 'entry points' stamp: 'e-itoh 10/15/2009 11:20'! sendAiboCommand: string self sendData: string asByteArray.! ! !ScratchClientSocket class methodsFor: 'send command' stamp: 'e-itoh 10/15/2009 13:25'! send: command to: address "Send the given command to the address." "ScratchClientSocket send: '' to: 'localhost'" | socket | "false ifTrue: [ Transcript show: command. ^ self ]." self initializeNetwork. socket _ self new. socket connectTo: (NetNameResolver addressForName: address). socket waitForConnectionUntil: self standardDeadline. socket sendAiboCommand: command. socket closeAndDestroy. "^ response"! ! !ScratchClientSocket class methodsFor: 'send command' stamp: 'e-itoh 10/15/2009 12:58'! sendAibo: message to: address "Broadcast the given message to the address." "ScratchClientSocket broadcast: 'beat' to: 'localhost'" | sizeStr | sizeStr _ message size asString. sizeStr _ ('00000000' copyFrom: 1 to: 8 - sizeStr size) , sizeStr. ^ self send: 'AIBO' , sizeStr , message to: address! ! !ScratchClientSocket class methodsFor: 'defaults' stamp: 'e-itoh 10/14/2009 21:32'! defaultPort "default port to connect on" ^ 54322! ! !ScriptableScratchMorph methodsFor: 'other ops' stamp: 'e-itoh 10/14/2009 21:32'! aiboMotion: t1 to: t2 | motionNo | motionNo _ t1 asString. motionNo _ ('0000' copyFrom: 1 to: 4 - motionNo size) , motionNo. ScratchClientSocket sendAibo: 'MO' , motionNo to: t2! ! !ScriptableScratchMorph methodsFor: 'blocks' stamp: 'e-itoh 10/14/2009 21:09'! defaultArgsFor: blockSpec "Answer the default argument for the given block specification." | defaultArgs stage sel currentSize list | defaultArgs _ blockSpec copyFrom: 4 to: blockSpec size. "may be empty" stage _ self ownerThatIsA: ScratchStageMorph. sel _ (blockSpec at: 3) asSymbol. #gotoX:y: = sel ifTrue: [ defaultArgs _ Array with: self referencePosition x rounded with: self referencePosition y rounded]. #glideSecs:toX:y:elapsed:from: = sel ifTrue: [ defaultArgs _ Array with: 1 with: self referencePosition x rounded with: self referencePosition y rounded]. #motor:direction: = self ifTrue: [ defaultArgs _ Array with: 'reverse' localized with: 'this way' localized with: 'that way']. #setSizeTo: = sel ifTrue: [ currentSize _ (100.0 * (self scalePoint x max: self scalePoint y)) rounded. defaultArgs _ Array with: currentSize]. #getAttribute:of: = sel ifTrue: [ (stage _ self ownerThatIsA: ScratchStageMorph) ifNotNil: [ list _ stage submorphs select: [:m | m isKindOf: ScratchSpriteMorph]. list sort: [:s1 :s2 | s1 objName asLowercase < s2 objName asLowercase]. list size > 0 ifTrue: [defaultArgs _ Array with: 'x position' with: list first] ifFalse: [defaultArgs _ Array with: 'background #' with: stage]] ifNil:[defaultArgs _ Array with: 'x position' with: self]]. #concatenate:with: = sel ifTrue: [ defaultArgs _ Array with: 'hello ' localized with: 'world' localized]. #doAsk = sel ifTrue: [ defaultArgs _ Array with: 'What''s your name?' localized]. #letter:of: = sel ifTrue: [ defaultArgs _ Array with: 1 with: 'world' localized]. #stringLength: = sel ifTrue: [ defaultArgs _ Array with: 'world' localized]. #say:duration:elapsed:from: = sel ifTrue: [ defaultArgs _ Array with: 'Hello!!' localized with: 2]. #say: = sel ifTrue: [ defaultArgs _ Array with: 'Hello!!' localized]. #think:duration:elapsed:from: = sel ifTrue: [ defaultArgs _ Array with: 'Hmm...' localized with: 2]. #think: = sel ifTrue: [ defaultArgs _ Array with: 'Hmm...' localized]. (#(lookLike: showBackground:) includes: sel) ifTrue: [ defaultArgs _ Array with: self costumeNames last]. (#(playSound: doPlaySoundAndWait) includes: sel) ifTrue: [ list _ self soundNames. defaultArgs _ list size <= 2 ifTrue: [Array with: ''] ifFalse: [Array with: (list at: (list size - 2))]]. (#(broadcast: doBroadcastAndWait) includes: sel) ifTrue: [ stage ifNotNil: [defaultArgs _ Array with: stage defaultEventName]]. (#(append:toList: deleteLine:ofList: insert:at:ofList:) includes: sel) ifTrue: [ defaultArgs size >= 1 ifTrue: [ defaultArgs at: 1 put: (defaultArgs at: 1) localized]]. (#(append:toList: deleteLine:ofList: getLine:ofList: insert:at:ofList: lineCountOfList:) includes: sel) ifTrue: [ defaultArgs _ defaultArgs copyWith: self defaultListName]. #setLine:ofList:to: = sel ifTrue: [ defaultArgs size >= 3 ifTrue: [ defaultArgs at: 2 put: self defaultListName. defaultArgs at: 3 put: (defaultArgs at: 3) localized]]. #appendLettersOf:toList: = sel ifTrue: [ defaultArgs size >= 2 ifTrue: [ defaultArgs at: 1 put: (defaultArgs at: 1) localized. defaultArgs at: 2 put: self defaultListName]]. #list:contains: = sel ifTrue: [ defaultArgs size >= 2 ifTrue: [ defaultArgs at: 1 put: self defaultListName. defaultArgs at: 2 put: (defaultArgs at: 2) localized]]. #aiboMotion:to: = sel ifTrue: [ defaultArgs _ Array with: 30 with: 'localhost']. ^ defaultArgs ! ! !ScriptableScratchMorph class methodsFor: 'block specs' stamp: 'e-itoh 10/14/2009 20:58'! blockSpecs "Answer a collection of block specifications for the blocks that are common to all objects. Block specificatons (Arrays) are interspersed with category names (Strings). A block specification is an Array of the form: ( [optional initial argument values]). Explanation of flags: - no flags b boolean reporter c c-shaped block containing a sequence of commands (always special form) r reporter s special form command with its own evaluation rule t timed command, like wait or glide E message event hat K key event hat M mouse-click event hat S start event hat W when hat (obsolete)" | blocks | blocks _ #( 'control' ('when %m clicked' S -) ('when %k key pressed' K -) ('when %m clicked' M -) - ('wait %n secs' t wait:elapsed:from: 1) - ('forever' c doForever) ('repeat %n' c doRepeat 10) - ('broadcast %e' - broadcast:) ('broadcast %e and wait' s doBroadcastAndWait) ('when I receive %e' E -) - ('forever if %b' c doForeverIf) ('if %b' c doIf) ('if %b' c doIfElse) ('wait until %b' s doWaitUntil) ('repeat until %b' c doUntil) - ('stop script' s doReturn) ('stop all' - stopAll) ('motion %n to %s' - aiboMotion:to: 30 'localhost') 'operators' ('%n + %n' r + - -) ('%n - %n' r - - -) ('%n * %n' r * - -) ('%n / %n' r / - -) - ('pick random %n to %n' r randomFrom:to: 1 10) - ('%s < %s' b < '' '') ('%s = %s' b = '' '') ('%s > %s' b > '' '') - ('%b and %b' b &) ('%b or %b' b |) ('not %b' b not) - ('join %s %s' r concatenate:with: 'hello ' 'world') ('letter %n of %s' r letter:of: 1 'world') ('length of %s' r stringLength: 'world') - ('%n mod %n' r \\ - -) ('round %n' r rounded -) - ('%f of %n' r computeFunction:of: 'sqrt' 10) 'sound' ('play sound %S' - playSound:) ('play sound %S until done' s doPlaySoundAndWait) ('stop all sounds' - stopAllSounds) - ('play drum %D for %n beats' t drum:duration:elapsed:from: 48 0.2) ('rest for %n beats' t rest:elapsed:from: 0.2) - ('play note %N for %n beats' t noteOn:duration:elapsed:from: 60 0.5) ('set instrument to %I' - midiInstrument: 1) - ('change volume by %n' - changeVolumeBy: -10) ('set volume to %n%' - setVolumeTo: 100) ('volume' r volume) - ('change tempo by %n' - changeTempoBy: 20) ('set tempo to %n bpm' - setTempoTo: 60) ('tempo' r tempo) 'motor' ('motor on for %n secs' t motorOnFor:elapsed:from: 1) ('motor on' - allMotorsOn) ('motor off' - allMotorsOff) ('motor power %n' - startMotorPower: 100) ('motor direction %W' - setMotorDirection: 'this way') 'variables' ('show variable %v' - showVariable:) ('hide variable %v' - hideVariable:) 'list' ('add %s to %L' - append:toList: 'thing') - ('delete %y of %L' - deleteLine:ofList: 1) ('insert %s at %i of %L' - insert:at:ofList: 'thing' 1) ('replace item %i of %L with %s' - setLine:ofList:to: 1 'list' 'thing') - ('item %i of %L' r getLine:ofList: 1) ('length of %L' r lineCountOfList:) ('%L contains %s' b list:contains: 'list' 'thing') ). ^ blocks, self obsoleteBlockSpecs ! !