Welcome to Phrogram Sign in | Join | Help


Re: How Can I create a Class Library for Phrogram?

  •  03-06-2007, 4:06 AM

    Re: How Can I create a Class Library for Phrogram?

    Attachment: DemoLibrary.zip

    For the impatient ones among you (me included!) who cannot wait for the Phrogram guys to release details of how to create extension libraries (dll files), take a look at the attached file, DemoLibrary.zip. As the name suggests this is a purely a demonstration, and I do not promise that you will find the library useful; it merely shows how a library can be created.

     

    When you unzip the attachment you should have five files, as follows:

     

    Phrogram.DNGLibrary.dll

    This is the actual library file itself. I called it DNGLibrary because my initials are D.N.G., so it seemed like a good idea at the time. The library contains 3 classes called AreaSelector, GameBoard and GameTime. You must move or copy this file into the Phrogram folder (located at C:\Program Files\The Phrogram Company\Phrogram on my system), which is where Phrogram keeps all its dll files. This library can now be used just like any of the “built-in” libraries.

     

    Phrogram.DNGLibrary.xml

    This is the corresponding XML file for the library. It contains all the info and instructions for the library. Phrogram uses it to display information about the library, its classes and the methods/functions within those classes. You should also move or copy this file to the same Phrogram folder as before. Now you are ready to go.

     

    AreaSelector.cs, GameBoard.cs, GameTime.cs

    These are the C# source code files for the classes in the library. Obviously you will need to know a little about C# in order to understand them, but you do not need them in order to use the library.

     

    When you have the dll and XML files in the Phrogram folder, start Phrogram (if it’s already running, close it down and start it again). Click View and then Class Library Browser. This displays a list of all the Phrogram libraries. Among those libraries should be DNGLibrary. Click the + sign to expand it and you’ll find the three classes. Click on each one to get full details about the class as well as a list of all the methods and functions within each class.

     

    This library is very simple but it shows that user-defined extensions are possible. Unfortunately the source files do not tell the whole story. For example, your library project must reference KPL.Extensibilty.dll, as well as any other Phrogram libraries it may use (DNGLibrary uses KPL.Core.Libraries.dll for the Phrogram.Rectangle class). If you take a look at the source files you will notice that each class has an [Extension] attribute. The reason for this is obvious (it’s an extension library), but this only applies to classes that can be instantiated (ie, you can create objects from them); if a class contains static methods, you must use the attribute [Extension(true)] so that Phrogram knows it is a static class. There are also rules governing the passing and returning of arrays to/from library methods (Phrogram arrays need to be converted to System.Array types – an advanced subject).

     

    There is a lot more to writing extension libraries than I have mentioned here, but as I don’t understand most of it myself, I can’t explain it! We may have to wait for the guys at Phrogram to reveal all (so to speak), unless someone else can take up the challenge…

     

    Dave

     

View Complete Thread