static void parseGridList(Util::ReferenceCount<Gui::GridSelect> list, std::map<int, unsigned int> & cursorLocations, const Token * token){
    if ( *token != "grid-list" ){
        throw LoadException(__FILE__, __LINE__, "Not a Grid Select List");
    }
    TokenView view = token->view();
    while (view.hasMore()){
        try{
            const Token * tok;
            view >> tok;
            int x=0,y=0;
            std::string layout;
            if (parseBaseList(list, cursorLocations, tok)){
            } else if (tok->match("grid-size", x, y)){
                list->setGridSize(x, y);
            } else if (tok->match("layout", layout)){
                if (layout == "static"){
                    list->setLayout(Gui::GridSelect::Static);
                } else if (layout == "infinite-vertical"){
                    list->setLayout(Gui::GridSelect::InfiniteVertical);
                } else if (layout == "infinite-horizontal"){
                    list->setLayout(Gui::GridSelect::InfiniteHorizontal);
                }
            } else {
                Global::debug(0) << "Unknown Grid List property: " << tok->getName() << std::endl;
            }
        } catch ( const TokenException & ex ) {
            throw LoadException(__FILE__, __LINE__, ex, "Grid Select parse error");
        }
    }
}
static void parseSimpleList(Util::ReferenceCount<Gui::SimpleSelect> list, std::map<int, unsigned int> & cursorLocations, const Token * token){
    if ( *token != "simple-list" ){
        throw LoadException(__FILE__, __LINE__, "Not a Simple Select List");
    }
    TokenView view = token->view();
    while (view.hasMore()){
        try{
            const Token * tok;
            view >> tok;
            int offset=0;
            std::string layout;
            int viewable = 0;
            if (parseBaseList(list, cursorLocations, tok)){
            } else if (tok->match("viewable", viewable)){
                list->setViewable(viewable);
            } else if (tok->match("layout", layout)){
                if (layout == "horizontal"){
                    list->setLayout(Gui::SimpleSelect::Horizontal);
                } else if (layout == "vertical"){
                    list->setLayout(Gui::SimpleSelect::Vertical);
                }
            } else if (tok->match("scroll-offset", offset)){
                list->setScrollOffset(offset);
            } else {
                Global::debug(0) << "Unknown Simple List property: " << tok->getName() << std::endl;
            }
        } catch ( const TokenException & ex ) {
            throw LoadException(__FILE__, __LINE__, ex, "Simple Select parse error");
        }
    }
}
Example #3
0
Item::Item(const Filesystem::AbsolutePath & filename, const Util::ReferenceCount<Stimulation> & stimulation, const string & check):
ObjectNonAttack(0, 0),
// collide(0),
stimulation(stimulation){
    TokenReader tr;

    setMaxHealth(1);
    setHealth(1);

    try{
        Token * head;
        head = tr.readTokenFromFile(filename.path());

        if (*head != check){
            throw LoadException(__FILE__, __LINE__, "Item does not begin with 'item'" );
        }

        TokenView view = head->view();
        while (view.hasMore()){
            const Token * next = NULL;
            view >> next;
            if (*next == "frame"){
                animation = singleFrameAnimation(next);
                /*
                string file;
                next->view() >> file;
                picture.load(Storage::instance().find(Filesystem::RelativePath(file)).path());
                */
            } else if (*next == "anim" || *next == "animation"){
                animation = Util::ReferenceCount<Animation>(new Animation(next, NULL));
            } else if (*next == "sound"){
                string path;
                next->view() >> path;
                sound = Sound(Storage::instance().find(Filesystem::RelativePath(path)).path());
            } else if (*next == "float"){
                floating.enabled = true;
                double value = 0;
                if (next->match("_/height", value)){
                    floating.height = value;
                }
                if (next->match("_/amplitude", value)){
                    floating.amplitude = value;
                }
                if (next->match("_/period", value)){
                    if (value < 1){
                        value = 1;
                    }
                    floating.period = value;
                }
            }
        }
Example #4
0
Game::Game(const std::string & filename){
    /* NOTE this is temporary to run tests on the engine
     * Eventually it will be replaced with a class that handles the entire game (worlds, etc...)
     */
    try {
        Global::debug(1,"platformer") << "Loading Platformer: " << filename << endl;
        TokenReader tr;
        Token * platformToken = tr.readTokenFromFile(filename);
        
        if ( *platformToken != "platformer" ){
            throw LoadException(__FILE__, __LINE__, "Not a Platformer");
        }

        TokenView view = platformToken->view();
        while (view.hasMore()){
            try{
                const Token * tok;
                view >> tok;
                if ( *tok == "world" ){
                    world = Util::ReferenceCount<Platformer::World>(new Platformer::World(tok));
                } else if ( *tok == "cutscene" ){
                    //std::string file;
                    //tok->view() >> file;
                    //Util::ReferenceCount<Gui::CutScene> cutscene(new Gui::CutScene(tok));
                    //Util::ReferenceCount<Gui::CutScene> cutscene(new Gui::CutScene(Filesystem::AbsolutePath(file)));
                    //cutscenes[cutscene->getName()] = cutscene;
                } else if (*tok == "font"){
                    Platformer::Font::Map::add(tok);
                } else {
                    Global::debug(3) << "Unhandled Platformer attribute: " << endl;
                    if (Global::getDebug() >= 3){
                        tok->print(" ");
                    }
                }
            } catch ( const TokenException & ex ) {
                throw LoadException(__FILE__, __LINE__, ex, "Platformer parse error");
            } catch ( const LoadException & ex ) {
                // delete current;
                throw ex;
            }
        }
    } catch (const TokenException & e){
        throw LoadException(__FILE__, __LINE__, e, "Error loading platformer file.");
    }
    
    // TODO remove test intro cutscene
    /*if (cutscenes["intro"] != NULL){
        cutscenes["intro"]->setResolution(worlds[0]->getResolutionX(), worlds[0]->getResolutionY());
    }*/
}
Example #5
0
BlockObject::BlockObject(const Token * tok):
type(ObjectFactory::NoneType),
aggression( -1 ),
map( 0 ),
health( 1 ),
coords_x( 0 ),
coords_z( 0 ),
id(-1){
    TokenView view = tok->view();
    while (view.hasMore()){
        try{
            const Token * current;
            view >> current;

            if ( *current == "type" ){
                string k;
                current->view() >> k;
                if ( k == "item" ){
                    type = ObjectFactory::ItemType;
                } else if (k == "breakable-item"){
                    type = ObjectFactory::BreakableItemType;
                } else if ( k == "enemy" ){
                    type = ObjectFactory::EnemyType;
                } else if ( k == "actor" ){
                    type = ObjectFactory::ActorType;
                } else if ( k == "cat" ){
                    type = ObjectFactory::CatType;
                } else {
                    tok->print(" ");
                    throw LoadException(__FILE__, __LINE__, "Not a valid type");
                }
            } else if ( *current == "stimulation" ){
                setStimulation(Util::ReferenceCount<Paintown::Stimulation>(Paintown::Stimulation::create(*current)));
                /*
                string type;
                double value;
                const Token * next;
                current->view() >> next;
                type = next->getName();
                next->view() >> value;
                setStimulationValue(value);
                setStimulationType(type);
                */
            } else if (*current == "id"){
                int id;
                current->view() >> id;
                setId(id);
                ObjectFactory::maxId(id);
            } else if ( *current == "path" ){
Example #6
0
Element::Element(const Token * token):
time(50),
alpha(255){
    if (token != NULL){
        TokenView view = token->view();
        while (view.hasMore()){
            try{
                const Token * tok;
                view >> tok;
                parseToken(tok);
            } catch ( const TokenException & ex ) {
                throw LoadException(__FILE__, __LINE__, ex, "Gui::Animation::Element parse error");
            } catch ( const LoadException & ex ) {
                throw ex;
            }
        }
    }
Example #7
0
 void importObject(const Token * token){
     if ( *token != "object-script" ){
         throw LoadException(__FILE__, __LINE__, "Not an object script.");
     }
     std::string module, function;
     bool hasPosition = false;
     int x=0, y=0;
     std::vector<const Token *> animations;
     TokenView view = token->view();
     while (view.hasMore()){
         try{
             const Token * tok;
             view >> tok;
             if (*tok == "module"){
                 tok->view() >> module;
             } else if (*tok == "function"){
                 tok->view() >> function;
             } else if (*tok == "position"){
Example #8
0
Camera::Camera(int resolutionX, int resolutionY, int worldWidth, int worldHeight, const Token * token):
id(0),
resolutionX(resolutionX),
resolutionY(resolutionY),
worldWidth(worldWidth),
worldHeight(worldHeight),
x(0),
y(0),
currentX(0),
currentY(0),
windowX(0),
windowY(0),
windowWidth(0),
windowHeight(0),
window(NULL),
scrollSpeed(2),
currentXSpeed(0),
currentYSpeed(0),
velocity(.5),
smoothScrolling(false),
smoothScrollWaitX(5),
smoothScrollWaitY(5),
smoothScrollModifier(5),
follow(false),
followVariance(1.5),
object(NULL), 
lockUp(false),
lockDown(false),
lockLeft(false),
lockRight(false){
    TokenView view = token->view();
    while (view.hasMore()){
        try{
            const Token * tok;
            view >> tok;
            if (*tok == "id"){
                // get the name
                tok->view() >> id;
            } else if (*tok == "dimensions"){
                // Get the resolution of the world
                tok->view() >> worldWidth >> worldHeight;
            } else if (*tok == "start"){
Example #9
0
Block::Block(const Token * tok, const Level::Cacher & cacher):
id(-1),
finished( -1 ),
continuous( false ){

    if ( *tok != "block" ){
        throw LoadException(__FILE__, __LINE__, "Not a scene block");
    }

    TokenView view = tok->view();
    while (view.hasMore()){
        try{
            const Token * current;
            view >> current;
            if (*current == "length"){
                int l;
                current->view() >> l;
                setLength(l);
            } else if ( *current == "wait" ){
                current->view() >> wait;
            } else if ( *current == "id" ){
Example #10
0
AnimationEventProjectile::AnimationEventProjectile(const Token * token ):
    projectile( NULL ),
    x( 0 ),
    y( 0 ),
    dx( 0 ),
    dy( 0 ),
    life( 0 ) {
    if ( *token != "projectile" ) {
        throw LoadException(__FILE__, __LINE__, "Token starts with " + token->getName() + " instead of 'projectile'." );
    }

    TokenView view = token->view();
    while (view.hasMore()) {
        const Token * current;
        view >> current;
        if ( *current == "at" ) {
            int x, y;
            current->view() >> x >> y;
            setX( x );
            setY( y );
        } else if ( *current == "path" ) {
Example #11
0
Effect::Effect( const char * _filename, int alliance ):
ObjectNonAttack( 0, 0, alliance ),
image(NULL){

    TokenReader tr;

    setMaxHealth( 100 );

    Token * head;
    try{ 
        head = tr.readTokenFromFile(_filename);
    } catch ( const TokenException * te ){
        throw LoadException(__FILE__, __LINE__, "Could not load effect");
    }

    if ( *head != "effect" ){
        cout<<_filename<< " is not an effect"<<endl;
        // delete head;
        throw LoadException(__FILE__, __LINE__, "Not an effect");
    }

    TokenView view = head->view();
    while (view.hasMore()){
        const Token * n = NULL;
        try{
            view >> n;

            // for ( int q = 0; q < head->numTokens(); q++ ){
            // n = head->getToken( q );

            if ( *n == "anim" ){
                if ( image ){
                    // cout<<"Mulitple animations specified"<<endl;
                    throw LoadException(__FILE__, __LINE__, "Multiple animations specified");
                }

                image = new Animation(n, NULL);
            } else {
                cout<<"Unhandled effect attribute: "<<endl;
                n->print(" ");
            }

            // }

            /* catch exception?? */
        } catch( const exception & ex ){
            // delete head;
            if (n != NULL){
                n->print(" ");
            }
            /*
               if ( n ){
               cout<<"Error with: "<<n<<endl;
               } else 
               cout<<"Something bad happened in character"<<endl;
               throw ex;
               */
            throw LoadException(__FILE__, __LINE__, "Effect parse error");
        }

    }

    // delete head;

}