Adds randomiseFloor and randomiseBorder functions

This commit is contained in:
Jayant Jain 2014-06-28 10:20:55 +05:30
parent 38bed0ee93
commit b401b04893
2 changed files with 88 additions and 8 deletions

View file

@ -6,7 +6,7 @@ block modal-header-content
block modal-body-content
div#normal-view
a(href="#")
div.choose-option(data-preset-type="grassy", data-preset-size="small")
div.choose-option(data-preset-type="dungeon", data-preset-size="small")
div.preset-size.name-label
span(data-i18n="ladder.small") Small
div.preset-name

View file

@ -2,6 +2,34 @@ ModalView = require 'views/kinds/ModalView'
template = require 'templates/modal/terrain_randomise'
CocoModel = require 'models/CocoModel'
presets = {
'dungeon': {
'type':'dungeon'
'borders':['Dungeon Wall']
'floors':['Dungeon Floor']
'decorations':[]
}
}
sizes = {
'small': {
'x':80
'y':68
}
'large': {
'x':160
'y':136
}
'floorSize': {
'x':20
'y':20
}
'borderSize': {
'x':4
'y':4
}
}
module.exports = class TerrainRandomiseModal extends ModalView
id: 'terrain-randomise-modal'
template: template
@ -18,16 +46,68 @@ module.exports = class TerrainRandomiseModal extends ModalView
onRandomise: (e) ->
@thangs = []
@thangs.push {
'id':'Grass01'
'pos':{
'x':20
'y':20
}
}
target = $(e.target)
presetType = target.attr 'data-preset-type'
presetSize = target.attr 'data-preset-size'
@randomiseThangs presetType, presetSize
Backbone.Mediator.publish('randomise:terrain-generated',
'thangs': @thangs
)
randomiseThangs: (presetName, presetSize) ->
preset = presets[presetName]
presetSize = sizes[presetSize]
@thangs = []
@randomiseFloor preset, presetSize
@randomiseBorder preset, presetSize
randomiseFloor: (preset, presetSize) ->
for i in _.range(0, presetSize.x, sizes.floorSize.x)
for j in _.range(0, presetSize.y, sizes.floorSize.y)
@thangs.push {
'id': @getRandomThang(preset.floors)
'pos': {
'x': i
'y': j
}
}
randomiseBorder: (preset, presetSize) ->
for i in _.range(0-sizes.floorSize.x/2+sizes.borderSize.x, presetSize.x-sizes.floorSize.x/2, sizes.borderSize.x)
@thangs.push {
'id': @getRandomThang(preset.borders)
'pos': {
'x': i
'y': 0-sizes.floorSize.x/2
}
}
@thangs.push {
'id': @getRandomThang(preset.borders)
'pos': {
'x': i
'y': presetSize.y - sizes.borderSize.y
}
}
for i in _.range(0-sizes.floorSize.y/2, presetSize.y-sizes.borderSize.y, sizes.borderSize.y)
@thangs.push {
'id': @getRandomThang(preset.borders)
'pos': {
'x': 0-sizes.floorSize.x/2+sizes.borderSize.x
'y': i
}
}
@thangs.push {
'id': @getRandomThang(preset.borders)
'pos': {
'x': presetSize.x - sizes.borderSize.x - sizes.floorSize.x/2
'y': i
}
}
getRandomThang: (thangList) ->
return thangList[_.random(0, thangList.length-1)]
getRenderData: ->
c = super()