MCPcopy Create free account
hub / github.com/codecombat/codecombat / cacheLockedImage

Method cacheLockedImage

app/models/Achievement.js:56–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54
55 // TODO Could cache the default icon separately
56 cacheLockedImage () {
57 if (this.lockedImageURL) { return this.lockedImageURL }
58 const canvas = document.createElement('canvas')
59 const image = new Image()
60 image.src = this.getImageURL()
61 const defer = $.Deferred()
62 image.onload = () => {
63 canvas.width = image.width
64 canvas.height = image.height
65 const context = canvas.getContext('2d')
66 context.drawImage(image, 0, 0)
67 let imgData = context.getImageData(0, 0, canvas.width, canvas.height)
68 imgData = utils.grayscale(imgData)
69 context.putImageData(imgData, 0, 0)
70 this.lockedImageURL = canvas.toDataURL()
71 return defer.resolve(this.lockedImageURL)
72 }
73 return defer
74 }
75
76 getLockedImageURL () { return this.lockedImageURL }
77

Callers

nothing calls this directly

Calls 1

getImageURLMethod · 0.95

Tested by

no test coverage detected