-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create the image manager, implement the remote image load.
- Loading branch information
1 parent
4257670
commit 94203be
Showing
7 changed files
with
67 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cloudfunction/login/node_modules | ||
cloudfunction/test | ||
cloudfunction/uploadScore | ||
cloudfunction/upload/node_modules |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = wx.getFileSystemManager() | ||
|
||
export default class ImageManager { | ||
constructor() { | ||
this.introPage = new Image() | ||
this.imageGet(this.introPage, 'cloud://classification-test-d20ada.636c-classification-test-d20ada/intro.jpg', 'intro.jpg') | ||
this.imageGet('cloud://classification-test-d20ada.636c-classification-test-d20ada/home_page.png', 'home_page.png') | ||
} | ||
|
||
/** | ||
* get an image from the server and save it. | ||
* The download will start right after the name start, | ||
* but the game won't be blocked and image objects will be empty initially. | ||
* If the image has already been stored, it will be obtained directly. | ||
* @param {Image} img: the image object. | ||
* @param {string} fileID: the ID for the picture. | ||
* @param {string} path: the location to store the image. | ||
*/ | ||
imageGet(img, fileID, path) { | ||
fs.getFileInfo({ | ||
filePath: `${wx.env.USER_DATA_PATH}/${path}`, | ||
success: res => { | ||
console.log('success') | ||
img.src = `${wx.env.USER_DATA_PATH}/${path}` | ||
}, | ||
fail: () => { | ||
console.log('reach') | ||
wx.cloud.downloadFile({ | ||
fileID: fileID, | ||
success: res => { | ||
fs.saveFile({ | ||
tempFilePath: res.tempFilePath, | ||
filePath: `${wx.env.USER_DATA_PATH}/${path}`, | ||
success: res => { | ||
console.log(res.savedFilePath) | ||
img.src = res.savedFilePath | ||
}, | ||
fail: err => { | ||
console.log('image load failed') | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters