#I need a help with my project structure and saving stuff

1 messages · Page 1 of 1 (latest)

warm echo
#

currently i have created a resource for every level that looks like this :

class_name LevelInfo
extends Resource

@export var unlocked : bool = false
@export var completed : bool = false
@export var min_lives_completed : int = -1 
@export var current_level : PackedScene
#in the future ill want to have an array of unlockables but not now

func update_min_lives_completed( newmin : int ):
    if min_lives_completed == -1:
        min_lives_completed = newmin
    elif newmin < min_lives_completed:
        min_lives_completed = newmin

func set_unlocked():
    unlocked = true

var next_level : LevelInfo
func unlock_next():
    next_level.set_unlocked()

func set_completed():
    completed = true

this is basically some data that i want every level to save

#

i have an autoload script which looks like this :

extends Node

var lives_total : int #all the lives used/collected/unused
@export var current_max_health : int = 5 #all lives - all used ones //needs recalculated after finishing an uncompleted/improving on a level 
var level_resource : LevelInfo # i'd like to load the resource when the level loads

#! when loading in a level the player should start with the currently availible lives which could be 1 + the number of lives ht mnaged to beath the level with if the level has been beaten before

func get_level_data(data : LevelInfo):
    return data

func change_level (level : PackedScene):
    get_tree().change_scene_to_packed(level)

func load_next_level(data : LevelInfo):
    
    #somehow do level_resource.update_min_lives_completed( new_minimum_ammount_of_lives ) and save it
    
    level_resource = get_level_data(data)
    change_level(level_resource.current_level)

this is supposed to act like a healthpool for all the levels more or less

#

and i also have this healthComponent ehich is attached to every level :

extends Node

var lives_total : int #all the lives used/collected/unused
@export var current_max_health : int = 5 #all lives - all used ones //needs recalculated after finishing an uncompleted/improving on a level 
var level_resource : LevelInfo # i'd like to load the resource when the level loads

#! when loading in a level the player should start with the currently availible lives which could be 1 + the number of lives ht mnaged to beath the level with if the level has been beaten before

func get_level_data(data : LevelInfo):
    return data

func change_level (level : PackedScene):
    get_tree().change_scene_to_packed(level)

func load_next_level(data : LevelInfo):
    
    #somehow do level_resource.update_min_lives_completed( new_minimum_ammount_of_lives ) and save it
    
    level_resource = get_level_data(data)
    change_level(level_resource.current_level)

func update_max_health():
    pass
    # when finishing a level recalculate max_health if there has been an improvement or the level has been completed for the first time
    #max health is based off of all the levels , but i think it only needs updated after each level , and maybe on initialisation 

whenever a lever is loaded this is initialised with the max current health from the autoload script and keeps track of spent lives on the level

#

i am currently still working on some of the above functions but i will update them whenever they are done

#

right now i am struggling with saving stuff for each level , for example set for each level an unlocked or completed state

warm echo
#

here is a flowchart , might help with understanding what i'm trying to do :