Exemplo n.º 1
0
bool CCStoryLayer::preloadStoryString(const string& storyScript) {
    // clear old
    gStoryCommandSet.removeAllObjects();
    unloadImageFiles();
    
    // load resources needed
    CCByteBuffer bb(storyScript.c_str(), storyScript.length(), storyScript.length());
    string line;
    bb.readLine(line);
    while(!line.empty()) {
        if(line.find("--$<") == 0) {
            string resCmd = line.substr(4);
            int comma = (int)resCmd.find(",");
            string type = resCmd.substr(0, comma);
            if(type == "atlas") {
                int secondComma = (int)resCmd.find(",", comma + 1);
                string plist = CCUtils::getExternalOrFullPath(resCmd.substr(comma + 1, secondComma - comma - 1));
                string atlas = CCUtils::getExternalOrFullPath(resCmd.substr(secondComma + 1));
                CCResourceLoader::loadZwoptex(plist, atlas, m_decFunc);
            } else if(type == "arm") {
                string json = CCUtils::getExternalOrFullPath(resCmd.substr(comma + 1));
                CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(json.c_str());
            } else if(type == "image") {
                string filename = resCmd.substr(comma + 1);
                string ext = CCUtils::getPathExtension(filename);
                string path;
                if(ext != ".png" && ext != ".jpg" && ext != ".jpeg") {
                    path = CCUtils::getExternalOrFullPath(filename + ".png");
                    if(!CCUtils::isPathExistent(path)) {
                        path = CCUtils::getExternalOrFullPath(filename + ".jpg");
                        if(!CCUtils::isPathExistent(path)) {
                            path = CCUtils::getExternalOrFullPath(filename + ".jpeg");
                            if(!CCUtils::isPathExistent(path)) {
                                path = filename + ".png";
                            }
                        }
                    }
                } else {
                    path = CCUtils::getExternalOrFullPath(filename);
                    if(!CCUtils::isPathExistent(path)) {
                        path = filename;
                    }
                }
                m_loadedImageFiles.push_back(path);
                CCResourceLoader::loadImage(path, m_decFunc);
            }
        } else {
            break;
        }
        
        bb.readLine(line);
    }
    
    // do script
    int ret = luaL_dostring(L, storyScript.c_str());
    if(ret != 0) {
        CCLOG("failed to load story, return code: %d", ret);
    }
    return ret == 0;
}
Exemplo n.º 2
0
CCStoryLayer::~CCStoryLayer() {
    CC_SAFE_RELEASE(m_player);
    CC_SAFE_RELEASE(m_doneFunc);
    unloadImageFiles();
    gStoryCommandSet.removeAllObjects();
    if(L) {
        lua_close(L);
        L = NULL;
    }
}
Exemplo n.º 3
0
bool CCStoryLayer::preloadStoryString(const string& storyScript) {
    // clear old
    gStoryCommandSet.removeAllObjects();
    unloadImageFiles();
    
    // load resources needed
    CCByteBuffer bb(storyScript.c_str(), storyScript.length(), storyScript.length());
    string line;
    bb.readLine(line);
    while(!line.empty()) {
        if(line.find("--$<") == 0) {
            string resCmd = line.substr(4);
            int comma = (int)resCmd.find(",");
            string type = resCmd.substr(0, comma);
            if(type == "atlas") {
                int secondComma = (int)resCmd.find(",", comma + 1);
                string plist = resCmd.substr(comma + 1, secondComma - comma - 1);
                string atlas = resCmd.substr(secondComma + 1);
                CCResourceLoader::loadZwoptex(plist, atlas, m_decFunc);
            } else if(type == "arm") {
                CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(resCmd.substr(comma + 1).c_str());
            } else if(type == "image") {
                string filename = resCmd.substr(comma + 1);
                m_loadedImageFiles.push_back(filename);
                CCResourceLoader::loadImage(filename, m_decFunc);
            }
        } else {
            break;
        }
        
        bb.readLine(line);
    }
    
    // do script
    int ret = luaL_dostring(L, storyScript.c_str());
    if(ret != 0) {
        CCLOG("failed to load story, return code: %d", ret);
    }
    return ret == 0;
}