MrScautHD / Sparkle

A fast, Cross-platform .NET 8 C# 12 game engine.
https://sparkle-engine.com
MIT License
105 stars 11 forks source link

Save System? #20

Open Gammer0909 opened 8 months ago

Gammer0909 commented 8 months ago

I propose a Saving System, to abstract save files to make a save game implementation easier.

Do I have to propose how I would have this implemented? If so I will, upon request.

I will start as soon as I'm cleared to start.

Thanks, Gammer0909

MrScautHD commented 8 months ago

Hello, Sounds very usefull, how would you impliment this?

Gammer0909 commented 8 months ago

@MrScautHD

Save/Load System Spec

By Gammer0909

SaveSettings

This is a data-holding class that needs:

This will create save files to the directory you specified.


LoadSettings

This class sets up your settings for loading your save file.

This needs:

This will extract the data from the save file and return it as a GameSettings object.

(This may change in the future, but for now, this is how it will work.)


Making Objects Saveable

To make an object saveable, you need to add the Saveable attribute to the class.

This will allow the object to be saved and loaded.

ex:

[Saveable]
public class Person : Entity {

    // Things derived from Entity
    // ....

    public string Name { get; set; }
    public int Age { get; set; }
}

Saving/Loading Objects

To save an object, you need to create a SaveSettings object, and call the Save() method.

ex:

SaveSettings settings = new SaveSettings("C:/Users/Me/Documents/MyGame/SaveFiles", new GameSettings(), EncryptionMethod.None, SaveType.YAML);

Person person = new Person("Bob", 20);

settings.Save(person);

Extra Dependency

I will be using the YamlDotNet library for the YAML serialization.

(Newtonsoft.Json is already a dependency for the project, so I will be using that for JSON serialization.)

Namespace and my Code Style

The namespace for the Saving system will be in

Sparkle.csharp.saving

and the load system will be in

Sparkle.csharp.loading

and the attributes will be in

Sparkle.csharp.attributes


Code Style

I will be using the C# code style, and I will be using the C# naming conventions.

However, I do some things differently:


// I always use `var` for objects, not new()
var person = new Person("Bob", 20);

// For braces, I use the `K&R` style
// Ex
void Method() {
    if (true) {
        // Do something
    } else {
        // Do something else
    }

    if (false)
        Statement();
}

If you request that I change this style for my PR, I will.


Thanks, Gammer0909

(Sorry for taking a long time to respond, I had some things to do and I had to design the API.)

MrScautHD commented 8 months ago

looks very cool!

(Sorry for taking a long time to respond)

Gammer0909 commented 7 months ago

Am I clear to start?

MrScautHD commented 7 months ago

Yep!