Esempio n. 1
0
TEST(Levels, load_npz)
{
    Levels l;
    
    l.addPath("data/C10_Standard.npz");
    ASSERT_EQ(9, l.numLevels());
    
    ASSERT_STREQ("plane sailing", l.levelName(0).c_str());
    ASSERT_STREQ("the leap", l.levelName(1).c_str());
    ASSERT_STREQ("nautilus", l.levelName(8).c_str());
    
    ASSERT_EQ(1, l.numCollections());
    ASSERT_EQ(9, l.collectionSize(0));
    
    int indexInCol;
    ASSERT_EQ(0, l.collectionFromLevel(0, &indexInCol));
    ASSERT_EQ(0, indexInCol);

    ASSERT_EQ(0, l.collectionFromLevel(1, &indexInCol));
    ASSERT_EQ(1, indexInCol);

}
Esempio n. 2
0
TEST(Levels, empty)
{
    Levels l;
    
    ASSERT_EQ(0, l.numLevels());
    
    ASSERT_EQ(string("err"), l.levelName(0, false));
    ASSERT_EQ(string("err"), l.levelName(0, true));
    
    ASSERT_LT(l.findLevel("non-existent"), 0);
    ASSERT_EQ(0, l.numCollections());
    ASSERT_LT(l.collectionFromLevel(0), 0);

    ASSERT_EQ(0, l.collectionSize(0));
    ASSERT_EQ(0, l.collectionSize(1));

    ASSERT_EQ(0, l.collectionLevel(0, 0));

    ASSERT_FALSE(l.demoPath(0).empty());
    ASSERT_FALSE(l.demoName(0).empty());
    ASSERT_FALSE(l.hasDemo(0));
}
Esempio n. 3
0
    void setCollection(int c, int levelInC)
    {
        if (c < 0 || static_cast<unsigned int>(c) >=m_levels->numCollections()) {
            return;
        }
        m_collection = c;
        m_dispbase = 0;
        m_dispcount = m_levels->collectionSize(c);
        m_scroll->virtualSize(Vec2(SCREEN_WIDTH,150+(SCREEN_HEIGHT/ICON_SCALE_FACTOR+40)*((m_dispcount+2)/3)));

        m_scroll->empty();
        Box *vbox = new VBox();
        vbox->add( new Spacer(),  10, 0 );
        Box *hbox = new HBox();
        Widget *w = new Button("<<",Event::PREVIOUS);
        w->border(false);
        hbox->add( w, BUTTON_WIDTH, 0 );
        hbox->add( new Spacer(), 10, 0 );
        Label *title = new Label(m_levels->collectionName(c));
        title->font(Font::headingFont());
        title->alpha(100);
        hbox->add( title, BUTTON_WIDTH, 4 );
        w= new Button(">>",Event::NEXT);
        w->border(false);
        hbox->add( new Spacer(), 10, 0 );
        hbox->add( w, BUTTON_WIDTH, 0 );
        vbox->add( hbox, 64, 0 );
        vbox->add( new Spacer(),  10, 0 );

        hbox = new HBox();
        hbox->add( new Spacer(),  0, 1 );
        int accumw = 0;
        for (int i=0; i<m_dispcount; i++) {
            accumw += SCREEN_WIDTH / ICON_SCALE_FACTOR + 10;
            if (accumw >= SCREEN_WIDTH) {
                vbox->add(hbox, SCREEN_HEIGHT/ICON_SCALE_FACTOR+30, 4);
                vbox->add( new Spacer(),  10, 0 );
                hbox = new HBox();
                hbox->add( new Spacer(),  0, 1 );
                accumw = SCREEN_WIDTH / ICON_SCALE_FACTOR;
            }
            m_thumbs[i] = new IconButton("--","",Event(Event::PLAY, //SELECT,
                                         m_levels->collectionLevel(c,i)));
            m_thumbs[i]->font(Font::blurbFont());
            m_thumbs[i]->setBg(SELECTED_BG);
            m_thumbs[i]->border(false);
            hbox->add( m_thumbs[i],  SCREEN_WIDTH / ICON_SCALE_FACTOR, 0 );
            hbox->add( new Spacer(), 0, 1 );
        }
        vbox->add(hbox, SCREEN_HEIGHT/ICON_SCALE_FACTOR+30, 4);
        vbox->add( new Spacer(), 110, 10 );
        m_scroll->add(vbox,0,0);

        for (int i=0; i<THUMB_COUNT && i+m_dispbase<m_dispcount; i++) {
            Canvas temp( SCREEN_WIDTH, SCREEN_HEIGHT );
            Scene scene( true );
            unsigned char buf[64*1024];
            int level = m_levels->collectionLevel(c,i);
            int size = m_levels->load( level, buf, sizeof(buf) );
            if ( size && scene.load( buf, size ) ) {
                scene.draw( temp, FULLSCREEN_RECT );
                m_thumbs[i]->text( m_levels->levelName(level) );
                m_thumbs[i]->canvas( temp.scale( ICON_SCALE_FACTOR ) );
                m_thumbs[i]->transparent(m_dispbase+i!=levelInC);
            }
        }
    }