Add utility strings, update game state with drone count and points calculation.
This commit is contained in:
parent
d879ca30bd
commit
491395e6b9
7 changed files with 105 additions and 5 deletions
37
utility/utility_strings.gd
Normal file
37
utility/utility_strings.gd
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
class_name StringUtilities extends Node
|
||||
|
||||
func seconds_to_hms(seconds: float) -> String:
|
||||
var ms = fmod(seconds, 1) * 100
|
||||
var s = fmod(seconds, 60)
|
||||
var m = fmod(seconds, 3600) / 60
|
||||
|
||||
var formatted : String = "%02d:%02d:%02d" % [m, s, ms]
|
||||
|
||||
return formatted
|
||||
|
||||
####
|
||||
## Formats the given number with commas every 3 digits.
|
||||
####
|
||||
func format_number(number: int) -> String:
|
||||
# Handle negative numbers by adding the "minus" sign in advance, as we discard it
|
||||
# when looping over the number.
|
||||
var formatted_number := "-" if sign(number) == -1 else ""
|
||||
var index := 0
|
||||
var number_string := str(abs(number))
|
||||
|
||||
for digit in number_string:
|
||||
formatted_number += digit
|
||||
|
||||
var counter := number_string.length() - index
|
||||
|
||||
# Don't add a comma at the end of the number, but add a comma every 3 digits
|
||||
# (taking into account the number's length).
|
||||
if counter >= 2 and counter % 3 == 1:
|
||||
formatted_number += ","
|
||||
|
||||
index += 1
|
||||
|
||||
return formatted_number
|
||||
|
||||
func float_to_percentage(value: float) -> String:
|
||||
return "%d%%" % int(value * 100)
|
||||
Loading…
Add table
Add a link
Reference in a new issue