Fix for flickering thangs due to exact same coordinates
This commit is contained in:
parent
598e727500
commit
dce6254d4a
1 changed files with 18 additions and 11 deletions
|
@ -135,66 +135,73 @@ module.exports = class TerrainRandomizeModal extends ModalView
|
||||||
randomizeBorder: (preset, presetSize, noiseFactor=1) ->
|
randomizeBorder: (preset, presetSize, noiseFactor=1) ->
|
||||||
for i in _.range(0, presetSize.x, thangSizes.borderSize.x)
|
for i in _.range(0, presetSize.x, thangSizes.borderSize.x)
|
||||||
for j in _.range(thangSizes.borderSize.thickness)
|
for j in _.range(thangSizes.borderSize.thickness)
|
||||||
@thangs.push {
|
while not @addThang {
|
||||||
'id': @getRandomThang(preset.borders)
|
'id': @getRandomThang(preset.borders)
|
||||||
'pos': {
|
'pos': {
|
||||||
'x': i + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.x/2, thangSizes.borderSize.x/2)
|
'x': i + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.x/2, thangSizes.borderSize.x/2)
|
||||||
'y': 0 + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.y/2, thangSizes.borderSize.y)
|
'y': 0 + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.y/2, thangSizes.borderSize.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@thangs.push {
|
continue
|
||||||
|
while not @addThang {
|
||||||
'id': @getRandomThang(preset.borders)
|
'id': @getRandomThang(preset.borders)
|
||||||
'pos': {
|
'pos': {
|
||||||
'x': i + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.x/2, thangSizes.borderSize.x/2)
|
'x': i + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.x/2, thangSizes.borderSize.x/2)
|
||||||
'y': presetSize.y - preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.y, thangSizes.borderSize.y/2)
|
'y': presetSize.y - preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.y, thangSizes.borderSize.y/2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
|
||||||
for i in _.range(0, presetSize.y, thangSizes.borderSize.y)
|
for i in _.range(0, presetSize.y, thangSizes.borderSize.y)
|
||||||
for j in _.range(3)
|
for j in _.range(3)
|
||||||
@thangs.push {
|
while not @addThang {
|
||||||
'id': @getRandomThang(preset.borders)
|
'id': @getRandomThang(preset.borders)
|
||||||
'pos': {
|
'pos': {
|
||||||
'x': 0 + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.x/2, thangSizes.borderSize.x)
|
'x': 0 + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.x/2, thangSizes.borderSize.x)
|
||||||
'y': i + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.y/2, thangSizes.borderSize.y/2)
|
'y': i + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.y/2, thangSizes.borderSize.y/2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@thangs.push {
|
continue
|
||||||
|
while not @addThang {
|
||||||
'id': @getRandomThang(preset.borders)
|
'id': @getRandomThang(preset.borders)
|
||||||
'pos': {
|
'pos': {
|
||||||
'x': presetSize.x - preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.x, thangSizes.borderSize.x/2)
|
'x': presetSize.x - preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.x, thangSizes.borderSize.x/2)
|
||||||
'y': i + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.y/2, thangSizes.borderSize.y/2)
|
'y': i + preset.borderSize/2 + noiseFactor * _.random(-thangSizes.borderSize.y/2, thangSizes.borderSize.y/2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
|
||||||
randomizeDecorations: (preset, presetSize)->
|
randomizeDecorations: (preset, presetSize)->
|
||||||
for name, decoration of preset.decorations
|
for name, decoration of preset.decorations
|
||||||
for num in _.range(_.random(decoration.num[0], decoration.num[1]))
|
for num in _.range(_.random(decoration.num[0], decoration.num[1]))
|
||||||
center =
|
center = {
|
||||||
{
|
|
||||||
'x':_.random(decoration.width, presetSize.x - decoration.width),
|
'x':_.random(decoration.width, presetSize.x - decoration.width),
|
||||||
'y':_.random(decoration.height, presetSize.y - decoration.height)
|
'y':_.random(decoration.height, presetSize.y - decoration.height)
|
||||||
}
|
}
|
||||||
min =
|
min = {
|
||||||
{
|
|
||||||
'x':center.x - decoration.width/2
|
'x':center.x - decoration.width/2
|
||||||
'y':center.y - decoration.height/2
|
'y':center.y - decoration.height/2
|
||||||
}
|
}
|
||||||
max =
|
max = {
|
||||||
{
|
|
||||||
'x':center.x + decoration.width/2
|
'x':center.x + decoration.width/2
|
||||||
'y':center.y + decoration.height/2
|
'y':center.y + decoration.height/2
|
||||||
}
|
}
|
||||||
for cluster, range of decoration.clusters
|
for cluster, range of decoration.clusters
|
||||||
for i in _.range(_.random(range[0], range[1]))
|
for i in _.range(_.random(range[0], range[1]))
|
||||||
@thangs.push {
|
while not @addThang {
|
||||||
'id':@getRandomThang(clusters[cluster])
|
'id':@getRandomThang(clusters[cluster])
|
||||||
'pos':{
|
'pos':{
|
||||||
'x':_.random(min.x, max.x)
|
'x':_.random(min.x, max.x)
|
||||||
'y':_.random(min.y, max.y)
|
'y':_.random(min.y, max.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
|
||||||
|
addThang: (thang) ->
|
||||||
|
for existingThang in @thangs
|
||||||
|
return false if thang.pos.x is existingThang.pos.x and thang.pos.y is existingThang.pos.y
|
||||||
|
@thangs.push thang
|
||||||
|
true
|
||||||
|
|
||||||
getRandomThang: (thangList) ->
|
getRandomThang: (thangList) ->
|
||||||
return thangList[_.random(0, thangList.length-1)]
|
return thangList[_.random(0, thangList.length-1)]
|
||||||
|
|
Reference in a new issue