38 lines
1,021 B
GDScript
38 lines
1,021 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 main := as_string_parts(coord)
|
||
var sector_name := str(main[0]) + str(main[1])
|
||
if include_subcoord:
|
||
sector_name += ".%02d/%02d" % [(coord.x - x) * 100, (coord.y - y) * 100]
|
||
return sector_name
|
||
|
||
static func as_string_parts(coord: Vector2) -> Array:
|
||
var x := floor(coord.x)
|
||
var y := floor(coord.y)
|
||
var x_str := to_letter(int(x))
|
||
var y_str := ""
|
||
if y < 0:
|
||
y_str = to_letter(int(y))
|
||
else:
|
||
y_str = str(int(y))
|
||
return [x_str, y_str]
|
||
|
||
|
||
static func to_letter(num: int) -> String:
|
||
#var letters = "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"
|
||
var letters := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||
if num == 0:
|
||
return "Α"
|
||
elif num < 0:
|
||
letters = "αβγδεζηθικλμνξοπρστυφχψω"
|
||
if num < 0:
|
||
num = -num
|
||
var out := ""
|
||
var base := letters.length()
|
||
while num > 0:
|
||
out = letters.substr(num % base, 1) + out
|
||
num /= base
|
||
return out
|