change to asset read
This commit is contained in:
@@ -10,7 +10,7 @@ private:
|
||||
QString result;
|
||||
|
||||
public:
|
||||
std::function<void()> resultCallback;
|
||||
std::function<void()> resultCallback = [] {};
|
||||
std::function<void()> exceptionCallback;
|
||||
std::function<void()> finishCallback;
|
||||
|
||||
|
@@ -12,8 +12,12 @@ std::shared_ptr<DoricAsyncResult> DoricAssetJSLoader::request(QString source) {
|
||||
QString protocol = "assets://";
|
||||
QString assetPath = source.mid(protocol.length());
|
||||
|
||||
QString script = DoricUtils::readAssetFile("/" + assetPath);
|
||||
|
||||
std::shared_ptr<DoricAsyncResult> asyncResult =
|
||||
std::make_shared<DoricAsyncResult>();
|
||||
|
||||
asyncResult->setResult(script);
|
||||
|
||||
return asyncResult;
|
||||
}
|
||||
|
@@ -24,6 +24,19 @@ public:
|
||||
return content;
|
||||
}
|
||||
|
||||
static QString readAssetFile(QString resourcePath) {
|
||||
QResource resource(":" + resourcePath);
|
||||
QFile *file = new QFile(resource.fileName());
|
||||
file->open(QFile::ReadOnly | QFile::Text);
|
||||
QTextStream in(file);
|
||||
in.setCodec("UTF-8");
|
||||
QString content = in.readAll();
|
||||
file->close();
|
||||
delete file;
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
template <typename Base, typename T>
|
||||
static inline bool instanceof (const T *) {
|
||||
return std::is_base_of<Base, T>::value;
|
||||
|
Reference in New Issue
Block a user