This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Classes/Coordinates.gd

29 lines
805 B
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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:
sector_name += ".%02d/%02d" % [(coord.x - x) * 100, (coord.y - y) * 100]
return sector_name
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