mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-24 11:50:58 -04:00
Fixed some click/add behavior in level editor. Fixed level editor canvas resizing. Fixed some dungeon terrain generation issues. Certain Thangs can be placed on top of other Thangs.
This commit is contained in:
parent
6085b70dfc
commit
b7d9e7a095
3 changed files with 43 additions and 36 deletions
app
|
@ -167,6 +167,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@loadThangsRequiredFromComponentList thangType.get('components')
|
||||
|
||||
loadThangsRequiredFromComponentList: (components) ->
|
||||
return unless components
|
||||
requiredThangTypes = []
|
||||
for component in components when component.config
|
||||
if component.original is LevelComponent.EquipsID
|
||||
|
|
|
@ -9,11 +9,11 @@ clusters = {
|
|||
}
|
||||
'trees': {
|
||||
'thangs': ['Tree 1', 'Tree 2', 'Tree 3', 'Tree 4']
|
||||
'margin': 0
|
||||
'margin': 0.5
|
||||
}
|
||||
'shrubs': {
|
||||
'thangs': ['Shrub 1', 'Shrub 2', 'Shrub 3']
|
||||
'margin': 0
|
||||
'margin': 0.5
|
||||
}
|
||||
'houses': {
|
||||
'thangs': ['House 1', 'House 2', 'House 3', 'House 4']
|
||||
|
@ -280,7 +280,7 @@ module.exports = class TerrainRandomizeModal extends ModalView
|
|||
'id': @getRandomThang(clusters['torch'].thangs)
|
||||
'pos': {
|
||||
'x': i + preset.borderSize
|
||||
'y': presetSize.y - preset.borderSize
|
||||
'y': presetSize.y - preset.borderSize / 2
|
||||
}
|
||||
'margin': clusters['torch'].margin
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ module.exports = class TerrainRandomizeModal extends ModalView
|
|||
'id': @getRandomThang(clusters['chains'].thangs)
|
||||
'pos': {
|
||||
'x': i + preset.borderSize
|
||||
'y': presetSize.y - preset.borderSize
|
||||
'y': presetSize.y - preset.borderSize / 2
|
||||
}
|
||||
'margin': clusters['chains'].margin
|
||||
}
|
||||
|
@ -346,53 +346,57 @@ module.exports = class TerrainRandomizeModal extends ModalView
|
|||
continue
|
||||
|
||||
buildRoom: (preset, presetSize, room) ->
|
||||
grid = preset.borderSize
|
||||
while true
|
||||
rect = {
|
||||
'width':presetSize.sizeFactor * (room.width[0] + preset.borderSize * _.random(0, (room.width[1] - room.width[0])/preset.borderSize))
|
||||
'height':presetSize.sizeFactor * (room.height[0] + preset.borderSize * _.random(0, (room.height[1] - room.height[0])/preset.borderSize))
|
||||
'width':presetSize.sizeFactor * (room.width[0] + grid * _.random(0, (room.width[1] - room.width[0])/grid))
|
||||
'height':presetSize.sizeFactor * (room.height[0] + grid * _.random(0, (room.height[1] - room.height[0])/grid))
|
||||
}
|
||||
# This logic isn't quite right--it makes the rooms bigger than intended--but it's snapping correctly, which is fine for now.
|
||||
rect.width = Math.round((rect.width - grid) / (2 * grid)) * 2 * grid + grid
|
||||
rect.height = Math.round((rect.height - grid) / (2 * grid)) * 2 * grid + grid
|
||||
roomThickness = _.random(room.thickness[0], room.thickness[1])
|
||||
rect.x = _.random(rect.width/2 + preset.borderSize * (roomThickness+1.5), presetSize.x - rect.width/2 - preset.borderSize * (roomThickness+1.5))
|
||||
rect.y = _.random(rect.height/2 + preset.borderSize * (roomThickness+2.5), presetSize.y - rect.height/2 - preset.borderSize * (roomThickness+3.5))
|
||||
rect.x = _.random(rect.width/2 + grid * (roomThickness+1.5), presetSize.x - rect.width/2 - grid * (roomThickness+1.5))
|
||||
rect.y = _.random(rect.height/2 + grid * (roomThickness+2.5), presetSize.y - rect.height/2 - grid * (roomThickness+3.5))
|
||||
# Snap room walls to the wall grid.
|
||||
rect.x = Math.round((rect.x - preset.borderSize / 2) / preset.borderSize) * preset.borderSize + preset.borderSize / 2
|
||||
rect.y = Math.round((rect.y - preset.borderSize / 2) / preset.borderSize) * preset.borderSize + preset.borderSize / 2
|
||||
rect.x = Math.round((rect.x - grid / 2) / grid) * grid
|
||||
rect.y = Math.round((rect.y - grid / 2) / grid) * grid
|
||||
break if @addRect {
|
||||
'x': rect.x
|
||||
'y': rect.y
|
||||
'width': rect.width + 2.5 * roomThickness * preset.borderSize
|
||||
'height': rect.height + 2.5 * roomThickness * preset.borderSize
|
||||
'width': rect.width + 2.5 * roomThickness * grid
|
||||
'height': rect.height + 2.5 * roomThickness * grid
|
||||
}
|
||||
|
||||
xRange = _.range(rect.x - rect.width/2 + preset.borderSize, rect.x + rect.width/2, preset.borderSize)
|
||||
xRange = _.range(rect.x - rect.width/2 + grid, rect.x + rect.width/2, grid)
|
||||
topDoor = _.random(1) > 0.5
|
||||
topDoorX = xRange[_.random(0, xRange.length-1)]
|
||||
bottomDoor = if not topDoor then true else _.random(1) > 0.5
|
||||
bottomDoorX = xRange[_.random(0, xRange.length-1)]
|
||||
|
||||
for t in _.range(0, roomThickness+1)
|
||||
for i in _.range(rect.x - rect.width/2 - (t-1) * preset.borderSize, rect.x + rect.width/2 + t * preset.borderSize, preset.borderSize)
|
||||
for i in _.range(rect.x - rect.width/2 - (t-1) * grid, rect.x + rect.width/2 + t * grid, grid)
|
||||
# Bottom wall
|
||||
thang = {
|
||||
'id': @getRandomThang(clusters[room.cluster].thangs)
|
||||
'pos': {
|
||||
'x': i
|
||||
'y': rect.y - rect.height/2 - t * preset.borderSize
|
||||
'y': rect.y - rect.height/2 - t * grid
|
||||
}
|
||||
'margin': clusters[room.cluster].margin
|
||||
}
|
||||
if i is bottomDoorX and bottomDoor
|
||||
thang.id = @getRandomThang(clusters['doors'].thangs)
|
||||
thang.pos.y -= preset.borderSize/3
|
||||
thang.pos.y -= grid/3
|
||||
@addThang thang unless i is bottomDoorX and t isnt roomThickness and bottomDoor
|
||||
|
||||
if t is roomThickness and i isnt rect.x - rect.width/2 - (t-1) * preset.borderSize and preset.type is 'dungeon'
|
||||
if ( i isnt bottomDoorX and i isnt bottomDoorX + preset.borderSize ) or not bottomDoor
|
||||
if t is roomThickness and i isnt rect.x - rect.width/2 - (t-1) * grid and preset.type is 'dungeon'
|
||||
if ( i isnt bottomDoorX and i isnt bottomDoorX + grid ) or not bottomDoor
|
||||
@addThang {
|
||||
'id': @getRandomThang(clusters['torch'].thangs)
|
||||
'pos': {
|
||||
'x': thang.pos.x - preset.borderSize / 2
|
||||
'y': thang.pos.y + preset.borderSize / 2
|
||||
'x': thang.pos.x - grid / 2
|
||||
'y': thang.pos.y + grid
|
||||
}
|
||||
'margin': clusters['torch'].margin
|
||||
}
|
||||
|
@ -402,22 +406,22 @@ module.exports = class TerrainRandomizeModal extends ModalView
|
|||
'id': @getRandomThang(clusters[room.cluster].thangs)
|
||||
'pos': {
|
||||
'x': i
|
||||
'y': rect.y + rect.height/2 + t * preset.borderSize
|
||||
'y': rect.y + rect.height/2 + t * grid
|
||||
}
|
||||
'margin': clusters[room.cluster].margin
|
||||
}
|
||||
if i is topDoorX and topDoor
|
||||
thang.id = @getRandomThang(clusters['doors'].thangs)
|
||||
thang.pos.y -= preset.borderSize
|
||||
thang.pos.y -= grid
|
||||
@addThang thang unless i is topDoorX and t isnt roomThickness and topDoor
|
||||
|
||||
for t in _.range(0, roomThickness)
|
||||
for i in _.range(rect.y - rect.height/2 - t * preset.borderSize, rect.y + rect.height/2 + (t+1) * preset.borderSize, preset.borderSize)
|
||||
for i in _.range(rect.y - rect.height/2 - t * grid, rect.y + rect.height/2 + (t+1) * grid, grid)
|
||||
# Left wall
|
||||
@addThang {
|
||||
'id': @getRandomThang(clusters[room.cluster].thangs)
|
||||
'pos': {
|
||||
'x': rect.x - rect.width/2 - t * preset.borderSize
|
||||
'x': rect.x - rect.width/2 - t * grid
|
||||
'y': i
|
||||
}
|
||||
'margin': clusters[room.cluster].margin
|
||||
|
@ -427,7 +431,7 @@ module.exports = class TerrainRandomizeModal extends ModalView
|
|||
@addThang {
|
||||
'id': @getRandomThang(clusters[room.cluster].thangs)
|
||||
'pos': {
|
||||
'x': rect.x + rect.width/2 + t * preset.borderSize
|
||||
'x': rect.x + rect.width/2 + t * grid
|
||||
'y': i
|
||||
}
|
||||
'margin': clusters[room.cluster].margin
|
||||
|
|
|
@ -20,6 +20,9 @@ componentOriginals =
|
|||
'existence.Exists': '524b4150ff92f1f4f8000024'
|
||||
'physics.Physical': '524b75ad7fc0f6d519000001'
|
||||
|
||||
# Let us place these on top of other Thangs
|
||||
overlappableThangTypeNames = ['Torch', 'Chains', 'Bird', 'Cloud 1', 'Cloud 2', 'Cloud 3', 'Waterfall', 'Obstacle']
|
||||
|
||||
class ThangTypeSearchCollection extends CocoCollection
|
||||
url: '/db/thang.type?project=original,name,version,slug,kind,components'
|
||||
model: ThangType
|
||||
|
@ -190,7 +193,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
super()
|
||||
|
||||
onViewSwitched: (e) ->
|
||||
@selectAddThang()
|
||||
@selectAddThang null, true
|
||||
@surface?.spriteBoss?.selectSprite null, null
|
||||
|
||||
onSpriteMouseDown: (e) ->
|
||||
|
@ -255,9 +258,12 @@ module.exports = class ThangsTabView extends CocoView
|
|||
if e.thang and (key.alt or key.meta)
|
||||
# We alt-clicked, so create a clone addThang
|
||||
@selectAddThangType e.thang.spriteName, @selectedExtantThang
|
||||
else if e.thang and not (@addThangSprite and @addThangType is 'Blood Torch Test') # TODO: figure out which Thangs can be placed on other Thangs
|
||||
else if @justAdded()
|
||||
console.log 'Skipping double insert due to extra selection event, since we just added', (new Date() - @lastAddTime), 'ms ago.'
|
||||
null
|
||||
else if e.thang and not (@addThangSprite and @addThangType.get('name') in overlappableThangTypeNames)
|
||||
# We clicked on a Thang (or its Treema), so select the Thang
|
||||
@selectAddThang null
|
||||
@selectAddThang null, true
|
||||
@selectedExtantThangClickTime = new Date()
|
||||
treemaThang = _.find @thangsTreema.childrenTreemas, (treema) => treema.data.id is @selectedExtantThang.id
|
||||
if treemaThang
|
||||
|
@ -270,16 +276,13 @@ module.exports = class ThangsTabView extends CocoView
|
|||
else if @addThangSprite
|
||||
# We clicked on the background when we had an add Thang selected, so add it
|
||||
@addThang @addThangType, @addThangSprite.thang.pos
|
||||
@lastAddTime = new Date()
|
||||
|
||||
# Commented out this bit so the extant thangs treema editor can select invisible thangs like arrows.
|
||||
# Couldn't spot any bugs... But if there are any, better come up with a better solution.
|
||||
# else
|
||||
# # We clicked on the background, so deselect anything selected
|
||||
# @thangsTreema.deselectAll()
|
||||
justAdded: -> @lastAddTime and (new Date() - @lastAddTime) < 150
|
||||
|
||||
selectAddThang: (e) =>
|
||||
selectAddThang: (e, forceDeselect=false) =>
|
||||
return if e? and $(e.target).closest('#thang-search').length # Ignore if you're trying to search thangs
|
||||
return unless e? and $(e.target).closest('#editor-level-thangs-tab-view').length or key.isPressed('esc')
|
||||
return unless (e? and $(e.target).closest('#editor-level-thangs-tab-view').length) or key.isPressed('esc') or forceDeselect
|
||||
if e then target = $(e.target) else target = @$el.find('.add-thangs-palette') # pretend to click on background if no event
|
||||
return true if target.attr('id') is 'surface'
|
||||
target = target.closest('.add-thang-palette-icon')
|
||||
|
@ -428,7 +431,6 @@ module.exports = class ThangsTabView extends CocoView
|
|||
thangID = Thang.nextID(thangType.get('name'), @world) until thangID and not @thangsTreema.get "id=#{thangID}"
|
||||
if @cloneSourceThang
|
||||
components = _.cloneDeep @thangsTreema.get "id=#{@cloneSourceThang.id}/components"
|
||||
@selectAddThang null
|
||||
else if @level.get('type') is 'hero'
|
||||
components = [] # Load them all from default ThangType Components
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue