30 lines
891 B
GDScript
30 lines
891 B
GDScript
class_name Coordinates
|
||
|
||
static func as_string(coord: Vector2, include_subcoord: bool = false) -> String:
|
||
var x = floor(coord.x)
|
||
var y = floor(coord.y)
|
||
var sector_name = to_letter(int(x))
|
||
if y < 0:
|
||
sector_name += to_letter(int(y))
|
||
else:
|
||
sector_name += str(int(y))
|
||
if include_subcoord:
|
||
var x_sub = floor((coord.x - x) * 100)
|
||
var y_sub = floor((coord.y - y) * 100)
|
||
sector_name += "." + str(int(x_sub)).pad_zeros(2) + "/" + str(int(y_sub)).pad_zeros(2)
|
||
return sector_name
|
||
|
||
static func to_letter(num: int) -> String:
|
||
#var letters = "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"
|
||
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||
if num == 0:
|
||
return "Α"
|
||
elif num < 0:
|
||
letters = "αβγδεζηθικλμνξοπρστυφχψω"
|
||
num = abs(num)
|
||
var out = ""
|
||
var base = letters.length()
|
||
while num > 0:
|
||
out = letters.substr(num % base, 1) + out
|
||
num /= base
|
||
return out
|