Fix ship labels for real this time
authorTheSaminator <thesaminator@users.noreply.github.com>
Wed, 13 Jul 2022 14:40:48 +0000 (10:40 -0400)
committerTheSaminator <thesaminator@users.noreply.github.com>
Wed, 13 Jul 2022 14:40:48 +0000 (10:40 -0400)
src/jsMain/kotlin/net/starshipfights/game/game_ui.kt

index 5749b2518d4508dcbb70c28dd426b851517142e0..6ebb9b4efa32f93f2fc795daf770ce1a938e5056 100644 (file)
@@ -158,6 +158,8 @@ object GameUI {
                }
        
        fun renderGameUI(controls: BattleCameraControls) {
+               fitLabels()
+               
                shipsOverlayCamera.position.copy(controls.camera.getWorldPosition(shipsOverlayCamera.position))
                shipsOverlayCamera.quaternion.copy(controls.camera.getWorldQuaternion(shipsOverlayCamera.quaternion))
                shipsOverlayRenderer.render(shipsOverlayScene, shipsOverlayCamera)
@@ -508,11 +510,14 @@ object GameUI {
                                })
                }
                
-               fitLabels()
+               hasFitLabels = false
        }
        
+       var hasFitLabels = false
        private fun fitLabels() {
+               if (hasFitLabels) return
                textFit(document.getElementsByClassName("ship-label"))
+               hasFitLabels = true
        }
        
        private fun DIV.drawShipLabel(state: GameState, abilities: List<PlayerAbilityType>, shipId: Id<ShipInstance>, ship: ShipInstance) {