gd: added menu template
This commit is contained in:
60
menus/scripts/game_state.gd
Normal file
60
menus/scripts/game_state.gd
Normal file
@ -0,0 +1,60 @@
|
||||
class_name GameState
|
||||
extends Resource
|
||||
|
||||
const STATE_NAME : String = "GameState"
|
||||
const FILE_PATH = "res://menus/scripts/game_state.gd"
|
||||
|
||||
@export var level_states : Dictionary = {}
|
||||
@export var max_level_reached : int
|
||||
@export var current_level : int
|
||||
@export var times_played : int
|
||||
|
||||
static func get_level_state(level_state_key : String) -> LevelState:
|
||||
var game_state := get_game_state()
|
||||
if level_state_key.is_empty() : return
|
||||
if level_state_key in game_state.level_states:
|
||||
return game_state.level_states[level_state_key]
|
||||
else:
|
||||
var new_level_state := LevelState.new()
|
||||
game_state.level_states[level_state_key] = new_level_state
|
||||
return new_level_state
|
||||
|
||||
static func has_game_state() -> bool:
|
||||
return GlobalState.has_state(STATE_NAME)
|
||||
|
||||
static func get_game_state() -> GameState:
|
||||
return GlobalState.get_state(STATE_NAME, FILE_PATH)
|
||||
|
||||
static func get_current_level() -> int:
|
||||
var game_state := get_game_state()
|
||||
if not game_state:
|
||||
return 0
|
||||
return game_state.current_level
|
||||
|
||||
static func get_max_level_reached() -> int:
|
||||
var game_state := get_game_state()
|
||||
if not game_state:
|
||||
return 0
|
||||
return game_state.max_level_reached
|
||||
|
||||
static func level_reached(level_number : int) -> void:
|
||||
var game_state := get_game_state()
|
||||
if not game_state:
|
||||
return
|
||||
game_state.max_level_reached = max(level_number, game_state.max_level_reached)
|
||||
game_state.current_level = level_number
|
||||
GlobalState.save()
|
||||
|
||||
static func set_current_level(level_number : int) -> void:
|
||||
var game_state := get_game_state()
|
||||
if not game_state:
|
||||
return
|
||||
game_state.current_level = level_number
|
||||
GlobalState.save()
|
||||
|
||||
static func start_game() -> void:
|
||||
var game_state := get_game_state()
|
||||
if not game_state:
|
||||
return
|
||||
game_state.times_played += 1
|
||||
GlobalState.save()
|
1
menus/scripts/game_state.gd.uid
Normal file
1
menus/scripts/game_state.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://yelhbgm3q31p
|
14
menus/scripts/level_list_and_state_manager.gd
Normal file
14
menus/scripts/level_list_and_state_manager.gd
Normal file
@ -0,0 +1,14 @@
|
||||
extends LevelListManager
|
||||
|
||||
func set_current_level_id(value : int) -> void:
|
||||
super.set_current_level_id(value)
|
||||
GameState.level_reached(value)
|
||||
|
||||
func get_current_level_id() -> int:
|
||||
current_level_id = GameState.get_current_level() if force_level == -1 else force_level
|
||||
return current_level_id
|
||||
|
||||
func _advance_level() -> bool:
|
||||
var _advanced := super._advance_level()
|
||||
GameState.set_current_level(current_level_id)
|
||||
return _advanced
|
1
menus/scripts/level_list_and_state_manager.gd.uid
Normal file
1
menus/scripts/level_list_and_state_manager.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://3yfyhcjuxm0t
|
5
menus/scripts/level_state.gd
Normal file
5
menus/scripts/level_state.gd
Normal file
@ -0,0 +1,5 @@
|
||||
class_name LevelState
|
||||
extends Resource
|
||||
|
||||
@export var color : Color
|
||||
@export var tutorial_read : bool = false
|
1
menus/scripts/level_state.gd.uid
Normal file
1
menus/scripts/level_state.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://d1dccbxlxbleg
|
Reference in New Issue
Block a user