ビューワ登録-ADVANCED

モーフ内の任意のメソッドをビューワに新しく登録する方法をT先生より教えていただきました。

※ユーザが任意に決めれる箇所はイタリックで表示

前提

  1. 新しく”NewMorph”クラスを作る
  2. 'newPropaty''newPropaty:''command'の3つのメソッドをビューワに登録する。newPropatyの値は数値とする

手順
1."Player"クラスのサブクラス"NewMorphPlayer"を作成
2."NewMorph"の'newPropaty''newPropaty:''command'に対応するメソッド'getNewPropaty''setNewPropaty:''newCommand'を"NewMorphPlayer"に作成
※各メソッド内容

NewMorphPlayer >> getNewPropaty
 ^self costume newPropaty

NewMorphPlayer >> setNewPropaty: t1
 self costume newPropaty: t1

NewMorphPlayer >> newCommand
 self costume command

3."NewMorph"にて、インスタンスメソッド'newPlayerInstance'をオーバーライド
これで、NewMorphPlayerのメソッドをビューワで使用できるようになる

NewMorph >> newPlayerInstance
 ^NewMorphPlayer newUserInstance

4."NewMorph"のクラスメソッドにて'additionsToViewerCategories'をオーバーライド
※additionsToViewerCategoriesについては
http://d.hatena.ne.jp/daina/20051113#1131887005
参照

NewMorph class >> additionsToViewerCategories
 ^#(#(
 CATEGORYNAME #(
   (slot newPropaty 'COMMENT FOR NEWPROPATY' Number readWrite Player getNewPropaty Player setNewPropaty:)
   (command newCommand 'COMMENT FOR COMMAND')
  )
 ))

これで出来るはず。(多分)