Add version check

This commit is contained in:
JeremyStar™ 2024-02-12 19:56:17 +01:00
parent 08338dba18
commit c2574a920f

View file

@ -57,6 +57,7 @@ var custom_modules_node: Node
# Preinitialization
func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
name = "CORE"
if !check_godot_version(): queue_free()
if !determine_basepath(): queue_free()
custom_modules_node = Node.new()
reload_configuration(new_config)
@ -189,22 +190,6 @@ func apply_configuration() -> void:
logger.diag("Updating configuration for custom module \"" + module.name + "\"")
module._pull_config()
# Determines CORE's installation/base path
## Determines CORE's installation/base path[br]
## [br]
## [b]Calling this function is likely to be safe, but shouldn't be done nonetheless![/b]
func determine_basepath() -> bool:
if FileAccess.file_exists("res://.corebasepath"):
basepath = "res://"
elif FileAccess.file_exists("res://CORE/.corebasepath"):
basepath = "res://CORE/"
elif FileAccess.file_exists("res://addons/CORE/.corebasepath"):
basepath = "res://addons/CORE/"
else:
assert(false, "CORE is not located at 'res://CORE/', aborting initialization")
return false
return true
# Return development mode status
## Returns if the CORE Framework is in development mode.
func is_devmode() -> bool:
@ -261,3 +246,36 @@ func get_version_semantic() -> Array[int]:
CoreTypes.VersionType.BETA: version_type_int = 1
CoreTypes.VersionType.ALPHA: version_type_int = 0
return [version_release, version_type_int, version_typerelease]
# Determines CORE's installation/base path
## Determines CORE's installation/base path[br]
## [br]
## [b]Calling this function is likely to be safe, but shouldn't be done nonetheless![/b]
func determine_basepath() -> bool:
if FileAccess.file_exists("res://.corebasepath"):
basepath = "res://"
elif FileAccess.file_exists("res://CORE/.corebasepath"):
basepath = "res://CORE/"
elif FileAccess.file_exists("res://addons/CORE/.corebasepath"):
basepath = "res://addons/CORE/"
else:
assert(false, "CORE is not located at 'res://CORE/', aborting initialization")
return false
return true
# Checks Godot's version
## Checks compatibility with the running version.
func check_godot_version() -> bool:
var version: Dictionary = Engine.get_version_info()
match(version["major"]):
4: pass
_:
assert(true, "The CORE Framework does not support Godot versions older or newer than 4.x.x")
return true
match(version["minor"]):
0: print("The CORE Framework does not support Godot versions older than 4.2.x. Please update to Godot 4.2.x to ensure full compatibility.")
1: print("The CORE Framework does not support Godot versions older than 4.2.x. Please update to Godot 4.2.x to ensure full compatibility.")
2: pass
_: print("The CORE Framework does not support Godot versions newer than 4.2.x. Please downgrade to Godot 4.2.x to ensure full compatibility.")
if version["status"] != "stable": print("The CORE Framework does not support unstable Godot versions. Please switch to Godot stable 4.2.1 to ensure full compatibility.")
return true