More hard-typed variables
This commit is contained in:
@@ -47,13 +47,13 @@ func _environment_to_string(env: EnvType) -> String:
|
||||
|
||||
|
||||
func save_environment() -> void:
|
||||
var config = ConfigFile.new()
|
||||
var config: ConfigFile = ConfigFile.new()
|
||||
config.set_value("environment", "current", str(current_environment))
|
||||
config.save(CONFIG_PATH)
|
||||
|
||||
|
||||
func load_environment() -> void:
|
||||
var config = ConfigFile.new()
|
||||
var config: ConfigFile = ConfigFile.new()
|
||||
if config.load(CONFIG_PATH) == OK:
|
||||
var env = config.get_value("environment", "current", str(EnvType.DEV))
|
||||
var env: String = config.get_value("environment", "current", str(EnvType.DEV))
|
||||
current_environment = int(env)
|
||||
|
||||
@@ -4,7 +4,7 @@ extends EditorExportPlugin
|
||||
func _get_name() -> String:
|
||||
return "KaluluExportToolExporter"
|
||||
|
||||
var tool_configs: Dictionary = {
|
||||
var tool_configs: Dictionary[String, Dictionary] = {
|
||||
"game": {
|
||||
"main_scene": "res://sources/menus/splash_screen/splash_screen.tscn",
|
||||
"output_name": "kalulu_app"
|
||||
@@ -26,6 +26,6 @@ func _export_begin(features: PackedStringArray, is_debug: bool, path: String, fl
|
||||
push_error("Outil '%s' non défini dans la configuration." % selected_tool)
|
||||
return
|
||||
|
||||
var config = tool_configs[selected_tool]
|
||||
var config: Dictionary[String, String] = tool_configs[selected_tool]
|
||||
ProjectSettings.set_setting("application/run/main_scene", config["main_scene"])
|
||||
ProjectSettings.save()
|
||||
|
||||
@@ -64,7 +64,7 @@ func _on_export_all_game_pressed():
|
||||
|
||||
func export_all_game_presets():
|
||||
var godot_path: String = OS.get_executable_path()
|
||||
var exportFolder = "../Export/autobuilds/"
|
||||
var exportFolder: String = "../Export/autobuilds/"
|
||||
var presets: Dictionary[String, String]= {
|
||||
"Android Kalulu AAB": "/Android/kalulu_app.aab",
|
||||
"Android Kalulu APK": "/Android/kalulu_app.apk",
|
||||
@@ -78,13 +78,13 @@ func export_all_game_presets():
|
||||
|
||||
for preset_name in presets.keys():
|
||||
await get_tree().create_timer(1).timeout
|
||||
var version = ProjectSettings.get_setting("application/config/version")
|
||||
var version: String = ProjectSettings.get_setting("application/config/version")
|
||||
var output_path: String = exportFolder + version + presets[preset_name]
|
||||
print("Start exporting " + preset_name)
|
||||
DirAccess.make_dir_recursive_absolute(output_path.get_base_dir())
|
||||
|
||||
var args: PackedStringArray = ["--headless", "--export-release", preset_name, output_path]
|
||||
var output: Array = []
|
||||
var output: Array[String] = []
|
||||
var result: int = OS.execute(godot_path, args, output, true)
|
||||
|
||||
if result != OK:
|
||||
|
||||
@@ -18,10 +18,10 @@ func _ready() -> void:
|
||||
func _configure_validator() -> void:
|
||||
if validator != null:
|
||||
return
|
||||
var parent = get_parent()
|
||||
var parent: Node = get_parent()
|
||||
if not parent:
|
||||
return
|
||||
var found = Validation.find_validator(parent)
|
||||
var found: Validator = Validation.find_validator(parent)
|
||||
if found:
|
||||
validator = found.duplicate(true)
|
||||
else:
|
||||
@@ -31,8 +31,8 @@ func _configure_validator() -> void:
|
||||
func _get_configuration_warnings() -> PackedStringArray:
|
||||
if not validator:
|
||||
return []
|
||||
var list = PackedStringArray()
|
||||
for rule in validator.rules:
|
||||
var list: PackedStringArray = PackedStringArray()
|
||||
for rule: ValidatorRule in validator.rules:
|
||||
if not rule.is_valid():
|
||||
list.append(rule.get_invalid_message())
|
||||
return list
|
||||
@@ -48,7 +48,7 @@ func _on_tree_exiting() -> void:
|
||||
|
||||
|
||||
func _on_validator_added() -> void:
|
||||
var parent = get_parent()
|
||||
var parent: Node = get_parent()
|
||||
if not parent or not validator:
|
||||
return
|
||||
Validation.validator_added.emit(parent, validator)
|
||||
|
||||
@@ -3,9 +3,9 @@ extends PanelContainer
|
||||
@onready var form_validator_control: FormValidator = $MarginContainer/FormValidator
|
||||
|
||||
|
||||
func _on_form_validator_control_control_validated(control, passed, messages) -> void:
|
||||
var error_label = _get_error_label(control)
|
||||
var valid_label = _get_valid_label(control)
|
||||
func _on_form_validator_control_control_validated(control: Control, passed: bool, messages: PackedStringArray) -> void:
|
||||
var error_label: Label = _get_error_label(control)
|
||||
var valid_label: Label = _get_valid_label(control)
|
||||
if passed:
|
||||
if error_label:
|
||||
error_label.hide()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
extends Control
|
||||
class_name FormValidator
|
||||
|
||||
signal control_validated(control: Control, passed: bool, messages: Array)
|
||||
signal control_validated(control: Control, passed: bool, messages: PackedStringArray)
|
||||
|
||||
class ValidatorInfo extends RefCounted:
|
||||
var control: Control
|
||||
@@ -15,7 +15,7 @@ class ValidatorInfo extends RefCounted:
|
||||
_update_validation_methods()
|
||||
|
||||
var _control_validator_map: Dictionary[Control, Validator] = {}
|
||||
var _control_messages_map: Dictionary = {}
|
||||
var _control_messages_map: Dictionary[Control, PackedStringArray] = {}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -36,8 +36,8 @@ func get_messages_for_control(control: Control) -> PackedStringArray:
|
||||
|
||||
func validate() -> bool:
|
||||
_control_messages_map.clear()
|
||||
var list = _get_validator_info_list()
|
||||
var valid = true
|
||||
var list: Array[ValidatorInfo] = _get_validator_info_list()
|
||||
var valid: bool = true
|
||||
for info: ValidatorInfo in list:
|
||||
if info.validator.skip_validation:
|
||||
continue
|
||||
@@ -45,8 +45,8 @@ func validate() -> bool:
|
||||
if control == null:
|
||||
Log.error("FormValidator: ValidatorInfo.control is not a Control: %s" % [info.control])
|
||||
continue
|
||||
var passed = info.validator.validate(control)
|
||||
var messages = info.validator.get_messages()
|
||||
var passed: bool = info.validator.validate(control)
|
||||
var messages: PackedStringArray = info.validator.get_messages()
|
||||
if not passed:
|
||||
_control_messages_map[control] = messages
|
||||
control_validated.emit(control, passed, messages)
|
||||
@@ -59,15 +59,15 @@ func validate() -> bool:
|
||||
|
||||
func _get_validator_info_list() -> Array[ValidatorInfo]:
|
||||
var list: Array[ValidatorInfo] = []
|
||||
for controlKey in _control_validator_map.keys():
|
||||
for controlKey: Control in _control_validator_map.keys():
|
||||
var control: Control = controlKey as Control
|
||||
if control == null:
|
||||
Log.error("FormValidator: _control_validator_map key is not a Control")
|
||||
continue
|
||||
var validator = _control_validator_map[control]
|
||||
var validator: Validator = _control_validator_map[control]
|
||||
if not validator:
|
||||
continue
|
||||
var info = ValidatorInfo.new()
|
||||
var info: ValidatorInfo = ValidatorInfo.new()
|
||||
info.control = control
|
||||
info.validator = validator
|
||||
list.append(info)
|
||||
@@ -78,9 +78,9 @@ func _get_validator_info_list() -> Array[ValidatorInfo]:
|
||||
|
||||
|
||||
func _update_validation_methods() -> void:
|
||||
var validators = _control_validator_map.values()
|
||||
var validators: Array = _control_validator_map.values()
|
||||
for item in validators:
|
||||
var validator = item as Validator
|
||||
var validator: Validator = item as Validator
|
||||
if not validator:
|
||||
continue
|
||||
validator.validation_method = validation_method
|
||||
@@ -88,7 +88,7 @@ func _update_validation_methods() -> void:
|
||||
|
||||
func _find_validators(node: Node) -> void:
|
||||
for child in node.get_children():
|
||||
var control_validator = child as ControlValidator
|
||||
var control_validator: ControlValidator = child as ControlValidator
|
||||
if control_validator:
|
||||
control_validator._on_validator_added()
|
||||
_find_validators(child)
|
||||
@@ -97,10 +97,10 @@ func _find_validators(node: Node) -> void:
|
||||
func _auto_validate(control: Control) -> void:
|
||||
if not auto_validate:
|
||||
return
|
||||
var validator = _control_validator_map[control] as Validator
|
||||
var validator: Validator = _control_validator_map[control] as Validator
|
||||
if not validator:
|
||||
return
|
||||
var passed = validator.validate(control)
|
||||
var passed: bool = validator.validate(control)
|
||||
control_validated.emit(control, passed, validator.get_messages())
|
||||
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ func _init() -> void:
|
||||
fail_message = "Value must contain only alpha characters."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.empty(value) or ValidatorFunctions.alpha(value)
|
||||
if not result.passed:
|
||||
|
||||
@@ -7,8 +7,8 @@ func _init() -> void:
|
||||
fail_message = "Value must contain only alphanumeric characters."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.empty(value) or ValidatorFunctions.alphanumeric(value)
|
||||
if not result.passed:
|
||||
|
||||
@@ -5,10 +5,10 @@ extends ValidatorRule
|
||||
@export var target_value: bool
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
if ValidatorFunctions.empty(fail_message):
|
||||
fail_message = "The value must equal %s." % target_value
|
||||
var result = RuleResult.new()
|
||||
var result: RuleResult = RuleResult.new()
|
||||
result.passed = value is bool and value == target_value
|
||||
if not result.passed:
|
||||
result.message = fail_message
|
||||
|
||||
@@ -7,13 +7,13 @@ class_name CustomRule
|
||||
var _expression: Expression = Expression.new()
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if not _validate_expression():
|
||||
result.passed = false
|
||||
result.message = "Specified expression is not valid."
|
||||
return result
|
||||
var res = _expression.execute([ control, value ])
|
||||
var res: Variant = _expression.execute([ control, value ])
|
||||
if _expression.has_execute_failed():
|
||||
result.passed = false
|
||||
result.message = "Execution of the specified expression has failed."
|
||||
|
||||
@@ -9,8 +9,8 @@ func _init() -> void:
|
||||
fail_message = "Invalid value."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.empty(value) or ValidatorFunctions.does_not_match(pattern, value)
|
||||
if not result.passed:
|
||||
|
||||
@@ -7,8 +7,8 @@ func _init() -> void:
|
||||
fail_message = "Value must be a valid email address."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.empty(value) or ValidatorFunctions.email(value)
|
||||
if not result.passed:
|
||||
|
||||
@@ -5,10 +5,10 @@ extends ValidatorRule
|
||||
@export var target_value: String
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
if ValidatorFunctions.empty(fail_message):
|
||||
fail_message = "The value must equal %s." % target_value
|
||||
var result = RuleResult.new()
|
||||
var result: RuleResult = RuleResult.new()
|
||||
result.passed = str(value) == target_value
|
||||
if not result.passed:
|
||||
result.message = fail_message
|
||||
|
||||
@@ -5,10 +5,10 @@ class_name GreaterThanRule
|
||||
@export var target_value: String
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
if ValidatorFunctions.empty(fail_message):
|
||||
fail_message = "The value must be greater than %s." % target_value
|
||||
var result = RuleResult.new()
|
||||
var result: RuleResult = RuleResult.new()
|
||||
result.passed = str(value) > target_value
|
||||
if not result.passed:
|
||||
result.message = fail_message
|
||||
|
||||
@@ -8,8 +8,8 @@ const FAIL_MESSAGE: String = "The value must be between %d and %d characters lon
|
||||
@export var max_length: int = 9999
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.length(value, min_length, max_length)
|
||||
if not result.passed:
|
||||
|
||||
@@ -5,10 +5,10 @@ class_name LessThanRule
|
||||
@export var target_value: String
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
if ValidatorFunctions.empty(fail_message):
|
||||
fail_message = "The value must be less than %s." % target_value
|
||||
var result = RuleResult.new()
|
||||
var result: RuleResult = RuleResult.new()
|
||||
result.passed = str(value) < target_value
|
||||
if not result.passed:
|
||||
result.message = fail_message
|
||||
|
||||
@@ -9,8 +9,8 @@ func _init() -> void:
|
||||
fail_message = "Invalid value."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.empty(value) or ValidatorFunctions.matches(pattern, value)
|
||||
if not result.passed:
|
||||
|
||||
@@ -7,8 +7,8 @@ func _init() -> void:
|
||||
fail_message = "Value must not be blank."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.not_blank(value)
|
||||
if not result.passed:
|
||||
|
||||
@@ -7,7 +7,7 @@ func _init() -> void:
|
||||
fail_message = "Value must not be empty."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.not_empty(value)
|
||||
|
||||
@@ -7,8 +7,8 @@ func _init() -> void:
|
||||
fail_message = "Value must contain only numbers."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.empty(value) or ValidatorFunctions.numeric(value)
|
||||
if not result.passed:
|
||||
|
||||
@@ -7,8 +7,8 @@ func _init():
|
||||
fail_message = "A value is required."
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
var result = RuleResult.new()
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
var result: RuleResult = RuleResult.new()
|
||||
if value is String:
|
||||
result.passed = ValidatorFunctions.not_blank(value)
|
||||
else:
|
||||
|
||||
@@ -5,7 +5,7 @@ extends Resource
|
||||
@export var fail_message: String = ""
|
||||
|
||||
|
||||
func apply(control: Control, value) -> RuleResult:
|
||||
func apply(control: Control, value: Variant) -> RuleResult:
|
||||
return RuleResult.new()
|
||||
|
||||
|
||||
|
||||
@@ -3,20 +3,20 @@ class_name ValidatorFunctions
|
||||
|
||||
|
||||
static func matches(pattern: String, text: String) -> bool:
|
||||
var regex = RegEx.create_from_string(pattern)
|
||||
var regex: RegEx = RegEx.create_from_string(pattern)
|
||||
if not regex.is_valid():
|
||||
Log.error("ValidatorFunctions: Invalid RegEx pattern supplied to matches function: %s" % pattern)
|
||||
return false
|
||||
var result = regex.search(text)
|
||||
var result: RegExMatch = regex.search(text)
|
||||
return result != null and result.strings.size() > 0
|
||||
|
||||
|
||||
static func does_not_match(pattern: String, text: String) -> bool:
|
||||
var regex = RegEx.create_from_string(pattern)
|
||||
var regex: RegEx = RegEx.create_from_string(pattern)
|
||||
if not regex.is_valid():
|
||||
Log.error("ValidatorFunctions: Invalid RegEx pattern supplied to does_not_match function: %s" % pattern)
|
||||
return false
|
||||
var result = regex.search(text)
|
||||
var result: RegExMatch = regex.search(text)
|
||||
return result == null
|
||||
|
||||
|
||||
@@ -39,26 +39,26 @@ static func not_blank(text: String) -> bool:
|
||||
|
||||
|
||||
static func alpha(text: String) -> bool:
|
||||
var regex = RegEx.create_from_string("[^a-zA-Z]+")
|
||||
var result = regex.search(text)
|
||||
var regex: RegEx = RegEx.create_from_string("[^a-zA-Z]+")
|
||||
var result: RegExMatch = regex.search(text)
|
||||
return result == null
|
||||
|
||||
|
||||
static func numeric(text: String) -> bool:
|
||||
var regex = RegEx.create_from_string("[^0-9]+")
|
||||
var result = regex.search(text)
|
||||
var regex: RegEx = RegEx.create_from_string("[^0-9]+")
|
||||
var result: RegExMatch = regex.search(text)
|
||||
return result == null
|
||||
|
||||
|
||||
static func alphanumeric(text: String) -> bool:
|
||||
var regex = RegEx.create_from_string("[^a-zA-Z0-9]+")
|
||||
var result = regex.search(text)
|
||||
var regex: RegEx = RegEx.create_from_string("[^a-zA-Z0-9]+")
|
||||
var result: RegExMatch = regex.search(text)
|
||||
return result == null
|
||||
|
||||
|
||||
static func email(text: String) -> bool:
|
||||
var regex = RegEx.create_from_string("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$")
|
||||
var result = regex.search(text)
|
||||
var regex: RegEx = RegEx.create_from_string("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$")
|
||||
var result: RegExMatch = regex.search(text)
|
||||
return result != null and result.strings.size() > 0
|
||||
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ class_name ButtonValidator
|
||||
|
||||
|
||||
func get_value(control: Control) -> Variant:
|
||||
var button = control as Button
|
||||
var button: Button = control as Button
|
||||
if not button:
|
||||
return null
|
||||
return button.button_pressed
|
||||
|
||||
|
||||
func is_type(node) -> bool:
|
||||
func is_type(node: Node) -> bool:
|
||||
return node is Button
|
||||
|
||||
@@ -4,11 +4,11 @@ class_name LineEditValidator
|
||||
|
||||
|
||||
func get_value(control: Control) -> Variant:
|
||||
var line_edit = control as LineEdit
|
||||
var line_edit: LineEdit = control as LineEdit
|
||||
if not line_edit:
|
||||
return null
|
||||
return line_edit.text
|
||||
|
||||
|
||||
func is_type(node) -> bool:
|
||||
func is_type(node: Node) -> bool:
|
||||
return node is LineEdit
|
||||
|
||||
@@ -4,12 +4,12 @@ class_name RangeValidator
|
||||
|
||||
|
||||
func get_value(control: Control) -> Variant:
|
||||
var range_control = control as Range
|
||||
var range_control: Range = control as Range
|
||||
if not range_control:
|
||||
return null
|
||||
return range_control.value
|
||||
|
||||
|
||||
func is_type(node) -> bool:
|
||||
func is_type(node: Node) -> bool:
|
||||
return node is Range and \
|
||||
not (node is ScrollBar or node is ProgressBar or node is TextureProgressBar)
|
||||
|
||||
@@ -4,11 +4,11 @@ class_name TextEditValidator
|
||||
|
||||
|
||||
func get_value(control: Control) -> Variant:
|
||||
var text_edit = control as TextEdit
|
||||
var text_edit: TextEdit = control as TextEdit
|
||||
if not text_edit:
|
||||
return null
|
||||
return text_edit.text
|
||||
|
||||
|
||||
func is_type(node) -> bool:
|
||||
func is_type(node: Node) -> bool:
|
||||
return node is TextEdit
|
||||
|
||||
@@ -24,9 +24,9 @@ func get_messages() -> PackedStringArray:
|
||||
|
||||
func validate(control: Control) -> bool:
|
||||
_messages.clear()
|
||||
var valid = true
|
||||
for rule in rules:
|
||||
var result = rule.apply(control, get_value(control))
|
||||
var valid: bool = true
|
||||
for rule: ValidatorRule in rules:
|
||||
var result: RuleResult = rule.apply(control, get_value(control))
|
||||
if not result.passed:
|
||||
_messages.append(result.message)
|
||||
valid = valid and result.passed
|
||||
|
||||
Reference in New Issue
Block a user