Skip to content

Commit cbffb3f

Browse files
committed
# 修复
修复Scale在设置为1.0时 无法成功应用上的BUG
1 parent 7fe9234 commit cbffb3f

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/style/ParticleGroupStyle.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,6 @@ abstract class ParticleGroupStyle(var visibleRange: Double = 32.0, val uuid: UUI
307307
particleDefaultLength[uuid] = it.value.length()
308308
}
309309
}
310-
if (scale == 1.0) {
311-
return
312-
}
313-
314310
locations.forEach {
315311
val uuid = it.key.uuid
316312
val len = particleDefaultLength[uuid]!!
@@ -331,13 +327,11 @@ abstract class ParticleGroupStyle(var visibleRange: Double = 32.0, val uuid: UUI
331327
}
332328

333329
protected open fun toggleScaleDisplayed() {
334-
if (scale == 1.0) {
335-
return
336-
}
337330
particleLocations.forEach {
338331
val uuid = it.key.controlUUID()
339332
val len = particleDefaultLength[uuid]!!
340333
val value = it.value
334+
if (len in -1e-3 .. 1e-3) return@forEach
341335
value.multiply(len * scale / value.length())
342336
}
343337
}

src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/style/SequencedParticleStyle.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ abstract class SequencedParticleStyle(visibleRange: Double = 32.0, uuid: UUID =
248248
super.toggleScale(locations.toMap())
249249
}
250250

251+
override fun scale(new: Double) {
252+
if (new < 0.0) {
253+
CooParticleAPI.logger.error("scale can not be less than zero")
254+
return
255+
}
256+
scale = new
257+
if (displayed) {
258+
toggleScaleDisplayed()
259+
}
260+
}
261+
251262
override fun display(pos: Vec3d, world: World) {
252263
if (displayed) {
253264
return
@@ -410,13 +421,11 @@ abstract class SequencedParticleStyle(visibleRange: Double = 32.0, uuid: UUID =
410421
}
411422

412423
final override fun toggleScaleDisplayed() {
413-
if (scale == 1.0) {
414-
return
415-
}
416424
sequencedParticles.forEach {
417425
val uuid = it.first.uuid
418426
val len = particleDefaultLength[uuid]!!
419427
val value = it.second
428+
if (len in -1e-3..1e-3) return@forEach
420429
value.multiply(len * scale / value.length())
421430
}
422431
}

src/main/kotlin/cn/coostack/cooparticlesapi/utils/helper/GroupScaleHelper.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ class GroupScaleHelper(minScale: Double, maxScale: Double, scaleTick: Int) :
3030
}
3131

3232
override fun scale(scale: Double) {
33-
if (scale < minScale || scale >= maxScale) {
34-
return
35-
}
36-
group.scale(scale)
33+
group.scale(scale.coerceIn(minScale, maxScale))
3734
}
3835
}

src/main/kotlin/cn/coostack/cooparticlesapi/utils/helper/ScaleHelper.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ abstract class ScaleHelper(var minScale: Double, var maxScale: Double, var scale
1818
}
1919

2020
fun recalculateStep(): ScaleHelper {
21+
val temp = min(minScale, maxScale)
22+
maxScale = max(minScale, maxScale)
23+
minScale = temp
2124
step = abs(maxScale - minScale) / scaleTick
2225
return this
2326
}
@@ -42,13 +45,15 @@ abstract class ScaleHelper(var minScale: Double, var maxScale: Double, var scale
4245
if (getLoadedGroup() == null) {
4346
return
4447
}
48+
current = 0
4549
scale(minScale)
4650
}
4751

4852
fun resetScaleMax() {
4953
if (getLoadedGroup() == null) {
5054
return
5155
}
56+
current = scaleTick
5257
scale(maxScale)
5358
}
5459

src/main/kotlin/cn/coostack/cooparticlesapi/utils/helper/StyleScaleHelper.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ class StyleScaleHelper(minScale: Double, maxScale: Double, scaleTick: Int) :
2727
}
2828

2929
override fun scale(scale: Double) {
30-
if (scale < minScale || scale >= maxScale) {
31-
return
32-
}
33-
group.scale(scale)
30+
group.scale(scale.coerceIn(minScale,maxScale))
3431
}
3532

3633
}

0 commit comments

Comments
 (0)