2014-05-19 17:20:50 -04:00
|
|
|
CocoModel = require './CocoModel'
|
2014-06-16 08:27:16 -04:00
|
|
|
utils = require '../lib/utils'
|
2014-05-19 17:20:50 -04:00
|
|
|
|
|
|
|
module.exports = class Achievement extends CocoModel
|
|
|
|
@className: 'Achievement'
|
|
|
|
@schema: require 'schemas/models/achievement'
|
2014-05-24 14:45:53 -04:00
|
|
|
urlRoot: '/db/achievement'
|
|
|
|
|
2014-05-26 12:21:56 -04:00
|
|
|
isRepeatable: ->
|
2014-07-30 16:23:43 -04:00
|
|
|
@get('proportionalTo')?
|
2014-06-03 06:40:47 -04:00
|
|
|
|
|
|
|
getExpFunction: ->
|
2014-08-29 15:28:45 -04:00
|
|
|
func = @get('function', true)
|
|
|
|
return utils.functionCreators[func.kind](func.parameters) if func.kind of utils.functionCreators
|
2014-07-28 09:14:11 -04:00
|
|
|
|
|
|
|
@styleMapping:
|
|
|
|
1: 'achievement-wood'
|
|
|
|
2: 'achievement-stone'
|
|
|
|
3: 'achievement-silver'
|
|
|
|
4: 'achievement-gold'
|
|
|
|
5: 'achievement-diamond'
|
|
|
|
|
2014-09-02 19:48:16 -04:00
|
|
|
getStyle: -> Achievement.styleMapping[@get 'difficulty', true]
|
2014-07-28 09:14:11 -04:00
|
|
|
|
2014-08-04 09:26:21 -04:00
|
|
|
@defaultImageURL: '/images/achievements/default.png'
|
|
|
|
|
2014-07-28 09:14:11 -04:00
|
|
|
getImageURL: ->
|
2014-08-04 09:26:21 -04:00
|
|
|
if @get 'icon' then '/file/' + @get('icon') else Achievement.defaultImageURL
|
|
|
|
|
|
|
|
hasImage: -> @get('icon')?
|
|
|
|
|
|
|
|
# TODO Could cache the default icon separately
|
|
|
|
cacheLockedImage: ->
|
|
|
|
return @lockedImageURL if @lockedImageURL
|
|
|
|
canvas = document.createElement 'canvas'
|
|
|
|
image = new Image
|
|
|
|
image.src = @getImageURL()
|
|
|
|
defer = $.Deferred()
|
|
|
|
image.onload = =>
|
|
|
|
canvas.width = image.width
|
|
|
|
canvas.height = image.height
|
|
|
|
context = canvas.getContext '2d'
|
|
|
|
context.drawImage image, 0, 0
|
|
|
|
imgData = context.getImageData 0, 0, canvas.width, canvas.height
|
|
|
|
imgData = utils.grayscale imgData
|
|
|
|
context.putImageData imgData, 0, 0
|
|
|
|
@lockedImageURL = canvas.toDataURL()
|
|
|
|
defer.resolve @lockedImageURL
|
|
|
|
defer
|
|
|
|
|
|
|
|
getLockedImageURL: -> @lockedImageURL
|
2014-08-12 11:59:33 -04:00
|
|
|
|
|
|
|
i18nName: -> utils.i18n @attributes, 'name'
|
|
|
|
|
|
|
|
i18nDescription: -> utils.i18n @attributes, 'description'
|