26#include "../../testResource.h"
32const char*
sceneManifests[] = {
"Manifests/AMTestScene1/project.manifest",
"Manifests/AMTestScene2/project.manifest",
"Manifests/AMTestScene3/project.manifest"};
33const char*
storagePaths[] = {
"CppTests/AssetsManagerExTest/scene1/",
"CppTests/AssetsManagerExTest/scene2/",
"CppTests/AssetsManagerExTest/scene3"};
34const char*
backgroundPaths[] = {
"Images/assetMgrBackground1.jpg",
"Images/assetMgrBackground2.png",
"Images/assetMgrBackground3.png"};
36AssetsManagerExTests::AssetsManagerExTests()
46 if (scene && scene->init())
60: _testIndex(testIndex)
62, _downloadMenu(nullptr)
72 if (!TestCase::init())
77 auto downloadLabel = Label::createWithTTF(
"Start Download",
"fonts/arial.ttf", 16);
87 auto sprite = Sprite::create(
"Images/Icon.png");
91 TTFConfig config(
"fonts/tahoma.ttf", 30);
92 _progress = Label::createWithTTF(config,
"0%", TextHAlignment::CENTER);
97 CCLOG(
"Storage path for this test : %s", storagePath.c_str());
98 _am = AssetsManagerEx::create(manifestPath, storagePath);
110 addChild(backgroundSprite, 1);
119 if (!
_am->getLocalManifest()->isLoaded())
121 CCLOG(
"Fail to update assets, step skipped.");
126 _amListener = cocos2d::extension::EventListenerAssetsManagerEx::create(
_am, [
this](EventAssetsManagerEx* event){
127 static int failCount = 0;
128 switch (event->getEventCode())
130 case EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST:
132 CCLOG(
"No local manifest file found, skip assets update.");
136 case EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION:
138 std::string assetId = event->getAssetId();
139 float percent = event->getPercent();
141 if (assetId == AssetsManagerEx::VERSION_ID)
143 str = StringUtils::format(
"Version file: %.2f", percent) +
"%";
145 else if (assetId == AssetsManagerEx::MANIFEST_ID)
147 str = StringUtils::format(
"Manifest file: %.2f", percent) +
"%";
151 str = StringUtils::format(
"%.2f", percent) +
"%";
152 CCLOG(
"%.2f Percent", percent);
158 case EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST:
159 case EventAssetsManagerEx::EventCode::ERROR_PARSE_MANIFEST:
161 CCLOG(
"Fail to download manifest file, update skipped.");
165 case EventAssetsManagerEx::EventCode::ALREADY_UP_TO_DATE:
166 case EventAssetsManagerEx::EventCode::UPDATE_FINISHED:
168 CCLOG(
"Update finished. %s", event->getMessage().c_str());
172 case EventAssetsManagerEx::EventCode::UPDATE_FAILED:
174 CCLOG(
"Update failed. %s", event->getMessage().c_str());
179 _am->downloadFailedAssets();
183 CCLOG(
"Reach maximum fail count, exit update process");
189 case EventAssetsManagerEx::EventCode::ERROR_UPDATING:
191 CCLOG(
"Asset %s : %s", event->getAssetId().c_str(), event->getMessage().c_str());
194 case EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS:
196 CCLOG(
"%s", event->getMessage().c_str());
203 Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_amListener, 1);
211 _eventDispatcher->removeEventListener(
_amListener);
218 return "AssetsManagerExTest";
const char * storagePaths[]
const char * backgroundPaths[]
const char * sceneManifests[]
virtual std::string title() const override
virtual bool init() override
cocos2d::Label * _progress
cocos2d::extension::EventListenerAssetsManagerEx * _amListener
void startDownloadCallback(cocos2d::Ref *sender)
cocos2d::extension::AssetsManagerEx * _am
cocos2d::Menu * _downloadMenu
static AssetsManagerExLoaderScene * create(int testIndex)
cocos2d::Layer * _loadLayer
AssetsManagerExLoaderScene(int testIndex)
virtual void onExit() override
static cocos2d::Vec2 center()
static cocos2d::Vec2 bottom()