imported main menu scene addon

This commit is contained in:
2026-05-10 15:48:56 +02:00
parent 86d9f75161
commit 71c2850a34
458 changed files with 14881 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
class_name GlobalState
extends Node
const SAVE_STATE_PATH = "user://global_state.tres"
const NO_VERSION_NAME = "0.0.0"
static var current : GlobalStateData
static var current_version : String
static func _log_opened() -> void:
if current is GlobalStateData:
current.last_unix_time_opened = int(Time.get_unix_time_from_system())
static func _log_version() -> void:
if current is GlobalStateData:
current_version = ProjectSettings.get_setting("application/config/version", NO_VERSION_NAME)
if current_version.is_empty():
current_version = NO_VERSION_NAME
if not current.first_version_opened:
current.first_version_opened = current_version
current.last_version_opened = current_version
static func _load_current_state() -> void:
if FileAccess.file_exists(SAVE_STATE_PATH):
current = ResourceLoader.load(SAVE_STATE_PATH)
if not current:
current = GlobalStateData.new()
static func open() -> void:
_load_current_state()
_log_opened()
_log_version()
save()
static func save() -> void:
if current is GlobalStateData:
ResourceSaver.save(current, SAVE_STATE_PATH)
static func has_state(state_key : String) -> bool:
if current is not GlobalStateData: return false
return current.has_state(state_key)
static func get_or_create_state(state_key : String, state_type_path : String) -> Resource:
if current is not GlobalStateData: return
return current.get_or_create_state(state_key, state_type_path)
static func reset() -> void:
if current is not GlobalStateData: return
current.states.clear()
save()

View File

@@ -0,0 +1 @@
uid://34ojrqt1klav

View File

@@ -0,0 +1,24 @@
class_name GlobalStateData
extends Resource
@export var first_version_opened : String
@export var last_version_opened : String
@export var last_unix_time_opened : int
@export var states : Dictionary
func get_or_create_state(key_name : String, state_type_path : String) -> Resource:
var new_state : Resource
var new_state_script = load(state_type_path)
if new_state_script is GDScript:
new_state = new_state_script.new()
if key_name in states:
var saved_state : Resource = states[key_name]
var saved_script = saved_state.get_script()
var new_script = new_state.get_script()
if saved_script and new_script and saved_script == new_script:
return saved_state
states[key_name] = new_state
return new_state
func has_state(key_name : String) -> bool:
return key_name in states

View File

@@ -0,0 +1 @@
uid://bb3tb71vb6p8w