Initially working on using team colors, but it's not working yet.

This commit is contained in:
Scott Erickson 2014-01-14 13:16:30 -08:00
parent f4a2209d6f
commit bf4011044f
10 changed files with 104 additions and 67 deletions

View file

@ -4,6 +4,7 @@ AudioPlayer = require 'lib/AudioPlayer'
LevelSession = require 'models/LevelSession'
ThangType = require 'models/ThangType'
app = require 'application'
World = require 'lib/world/world'
# This is an initial stab at unifying loading and setup into a single place which can
# monitor everything and keep a LoadingScreen visible overall progress.
@ -70,17 +71,17 @@ module.exports = class LevelLoader extends CocoClass
onSupermodelLoadedOne: (e) =>
@notifyProgress()
if e.model.type() is 'ThangType'
thangType = e.model
options = {async: true}
if thangType.get('name') is 'Wizard'
options.colorConfig = me.get('wizard')?.colorConfig or {}
building = thangType.buildSpriteSheet options
if building
@spriteSheetsToBuild += 1
thangType.on 'build-complete', =>
@spriteSheetsBuilt += 1
@notifyProgress()
# if e.model.type() is 'ThangType'
# thangType = e.model
# options = {async: true}
# if thangType.get('name') is 'Wizard'
# options.colorConfig = me.get('wizard')?.colorConfig or {}
# building = thangType.buildSpriteSheet options
# if building
# @spriteSheetsToBuild += 1
# thangType.on 'build-complete', =>
# @spriteSheetsBuilt += 1
# @notifyProgress()
onSupermodelLoadedAll: =>
@trigger 'loaded-supermodel'
@ -111,7 +112,50 @@ module.exports = class LevelLoader extends CocoClass
tempSession = new LevelSession _id: @session.id
tempSession.save(patch, {patch: true})
@sessionDenormalized = true
# World init
initWorld: ->
return if @world
@world = new World @level.get('name')
serializedLevel = @level.serialize(@supermodel)
@world.loadFromLevel serializedLevel, false
# @setTeam @world.teamForPlayer 1 # We don't know which player we are; this will go away--temp TODO
@buildSpriteSheets()
buildSpriteSheets: ->
thangTypes = {}
thangTypes[tt.get('name')] = tt for tt in @supermodel.getModels(ThangType)
colorConfigs = @world.getTeamColors()
thangsProduced = {}
baseOptions = {resolutionFactor: 4, async: true}
for thang in @world.thangs
continue unless thang.spriteName
thangType = thangTypes[thang.spriteName]
options = thang.getSpriteOptions(colorConfigs)
options.async = true
thangsProduced[thang.spriteName] = true
@buildSpriteSheet(thangType, options)
for thangName, thangType of thangTypes
continue if thangsProduced[thangName]
thangType.spriteOptions = {resolutionFactor: 4, async: true}
@buildSpriteSheet(thangType, thangType.spriteOptions)
buildSpriteSheet: (thangType, options) ->
if thangType.get('name') is 'Wizard'
options.colorConfig = me.get('wizard')?.colorConfig or {}
building = thangType.buildSpriteSheet options
return unless building
console.log 'Building:', thangType.get('name'), options
@spriteSheetsToBuild += 1
thangType.on 'build-complete', =>
@spriteSheetsBuilt += 1
@notifyProgress()
# Initial Sound Loading
loadAudio: ->
@ -159,7 +203,9 @@ module.exports = class LevelLoader extends CocoClass
notifyProgress: ->
Backbone.Mediator.publish 'level-loader:progress-changed', progress: @progress()
@trigger 'ready-to-init-world' if @allDone()
@initWorld() if @allDone()
# @trigger 'ready-to-init-world' if @allDone()
@trigger 'loaded-all' if @progress() is 1
destroy: ->
@supermodel.off 'loaded-one', @onSupermodelLoadedOne

View file

@ -72,10 +72,10 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
toString: -> "<CocoSprite: #{@thang?.id}>"
spriteSheetKey: ->
"#{@thangType.get('name')} - #{@options.resolutionFactor}"
buildSpriteSheet: -> @thangType.getSpriteSheet @options
buildSpriteSheet: ->
options = @thang?.getSpriteOptions() or {}
options.async = false
@thangType.getSpriteSheet options
buildFromSpriteSheet: (spriteSheet) ->
if spriteSheet

View file

@ -115,10 +115,9 @@ module.exports = class Mark extends CocoClass
buildSprite: ->
#console.log "building", @name, "with thangtype", @thangType
options = resolutionFactor: 4
CocoSprite = require './CocoSprite'
markSprite = new CocoSprite @thangType, options
markSprite.queueAction "idle"
markSprite = new CocoSprite @thangType, @thangType.spriteOptions
markSprite.queueAction 'idle'
@mark = markSprite.displayObject
update: (pos=null) ->

View file

@ -87,7 +87,7 @@ module.exports = class SpriteBoss extends CocoClass
@selectionMark = new Mark name: 'selection', camera: @camera, layer: @spriteLayers["Ground"], thangType: @thangTypeFor("Selection")
createSpriteOptions: (options) ->
_.extend options, camera: @camera, resolutionFactor: 4, groundLayer: @spriteLayers["Ground"], textLayer: @surfaceTextLayer, floatingLayer: @spriteLayers["Floating"], markThangTypes: @markThangTypes(), spriteSheetCache: @spriteSheetCache, showInvisible: @options.showInvisible
_.extend options, camera: @camera, resolutionFactor: 4, groundLayer: @spriteLayers["Ground"], textLayer: @surfaceTextLayer, floatingLayer: @spriteLayers["Floating"], markThangTypes: @markThangTypes(), spriteSheetCache: @spriteSheetCache, showInvisible: @options.showInvisible, world: @world
createIndieSprites: (indieSprites, withWizards) ->
unless @indieSprites

View file

@ -156,4 +156,13 @@ module.exports = class Thang
for prop, val of o.finalState
# TODO: take some (but not all) of deserialize logic from ThangState to handle other types
t[prop] = val
t
t
getSpriteOptions: ->
colorConfigs = @world?.getTeamColors() or {}
options = {}
if @team and colorConfigs[@team]
options.colorConfig = {team: colorConfigs[@team]}
if @spriteName is 'Tharin'
console.log 'THARIN made options', options, colorConfigs, @world
options

View file

@ -457,3 +457,9 @@ module.exports = class World
lastAction = action
@actionsForThangCache[cacheKey] = actions
return actions
getTeamColors: ->
teamConfigs = @teamConfigs or {}
colorConfigs = {}
colorConfigs[teamName] = config.color for teamName, config of teamConfigs
colorConfigs

View file

@ -4,10 +4,11 @@ SpriteBuilder = require 'lib/sprites/SpriteBuilder'
module.exports = class ThangType extends CocoModel
@className: "ThangType"
urlRoot: "/db/thang.type"
building: 0
building: {}
initialize: ->
super()
@building = {}
@setDefaults()
@on 'sync', @setDefaults
@spriteSheets = {}
@ -47,15 +48,18 @@ module.exports = class ThangType extends CocoModel
options
buildSpriteSheet: (options) ->
@options = @fillOptions options
key = @spriteSheetKey(@options)
return if @building[key]
@initBuild(options)
# @options.portraitOnly = true
@addGeneralFrames() unless @options.portraitOnly
@addPortrait()
@finishBuild()
@building[key] = true
result = @finishBuild()
return result
initBuild: (options) ->
@buildActions() if not @actions
@options = @fillOptions options
@vectorParser = new SpriteBuilder(@, options)
@builder = new createjs.SpriteSheetBuilder()
@builder.padding = 2
@ -132,7 +136,7 @@ module.exports = class ThangType extends CocoModel
@builder.on 'complete', @onBuildSpriteSheetComplete, @, true, key
return true
console.warn 'Building', @get('name'), 'and blocking the main thread. LevelLoader should have it built asynchronously instead.'
console.warn 'Building', @get('name'), 'and blocking the main thread.', @options, @spriteSheets
spriteSheet = @builder.build()
@spriteSheets[key] = spriteSheet
spriteSheet

View file

@ -1,41 +1,12 @@
@import "bootstrap/variables"
#editor-level-view
.images
margin: 30px 0
text-align: center
div
float: left
width: 25%
padding: 10px 40px
box-sizing: border-box
img
width: 100%
#image-modal
.modal-body
max-height: 100%
height: 80%
width: 80%
margin-left: -40%
img
display: block
margin: 0 auto
max-height: 80%
#after-images
clear: both
ul#prereqs
margin: 20px 40px
.editor-column
width: 33%
box-sizing: border-box
padding-right: 20px
float: left
h3
text-decoration: underline
margin-bottom: 2px
#editor-links .btn
margin-right: 20px
margin-bottom: 30px
//.screencast-wrapper
// text-align: center
// background: $gray
// object
// display: inline-block

View file

@ -20,7 +20,7 @@ module.exports = class ThangAvatarView extends View
thangs = @supermodel.getModels(ThangType)
thangs = (t for t in thangs when t.get('name') is @thang.spriteName)
thang = thangs[0]
context.avatarURL = thang.getPortraitSource()
context.avatarURL = thang.getPortraitSource(@thang.spriteOptions)
context.includeName = @includeName
context

View file

@ -74,6 +74,7 @@ module.exports = class PlayLevelView extends View
sessionID = @getQueryVariable "session"
@levelLoader = new LevelLoader(@levelID, @supermodel, sessionID)
@levelLoader.once 'ready-to-init-world', @onReadyToInitWorld
@levelLoader.once 'loaded-all', @onLevelLoaderLoaded
$(window).on('resize', @onWindowResize)
@supermodel.once 'error', =>
@ -96,11 +97,12 @@ module.exports = class PlayLevelView extends View
@loadingScreen.show()
super()
onReadyToInitWorld: =>
onLevelLoaderLoaded: =>
@session = @levelLoader.session
@level = @levelLoader.level
@world = @levelLoader.world
@loadingScreen.destroy()
@initWorld()
# @initWorld()
@initSurface()
@initGod()
@initGoalManager()