Files
fps_project_1/scripts/HelperFuncs.gd

69 lines
1.8 KiB
GDScript

@tool
extends Node
var letter_to_number = {
"A": 1, "B": 2, "C": 3, "D": 4, "E": 5,
"F": 6, "G": 7, "H": 8, "I": 9, "J": 10,
"K": 11, "L": 12, "M": 13, "N": 14, "O": 15,
"P": 16, "Q": 17, "R": 18, "S": 19, "T": 20,
"U": 21, "V": 22, "W": 23, "X": 24, "Y": 25, "Z": 26
}
## ANGLES
# Check if a colliding body is aligned within a given angle of the object
# max_angle_diff --- note: set to 1 if angle won't be counted
# currently only works when objects are scaled (1,1,1)
func angle_velocity_aligned(source:Node, source_angle:Vector3, body:Node, max_angle_diff:Vector3):
var obj_direction = source.basis * source_angle
var player_direction = body.velocity.normalized()
var diff = abs(abs(obj_direction) - abs(player_direction))
if diff.x <= max_angle_diff.x and diff.y <= max_angle_diff.y and diff.z <= max_angle_diff.z:
return true
else:
return false
#pass in a dictornary of weighted random choices, returns id of selection
func weighted_random(choices):
var sum_of_choices = 0.0
#Get sum of all choices
for i in choices:
sum_of_choices += choices[i]
var random_number = randf_range(0,sum_of_choices)
for i in choices:
if random_number < choices[i]:
return i
random_number -= choices[i]
func only_valid_chars(input_string: String) -> String:
var valid_chars = ""
for char in input_string:
if char.is_valid_identifier():
valid_chars += char
return valid_chars
func checksum(check_data):
var checksum_array = []
#hash all passed-in data and add to new array
for data in check_data:
var hashed_data = hash(data)
checksum_array.append(hashed_data)
#add together
var checksum_final = 0
for num in checksum_array:
if num is int:
checksum_final += num
#finally, re-hash
checksum_final = hash(checksum_final)
return checksum_final