From f8d4e42c6789abd386dd4771927df974c330f456 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Mon, 18 Aug 2014 15:25:22 -0700 Subject: [PATCH] Set up thang types to now have a raster portrait icon if we want to give them custom ones not based on vector artwork. --- app/models/ThangType.coffee | 5 ++++- app/schemas/models/thang_type.coffee | 1 + app/templates/editor/level/add_thangs.jade | 5 ++--- app/templates/editor/thang/table.jade | 15 +++++++-------- .../editor/level/thangs/AddThangsView.coffee | 14 +++++++------- .../editor/level/thangs/ThangsTabView.coffee | 2 +- app/views/editor/thang/ThangTypeSearchView.coffee | 1 + server/levels/thangs/thang_type_handler.coffee | 1 + 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/models/ThangType.coffee b/app/models/ThangType.coffee index d35f4c0b8..24e191d29 100644 --- a/app/models/ThangType.coffee +++ b/app/models/ThangType.coffee @@ -264,7 +264,10 @@ module.exports = class ThangType extends CocoModel @wizardType.fetch() @wizardType - getPortraitURL: -> "/file/db/thang.type/#{@get('original')}/portrait.png" + getPortraitURL: -> + if iconURL = @get('rasterIcon') + return "/file/#{iconURL}" + "/file/db/thang.type/#{@get('original')}/portrait.png" # Item functions diff --git a/app/schemas/models/thang_type.coffee b/app/schemas/models/thang_type.coffee index d93b0e625..177c81f22 100644 --- a/app/schemas/models/thang_type.coffee +++ b/app/schemas/models/thang_type.coffee @@ -124,6 +124,7 @@ _.extend ThangTypeSchema.properties, type: 'number' positions: PositionsSchema raster: {type: 'string', format: 'image-file', title: 'Raster Image'} + rasterIcon: { type: 'string', format: 'image-file', title: 'Raster Image Icon' } colorGroups: c.object title: 'Color Groups' additionalProperties: diff --git a/app/templates/editor/level/add_thangs.jade b/app/templates/editor/level/add_thangs.jade index cec7666f9..092547d66 100644 --- a/app/templates/editor/level/add_thangs.jade +++ b/app/templates/editor/level/add_thangs.jade @@ -5,7 +5,6 @@ div.editor-nano-container.nano for group in groups h4= group.name for thangType in group.thangs - div.add-thang-palette-icon(data-thang-type=thangType.name) - - path = '/file/db/thang.type/'+thangType.original+'/portrait.png' - img(title="Add " + thangType.name, src=path, alt="") + div.add-thang-palette-icon(data-thang-type=thangType.get('name')) + img(title="Add " + thangType.get('name'), src=thangType.getPortraitURL(), alt="") div.clearfix \ No newline at end of file diff --git a/app/templates/editor/thang/table.jade b/app/templates/editor/thang/table.jade index 26a9f6583..6036bacfd 100755 --- a/app/templates/editor/thang/table.jade +++ b/app/templates/editor/thang/table.jade @@ -12,14 +12,13 @@ table.table th(data-i18n="general.description") Description th(data-i18n="general.version") Version - for data in documents - - data = data.attributes; + for thang in documents tr td - - path = '/file/db/thang.type/'+data.original+'/portrait.png' - img(title="Add " + data.name, src=path, alt="").portrait + img(title="Add " + thang.get('name'), src=thang.getPortraitURL(), alt="").portrait td - a(href="/editor/thang/#{data.slug || data._id}") - | #{data.name} - td.body-row #{data.description} - td #{data.version.major}.#{data.version.minor} \ No newline at end of file + a(href="/editor/thang/#{thang.get('slug') || thang.id}") + | #{thang.get('name')} + td.body-row #{thang.get('description')} + - var version = thang.get('version') + td #{version.major}.#{version.minor} \ No newline at end of file diff --git a/app/views/editor/level/thangs/AddThangsView.coffee b/app/views/editor/level/thangs/AddThangsView.coffee index e41f42967..3bbfae0f9 100644 --- a/app/views/editor/level/thangs/AddThangsView.coffee +++ b/app/views/editor/level/thangs/AddThangsView.coffee @@ -4,7 +4,7 @@ ThangType = require 'models/ThangType' CocoCollection = require 'collections/CocoCollection' class ThangTypeSearchCollection extends CocoCollection - url: '/db/thang.type?project=true' + url: '/db/thang.type?project=original,name,version,description,slug,kind,rasterIcon' model: ThangType addTerm: (term) -> @@ -33,18 +33,18 @@ module.exports = class AddThangsView extends CocoView else models = @supermodel.getModels(ThangType) - thangTypes = (thangType.attributes for thangType in models) - thangTypes = _.uniq thangTypes, false, 'original' - thangTypes = _.reject thangTypes, kind: 'Mark' + thangTypes = _.uniq models, false, (thangType) -> thangType.get('original') + thangTypes = _.reject thangTypes, (thangType) -> thangType.get('kind') is 'Mark' groupMap = {} for thangType in thangTypes - groupMap[thangType.kind] ?= [] - groupMap[thangType.kind].push thangType + kind = thangType.get('kind') + groupMap[kind] ?= [] + groupMap[kind].push thangType groups = [] for groupName in Object.keys(groupMap).sort() someThangTypes = groupMap[groupName] - someThangTypes = _.sortBy someThangTypes, 'name' + someThangTypes = _.sortBy someThangTypes, (thangType) -> thangType.get('name') group = name: groupName thangs: someThangTypes diff --git a/app/views/editor/level/thangs/ThangsTabView.coffee b/app/views/editor/level/thangs/ThangsTabView.coffee index 0c2b030d8..748e1a575 100644 --- a/app/views/editor/level/thangs/ThangsTabView.coffee +++ b/app/views/editor/level/thangs/ThangsTabView.coffee @@ -119,7 +119,7 @@ module.exports = class ThangsTabView extends CocoView $('#thangs-list').bind 'mousewheel', @preventBodyScrollingInThangList @$el.find('#extant-thangs-filter button:first').button('toggle') $(window).resize @onWindowResize - @addThangsView = @insertSubView new AddThangsView world: @world, supermodel: @supermodel + @addThangsView = @insertSubView new AddThangsView world: @world @buildInterface() # refactor to not have this trigger when this view re-renders? if @thangsTreema.data.length @$el.find('#canvas-overlay').css('display', 'none') diff --git a/app/views/editor/thang/ThangTypeSearchView.coffee b/app/views/editor/thang/ThangTypeSearchView.coffee index c3b79b2bc..52807f331 100644 --- a/app/views/editor/thang/ThangTypeSearchView.coffee +++ b/app/views/editor/thang/ThangTypeSearchView.coffee @@ -6,6 +6,7 @@ module.exports = class ThangTypeSearchView extends SearchView model: require 'models/ThangType' modelURL: '/db/thang.type' tableTemplate: require 'templates/editor/thang/table' + projection: ['original', 'name', 'version', 'description', 'slug', 'kind', 'rasterIcon'] getRenderData: -> context = super() diff --git a/server/levels/thangs/thang_type_handler.coffee b/server/levels/thangs/thang_type_handler.coffee index fe775a358..fe6db8587 100644 --- a/server/levels/thangs/thang_type_handler.coffee +++ b/server/levels/thangs/thang_type_handler.coffee @@ -21,6 +21,7 @@ ThangTypeHandler = class ThangTypeHandler extends Handler 'colorGroups' 'kind' 'raster' + 'rasterIcon' ] hasAccess: (req) ->