コード例 #1
0
ファイル: project_item.cpp プロジェクト: BenCastricum/scummvm
void CProjectItem::loadGame(int slotId) {
    CompressedFile file;

    // Clear any existing project contents and call preload code
    preLoad();
    clear();

    // Open either an existing savegame slot or the new game template
    if (slotId >= 0) {
        Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(
                                           g_vm->generateSaveName(slotId));
        file.open(saveFile);
    } else {
        Common::File *newFile = new Common::File();
        if (!newFile->open("newgame.st"))
            error("Could not open newgame.st");
        file.open(newFile);
    }

    // Load the savegame header in
    TitanicSavegameHeader header;
    readSavegameHeader(&file, header);
    delete header._thumbnail;

    // Load the contents in
    CProjectItem *newProject = loadData(&file);
    file.IsClassStart();
    getGameManager()->load(&file);

    file.close();

    // Clear existing project
    clear();

    // Detach each item under the loaded project, and re-attach them
    // to the existing project instance (this)
    CTreeItem *item;
    while ((item = newProject->getFirstChild()) != nullptr) {
        item->detach();
        item->addUnder(this);
    }

    // Loaded project instance is no longer needed
    newProject->destroyAll();

    // Post-load processing
    postLoad();
}
コード例 #2
0
ファイル: project_item.cpp プロジェクト: BenCastricum/scummvm
CProjectItem *CProjectItem::loadData(SimpleFile *file) {
    if (!file->IsClassStart())
        return nullptr;

    CProjectItem *root = nullptr;
    CTreeItem *parent = nullptr;
    CTreeItem *item = nullptr;

    do {
        CString entryString = file->readString();

        if (entryString == "ALONG") {
            // Move along, nothing needed
        } else if (entryString == "UP") {
            // Move up
            if (parent == nullptr ||
                    (parent = parent->getParent()) == nullptr)
                break;
        } else if (entryString == "DOWN") {
            // Move down
            if (parent == nullptr)
                parent = item;
            else
                parent = parent->getLastChild();
        } else {
            // Create new class instance
            item = dynamic_cast<CTreeItem *>(CSaveableObject::createInstance(entryString));
            assert(item);

            if (root) {
                // Already created root project
                item->addUnder(parent);
            } else {
                root = dynamic_cast<CProjectItem *>(item);
                assert(root);
                root->_filename = _filename;
            }

            // Load the data for the item
            item->load(file);
        }

        file->IsClassStart();
    } while (file->IsClassStart());

    return root;
}