util
The Util class is a private utility class that is used internally to provide a collection of static helper methods.
Util private
Methods
lerp()
static function lerp(start: number, end: number, ratio: number): numberPerforms linear interpolation between start and end based on ratio. The ratio is capped at 1.2; if it exceeds that value, it is clamped to 1.
mod()
static function mod(a: number, b: number): numberCalculates the mathematical modulo of a % b. Unlike the standard JavaScript % operator, this function correctly handles negative numbers, ensuring the result is always within the range [0, b).
interpolateYaw()
static function interpolateYaw(target: number, from: number): numberInterpolates between two rotation angles (in degrees) based on the current renderer tick progress. It ensures the rotation follows the shortest path between the two angles.
angleTo()
static function angleTo(xFrom: number, yFrom: number, xTo: number, yTo: number): numberCalculates the angle in degrees from point (xFrom, yFrom) to point (xTo, yTo).
hexToRgb()
static function hexToRgb(hex: string): object | nullConverts a hexadecimal color string (e.g., #FFFFFF or #FFF) into an object with r, g, and b properties. Returns null if the input string is invalid.
canAfford()
static function canAfford(data: object, tier: number = 1, multiplier: number = 1): booleanChecks if the player currently has enough resources (wood, stone, gold, tokens) to afford an item at the specified tier and multiplier.
createResourceCostString()
static function createResourceCostString(data: object, tier: number = 1, multiplier: number = 1): stringGenerates a formatted HTML string representing the resource costs. If the player cannot afford a specific resource, the generated span includes the hud-resource-low CSS class.
createResourceRefundString()
static function createResourceRefundString(data: object, tier: number = 1): stringGenerates a formatted HTML string representing the resource refund amount, typically calculated as 50% of the total costs spent up to the current tier.