Extending Vilya Puzzle Classes From the ToyBox
From Gardenwiki
Contents |
The Vilya puzzle package
The Vilya puzzle library is the used by threerings in Puzzle Pirages puzzle (most probably, at least Swordfighting and Sailing). Classes in the package com.threerings.puzzle provide support for drawing a set of pieces on a rectangular board and moving them around. Classes in the package com.threerings.puzzle.drop provide additional support for having the pieces fall, for rotating or pushing them, and for things like the "last second move".
The problem
Suppose you want to work with the puzzle package. Your controller has to extend PuzzleController, whose init() method awaits a PuzzleContext and a PuzzleConfig. However, the ToyBox framework provides your controller with a ToyBoxConfig and a ToyBoxGameContext instead, which cannot be casted to PuzzleContext and PuzzleConfig respectively. Indeed, ToyBoxConfig and ToyBoxGameContext are generic classes, that cannot extend all types of games (puzzle, card, etc. ).
The solution
The ToyBoxPuzzle library contains adapator classes to overcome this problem. Have your controller extend ToyBoxPuzzleController, which will create a suitable PuzzleContext. The manager class also has to extend ToyBoxPuzzleManager, in order to create a suitable PuzzleConfig. The following image shows the resulting class hierarchy:
Distributing your Game with the puzzle package
You'll have to include the Vilya puzzle classes in your jar distribution.
External Links
- Documentation for the Vilya API (see. for example the DropBoardView class)
- sources for the ToyBoxPuzzle library
- javadoc API documentation for the ToyBoxPuzzle classes
- Contact me if you would like to get some help on using the ToyBoxPuzzle classes.


