75 lines
No EOL
1.9 KiB
GDScript
75 lines
No EOL
1.9 KiB
GDScript
class_name Utils
|
|
extends Object
|
|
|
|
static func generate_guid() -> String:
|
|
var guid = ""
|
|
var time = Time.get_ticks_msec()
|
|
var rng = RandomNumberGenerator.new()
|
|
rng.randomize()
|
|
|
|
# Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
guid += "%08x" % time
|
|
guid += "-"
|
|
guid += "%04x" % rng.randi()
|
|
guid += "-"
|
|
guid += "4"
|
|
guid += "%03x" % rng.randi()
|
|
guid += "-"
|
|
guid += "%x" % (8 + rng.randi() % 4)
|
|
guid += "%03x" % rng.randi()
|
|
guid += "-"
|
|
guid += "%012x" % rng.randi()
|
|
|
|
return guid
|
|
|
|
|
|
static func convert_algebraic_to_location(square: String) -> String:
|
|
var file = square[0] # letter (a-h)
|
|
var rank = int(square[1]) # number (1-8)
|
|
|
|
# Convert file letter to number (a=0, b=1, etc)
|
|
var file_num = file.unicode_at(0) - 'a'.unicode_at(0)
|
|
|
|
# Since we're working with black's moves and our board is oriented with white at bottom:
|
|
# 1. Flip rank: 8 - rank to mirror vertically
|
|
file_num = file_num
|
|
var rank_num = 8 - rank
|
|
|
|
return "%d-%d" % [file_num, rank_num]
|
|
|
|
|
|
static func location_to_algebraic(location: String) -> String:
|
|
# Convert from "x-y" format to algebraic notation
|
|
var coords = location.split("-")
|
|
var x = int(coords[0])
|
|
var y = int(coords[1])
|
|
|
|
# Convert x to file letter (0 = 'a', 1 = 'b', etc.)
|
|
var file = char(97 + x) # 97 is ASCII 'a'
|
|
|
|
# Convert y to rank number (flip since our board has 0 at top)
|
|
var rank = str(8 - y)
|
|
|
|
return file + rank
|
|
|
|
static var LIGHT_CELL = Color(0.5, 0.5, 0.5, 1)
|
|
static var DARK_CELL = Color(0.2, 0.2, 0.2, 1)
|
|
static var GREEN_CELL = Color(0.36, 0.62, 0.43, 1)
|
|
static var WALL_CELL = Color(0.59, 0.29, 0.0, 1) # Brown (#964B00)
|
|
static var DOUBLE_WALL = Color(0.36, 0.17, 0.0, 1) # Dark Brown (#5C2B00)
|
|
|
|
enum RoomType {
|
|
STARTING,
|
|
NORMAL,
|
|
BOSS,
|
|
FINAL,
|
|
SHOP,
|
|
EVENT
|
|
}
|
|
|
|
|
|
enum WinCondition{
|
|
King,
|
|
Clear,
|
|
Tile,
|
|
} |